Lilypad bike jacket signal indicator

Before I started to work on Smart Turn signal indicator, I built another signal indicator jacket using a Lilypad Arduino and a Lilypad accelerometer. That was almost three years ago, but since then I have received quite a few inquiries about how it works. So I am going to give a quick overview about it in this post.

In case you didn’t come here after watching my youtube video, then here it is:

This jacket uses an accelerometer to detect the position of the hand, and activates the correct signal light. The accelerometer is attached to a glove, which is worn on the left hand. I used a Lilypad accelerometer because it can be sewn to the glove using conductive thread. Conductive thread is more flexible and lighter than wire. The Lilypad accelerometer outputs a voltage proportional to the acceleration on each of its three axes.  I used metal buttons to transfer the accelerometer signal from the glove to the jacket.

The schematic below shows all the components used to make this jacket. All connections are made using conductive thread. Notice how the LEDs do not have series resistors. This is because, unlike wire, conductive thread has a significant amount of resistance already. So there is no need to have additional resistors to limit current going though each LED.

Lilypad Bike Jacket schematic

Lilypad Bike Jacket schematic (click to enlarge)

And finally here’s a sample code for the Lilypad:

/*
 * This program implements a signal indicator jacket using a Lilypad Arduino and a 
 * Lilypad accelerometer. 
 * 
 * Author: Kasun Somaratne
 * Created: Dec 1, 2013
 * Modified: Dec 2, 2016
 */

void setup()
{
 // declare all digital pins as outputs
 for(int pin = 2; pin < 14; pin++)
 {
 pinMode(pin,OUTPUT);
 digitalWrite(pin,LOW);
 }
 // we will also need to use three of the analog pins as digital output pins
 for(int pin = A0; pin < A3; pin++)
 {
 pinMode(pin,OUTPUT);
 digitalWrite(pin,LOW);
 }
}

void loop()
{
 clearLights();
 // Analog pins A3 and A4 will be used to read the X and Y outputs of the Lilypad
 // accelerometer. Use the analog values to determine the correct signal to display. 
 if((analogRead(A4) > 500) && (analogRead(A3) < 450))
 {
 leftSignal();
 delay(100);
 }
 else if((analogRead(A4) < 450) && (analogRead(A3) > 500))
 {
 rightSignal();
 delay(100);
 }
 else if(analogRead(A3) > 600)
 {
 breakLights();
 }
 else
 {
 idleLights();
 }
}

void leftSignal()
{
 for(int pin = 6; pin > 1; pin--)
 {
 digitalWrite(pin,HIGH);
 delay(100);
 }
 
 for(int pin = 2; pin < 7; pin++)
 {
 digitalWrite(pin,LOW);
 } 
}

void rightSignal()
{
 for(int pin = 12; pin < 14; pin++)
 {
 digitalWrite(pin,HIGH);
 delay(100);
 }
 for(int pin = A0; pin < A3; pin++)
 {
 digitalWrite(pin,HIGH);
 delay(100);
 }
 for(int pin = 12; pin < 14; pin++)
 {
 digitalWrite(pin,LOW);
 }
 for(int pin = A0; pin < A3; pin++)
 {
 digitalWrite(pin,LOW);
 } 
}

void idleLights()
{
 for(int pin = 7; pin < 12; pin++)
 {
 digitalWrite(pin-1,LOW);
 digitalWrite(pin,HIGH);
 delay(100);
 }
 for(int pin = 11; pin > 7; pin--)
 {
 digitalWrite(pin,LOW);
 digitalWrite(pin-1,HIGH);
 delay(100);
 } 
}

void breakLights()
{
 for(int pin = 7; pin < 12; pin++)
 {
 digitalWrite(pin,HIGH);
 } 
}

void clearLights()
{
 for(int pin = 2; pin < 14; pin++)
 {
 digitalWrite(pin,LOW);
 }
 for(int pin = A0; pin < A3; pin++)
 {
 digitalWrite(pin,LOW);
 }
}

Smart Signal light for a bicycle

