Pages: [1]   Go Down
Author Topic: shortest code for techometer using reed switch  (Read 514 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i want the shortest possible  code for tachometer using reed switch. plz help
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25671
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't use a reed, they bounce.
Use a digital Hall effect.

Where is your code so far?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33295
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i want the shortest possible  code for tachometer using reed switch. plz help
Why is it for a compertition?
Short code is very often the most difficult to read and understand.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

actually i want to measure the speed of my bicycle using arduino, and i have ready made reed switch assembly available to be placed on bicycle
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13477
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
uint32_t x;float d=1;void setup(){}void loop(){if(digitalRead(4))x++;Serial.println(x*P*d);}
Can't make it shorter than 1 line smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8662
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Connect the reed switch through a circuit that will produce a fixed-length LOW pulse.  In the example below the LOW time has been determined experimentally to be 3446 microseconds.  Add the LOW time to the HIGH time measured by 'pulseIn()' to get microseconds per revolution.  Divide that into microseconds per minute (60 * 1000 * 1000) to get REVOLUTIONS PER MINUTE.

Code:
int RPM = 60000000UL / (pulseIn(5, HIGH)+3446);

Because of the LOW pulse time the maximum measurable RPM is around 17,000.  How short a LOW pulse you can use depends on the bounce time of your reed switch.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25671
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the maximum measurable RPM is around 17,000
It's a bicycle - that's unlikely to be a problem.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanx... and from this speed i want to drive a high torque servo motor which is connected to the gear shifter. so at regular speed interval gear shift can be achieved.  so please provide me with an ultra responsive code which would perform this job perfectly.  Assume every gear shift at 10 degree of servo rotation for every increment in speed of 5 km/hr
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13477
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
thanx... and from this speed i want to drive a high torque servo motor which is connected to the gear shifter.
OK,

Quote
so please provide me with an ultra responsive code which would perform this job perfectly. Assume every gear shift at 10 degree of servo rotation for every increment in speed of 5 km/hr.
Sorry, helped you to get started, now it is your turn to do some coding (we help people here to help themselves)

After a serious try you can post your code and we will help you to make another step.


Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanx  smiley i undestand
Logged

Pages: [1]   Go Up
Jump to: