Just started learning Arduino and did some amazing personal projects. but now I am a bit trouble by a simple project which is giving me errors.
1.) I am trying to make my own encoder disc to measure a distance when a pin is high.
2.) The encoder disc I used has 90 degree slots which will measure every 90 degree using a photo electric sensor.
3.) I encountered when my motor is not turning and a pin is high, the Arduino is still measuring.
4.) Motor is variable speed so i cannot use delays.
ninetydegree = digitalRead(7);
if (ninetydegree == HIGH) {
distanceSensor.startRanging();
while (!distanceSensor.checkForDataReady());
int distance = distanceSensor.getDistance();
distanceSensor.clearInterrupt();
distanceSensor.stopRanging();
Serial.println(distance);
}
I need to make one time measurement when pin(7) gets high. but my code just throws lots of data into serial even when my motor is not moving and pin(7) is high.
Could you guys help me with that? I hope I have explained my problem clearly.
Thank you for noticing my post larryd. its a bit messy on a breadboard (rats nest). I am using a VL53L1x (I2C), H-Bridge for the motor(12V), a photoelectric sensor (below photo) on an Arduino Nano.
Sorry evanmars, i dont get what you mean. i checked pinout of photo electric sensor and once its blocked the output goes low. @6v6gt, doing it right now.