Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Digital Speedometer (PIC16f84 & CatEye bicycle sensor)

Status
Not open for further replies.
Hello everyone,

After finishing an awesome Digital Fuel Gauge with Sir Eric, Im moving on to a new project.

Key points:

#1 I can only use PIC16f84a MCU because, its the only one available here and the only MCU in which I have a loader.

#2 We have a broken CatEye Velo 8 bicycle speedometer which stopped working a few weeks ago. Its wheel RPM sensor is still fine because only the computer stopped working (won't power or turn on).
**broken link removed**

So I need help on how to use this CatEye speed sensor to work with MCUs (PIC16f84). Im guessing that the sensor is a hall effect sensor and as observed, you can hear a 'tick' sound everytime the magnet from the spokes line up with sensor.

It would be easier to program and calculate the speed if I can convert the sensors output into an on/off signal (1 & 0 logic just like a pressed always open switch).

Schemes, designs, inputs, CatEye info's on how exactly the sensor works, and anything to help would be much appreciated.
 
Hello everyone,

After finishing an awesome Digital Fuel Gauge with Sir Eric, Im moving on to a new project.

Key points:

#1 I can only use PIC16f84a MCU because, its the only one available here and the only MCU in which I have a loader.

#2 We have a broken CatEye Velo 8 bicycle speedometer which stopped working a few weeks ago. Its wheel RPM sensor is still fine because only the computer stopped working (won't power or turn on).


So I need help on how to use this CatEye speed sensor to work with MCUs (PIC16f84). Im guessing that the sensor is a hall effect sensor and as observed, you can hear a 'tick' sound everytime the magnet from the spokes line up with sensor.

It would be easier to program and calculate the speed if I can convert the sensors output into an on/off signal (1 & 0 logic just like a pressed always open switch).

Schemes, designs, inputs, CatEye info's on how exactly the sensor works, and anything to help would be much appreciated.

hi bb,
Its possible that bicycle sensor is a reed relay, that would be the click you hear as the reed passes the magnet.
If it is reed contact it fairly easy to interface to a 16F84A.
You say the unit is faulty, so you want to take a chance, cut the wire from the click/reed end, keep the cable as long as possible. Cut close to the computer.

Connect a ohm meter across the bared ends of the wire and move the magnet near to the reed, the meter should indicate a short circuit.

Let me know what you see.
 
Last edited:
Hello Eric,

Indeed it was a reed realy. LoL! Just tested it and it shorts when the sensor is aligned with the magnet, awesome! Now, can i just pass 5v (MCU voltage) to one of the 16F84s port thru the reed relay and count the pulses? I'm gonna start writing the code now. Thanks!
 
Hello Eric,

Indeed it was a reed realy. LoL! Just tested it and it shorts when the sensor is aligned with the magnet, awesome! Now, can i just pass 5v (MCU voltage) to one of the 16F84s port thru the reed relay and count the pulses? I'm gonna start writing the code now. Thanks!

hi bb,
Add a pullup resistor to the pin that is the reed input, say 2k2 thru 4k7 should do.
EDIT:
The reed wires, one to 0V and one to the PORT pin with the pullup.

Use tmr0 as the 1 second counter [ with internal register counter] and PORTB.0 as the reed input, set for interrupt on PORTB.0 to count the pulses over one second.
What programming language do you use.?
 
Last edited:
I use mikrobasic from Microe.com. Thou I can write in C and assembly, Mikrobasic is by far the most efficient language for PIC's I've used so I'll stick to it.

Can you help me with the formula?

My tire's diameter is 114cm. What's the best way to calculate it into Km/H speed using 1 second counter (tmr0)?

Pull-up resistor noted.
 
I use mikrobasic from Microe.com. Thou I can write in C and assembly, Mikrobasic is by far the most efficient language for PIC's I've used so I'll stick to it.

Can you help me with the formula?

My tire's diameter is 114cm. What's the best way to calculate it into Km/H speed using 1 second counter (tmr0)?

Pull-up resistor noted.

hi,
The circumference is pi * D = 3.142 * 0.114mtr = 2.249 mtrs.

For every switch closure the cycle has moved 2.25 mtr/sec.

So the slowest speed/increment you can measure is 8.1km/hr

If you assume that the top speed is 81km/hour, which is 22.5mtr/sec.
which is 10 pulses/sec.

If this speed resolution is too low, you could add one or more magnets.

Let me know.
EDIT:
The above calculations are incorrect.!
 
Last edited:
I can live with the 8.1km/hr minimum so your formula is a go. My motorcycle can go as fast as 120km/hr and the original CatEye spec can read upto 300km/hr so there won't be a problem with the reed relay's limit.
 
I can live with the 8.1km/hr minimum so your formula is a go. My motorcycle can go as fast as 120km/hr and the original CatEye spec can read upto 300km/hr so there won't be a problem with the reed relay's limit.
hi,
You did say in your OP,, bicycle not motor cycle.:)
You would have to pedal very fast to reach 300km/hr..

How are you going to display the speed, also do you plan to have a 'tripometer' [ kms travelled on a lap or journey?]
 
Uh oh! I was wrong when I said 114cm wheel diameter, I meant the circumference on the previous post. So it will be 1.14m/pulse.

I'm displaying it on a 3 multiplexed 7-segments. No need for a tripometer, I would also want to have an odometer for it (saved on eeprom) and planning on using a cheap cellphone LCD to display the odometer.
 
Last edited:
Uh oh! I was wrong when I said 114cm wheel diameter, I meant the circumference on the previous post. So it will be 1.14m/pulse.

I'm displaying it on a 3 multiplexed 7-segments. No need for a tripometer, I would also want to have an odometer for it (saved on eeprom) and planning on using a cheap cellphone LCD to display the odometer.

hi,
I also got my sums wrong, got the decimal point in the wrong place...:eek:
So we agree its a pulse every 1.14mtrs of linear movement, up to a maximum speed of 120km/hr
OK, I will look at the program. will you post the program as you write it.?
 
Ok. I will post the program as I write it. Currently im still soldering the parts. Will keep you updated once I start writing. And also I don't want to put a maximum limit on the readings, just let it calculate however fast it can upto the reed relay's limit, lol.
 
Hello Eric,

Don't bother about the test code. I've coded one already and its working great. I'll borrow my GF's laptop and update you soon.

I'm also planning on not using a 1 sec timer interrupt as it will give it that dullness common to most digital speed meters. An analog feel on the meter is I think better but harder to code. I want the numbers to increase as you accelerate and decrease accordingly as you decelerate, not that instant jump to a certain speed reading after 1 sec refresh, specially when doing sudden stops or acceleration.

@Aljami, maybe you could help me on how to achieve that analog feel?
 
Hi,

Can anyone here help me with some code in Mikrobasic?

I'm not really good with timer/interrupts and I want to achieve something like these:

The timer should count pulses every 0.5 secs and it should be converted to Km/hr. Distance between pulses is 1.14m.
 
Code:
program Speedometer

dim cnt as word
dim _ones as byte
dim _tens as byte
dim _hund as byte
dim _reed as byte

sub function Mask(dim num as byte) as byte    ' this function returns masks
  select case num                             ' for common cathode 7-seg. display
    case 0  result = 252
    case 1  result = 48
    case 2  result = 218
    case 3  result = 122
    case 4  result = 54                  '00110110
    case 5  result = 110                  '01101110
    case 6  result = 238                 '11101110
    case 7  result = 56                   '00111000
    case 8  result = 254                   '11111110
    case 9  result = 126                    '01111110
  end select                                  'case end
end sub

sub procedure interrupt
    cnt = cnt + 1
    if _hund > 0 then
      PortA.1 = 0
      PortB = Mask(_hund)
    End if
    Delay_ms(5)
    PortA.1 = 1
    if _tens = 0 then
       if _hund > 0 then
         PortA.2 = 0
         PortB = Mask(_tens)
       end if
    else
      PortA.2 = 0
      PortB = Mask(_tens)
    end if
    Delay_ms(5)
    PortA.2 = 1
    PortA.3 = 0
    PortB = Mask(_ones)
    Delay_ms(5)
    PortA.3 = 1
    TMR0 = 96
    INTCON = $20
end sub

main:
    Option_reg = $84
    TrisB = 0
    TrisA = 0
    PortB = %11111111
    PortA = %00000
    'Initialize Input
    TrisB.0 = 1
    PortB.0 = 1
    'Flash for power check
    Delay_ms(1000)
    PortA = %11111
    Delay_ms(500)
    'Set variables
    _ones = 0
    _tens = 0
    _hund = 0
    _reed = 0
    'Initialize Timer
    TMR0 = 96
    INTCON = $A0
    cnt = 0
    while true
          if (cnt = 10) then
             _ones = _ones + 1
             if (_ones) > 9 then
                _tens = _tens + 1
                _ones = 0
                if (_tens) > 9 then
                   _hund = _hund + 1
                   _tens = 0
                   if (_hund) > 9 then
                      _hund = 0
                    end if
                end if
             end if
             cnt = 0
          end if
    wend
end.

Here's the code I've written so far. At this point it counts from 1 to 999 and repeats and it is displayed on a 3 multiplexed 7 segments.

This is just to test the segments and the circuit. Its pretty doing well.

My way of knowing the speed is by catching 2 pulses and count the number of 'cnt' (from the interrupt) in between the 2 pulses. If each 'cnt' is about 50ms (1000ms = 1sec) so 1sec is around 'cnt = 20'.

So example, if 'cnt = 40' in between the 2 pulses that means Im travelling at 1.14m in 2 seconds.

((1.14m/2sec) * 60 * 60) / 1000m (1Km) = 2.052 Km/hr

Will this be fine? If the pulses can go faster than the interrupt can iterate then this will not work.

Its 4AM now... gotta sleep.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top