# programming quetion

**URL:** <https://community.sparkfun.com/t/programming-quetion/15410>\
**Category:** SparkFun Site Questions/Comments\
**Created:** [April 20, 2010, 11:31am UTC](https://community.sparkfun.com/t/programming-quetion/15410 "2010-04-20T11:31:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![leo357leo](https://avatars.discourse-cdn.com/v4/letter/l/e9bcb4/32.png) [@leo357leo](https://community.sparkfun.com/u/leo357leo)\
**Post date:** [April 20, 2010, 11:31am UTC](https://community.sparkfun.com/t/programming-quetion/15410/1 "2010-04-20T11:31:23Z")

</div>

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](http://luckylarry.co.uk)

Serial.println(distance); // print the distance

delay(10); // arbitary wait time.

} Thanks
