/* Open Source Arduino Code for a Infrared Proximity Switch http://creativecommons.org/license/cc-gpl */ //The sensor's analog output ranges between 3.2V for an object 6cm away to 0.4V at 80cm away. Non-linear V-D relationship; check the sensor datasheet for a graph. int sensorpin = A0; // analog input pin to read sensor output int outputpin = 13; // digital output pin to send trigger signals int i; //variable for sample repetition count int samplenumber = 50; //number of samples per reading float samples[50]; //variables to store sample values int sampledelay = 10;//time delay per sample float sense = 0; //analog reading variable float hightrigger = 1; //trigger value to activate float lowtrigger = 0.5; //trigger value to deactivate int loopdelay = 10; //time delay at end of loop void setup() { Serial.begin(9600); // start serial communication between the computer and the Arduino microcontroller pinMode(sensorpin, INPUT); //The sensor pin is designated as an input pinMode(outputpin, OUTPUT); //The output pin is designated as an output } void loop() { for(i = 0;i hightrigger){ digitalWrite(outputpin, HIGH); } if (sense < lowtrigger){ digitalWrite(outputpin, LOW); } delay(loopdelay); }