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