Hi, all,
I'm new here. I read the sticky posts. I am a huge newbie to both building and programming. Please feel free to correct me if I'm doing this post wrong.
What I'm trying to do:
Test IR distance sensors. These sensors (all Sharp; mostly GP2Dxxx) will eventually go in a mini sumo robot, but right now, I just want to make sure they work, and test the readings at different distances from a target object.
What I've done:
- Tested my Arduino board to make sure it was working. New board. Uploaded Blink. It worked.
- Connected sensor to board using diagram from sensor specs: http://www.sharpsma.com/webfm_send/1205 (that is, connected to ground, 5V, and an analog pin -- tried 9, 10, and 11)
- Ran the program below and got all readings around 300, varying by a little
- Moved target objects around for a while and readings all stayed the same, no matter what pin I was hooked up to
- Went to my dad, the robotics professor, and asked him what's going on. He hooked up a potentiometer and I wish I could remember exactly what made him say this, but he said he thought there was probably an issue with my board, because he could see I was making a connection.
- Tried the same setup with multiple Arduino boards (extras he had lying around) and multiple sensors (ditto) and got the same result. Figured maybe the code's just wrong, unless it's true that all five Arduinos are b0rked.
The code:
int IR_SENSOR1 = 9;
int IR_SENSOR2 = 10;
int IR_SENSOR3 = 11;
int irV1 = 0;
int irV2 = 0;
int irV3 = 0;
void setup() {
Serial.begin(9600);
pinMode(9,INPUT);
pinMode(10,INPUT);
pinMode(11,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// read the value from the ir sensors
irV1 = analogRead(IR_SENSOR1);
irV2 = analogRead(IR_SENSOR2);
irV3 = analogRead (IR_SENSOR3);
Serial.println("Here are your sensor readings");
Serial.println(irV1);
Serial.println(irV2);
Serial.println(irV3);
delay(500);
}
The way it looked to me was something like this:
Here are your sensor readings
293
300
295
Here are your sensor readings
300
302
294
and so on.
Can you give me some idea of what to try next?