Bicycle Blinker
Cycling is a brilliant activity and to be honest, one of my favorite. Every day I pedal for 20km to keep myself fit and engaged. The biggest issue I face daily is traffic.
I live in Bengaluru, the silicon capital of India, with a population of over 13 Million. In such a highly dense city, traffic is one of the major issues,s and to add up to my problems, there are no cycling tracks near my home. I have to use the road to keep my spirit ignited.
Compared to other parts of India, roads are better here but still, traffic rush and rash driving are significant. Finally adding a cherry on top, I tour at dusk, when the rush is highest.
You can see that I am the epitome of problems. A very simple solution to all this is a safety light, so I started my search for it. All the things that I found in the market had serious problems. Some of them were so cheap that they could break in your palm, some did not have rechargeable batteries and some were too dim to be called a safety light. Frustrated from all this, I decided to make my version, where I get to choose the variables and features.
Bicycle Blinker has a total of 5 blinking modes. In the first mode, it blinks in two short bursts at an interval of 1 second. In the second mode, it blinks at an interval of a quarter second or 250 milliseconds. In the third one, it continuously glows and in the fourth one, it fades from dim to bright. Talking about the battery, it has a 500mah battery that can last up to 30 days on standby mode and can fully recharge in about 30-40 minutes. You can add other modes also by editing the code. It is simply easy to understand.
I have attached one video where you can see the device in action. The distance between the camera and device is around 100 feet. I have recorded it in my hostel. The condition of my hostel is not good actually. It's a very old hostel (built-in 1977) and is under renovation
PS: Pardon me if the photo quality is poor. I am capturing everything from a 4-year-old phone, in a very weird lighting setup. I have tried my best to capture all the angles. If you want, you can have a look at my setup in the last step.
Downloads
Supplies
All the important supplies are mentioned below. For programming the AtTiny85 chip, I am using Arduino Nano. You can use other programmers also like USBasp etc. It is up to you. Also, I have mentioned two 100ohm resistors because I did not have a 47ohm resistor. If you have it, you can use a single resistor instead of two. More about it is explained later in the article. I did not have an 8-pin IC base therefore in my circuit, I have used a 14-pin base, but I recommend you to use an 8-pin base only.
- AtTiny85
- Li-ion Battery (I am using 500mah battery)
- Li-ion battery charger
- Red LEDs (X2)
- 100ohm resistor (X2)
- Push-button
- 8-pin IC base
- Bicycle reflector clip
For programming the AtTiny85, you need:
- Arduino Nano/Uno
- 10uF capacitor
- Jumper cables
Preparing the Hardware for Coding
To code the AtTiny85, you need hardware. I am using Arduino Nano board but you can use other programmers too. It's up to you. The method uses Arduino as an ISP. It's very simple and handy and you can find hundreds of articles and videos on how to do it. One tip that I'll give is that if you are using the same setup, use a capacitor between reset and ground of the Arduino, not AtTiny85. You may face difficulties in uploading if you don't do it. I have wasted several hours on such a simple problem.
The Code
// **** INCLUDES ***** #include <avr/sleep.h> // Sleep Modes #include <avr/power.h> #include <avr/wdt.h> byte state = 0; byte fadeValue = 0; boolean increment = 0; #define LED 0 #define SWITCH 4 void setup() { pinMode(SWITCH, INPUT_PULLUP); pinMode(LED, OUTPUT); //Serial.begin(115200); indicator(); // pin change interrupt (example for D4) PCMSK |= bit (PCINT4); // want pin D4 / pin 3 GIFR |= bit (PCIF); // clear any outstanding interrupts GIMSK |= bit (PCIE); // enable pin change interrupts } void loop() { //attachInterrupt(0, wakeUp, LOW); if (state == 0) { digitalWrite(LED, LOW); goToSleep(0); //detachInterrupt(0); indicator(); state += 1; } else if (state == 1) { digitalWrite(LED, HIGH); delay(50); digitalWrite(LED, LOW); delay(100); digitalWrite(LED, HIGH); delay(50); digitalWrite(LED, LOW); //LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); //detachInterrupt(0); goToSleep(1); button(0); } else if (state == 2) { digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); //LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF); //detachInterrupt(0); goToSleep(2); button(0); } else if (state == 3) { digitalWrite(LED, HIGH); delay(10); //digitalWrite(LED, LOW); goToSleep(0); //button(0); state += 1; indicator(); } else if (state == 4) { analogWrite(LED, fadeValue); delay(7- (fadeValue/70 * 2)); increment == 0 ? fadeValue++ : fadeValue--; if(fadeValue == 254 || fadeValue == 0) increment = ! increment; if(fadeValue == 0) { digitalWrite(LED, LOW); delay(100); } button(1); } } void button(boolean type) { if (digitalRead(SWITCH) == LOW) { //detachInterrupt(0); indicator(); if (type == 0) state += 1; else { state = 0; increment = 0; fadeValue = 0; } } } void indicator() { digitalWrite(LED, LOW); delay(500); digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(100); digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(100); digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(500); } ISR (PCINT0_vect) { // do something interesting here } ISR ( WDT_vect ) { wdt_disable (); } // end of ISR void goToSleep (byte delayType) { set_sleep_mode(SLEEP_MODE_PWR_DOWN); ADCSRA = 0; // turn off ADC power_all_disable (); // power off ADC, Timer 0 and 1, serial interface if (delayType == 0) wdt_disable (); else resetWatchDog (delayType); sleep_enable(); sleep_cpu(); sleep_disable(); power_all_enable(); // power everything back on } // end of goToSleep void resetWatchDog (byte delayType) { MCUSR = 0; WDTCR = bit ( WDCE ) | bit ( WDE ) | bit ( WDIF ); // allow changes, disable reset, clear existing interrupt if (delayType == 1) WDTCR = bit ( WDIE ) | bit ( WDP2 ) | bit ( WDP1 ); else if(delayType == 2) WDTCR = bit ( WDIE ) | bit ( WDP2 ); wdt_reset (); // reset WDog to parameters } // end of resetWatchDog ()
Making the Cirucit
The circuit of this project is very simple. Only one IC and two resistors need to be soldered. I prefer not to solder the IC directly as it may damage it. Instead, use an 8-Pin IC base. At the time of making this project, I did not have an 8-pin IC base, therefore I used a 14-Pin base. Some extra space will be filled but that much is manageable. The circuit diagram is given above. You can follow it to make the connections. The connection of buttons, LEDs, and battery is given in the next step.
Connecting the Secondary Parts to the Circuit
Starting with the battery, we are going to attach a charging module between the battery and the circuit. This module has short circuit protection along with charging and over-discharging protection circuit. This protects our circuit by preventing complete discharge of the battery and hence improves its life. Connect the battery to the battery terminal of the module and the output of the module to the power pins of AtTiny85.
As you know I am using two LEDs, so I have joined the negative terminal of both the LEDs together. Since I do not have a 47ohm resistor in my inventory, I am using two 100ohm resistors because if I connect both the LEDs in parallel to a single 100ohm resistor, the voltage drop across the resistor will be significant, which will decrease the brightness of the LED. Therefore I am using two 100hm resistors instead of one. A single 47ohm resistor can power both the LEDs well. Here I have connected one wire to both the positive terminal of LEDs and one to the common negative, which makes a total of three wires. Connect those wires to the circuit on the floating terminal of the resistors.
Similarly, I connect wires to terminals of the push-button and then to the ground and pin 3 of IC. You can use a heat shrink tube to further protect the connections but I personally did not feel the need for it.
Testing the Connections
The circuit is done and it is a good point to check whether all of the parts are working or not. You can tap the push button to scroll through various modes. In total, it has a total of 5 blinking modes. In the first mode, it blinks in two short bursts at an interval of 1 second. In the second mode, it blinks at an interval of a quarter second or 250 milliseconds. In the third one, it continuously glows and in the fourth one, it fades from dim to bright. If everything is okay, it should work as expected.
3D Printing the Parts
To make our blinker ready for use, we have to encase it. The best option that I feel is 3D printing the parts. They are strong durable and easy to manufacture. Other materials can be used too but I personally feel they will be too hectic for such a simple project. I have attached the 3D files of the project with this step. They are all designed in Tinkercad. I don't have a 3D printer right now therefore I am utilizing a local printing service. They print the parts quickly at an effective rate and the overall print is fantastic. Since I personally didn't print the parts, I can't give any suggestions on how to proceed. That you have to figure out on your own. Sorry.
The clip I am using fits perfectly with my old light reflector. Yours may differ in dimension so modify the files according. Don't worry, soon I'll attach a bicycle mount also that will solve this problem. I am working on it.
Assemblying Everything Together
Now the time comes to assemble everything. The small hole in the bottom part is for the charging port. Secure the charging module in the lower segment with plenty of hot glue. That is the best option for me but you are free to explore. Even the push button, that gets fixed to the upper bracket needs to be secured with hot glue. The other parts can simply be placed using sided tape. As for the LEDs, the friction from the holes is strong enough to hold them in place but to be on the safer side, put a little bit of super glue on the boundaries.
Finally, you can join both the segments together using super glue. It will do a fantastic job there. For the clip also, use superglue. It will wor. Preferably attach the clip to the backside. Other sides may cause some obstruction to the LEDs.
This completes the project and it is now ready to use.
End
Thank you for checking out my article. I am grateful for that. The last image is of my setup. The issue is, I am staying in a dormitory so there are a lot of constraints here. I cannot set up a proper studio, therefore I have to work with whatever temporary solutions I have. Anyway, I have tried my level best to make this article.
Happy cycling.