Saturday, March 13, 2010

March Madness Entry 13

Finally got an Arduino of my own, so I figured while I'm traveling I'll get a simple Arduino program up and running. No video or pictures as I'm in Philly. Simple, short script to get myself up to speed with the Arduino.

The formula I used to calculate the actual distance is linearizing the otherwise cubic return of a typical Sharp IR rangefinder - a popular, easy to use rangefinder that simply returns an analog voltage. This formula can be found in a datasheet provided by Sharp. It may require some minor adjustments for different Sharp sensors.

/*
Sample simple program by Keith Chester

Just print out the distance read from a SHARP IR Rangefinder.
*/

int IR_signal_pin = 1;

void setup(){
  Serial.begin(9600);
}

void loop(){
  int IR_raw_read = analogRead(IR_signal_pin);
  int actual_distance = (6787 / (IR_raw_read - 3)) - 4;
  Serial.println(actual_distance);
}

No comments:

Post a Comment