This is a project I have been interested in for many years: A signal indicator for cyclists. Cycling is one of my favorite activities. As a commuter cyclist I’m on the road a lot, and safety is always on the back of my mind. When you ride your bike on the road alongside cars, trucks and buses, the chances of you walking out of an accident is very slim. One of the most important things you can do to avoid an accident is to be seen! So about 3 years ago I decided to build a wearable signal indicator for cyclists called Smart Turn. I was able to make a prototype of Smart Turn using a Lilypad Arduino and a BlueSMiRF Silver Bluetooth module.

Smart Turn prototype 1

Smart Turn prototype 1

Using the Bluetooth module I was able to control the lights on the jacket using my phone. This prototype had three major issues:

  1. The jacket was hideous and cumbersome to wear.
  2. The lights were not bright enough to be seen effectively.
  3. The cell phone battery drained after only a few hours of use.

Because of these problems the first prototype was not very practical, and I never actually ended up using it on the road. Since I was busy with school at the time the project was shelved. After school ended I slowly got back into this project and now I have built a second prototype that fixes all the problems I had with the first version.

Smart Signal belt. Prototype 2

Smart Signal belt. Prototype 2

The new Smart Signal is a belt. The major advantage of this is that you can wear it around your waist or around your backpack if you happen to ride with a backpack on like I do. The second improvement is using Neopixel RGB LEDs instead of regular LEDs. The Neopixels are significantly brighter than regular LEDs, and they can be connected serially and controlled with only three connections. The third major improvement is using a Bluetooth Low Energy (BLE) module to control the lights. Using BLE helped increase the battery lifetime significantly over the previous version. The fourth major improvement is having a separate controller attached to the handle bar of the bicycle rather than using a phone. This controller was physically actuated with the brake lever, and is much more reliable than using the accelerometer of the phone to detect braking.

Inside Smart Signal belt

I used enamel wire to make the connections between the three LED sticks. I found this to be more reliable than using conductive thread. After making all the connections, I sandwiched the LED sticks and enamel wire between two pieces of fabric and sew the fabric together. Holes were cut out to expose the LEDs. The rest of the components including the Li-polymer battery are placed on the small red case which links the belt to the belt buckle.

BLE module, ATTINY85 microcontroller and the Li-poly battery are placed inside the red case

BLE module, ATTINY85 microcontroller and the Li-poly battery are placed inside the red case

The following schematic shows the components of the Smart Signal belt. It consists of three main components: A BLE113 breakout board for wireless control, an ATTINY85 for controlling the Neopixel LEDs and Neopixel LEDs.

Schematic of Smart Signal Belt

Schematic of Smart Signal Belt

The Neopixel LEDs can be programmed with just one data pin. The only timer available with the BLE113 module is 32.768 kHz, not sufficient to meet the timing requirements of the Neopixels. So I decided to use a ATTINY85 to control the LEDs. The BLE113 breakout board, which I talked about in my previous post, includes a Li-polymer battery charger.

The following is a flow chart showing how the Smart Signal operates.

Flow chart for the Smart Signal belt operation

Flow chart for the Smart Signal belt operation

Upon startup the BLE module starts advertising that it is a Smart Signal device and that it is available for connecting to a master. This allows the controller that sits on the handle bar to find and connect to the Smart Signal belt. Once a connection is established, the Smart Signal belt stays in idle mode until a signal state update is received from the controller.

There are four lighting modes: left turn signal, right turn signal, brake and off. Brake signal overrides any of the turn signals. The BLE module sets the status of two output pins (sw1 & sw2) according to the signal state received from the controller. The ATTINY reads the sw1 & sw2 pin statuses and activates the correct lighting mode.

Smart Signal Controller

The controller is attached to the handle bar of the bicycle. The turn signals are activated by a slide switch. I used a momentary switch to detect the brake position as shown in the image below.

Smart signal controller with the brake lever status detection mechanism

Smart signal controller with the brake lever position detection mechanism

The controller also has a BLE113 module, which connects to the BLE module of the belt. If the BLE module of the controller detects a change in any of the switch positions, it will send the appropriate command to the Smart Signal belt.

The second prototype is functional, and I do use it on the road. The only gripe I have with it is that the controller is very specific to the orientation of the brake handles of my bicycle. So it is not easily transferable between bicycles. The next step for this project is to update the controller to make it universal. But for the time being I am glad to have a Smart Signal device that I can use in my daily commute. Here is a short video that shows what the Smart Signal belt looks like in action:

Let me know if you have any questions, thoughts or suggestions. Thanks for reading!

Assembling surface mount components at home

Currently I am working on improving the Smart Turn project to build a turn signal indicator for my bicycle. I have made significant progress on this project which I will cover in a later post. But in this post I am going to show you how I assemble surface mount components on to a PCB using my home made reflow oven.

If I can get away with just using through hole components I will  never bother with surface mount at all. But some components only come in surface mount packages like the Bluetooth Low Energy modules from Bluegiga, which I am using for the Smart Turn project. Also through hole is bulky and takes too much space. So inevitably I found myself needing to use surface mount components.

Hand soldering surface mount components is not too difficult if you are only dealing with size 0603 (inch) or greater, but some packages have pads underneath the component and is impossible to access with a soldering iron. So I decided to build a reflow oven a while ago to take care of my surface mount assembling.

While working on the Smart Turn project I created a video that shows step by step from start to finish how I use my reflow oven to assemble surface mount components. As you can see in the video below it is not that complicated of a process. It requires a bit of patience to get solder paste onto the pads, but once that’s done you can sit back and relax while the reflow oven takes care of the rest. Try it out and let me know if you have any questions or suggestions.

Rechargeable Motion Activated Light

I made this device for our driveway at the back of the house. There is a motion activated light near the back door but it doesn’t quite cover the driveway section because of a tree that’s on the way. So this presented quite a good opportunity for a side project.

The requirements

  1. Must be powered by a battery since no power outlet available.
  2. Motion activated
  3. Rechargeable
  4. Weatherproof
  5. Works only when dark

Motion detection can be achieved using a PIR (Passive Infrared) sensor. For this project I am using a PIR sensor I got from Adafruit. This sensor has a built-in signal processor, which makes using the sensor very simple.

This motion sensor runs on 5-12 V so I decided to use four NiMH rechargeable batteries. These batteries are 1.2 V each. For charging these batteries the easiest and most convenient solution is to use solar power. The solar cell I picked up from the local electronics store is rated at 100 mA at 7.2 V in full sunlight. Since the maximum amperage is lower than 1/10th the battery capacity (2500 mAh) I don’t need to worry about charge control circuitry (Check out this document by TI about battery charging).

So how to detect if it is dark? I am using a photocell for that. The resistance of the photocell increases as the ambient light decreases. By putting the photocell in a voltage divider the change in resistance can be translated into a change in voltage, which is used to control a MOSFET that drives the LEDs.

As with all my projects I first breadboard it to see if theory works as it should. If it works on the breadboard, there is a very good chance the actually circuit will work. As seen below in the schematic the circuit is quite simple. The schottky diode prevents current flow back into the solar cell, and also it has a very low forward voltage drop (~0.15 V) compared to regular diodes (0.7 V).

 

schematic

Schematic of the Rechargeable Motion Activated Light

Once I verified the circuit works on the breadboard the next step is to make a case for it. And that’s why I got my 3D printer. I designed this case to fit the particular fence we have in the backyard so it is not universal.

For the light, I decided to use the front section of an old LED flashlight. This gives a better beam for the light than making my own LED assembly. The photos below show the assembly of the device.

20161001_081511

The main body that holds the circuitry and the batteries. I used enamel wire for connections because they are thin and insulated

20161001_155418

The front and top sections showing the LED lamp, PIR sensor, and the Solar cell

After putting the case together and verifying everything still works the last thing to do is to waterproof it. Completely waterproofing things is very difficult. I used a glue gun to cover all open edges. This should keep most of the water out but time will tell if it will be enough.

20161001_173901

The rechargeable motion activated light attached to a fence facing the driveway

And finally here’s a video that shows how this works:

 

Harnessing energy from a bicycle

I enjoy cycling not only because it is one of the most efficient and cheapest forms of transportation, but also it is very satisfying. Yeah hills can be a pain but what goes up must come down, eventually.

