Bright Bike v1

After spending considerable time biking to school every

morning and having a few close class with cars (fortunately no collisions yet) I decided to see what else I could do with a basic bike light since they didn’t seem to be doing a whole lot. The design for this is pretty straightforward. There is a 9v battery powering an Arduino Uno inside which is hooked up to an Ultrasonic sensor,

which has a range of 6.45m. You can see the entire schematic at Upverter. Depending on how close an object comes to the back of the bike more or less LEDs begin to light up in. There are 3 different patterns depending on the range with 4 colors of LEDs (red, green, blue, yellow). After this was posted on Hackaday people pointed out a number of improvements that I could make to this including using a smaller micro controller so stay on the lookout for Bright Bike v2.

The schematic:

And the final code.


const int Ultrasonic = 11; //Ultrasonic input

void setup() {

Serial.begin(9600);

pinMode(1,OUTPUT);

pinMode(2,OUTPUT);

pinMode(3,OUTPUT);

pinMode(4,OUTPUT);

pinMode(5,OUTPUT);

pinMode(6,OUTPUT);

pinMode(7,OUTPUT);

pinMode(8,OUTPUT);

pinMode(9,OUTPUT);

pinMode(10,OUTPUT);

pinMode(12, OUTPUT);

pinMode(A5,OUTPUT);

pinMode(A4,OUTPUT);

pinMode(A3,OUTPUT);

pinMode(A2,OUTPUT);

pinMode(A1,OUTPUT);

pinMode(13,OUTPUT); //Handle bar LEDs

}

void loop()

{

long duration, cm;

pinMode(Ultrasonic, OUTPUT);

digitalWrite(Ultrasonic, LOW);

delayMicroseconds(2);

digitalWrite(Ultrasonic, HIGH);

delayMicroseconds(5);

digitalWrite(Ultrasonic, LOW);

pinMode(Ultrasonic, INPUT);

duration = pulseIn(Ultrasonic, HIGH);

cm = microsecondsToCentimeters(duration);

Serial.print(cm);

Serial.print("cm");

Serial.println();

if (cm > 600){

onebyone();

}

if (cm >= 250 && cm <= 600){ //Adjust these values depending on how far away from the car you want additional LEDs to light up

colorblocks();

}

if (cm < 249) { //The car is getting to close light everything up, although you might want to adjust this if you are sitting in bumper to bumper traffic a lot

allLEDs();

}

}

void onebyone(){

digitalWrite(9,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(9,LOW);

digitalWrite(10,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(10,LOW);

digitalWrite(A4,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(A4,LOW);

digitalWrite(8,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(8,LOW);

digitalWrite(1,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(1,LOW);

digitalWrite(2,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(2,LOW);

digitalWrite(4,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(4,LOW);

digitalWrite(12,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(12,LOW);

digitalWrite(A2,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(A2,LOW);

digitalWrite(5,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(5,LOW);

digitalWrite(7,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(7,LOW);

digitalWrite(A1,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(A1,LOW);

digitalWrite(A3,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(A3,LOW);

digitalWrite(6,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(6,LOW);

digitalWrite(3,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(3,LOW);

digitalWrite(A5,HIGH);

delay(1500); //Control time each LED is on

digitalWrite(A5,LOW);

}

void allLEDs(){

digitalWrite(1,HIGH);

digitalWrite(2,HIGH);

digitalWrite(3,HIGH);

digitalWrite(4,HIGH);

digitalWrite(5,HIGH);

digitalWrite(6,HIGH);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);

digitalWrite(10,HIGH);

digitalWrite(12,HIGH);

digitalWrite(A1,HIGH);

digitalWrite(A2,HIGH);

digitalWrite(A3,HIGH);

digitalWrite(A4,HIGH);

digitalWrite(A5,HIGH);

digitalWrite(13,HIGH); // Light up the LED on the handle bars

}

void colorblocks(){

toph();

delay(750);

topl();

righth();

delay(750);

rightl();

bottomh();

delay(750);

bottoml();

lefth();

delay(750);

leftl();

}

void toph(){ // h for heigh

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);

digitalWrite(10,HIGH);

digitalWrite(A4,HIGH);

}

void topl(){ // l for low

digitalWrite(9,LOW);

digitalWrite(10,LOW);

digitalWrite(A4,LOW);

digitalWrite(8,LOW);

}

void righth(){

digitalWrite(1,HIGH);

digitalWrite(2,HIGH);

digitalWrite(4,HIGH);

digitalWrite(12,HIGH);

}

void rightl(){

digitalWrite(1,LOW);

digitalWrite(2,LOW);

digitalWrite(4,LOW);

digitalWrite(12,LOW);

}

void bottomh(){

digitalWrite(A2,HIGH);

digitalWrite(5,HIGH);

digitalWrite(7,HIGH);

digitalWrite(A1,HIGH);

}

void bottoml(){

digitalWrite(A1,LOW);

digitalWrite(A2,LOW);

digitalWrite(5,LOW);

digitalWrite(7,LOW);

}

void lefth(){

digitalWrite(A5,HIGH);

digitalWrite(3,HIGH);

digitalWrite(6,HIGH);

digitalWrite(A3,HIGH);

}

void leftl(){

digitalWrite(A3,LOW);

digitalWrite(A5,LOW);

digitalWrite(3,LOW);

digitalWrite(6,LOW);

}

long microsecondsToCentimeters(long microseconds)

{

return microseconds / 29 / 2;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s