SparkFun Forums 

Where electronics enthusiasts find answers.

General suggestions or questions about the SparkFun Electronics website
By leo357leo
#98910
I want a buzzer to go off when my IR sensor (which is in a stationary position) senses a change in distance( call the change in distance x for this purpose), and the initial Distance= distance1. Any ideas? I'm using an Arduino.

I already have the program to measure distance:
int IRpin = 1; // analog pin for reading the IR sensor

void setup() {
Serial.begin(9600); // start the serial port
}

void loop() {
float volts = analogRead(IRpin)*0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
float distance = 65*pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
Serial.println(distance); // print the distance
delay(10); // arbitary wait time.
} Thanks