Distance sensor for Rover5

If we take a look at the pins on the arduino we see it goes GND, VCC, SENSOR.

IMG_0453

And if we look at the pinout from the distance sensor on the end of the lead we see SIGNAL, GND, VCC or VCC, GND, SIGNAL. Either way it isn’t going to work.

IMG_0454

So, as a crude fix I just swapped the red and the black cables around half way down the cable and then used electrical tape to label the plug pins correctly.

IMG_0457

Then I ran some basic test code on the Arduino and read in the values from the sensor. It seems that numbers under 10 are very close objects, 10 – 20 near by, and anything over 100 seems to mean nothing much around. Will need to do some more tuning later on this I expect.

Screen Shot 2013-05-18 at 8.27.49 PM

Here’s my current test code:

#include <SoftwareSerial.h>
int i;
int val;
int redpin=6;
void setup()
{
pinMode(redpin,OUTPUT);
Serial.begin(9600);
}
void loop()
{
int i=analogRead(redpin);
int val=(6762/(i-9))-4;
Serial.println(val);
delay(1000);
}
Share on Facebook

Leave a Comment