Infrared Obstacle Detector
Infrared Obstacle Detector Arduino compatible Detects obstacles between 2 and 30 cm from the sensor Sensitivity adjustable via on-board potentiometer
- Code
- Questions & Answers
- Specifications
basic Infrared Obstacle Detector Arduino compatible
Open the serial port and set to 9600 Baud Use the inbuilt potetial meter to adjust sensitivity Put an object in front of the IR-Sensor to trigger a count The program will count the number of times that the module has been triggered
/**************************** ***** Infrared Sensor ***** ***************************** Connections: VCC to 5V GND to GND OUT to Pin 7 ************************************************************* Open the serial port and set to 9600 Baud Use the inbuilt potetial meter to adjust sensitivity Put an object in front of the IR-Sensor to trigger a count *************************************************************/ // Declare Input Pin int irSensor = 7; // Set printed boolean to false to stop multiple prints bool printed = false; // Set count interger int i = 0; void setup() { // Open a Serial port to 9600 Baud Serial.begin(9600); Serial.println("Automation Bros test program for Infrared Proximity Sensor"); Serial.println(""); // Print a blank line Serial.println("Ready"); Serial.println(""); // Print a blank line // Declare digital pin 7 as an input pinMode(irSensor, INPUT); } void loop() { // Declare an interger to read the irSensor value int sens = digitalRead(irSensor); if (sens) { printed = false; delay(10); // De-Bounce Delay (give the sensor time to reset otherwise you may get false counts) } else if (!sens && !printed) { i += 1; // Add 1 to the count value Serial.print("The IR-Sensor has been triggered "); Serial.print(i); // if the count = 1 say time if (i == 1) { Serial.println(" time"); Serial.println(""); // Print a blank line printed = true; } // if the count is greater than 1 say times else { Serial.println(" times"); Serial.println(""); // Print a blank line printed = true; } } }
Infrared Obstacle Detector
Infrared Obstacle Detector Arduino compatible 2 Inbuilt LEDs 1 for Power and 1 to indicate that an object has been detected Adjustable potetiometer to adjust sensitivity 3 Pins: VCC / GND / OUT (Connection instructions are in the comments at the top of the example code). Active LOW When an object is detected the OUT pin will go LOW NOTE: Does not detect BLACK objects as it absorbs most of the IR light