When I ride my bike I like to have my phone with me so that I can have a map, a list of directions and also see how fast I am going. Couple of years ago I created an electronic dashboard for cyclists called Smart Turn. It was designed to help cyclists navigate safely through urban roads.

Smart Turn consisted of a mobile phone app and a safety vest with lights. The lights can be activated wirelessly to indicate turn signals and braking. I successfully created a working prototype of Smart Turn. However, it had several issues:

  1. The cell phone battery dies fast
  2. The turn signal lights cannot be seen during the day
  3. The vest is cumbersome to wear, specially in hot weather

The biggest problem it had is with the cell phone. The Smart Turn app uses GPS, Bluetooth and keeps the screen on all the time. This makes the cell phone battery drain in a couple of hours. So to fix this issue I created a cell phone charging system for my bicycle.

The cell phone charging system uses both solar and pedal power to charge the phone. While building this I decided to also include a battery pack, a front lamp, and a rear lamp which could also be powered by the same charging system.

The following is a schematic of the charging system:

ChargeSch

Schematic of bicycle charging system

The Dynamo

For the dynamo I used a stepper motor. This Nema17 stepper motor was rated at 12 V and 1.2 A per phase. Generally the higher the amp rating of the motor, the more power it can generate. The first thing I needed to do is to verify that this motor can generate enough power to charge the cell phone and accessories. To do that I had to attach the motor to the bicycle wheel. Thanks to my 3D printer I was able to make a holder to attach the motor to the bicycle. Then I also 3D printed a contact wheel for the motor.

Dynamo motor attached to the bicycle

Dynamo motor attached to the bicycle

Contact wheel of the dynamo

Contact wheel of the dynamo

This stepper motor has two pairs of windings. Each pair of windings generates an alternating current when the motor is rotated. To convert the AC to DC, I used a multi-phase rectifier bridge as shown in the schematic.

During initial testing I found that the motor can generate up to 70 V when hand cranking the pedal. So it was obvious that I needed a regulator before connecting it to a cell phone. As shown in the schematic I made a simple regulator using a 5.6 V Zener diode and a TP129 transistor. The transistor needed to have a heat sink since it will be generating a fair amount of heat. I put the regulator and the mode select switch in a control box under the back of the seat. The six position mode switch selects which power source is connected to which device.

Six position mode switch for selecting which power source is connected to which device

Six position mode switch for selecting which power source is connected to which device

Solar Panel

The Solar Panel I found at a local electronics store is rated to produce 200 mA at 5 V in direct sunlight. The only thing I had to do for this is to design a holder to attach it to the bicycle.

Solar panel attached to the front handle bar

Solar panel attached to the front handle bar

The Battery Pack

The battery pack consists of six Ni-Cd batteries arranged in two rows with three batteries per row connected in series. These batteries are salvaged from old solar garden lights. Ni-Cd batteries are safer and easier to charge compared to Li-Ion batteries. Also a special charging circuit is not required for Ni-Cd batteries as long as the charge current is limited.  The two rows of batteries power the front and rear lamps when neither the solar power or pedal power is available. The battery pack can be recharged by either the solar panel or the dynamo. I made a case for the battery pack using the 3D printer and sealed the case using a glue gun.

Rechargeable Ni-Cd battery pack made using solar garden light batteries

Rechargeable Ni-Cd battery pack made using solar garden light batteries

Front & Rear Lights

Both the front and the rear lights consist of two LEDs that blink alternatively. The blinking circuit is simply an astable multivibrator made with a couple of transistors. For the rear light I designed and printed a case from  scratch. But the front light is hacked from a purse light. The lights can be power from either the battery pack, solar panel or the dynamo. Although powering the lights with the solar panel is somewhat useless since there is no need for lights when it is sunny.

Front and rear lights

Front and rear lights

This charging system will significantly extend the battery life of the cell phone and uses energy that is freely available. The next step is to make turn signal indicators that are visible during the day. Unlike the front and rear lights the turn signals will be attached to the rider instead, making them more effective. More on wearable turn signal indicators will be covered in the next post.

New & Improved Gyro’clock case (V2)

