Hi guys! This is my first time in this website. Just newly found out this community of robot enthusiasts, so I guess, and I hope you can help me with this problem, and by the way, I'm also a beginner of this one..
I just brought an ultrasonic sensor. Well it's working well after testing it with a code. But once I put some "if, else" statements, it's giving me inaccurate distances...
for instance... if I give the loop as ReadDist(); (// It is assumed that I've already put the right code for the Ultrasonic Sensor).
void loop()
{
ReadDist();
}
... then its giving me accurate distances in inches in the serial monitor...
(5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5) // so with that, we can conclude that it's working well with readings saying that the object is still in front without any movements...
but with this...
void loop()
{
ReadDist();
if (inches > 3)
{
forward();
delay(100);
}
else
{
halt();
delay(100);
}
the readings are very inaccurate... (5,5,0,5,5,5,0,5,0,5,0,5,0,5,0,0,5,5 and so on...) it's causing the wheels to stop for 0.1 sec. every time it drops to 0 , a thing that I dont want to happen for the distance that I gave from the sensor is still greater than 3 inches...
What could be the possible reasons why it's happening? any advices/suggestions guys?
- Ellimenopy