Bryan Johnson
Published

Light Sensing Backpack

This backpack hopes to create higher visibility for users riding personal electric vehicles.

IntermediateFull instructions provided14 hours2,211
Light Sensing Backpack

Things used in this project

Hardware components

Arduino LilyPad USB
Arduino LilyPad USB
×1
LilyPad LED Red (5pcs)
SparkFun LilyPad LED Red (5pcs)
×1
LilyPad LED Blue (5pcs)
SparkFun LilyPad LED Blue (5pcs)
×1
Sewable Conductive Thread
Sewable Conductive Thread
×1
Lilypad Light Sensor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Code

Light Sensing Backpack

Arduino
Light Sensor reads light levels and sends values to LEDs
// Create variables for the pins we'll use:

int sensorPin = A2;
int sensorValue = 0;
int redLED = 6;
int blueLED = A8;

void setup()
{
  // Initialize the sensor pin as an input, but without a pullup
  // (Pullups are only used for switch inputs)
  
  pinMode(sensorPin, INPUT);

  // Initialize the output pins:
  
  pinMode(redLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
 
  // Initialize the serial monitor:

  Serial.begin(9600);
}

void loop()
{
  int sensorValue;

  // Read the sensor value (will be 0 to 1023):

  sensorValue = analogRead(sensorPin);
  sensorValue = map(sensorValue,0,1023,0,255);
  // Print out the sensor reading to the serial monitor:

  Serial.print("sensor value: ");
  Serial.println(sensorValue);

  // Since the sensor value is 0 to 1023,
  // and analogWrite needs a value from 0 to 255,
  // we'll divide the sensor value by four to scale it down:

  analogWrite(redLED,sensorValue -255 / 2);
  analogWrite(blueLED,sensorValue -255 / 2);
  delay(1000);
}

Credits

Bryan Johnson

Bryan Johnson

7 projects • 0 followers

Comments