Making the first version of the Gyro’clock case showed me some of its design flaws. Also I got to learn about some of the limitations of my 3D printer and 3D printing in general. So for the second version I have made the following improvements:

  1. Thickness of the walls increased to 2 mm to increase rigidity.
  2. Added a window for the switch and the charge status indicator LED.
  3. Replaced the top piece with a sliding door on the side. The sliding door doesn’t require any screws and fits snugly.

And here is the result

SecondCase

I am happy with this version of the case. Now I can actually carry around the Gyro’clock with me wherever I go. Gyro’clock is now complete. To wrap this all up I created a video about the project:

 

 

3D printer and first case for Gyro’clock

The 3D printer arrived a week ago and I have been using it pretty much every day since. The Prusa I3 DIY printer kit I ordered from Amazon came from a company called Shenzhen Anet Technology. They provided instructional videos of how to assemble it, and it took me about a full day to put it all together. Assembling the printer was quite fun and it’s great to know what every nut and bolt in it does. The printer also came with two spools of PLA filament.

Here’s the completely assembled 3D printer:

Fully assembled 3D printer

Fully assembled 3D printer

So for my first test I decided to print the Gyro’clock case I designed previously. The 3D printer firmware understands G-code. To convert the 3D design made in FreeCAD to G-code it must be given to a slicer software. The 3D printer manual recommended to use Cura for slicing, so I decided to use it. The slicer program literally slices the 3D model into many layers for the 3D printer to print one by one.

After exporting the design in FreeCAD as a .stl (stereo-lithography) file I opened it up in Cura. When you first start up Cura, you have to give it information about your 3D printer such as print size, nozzle and filament type etc. After loading the .stl file, Cura also gives options to scale, rotate and mirror the object, which is handy. After converting the image to G-code I saved it in an SD card, which can be inserted into a slot in the printer.

It took about an hour and a half to print the bottom part of the case, and this is how it turned out:

Bottom piece of the Gyro'clock case with the Gyro'clock PCB

Bottom piece of the Gyro’clock case with the Gyro’clock PCB

The top piece took only 30 minutes or so since it was smaller in size, and this is how it turned out:

Top piece of the Gyro'clock board

Top piece of the Gyro’clock case

During this first run of the printer I noted a few problems with my design and a few issues with the printer:

  1. The walls were too thin. I designed the walls to be 0.8 mm wide. This made the case too flimsy and it was too flexible. My attempt to remove the pieces from the printer bed caused them to bend slightly.
  2. The holes were too small. The screw holes I made to attach the board to the case and the top piece to the bottom piece were non-existent in the print.
  3. Printer does not wait for minimum time interval before moving to the next layer. There is a setting in Cura for selecting the minimum time spent on a layer. I set this value to 5 s. But I noticed when the top piece was printing the printer does not wait the minimum interval between the layers. This caused the snap on part of the top piece to deform. Could be a firmware bug.
  4. I forgot to create a window for the switch and the charger LED. There is no excuse for such carelessness!
  5. The printer has trouble making small overhanging features at 90°. This is understandable because there is no support underneath to hold the thin strands of melted plastic. So the first few layers of an overhanging section (or a bridge) does not hold well. But if the overhang is thicker and the bridge is not that wide then later layers will build up properly.
  6. Masking tape on the heated bed lifts causing the print to bend. This printer has a heated bed. Masking tape is put on the metal bed so the print job will not stick to it. On repeated use this masking tape looses its adhesiveness and lifts from the bed causing the printed object to bend. The solution for this is to replace the masking tape for each print.
  7. Formation of snags causes the printer head to jump. It was good that I noticed this problem before it became an issue. When the printer head moves across a gap following the same route multiple times, excess plastic can cause snags to form. The next time the printer head comes around the same path the snag could block it. This could cause the printer to misalign. Fortunately I saw the printer jolt a few times on a snag and cut off the snag before it got too large. A good reason not to leave a print job unattended for too long.

After cleaning up the two pieces of the case to remove snags and excess plastic I put the two pieces together. There was no need to attach the board to the case with screws since it fitted snugly. I also cut off the deformed snap on piece of the top part.

And here’s the resulting case:

First 3D printed Gyro'clock case

First 3D printed Gyro’clock case

This was a good learning experience about 3D printing. Now I know what to do for the second version of the case. It’s coming soon!