I have a 180 degree rotation servo. I mounted the ultrasonic sensor to this servo. Both are powered from 5v pin of arduino duemilanove.
I want to rotate the servo every 90 degrees and take a ping reading. I am giving a delay of 2000 milliseconds after invoking the servo rotation call.
apparently, the delay is observed. But, the ping reading is not working all the times. ping is doing a sensor reading only on one specific angle [I believe it is at 180 degrees].
If I do not rotate the servo and just take the ping readings for every 2 seconds. that works like a charm. I am really confused and wondering what is the wrong I am doing ?? :-/
int front, left, right;
while(intialReading == 0) {
front = ping(0);
Serial.println(front);
left = ping(1);
Serial.println(left);
right = ping(2);
Serial.println(right);
}
The output may be correct. You don't say anything about what is in front of the ping sensor at each position. If there is nothing near the sensor at the 180 degree position, and there is at the 0 and 90 degree position, the output could be correct.
What version of the IDE are you using? What pins are the servo and ping sensor connected to?
hmm .. actually there are objects at a distance of 1 to 3 feet on all 3 angles [0, 90, 180].
If I do not rotate the servo, the ping sensor is taking the readings every 2 seconds. [If I rotate it using the hand .. it was finely taking the readings as expected]
Ping sensor is connected to port 7 and Servo is connected to port 9.
Please let me know if you need more information. Greatly appreciate your help.
Probably this might be a very common thing to do in robotics. to mount a sensor onto a servo and rotate it using the servo. Wondering if anybody have a sample code to achieve this and would like to share it? Thanks a lot !!
Since there is no load on the servo (nothing to make it drift), you might try detaching the servo before doing the ping sensor stuff, and then reattaching the servo.
I am rotating the servo .. giving it 2 secs to complete the rotation. Then detach it. wait another 2 secs. take ping reading and attach the servo back ..
Working excellent !! I am wondering if for some reason .. the board was unable to supply required power to run both servo and sensor. I will probably run the sensor using an external source and see if that will work.
will update here !! hoping it may help others with similar problem !! Thanks !!
I was trying to run a servo motor and an infrared sensor but everytime I hooked them both up the timing values I read from the infrared were screwed up. It was only when I hooked up a different power source to run the servo from the arduino when I got it work. I connected the grounds together.