Ultrasound Based Tail Light for Bike

by ramyaasakthi in Circuits > Arduino

275 Views, 0 Favorites, 0 Comments

Ultrasound Based Tail Light for Bike

Arduino_light_2022-Apr-25_06-40-51PM-000_CustomizedView13089073213_jpg.jpg

First Instructable. The idea is simple wanted to make a flashing tail light for my e-bike, to make it more interesting wanted to make it flash faster as vehicles comer to the bike.

Supplies

WIN_20220426_02_34_52_Pro.jpg

Arduino Micro.

Soldering Iron and Supplies.

Wires.

LED - I'm using 5 Red, 5mm LEDs

Transistor 2N2222

Resistor 220R

Ultrasonic Sensor, HC-SR04

Zip Ties - (I decided to use this to mount the light to the bike)

M2 screws and lock nut (To hold the case)

Power supply, I'm building this for my e-bike will be plugging into the controllers 5V directly.

A 3D Printer, Maybe.

Wild Run

Screenshot 2022-04-26 013952.jpg
ezgif.com-gif-maker.gif

Connections are straight forward,

Ultrasonic Sensor

ECHO pin -> Arduino 2

TRIGGER Pin -> Arduino 3

Vcc -> 5V

Gnd -> Gnd

Code.

#define echoPin 2 
#define trigPin 3
#define LEDPin 12
long duration;

void setup()
{
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(LEDPin,OUTPUT);
}

void loop()
{digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin, HIGH);
int distance=duration*0.034/2;
//Serial.println(distance);
int LED_time=map(distance,100,600,100,1000); //Play with values here.
flash(LED_time);
}

void flash(int flash_time)
{
  digitalWrite(LEDPin, HIGH);
  delay(flash_time);         
  digitalWrite(LEDPin, LOW); 
  delay(flash_time);
}      


For a quick check to see if things work, Just hooked up the sensor to an Arduino Mega, and tried to flash the builtin LED and Voila.

The Enclosure

Arduino_light_2022-Apr-25_05-26-18PM-000_CustomizedView22551041984_jpg.jpg
Arduino_light_2022-Apr-25_05-01-07PM-000_CustomizedView33693725063_jpg.jpg
Arduino_light_2022-Apr-25_04-58-03PM-000_CustomizedView4123290196_jpg.jpg
Arduino_light_2022-Apr-25_07-09-09PM-000_CustomizedView16132606980_jpg.jpg
Screenshot 2022-04-26 025224.jpg
Screenshot 2022-04-26 025259.jpg
Screenshot 2022-04-26 025331.jpg

As mentioned earlier, the light is going to be mounted using zip ties. I use fusion 360 for this. A couple of sketches in fusion and the model is done.

The enclosure is actually 3parts secured together using M2 screws,

Attached STL files.

Arduino_light_2022-Apr-25_05-10-36PM-000_CustomizedView5375535909_jpg.jpg
WIN_20220424_22_23_49_Pro.jpg
WIN_20220424_22_23_45_Pro.jpg

Went forward and started to print the case, unfortunate that the extruder stepper got fired.

Have ordered a new motor and it, without the enclosure the soldering couldn't be done. Waiting for the new Stepper to arrive.