Hi all,
I read some other forums on how to get the vex range finder to work with the arduino uno. I am having some troubles though. The only numbers i have been able to get are 5 digit numbers in the 30,000 range. This is the code I used that supposedly worked for someone else but gives me these funky numbers that dont even correspond to how close an object is to the range finder.
Code
/*
Uses the Vex Range Finder in conjunction with
Arduino Mega 2560
Pin 13 Triggers the Pulse (Yellow lead)
Pin 10 Recieves the Echo (Orange lead)
*/
const int Trig_pin = 13; // pin for triggering pulse
const int Echo_pin = 10; // pin for recieving echo
long duration;
void setup() {
Serial.begin(9600);
Serial.println ("Starting");
// initialize the pulse pin as output:
pinMode(Trig_pin, OUTPUT);
// initialize the echo_pin pin as an input:
pinMode(Echo_pin, INPUT);
}
void loop(){
digitalWrite(Trig_pin, LOW);
delayMicroseconds(2);
digitalWrite(Trig_pin, HIGH);
delayMicroseconds(10);
digitalWrite(Trig_pin, LOW);
duration = pulseIn(Echo_pin,HIGH);
Serial.println("Duration: ");
Serial.println(duration, DEC);
}
funky numbers ----
36731
0
36730
0
36728
0
36733
0
36732
0
36732
0
36731
0
36732
0
36732
0
36733
0
36732
0
36735