Bike Odometer - something which measures distance!!
 This projecht made me say

'I hate this electronics!'

 

Hmmm, okay how to start? How about... from the start ;)
Well, one day I was sifting thru the picaxe.orcon.net.nz website. A HAH!

 


As you can see! Bike Odometer looks like a 'bright idea'!

I wonder where I started... Oh yes! First of all, off the 'brightsparks' website, I ordered the following bits:

2 way AA switched battery holder
Piezo Speaker
Picaxe08
Reed Switch

I think that's it. Yes it must have been. Also used were 3push to make buttons, various lengths of solid core wire and a couple of resistors.

So far, this is my first 'REAL' project using a PICAXE so please bear with me ;) (while I go make lunch of course)

Making a circuit involving a PICAXE is quite different to normal linear circuits, mainly because you need to do some more planning and programming. Before I started designing the circuit I wanted to write a program - a program which would store a number into the PIC memory. This made it so that if the power supply is removed, the number would still be able to be recalled next time the power is restored.


 

 

 

 

 

This is a 'Reed Swtich'
Think of it as a magnetic switch, when a magnet gets close the switch it activate and complete the circuit.

This is my original program.

symbol value = w0
read 1,value

start:
write 1,value
debug value
value = value + 1
pause 2000
goto start

I know I should have included comments, but I will explain each line on what it does in the program in full English :).


This here is a Piezo Speaker

The first line lets a variable called 'value' to be a word - any number between 0 and 65535. This is 16bits or 2 bytes. I will come back to the second line later. 'Start:' creates a 'landmark' which allows the program to jump to this location anytime I write the line 'goto start'.

...jumping down to value = value + 1. Well, combined with pause 2000 and the goto start, the number in 'value' will increase by one every 2000 milliseconds. Note that the original value of 'value' is 0. After adding 1 to 'value' it will start at 'start:' again.

When it gets there, it will write the value of 'value' into byte 1. Debug Value means that (when the PICAXE is connected to the computer via the serial port) it will return the value of 'value' on screen.

Going back to the 'read 1,value' this line looks at the number in byte 1 and stores that number into the 'value' variable.


This is a PICAXE-08 Microcontroller

 Everytime you turn it off, then turn it back on, the program will run from the first line. As long as value of 'value' gets written into byte 1, then if the power is removed, the number stored into byte 1 will be able to be retrieved.

GREEEAT! We got that sorted!

Now the more simple part. Write a program which increments by 1 each time a button or switch is turned on. Easy. It was time to design the circuit. Let's see, I need to have in place 3 swtiches connecting to inputs 1,2,4, the reed switch connected to Input3 and a speaker connected to Output0.

I also need to measure the circumference. I did this twice, using two techniques as well.

#1. I measured the diameter of the front wheel and multiplied it by Pi (3.1454...). The diameter was about 65cm - multiplied by Pi gave me the circumference of about 2.04m.
 

#2. I put the wheel on the ground as seen in the photo. I took the middle spoke on which the reflector was on and drew a line using bark. I rolled the bicycle slowly until the same mark was reached. I then drew another line. I measured the distance between these two lines. The distance came out to be 2.00m Nice :).

Not wanting to make things difficult for myself I took 2m as the circumference. This is a nice round number and would be easy to convert into 10's of metres and kilometres etc.

Now for the maths. I have 3 buttons to use. Okay, I decided that I want a long term measurement (sorta like the car odometre, except you can reset it when ever you want to ;)) the next one I wanted one to measure a short distance, say a short little journey.

The way I wanted to see how far I travelled was to use a Piezo speaker. Its not so much seeing how far I've travelled, but hearing how far I had travelled. Each High pitch tone means '10' and each low tone means '1'. eg, so a 'Hi-Hi' 'Lo-Lo-Low' means 23. Here comes the more complicated part. I have two ways of reading it, either using the short term 10m per low tone and for the long term measurement100m per low tone.

If you do the maths (if you understand the above paragraph) then each high beep for the short term is 100m and each hi tone for the long term measurement will be 1km (100 x 10). As you probably guesssed waiting about 2minutes / 120seconds just to hear your travelled distance isnt very fun, and you might lose count. So that's why I have the long term one for - its in km's!

okay, here is my FINAL program:... I think I might want to add comments now :p, much easier than paragraphs. This is version 1.0Final. But during typing this, I found a fault... scroll down to seeish...

symbol counter = w0            'lets a variable named counter a number from 0-65535
symbol tens = b2                  'lets ' ' '  tens be a number from 0 - 255
symbol ones = b3                 'lets ' ' ' ones be a number from 0 - 255
symbol sounds = b4
symbol counter2 = w3
symbol kmcounter = w4

read 0,kmcounter

onekm:
kmcounter = counter2 / 10 + kmcounter
write 0,kmcounter
tens = kmcounter / 10
ones = kmcounter // 10
counter2 = 0
goto playsound


Main:

if input3=0 then plus
if input4=1 then play10
if input1=1 then reset
if input2=1 then onekm

goto main

plus:
counter = counter + 1
nocount:
if input3=0 then nocount

goto main

