Ultrasound Based Tail Light for Bike
by ramyaasakthi in Circuits > Arduino
275 Views, 0 Favorites, 0 Comments
Ultrasound Based Tail Light for Bike
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
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
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
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.
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.