You are on page 1of 2

/*

CoasterBot Sensor test


March-May 2010
for MAKE Robot build challenge

Brian Smith
Black Dog Robotics

Test Coasterbot sensors


4 x Sharp Digital IR
1 x Maxbotix sonar
*/

// set pin numbers:


#define LED_PIN 13// the number of the LED pin
#define LF_IR 2// left front IR
#define RF_IR 3// right front IR
#define LR_IR 4// left rear IR
#define RR_IR 5// right rear IR
#define SONAR 0
void setup() {
// initialize the LED pin as an output:
pinMode(LED_PIN, OUTPUT);
// digital inputs
pinMode(RF_IR, INPUT);
pinMode(LF_IR, INPUT);
pinMode(RR_IR, INPUT);
pinMode(LR_IR, INPUT);
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// flash ready
digitalWrite(LED_PIN, HIGH);
delay(1000);
digitalWrite(LED_PIN, LOW);
}
//
//
//
void loop()
{
int rawSonar =analogRead(SONAR);
// note - this conversion is approximate!
// maxbotix returns 0.01V/inch starting at 6" from front of senso
// also seems to float a bit, might be Arduino A2D or sensor
// need to look at output voltage for a stable distance to verify
// but this will get me close anyway.
float convertedSonar = (float)rawSonar * 0.49;
Serial.print("Sonar ");
Serial.print(rawSonar);
Serial.print("/");
Serial.print(convertedSonar);
Serial.print(" in ");
Serial.print(" RF ");
Serial.print(digitalRead(RF_IR) == HIGH ?"Clear" :"Blocked");
Serial.print(" LF ");
Serial.print(digitalRead(LF_IR) == HIGH ?"Clear" :"Blocked");
Serial.print(" RR ");
Serial.print(digitalRead(RR_IR) == HIGH ?"Clear" :"Blocked");
Serial.print(" LR ");
Serial.print(digitalRead(LR_IR) == HIGH ?"Clear" :"Blocked");
Serial.println("");
delay(1000);
}

You might also like