Project 2 – Bicycle Dashboard

Following on from project 1, this second project aims to build on skills and knowledge learned from the first part. This project is looking at building a bicycle dashboard, consisting of indicators, speedometer and headlights.

To gain inspiration for this project, I looked at a range of Arduino projects that had been done before, of which would perform some or all of the functions that I wish mine to perform.

I first looked at a range of Arduino controlled speedometers, for various transportation systems including cars, skateboards and bicycles.

http://www.instructables.com/id/Compact-Arduino-GPS-Speedo-and-more/

http://www.instructables.com/id/Arduino-Skateboard-Speedometer/

http://www.instructables.com/id/pimpMyBike2-Arduino-SpeedometerOdometer/

http://www.instructables.com/id/Arduino-Bike-Speedometer/

http://www.apartmenttherapy.com/build-your-own-altoids-bike-sp-145185

Looking at these gave me an insight into what would be needed to create a speedometer for the bike, including coding, components and wiring.

Following on from this, I looked into Arduino controlled indicators for bicycles, and found a range of projects to look at, giving me inspiration.

http://hackedgadgets.com/2012/11/30/arduino-based-bike-turning-indicators/

http://www.instructables.com/id/turn-signal-biking-jacket/

http://www.instructables.com/id/Bicycle-turning-lightsindicators/#step0

http://www.instructables.com/id/pimpMyBike1-Arduino-Turning-Indicators-and-St/

After looking at previous projects for inspiration and some advice, I began sourcing the appropriate components for my project, as well as beginning to compile appropriate code for each component and its desired function.

The idea is to have a series of switches, buttons and sensors which will allow me to create a setup that includes two switches located on the handlebars that are connected to two indicator lights on the bike, along with an LCD screen that will be displaying the bikes speed in MPH, which is calculated from a reed switch that will be attached to the front fork leg. Also located on the front of the handlebars will be a headlight, which can be operated via a push button on the LCD screen component.

At the rear of the bike, there will be the two indicators attached to the seat post, along with a rear headlight that can be operated via a push switch on the handlebars. In order to do this, a parts list was drawn up:

1 x Arduino UNO board

1 x Breadboard

1 x Reed switch

1 x magnet

1 x 10k resistor

2 x 9v external power supply

3 x TIP120 transistors

1 x 16, 2 LCD screen

2 x Toggle switch

1 x pushbutton

2 x Orange LED strip (indicators)

2 x LED lamp (one for front and one for rear headlight)

1 x Potentiometer

Bread board wires

Button Potent Switch Wires Lamp Indicator LCD Reed Resistor 9V Transis Magnet Breadboard Uno

The project can be broken down into different sections, to make it easier to code, assemble and debug, if there are any problems. These sections are:

-Reed switch and magnet with LCD

-Left indicator

-Right indicator

-Headlights

Once the parts were sourced and tested, I began to assemble each section, and test them individually. Fritzig diagrams were created for each section, along with coding to enable it to work on the Arduino.

Reed Switch and magnet with LCD

The reed switch is a magnetically operated switch, which means it opens and closes when a magnet passes by the strip. This is going to be used to measure the speed of the bicycle. A magnet will be attached to the wheel, with the switch attached to the fork leg. A reading will be taken each time the magnet passes by the switch, and the time taken between each pass. Some calculations will then enable me to convert this to MPH, and then eventually display it on the LCD.

The fritzig diagram for the reed switch is below.

Fritz Reed

The code I used to work out the MPH is one that was a little similar, that was found on a skateboard speedometer project. Some parts of the code had to be changed to accommodate a bicycle and higher speeds. The code is as follows:

// include the library code:

#include <LiquidCrystal.h>

const int transistorPin = 9;   // connected to the base of the transistor

#define reed A0//pin connected to read switch

//storage variables

int reedVal;

long timer;// time between one full rotation (in ms)

float mph;

float radius = 13.5;// tire radius (in inches)

float circumference;

int maxReedCounter = 100;//min time (in ms) of one rotation (for debouncing)

int reedCounter;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){

lcd.begin(16, 2);

reedCounter = maxReedCounter;

circumference = 2*3.14*radius;

pinMode(reed, INPUT);

// TIMER SETUP- the timer interrupt allows precise timed measurements of the reed switch

cli();//stop interrupts

//set timer1 interrupt at 1kHz

TCCR1A = 0;// set entire TCCR1A register to 0

TCCR1B = 0;// same for TCCR1B

TCNT1 = 0;

// set timer count for 1khz increments

OCR1A = 1999;// = (1/1000) / ((1/(16*10^6))*8) – 1

// turn on CTC mode

TCCR1B |= (1 << WGM12);

// Set CS11 bit for 8 prescaler

TCCR1B |= (1 << CS11);

// enable timer compare interrupt

TIMSK1 |= (1 << OCIE1A);

sei();//allow interrupts

//END TIMER SETUP

}

ISR(TIMER1_COMPA_vect) {//Interrupt at freq of 1kHz to measure reed switch

reedVal = digitalRead(reed);//get val of A0

if (reedVal){//if reed switch is closed

if (reedCounter == 0){//min time between pulses has passed

mph = (56.8*float(circumference))/float(timer);//calculate miles per hour

timer = 0;//reset timer

reedCounter = maxReedCounter;//reset reedCounter

}

else{

if (reedCounter > 0){//don’t let reedCounter go negative

reedCounter -= 1;//decrement reedCounter

}

}

}

else{//if reed switch is open

if (reedCounter > 0){//don’t let reedCounter go negative

reedCounter -= 1;//decrement reedCounter

}

}

if (timer > 2000){

mph = 0;//if no new pulses from reed switch- tire is still, set mph to 0

}

else{

timer += 1;//increment timer

}

}

void displayMPH(){

lcd.print(mph);

}

void loop(){

lcd.setCursor(0, 1);

//print mph once a second

displayMPH();

delay(1000);

}

Indicators
The indicators will be two led strips, situated on the back of the back that will continuously blink individually when a switch is flipped. To do this, an external power supply was needed to handle the amount of LED’s. A TIP120 transistor was used in order to allow me to control them using the Arduino. ‘If’ statements were used to control the LED’s, meaning that if the switch is on, then the light will blink continuously. Two toggle switches will be located on the handlebars, where the user can flip them whilst on the bike.

The fritzig is as follows:

Fritz indicator

The above diagram is for one indicator, but for two indicators, another LED, transistor and button will needed to be added:

Fritz 2 indicator

The code for the indicators is as follows:

int buttonpin = 7;

const int transistorPin2 = 12;

byte leds = 0;

void setup() {

// set the transistor pin as output:

pinMode(buttonpin, INPUT_PULLUP);

pinMode(transistorPin2, OUTPUT);

}

void loop() {

if (digitalRead(buttonpin) == LOW)

{

digitalWrite(transistorPin2, HIGH);

delay(500);

digitalWrite(transistorPin2, LOW);

delay(500);

}

if (digitalRead(buttonpin) == HIGH)

{

digitalWrite(transistorPin2, LOW);

}

}

Headlights

A pushbutton located on the handlebars will be used to power the LED headlights located on the front and back of the bike. An external power supply will be needed for this, to power the number of LED’s that will be used. ‘If’ statements were used again to code the switch and lights together. The switch will be located on the handlebars, allowing easy access for the user. A TIP120 transistor was used to allow me to control the high power lights.

The fritzig diagram is as follows:

Fritz Lights

The code for the headlights is as follows:

const int ledPin = 13 ;

int buttonpin = 9;

byte leds = 0;

void setup()

{

pinMode(ledPin, OUTPUT);

pinMode(buttonpin, INPUT_PULLUP);

}

void loop()

{

if (digitalRead(buttonpin) == LOW)

{

digitalWrite(ledPin, HIGH);

}

if (digitalRead(buttonpin) == HIGH)

{

digitalWrite(ledPin, LOW);

}

}

Final set up

Putting all the code and components together was time consuming, but essential to get right. The code fitted together well, and the switches and lights were all mounted in user friendly areas of the bike e.g. the handlebars.

The final Fritzig diagram for the project is as follows:

Final Fritz

Here you can see all the components together, with the two external power supplies that were needed. The LED’s represent the indicators and the headlights, and the buttons represent the switches that are used to power the lights and indicators. The potentiometer was there to allow me to control the contrast of the LCD screen. The reed switch is shown at the bottom. The TIP120 transistors were used to control the lights being powered by an external power supply.

The final code for the project, with all parts added, is shown below:

// include the library code:

#include <LiquidCrystal.h>

#define reed A0//pin connected to read switch

//storage variables

int reedVal;

long timer;// time between one full rotation (in ms)

float mph;

float radius = 13.5;// tire radius (in inches)

float circumference;

int maxReedCounter = 100;//min time (in ms) of one rotation (for debouncing)

int reedCounter;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const in headlight = 13;

int headlightbutton = 1;

const int indicatorleft = 10;

int leftbutton = 9;

const int indicatorright = 8;

int rightbutton = 7;

byte leds = 0;

void setup(){

lcd.begin(16, 2);

Serial.begin(9600);

reedCounter = maxReedCounter;

circumference = 2*3.14*radius;

pinMode(reed, INPUT);

pinMode (leftbutton, INPUT_PULLUP);

pinMode (indicatorleft, OUTPUT);

pinMode(headlight, OUTPUT);

pinMode(headlightbutton,INPUT_PULLUP);

// TIMER SETUP- the timer interrupt allows precise timed measurements of the reed switch

cli();//stop interrupts

//set timer1 interrupt at 1kHz

TCCR1A = 0;// set entire TCCR1A register to 0

TCCR1B = 0;// same for TCCR1B

TCNT1 = 0;

// set timer count for 1khz increments

OCR1A = 1999;// = (1/1000) / ((1/(16*10^6))*8) – 1

// turn on CTC mode

TCCR1B |= (1 << WGM12);

// Set CS11 bit for 8 prescaler

TCCR1B |= (1 << CS11);

// enable timer compare interrupt

TIMSK1 |= (1 << OCIE1A);

sei();//allow interrupts

//END TIMER SETUP

}

ISR(TIMER1_COMPA_vect) {//Interrupt at freq of 1kHz to measure reed switch

reedVal = digitalRead(reed);//get val of A0

if (reedVal){//if reed switch is closed

if (reedCounter == 0){//min time between pulses has passed

mph = (56.8*float(circumference))/float(timer);//calculate miles per hour

timer = 0;//reset timer

reedCounter = maxReedCounter;//reset reedCounter

}

else{

if (reedCounter > 0){//don’t let reedCounter go negative

reedCounter -= 1;//decrement reedCounter

}

}

}

else{//if reed switch is open

if (reedCounter > 0){//don’t let reedCounter go negative

reedCounter -= 1;//decrement reedCounter

}

}

if (timer > 2000){

mph = 0;//if no new pulses from reed switch- tire is still, set mph to 0

}

else{

timer += 1;//increment timer

}

}

void displayMPH(){

lcd.print(mph);

}

void loop()

{

{

if (digitalRead(leftbutton) == LOW)

{

digitalWrite(indicatorleft, HIGH);

delay(200);

digitalWrite(indicatorleft,LOW);

delay(200);

}

if (digitalRead(leftbutton) ==HIGH)

{

digitalWrite(indicatorleft, LOW);

}

{

if (digitalRead(rightbutton) == LOW)

{

digitalWrite(indicatorright, HIGH);

delay(200);

digitalWrite(indicatorright,LOW);

delay(200);

}

if (digitalRead(rightbutton) ==HIGH)

{

digitalWrite(indicatorright, LOW);

}

{

if (digitalRead(headlightbutton) == LOW)

{

digitalWrite(headlight, HIGH);

}

if (digitalRead(headlightbutton) == HIGH)

{

digitalWrite(headlight, LOW);

}

}

lcd.setCursor(0, 1);

//print mph once a second

displayMPH();

delay(1000);

}

The final Videos for the bicycle dashboard:

Front Handlebars Left Indicator Right Indicator Overall Wiring Rear Indicators Reed Switch and Magnet

Overall, I feel that this project has enhanced my basic understanding of Arduino coding and components, as this project required me to compile a working code that drew in lots of different functions. I feel that the fact that I had to add lots of different code together enriched my understanding for each code function and how it affects the Arduino. I feel I could have added some more inputs for the final piece, such as incorporating light or temperature sensors, something that could have been brought forward from the part 1 project. After reviewing the final piece, and gaining feedback from others, I feel that the addition of ultrasonic range sensor would enhance the product and giving it more meaning and true usage. The range finder would detect if a car was close to the bike, and alert the rider appropriately either through a visual cue on the lcd screen or perhaps a Bluetooth ear piece.

If I were to conduct this project again, one area that I would reconsider is the robustness of the final model, as I experience problems with reliability and strength of the housing units that the components were in, so much so that when the bike fell over, several components, including my reed switch and lcd screen, completely broke. I would create a more robust housing and attachment units, giving the components complete protection if such a scenario were to occur again. This would also simulate something such as an accident occurring when the rider is on the bike, something that would have to be considered if this project were to go to market.

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