I have a motor passing a bar through an IR slot sensor similar to this one.
every time the bar passes through, the LED on D13 comes on (or flashes as the bar passes through)
The sketch is here
/*
monitor a motor passing a bar through an ir slot sensor and turning the led on D13
on every pass.
*/
int buttonstate;
int sensorValue;
int outputValue;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(4,INPUT_PULLUP);
pinMode(5,OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
sensorValue = analogRead(A0);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(5,outputValue); //drive motor
// Serial.print(outputValue);
buttonstate = digitalRead (4);
if (buttonstate == LOW)
{
digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
delay(1); // wait for a second
}
else
{
digitalWrite(13, HIGH); // turn the LED off by making the voltage LOW
delay(1); // wait for a second
}
// Serial.println(buttonstate);
}
Is there any way of being able to turn the signal into an RPM of the motor that can be printed, say, on the monitor?
Even if the RPM is completely wrong and needs to be manipulated to make it similar to the actual RPM of the motor.
Thanks.