play10:
pause 255
counter2 = counter / 5
tens = counter2 / 10
ones = counter2 //10

playsound:

if tens = 0 then skip

for sounds = tens to 1 step -1

sound 0,(109,60)
low 0
pause 150

next sounds

skip:
if ones = 0 then Main
for sounds = ones to 1 step -1

sound 0,(55,50)
pause 150

next sounds

goto Main

reset:
kmcounter = 0
counter2 = 0
for sounds = 0 to 127
sound 0,(sounds,2)
next sounds
goto main

Actually dudes, this program was not my final program... Why? Well first of all, my mileage was limited by the variable 'tens' only being up to 255. This meant that the furthest my program would allow would be, 255 x 10 x 10. Which is 25km about... WAAAAA, I WANT MORE!!!

So I changed it to a word. This was not the only problem though. The line, Write 0,kmcounter meant that it would write the first 8bits of the 16bit digit out. Again this meant that the kmcounter (would only ever get up to 255) again, 25.5km. In order to increase my maximum distance, i needed to write both parts of the 16bit digit into the memory. Ie. the first 8bits as well as the last 8bits.


This is the original design.
Very poor indeed, reed swtich attached to fork and the magenet attached to spokes. You'll see why its such a poor design :).

symbol counter = w0
symbol tens = w1
symbol ones = b10
symbol sounds = w2
symbol counter2 = w3
symbol kmcounter = w4            'w4 consists of b8 and b9
symbol kmcounterlow = b8        'added this line
symbol kmcounterhigh = b9        'added this line

read 0,kmcounterlow                'write into memory b8
read 1,kmcounterhigh               'write into memory b9

goto main

plus:
counter = counter + 1
nocount:
if input3=0 then nocount

Main:
if input3=0 then plus                    'every circumference, plus one to counter
if input4=1 then play10                'play the song if this button is pressed.
if input1=1 then reset                   'reset kmcounter back to 0km.
if input2=1 then onekm                'play the total mileage I have travelled in km.


goto main


play10:
counter2 = counter / 5
tens = counter2 / 10
ones = counter2 //10
'debug b0
pause 250
if input4=0 then main

playsound:

if tens = 0 then skip

for sounds = tens to 1 step -1
sound 0,(109,60)
pause 150

next sounds

skip:
if ones = 0 then Main
for sounds = ones to 1 step -1
sound 0,(55,50)
pause 150
next sounds

goto Main

reset:
kmcounter = 0
sound 0,(120,2)        'deleted the increasing tone and used a monotone noise for reset to save space.
goto main

onekm:
kmcounter = counter2 / 10 + kmcounter
write 0,kmcounterlow
write 1,kmcounterhigh
tens = kmcounter / 10
ones = kmcounter // 10

goto playsound


But after refining the code the end product was still too big. So a cut there and a cut here meant that I had to rid of the cool reset noise. Instead of it generating a sound wave ever increasing in frequency (like going up the keys on a piano) I had to settle with a monotone '120' tone noise.

With the program all finished, it was time to test. Yea yea, very accurate indeed. Though I had one buggy and nagging problem, the stupid PICAXE would keep beeping and resetting itself for NO APPARENT REASON!! Okay, I reliquified every single bit of solder just to make sure there were no dry joints. After that it WORKED!!! (for 24hours approx.) and then it stuffed up. Back to checking joints etc, getting soldering iron out, liquifying etc. All to get the same result.

Works,attached to bike ->(after 24hours) -> stuffs up, dismantle from bike ->(fixed) Works, reattached to bike ->(after 24hours) -> stuffs up, dismantle from bike.

This process repeated about 5 times REALLY!! Okay, time to ask the PICAXE guru Andrew (the admin at brightsparks). Hummm, he says that if Leg2 is not used, you must connect it to ground. This is also stated in the FAQ. CONNECT TO GROUND FOR RELIABLE PERFORMANCE. I did NOT connect it to ground but instead left it. tsk tsk. Connecting it to ground fixed it. Refining the code and getting the thing to work properly took about 5 days. But the most frustrating bit was dismantling it from the bike and then having to reattach it only to have to take it back off after sometime :(. Anyway, due to taking it on and off so many times, the wires snapped and were pulled loose from the PCB. This was not helped with my poor design too. Each time I turned the wheel, the wires would be pulled and tension would be placed on them, causing them to rip off too. Analysing the problem I swiftly came up with another design. This time everything (battery box and PCB) was attached to the fork of the bike. Now when I turned the wheel, everything would move with it, not just the reed swtich :).

 

As you can see, nothing is attached to the frame (as it was before). All components are on the forks.

 

 

 

As you can see, there are 3 push buttons, a PICAXE-08 Piezo speaker, wires and some resistors.
 

This is the second component for the reed switch to work. It is essentially a magnet, and each time it passes the detector on the fork, the counter = counter + 1. :)

At time of writing, I have travelled 5km since the last restart. It is working fine with no problems :). Today is 28 January 2004 and it is very accurate, nearest 10metres, tried and TESTED!

This concludes the projecht of:
Bike Odometer - something which measures distance!!
 This projecht made me say

'I hate this electronics!'