Hi All,
Here is the info on the RPM Sensor.
Circuit - Signal is connected to digital pin
Photo - Yes the bike wheel shaft does come out of the workshop wall.
The resistors are on a small circuit board under the bracket.
Sketch:
/* RPM sensor using a Reflective Object Sensor OPB705WZ from OPEK Technology
Using pulseIn() to measure a high pulse length in micro seconds
Reflective surface is aluminium dsk with two black quadrants painted on
Convert pulse time to RPM. Print out duration and RPM to serial monitor.
*/
int pin = 7;
float RPM;
unsigned long duration;
void setup()
{
Serial.begin(9600); // initialize serial communication at 9600 bits per second:
pinMode(pin, INPUT);
}
void loop()
{
duration = pulseIn(pin, HIGH); // read HIGH, duration = 1/4 rotation
if(duration > 5000) // duration of 5000 micro seconds limits speed to 3000 RPM. This stops erroneous data caused by transient spikes
{
RPM = (15000000.0/duration); // (1000000uS * 1/4 * 60s) / duration = 15000000.0 / duration keeps calculation simple
Serial.print(duration);
Serial.print(" micro seconds ");
Serial.print(RPM);
Serial.println(" RPM");
delay(10); // delay
}
}
I hope this sketch is readable. Any suggestions welcome.
Peter
Here is the info on the RPM Sensor.
Circuit - Signal is connected to digital pin
Photo - Yes the bike wheel shaft does come out of the workshop wall.
The resistors are on a small circuit board under the bracket.
Sketch:
/* RPM sensor using a Reflective Object Sensor OPB705WZ from OPEK Technology
Using pulseIn() to measure a high pulse length in micro seconds
Reflective surface is aluminium dsk with two black quadrants painted on
Convert pulse time to RPM. Print out duration and RPM to serial monitor.
*/
int pin = 7;
float RPM;
unsigned long duration;
void setup()
{
Serial.begin(9600); // initialize serial communication at 9600 bits per second:
pinMode(pin, INPUT);
}
void loop()
{
duration = pulseIn(pin, HIGH); // read HIGH, duration = 1/4 rotation
if(duration > 5000) // duration of 5000 micro seconds limits speed to 3000 RPM. This stops erroneous data caused by transient spikes
{
RPM = (15000000.0/duration); // (1000000uS * 1/4 * 60s) / duration = 15000000.0 / duration keeps calculation simple
Serial.print(duration);
Serial.print(" micro seconds ");
Serial.print(RPM);
Serial.println(" RPM");
delay(10); // delay
}
}
I hope this sketch is readable. Any suggestions welcome.
Peter
Comment