Pages: [1]   Go Down
Author Topic: Electrical to mechanical speedo  (Read 817 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there Im brand new to Arduino and to programming really. Im trying to build some code to take the signal from a magnitic switch (Bike speedo) and outputing it to a PWM output to evenutally turn a motor (Im using a LED at the moment for test purposes for output). Ive been using 'time = pulseIn(SWITCH,HIGH)' for the switch but with little success. Please see the code below. Some of the equasions ect may be incorrect but The serial output does not vary from 0. Ive double checked the inputs and everything should work, the transistor will operate for the LED and the witch gets 5 v closed and 0 v accross the input resistor.

Any sugestions is pulseIn a bad choice for this type of code?



const int LED = 9; //pin 9 for Led
const int SWITCH = 7; //input for the magnetic switch
unsigned long time;
float sped;
int level;

int diamiter = 2237; //wheel diamiter 28 in in mm
void setup()
    pinMode(LED, OUTPUT);
    //pinMode(SWITCH, INPUT);
void loop()
    time = pulseIn(SWITCH,HIGH);
    sped = 2.24*(diamiter/(time*.001));//speed in mph 2.24 converts ms-1 to mph
    level = sped*10;
    if (level >255)
     { level = 255;}

* speedo1.ino (0.55 KB - downloaded 2 times.)

Offline Offline
Edison Member
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can place your code between the code tags. Use the '#' button (above the smileys when you are writing a message).
You can also copy an URL in the text, like this:

My first thought was to measure the number of pulses during a certain time, but measuring the pulse length is a smart idea. You get the speed immediate for every rotation of the wheel. If it is accurate enough ...
But I think that the diameter of the wheel does not influence the pulse length.

But I have many questions:
- If your sketch is not working, so what is not working ? Please be more precise.
- How is the magnetic switch connected to the arduino ? can you upload a schematic ?
- Is the magnetic switch some kind of reed contact, and not some fancy hall sensor ?
- You checked the inputs ? are you sure the magnetic switch is working ?
- Can you turn the led on and off with code ?
- Is the variable 'time' chaning if you rotate the wheel with different speeds ?

Pages: [1]   Go Up
Jump to: