As the dark season is around, let's make smart bright lights for your bike using a photocell and some powerful leds. This could be useful for 'cops on bike' also...
Find all the components such as photocell, powerful leds, resistor... and a small controller such as Arduino Nano. Then put it all together...
I found difficult to get right cathodes / anodes from first time and messed a bit the circuit ...
After you get it right this should like this...
Focus on the arduino board now. Digital pins from 7 to 12 on each 'long leg' and ground on the others.
The resistor is need it for connection of the analog pin and photocell, learn more from Adafruit - We connected to A0, VCC and GND
In your Arduino IDE first of define the variables
int photocellPin = 0; // A0 photo cell connection
int photocellReading; // the analog reading from the sensor divider
int CellIntensVal; // values of the intensity
int LEDred1 = 12; // pins definition
int LEDred2 = 11;
int LEDblue1 = 10;
int LEDblue2 = 9;
int LEDgreen1 = 8;
int LEDgreen2 = 7;
We want to have 3 case scenarios in regards to lights games
- Normal - No bright leds
- Dark mode - Ordinary lights
- Car behind - Let's get flashy
void cmdOffLights() {
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
}
void cmdDarkLights() {
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
delay(20); .....
}
void cmdWoopWoop() {
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
......
}
On the setup area initialize Led modes
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
On the loop void - photocell readings
photocellReading = analogRead(photocellPin);
CellIntensVal = photocellReading;
Serial.println(photocellReading); // the raw analog reading
// LED gets brighter the darker it is at the sensor
// that means we have to -invert- the reading from 0-1023 back to 1023-0
photocellReading = 1023 - photocellReading;
//now we have to map 0-1023 to 0-255 since thats the range analogWrite uses
LEDbrightness = map(photocellReading, 0, 1023, 0, 255);
... and some 'magic' based on the light intensity
if (CellIntensVal > 760) { cmdWoopWoop(); }
if (CellIntensVal < 761 && CellIntensVal > 100 ) { cmdOffLights();}
else if (CellIntensVal < 101) {
cmdDarkLights();
}
delay(200);
The result:
In the box - ready to be mounted!
Get noticed and enjoy your night ride!
Comments