Hello. Could someone please help me to use this speed measuring module? I'm not really good at robotics and it's my first work and I don't know how to use it
Thanks!
Maybe you should tell us the name of the module with a link... From the picture I could say that it's an optical sensor for an encoder, so you have to start reading some guides on how encoders work and how use it for your purpose
Mine looks something like this but it's a bit different. I bought it in Lithuania and in our page there is no code or exactly model.
Your module is probably an "optointerruptor", which means it detects when something blocks light passing between the two black posts. Unfortunately you are showing only the back side of the sensor.
They can be used with slotted disks to measure shaft rotation rates.
In your case, connect GND to GND (on the Arduino), VCC to VCC and OUT to a digital input. Read the digital input and check for a "1" or "0" depending on whether the light path is blocked.
It's a stretch to call that a speed detector if it's just an opto-interrupter: you have to do all the speed related stuff yourself.
Use a method like in State Change Detection and take the time with millis() every time it goes (say) high, and subtract the times to get a time between slots.
Then calculate rpm based on the time between slots and the number of slots per revolution.
Mine speed module works when a wheel goes round, it sends 1 or 0.So I need to calculate times when 1 is pressed, right?
The time between successive 1s or 0s is inversely proportional to the wheel rotation rate.
I remembered I had done some messing around with a similar configuration. You're welcome to it but remember, YMMV.
This is not a complete sketch necessarily: I just pulled some parts out of a bigger one. It does at least compile.
byte pulsesPerRev = 1; // this is to do with how many slots
unsigned long prevMillis = 0;
unsigned long nowMillis = 0;
unsigned long pulseTime ;
boolean sensorState;
boolean lastSensorState;
byte sensorPin = 2;
int motorSpeedActual =0; //rpm
void setup()
{
 pinMode(sensorPin, INPUT_PULLUP);
}
void loop()
{
 calcMotorSpeedActual();
}
void calcMotorSpeedActual()
{
 sensorState = digitalRead(sensorPin);
 if ((sensorState != lastSensorState) && sensorState == HIGH) //changed and HIGH means just got interrupted
 {
  nowMillis = millis();
  pulseTime = nowMillis - prevMillis;
  motorSpeedActual = 60000 / pulsesPerRev / pulseTime;
  Serial.print(pulseTime);
  Serial.print(" ");
  Serial.println(motorSpeedActual);
  prevMillis = nowMillis;
 }
 lastSensorState = sensorState;
}// calcMotorSpeedActual
ardy_guy:
I remembered I had done some messing around with a similar configuration. You're welcome to it but remember, YMMV.This is not a complete sketch necessarily: I just pulled some parts out of a bigger one. It does at least compile.
byte pulsesPerRev = 1; // this is to do with how many slots
unsigned long prevMillis = 0;
unsigned long nowMillis = 0;
unsigned long pulseTime ;
boolean sensorState;
boolean lastSensorState;
byte sensorPin = 2;
int motorSpeedActual =0; //rpm
void setup()
{
pinMode(sensorPin, INPUT_PULLUP);
}
void loop()
{
calcMotorSpeedActual();
}
void calcMotorSpeedActual()
{
sensorState = digitalRead(sensorPin);
if ((sensorState != lastSensorState) && sensorState == HIGH) //changed and HIGH means just got interrupted
{
nowMillis = millis();
pulseTime = nowMillis - prevMillis;
motorSpeedActual = 60000 / pulsesPerRev / pulseTime;
Serial.print(pulseTime);
Serial.print(" ");
Serial.println(motorSpeedActual);
prevMillis = nowMillis;
}
lastSensorState = sensorState;
}// calcMotorSpeedActual
That should be a good beginning. The devil is in the details, as they say. You have the situation where there is no speed at the beginning of a timing session, and a situation at the end, where the coded wheel may stop on a slot or may stop on a black area.
Paul
Hi Guys,
I just joined the forum and wonder where I should post a question regarding questions about GPS setup. I followed the examples on YouTube religiously but there is no transfer of valid data through the Uno to the serial display. Thank you.