See also original post. An IR sensor is an electronic instrument that scans IR signals in specific frequency ranges defined by standards and converts them to electric signals on its output pin (typically called signal pin). The IR signals are mainly used for transmitting commands over the air on short distances (typically few meters) like what you’ve already worked with on TV remote controls or other similar electronic devices..
The connections are pretty easy, see the image below with the breadboard circuit schematic. The sensor will give an analog output or digital, according to the amount of IR light received. You could use this as a switch or sensor of light or fire.
We read the analog value from the sensor and print that to the serial monitor. You could make your own code and activate stuff, detect fire, etc...
// IR sensor Test
// http://www.electronoobs.com/eng_arduino_tut74.php
int LED = 11; // Use the onboard Uno LED
int isObstaclePin = 7; // This is our input pin
int isObstacle = HIGH; // HIGH MEANS NO OBSTACLE
void setup() {
pinMode(LED, OUTPUT);
pinMode(isObstaclePin, INPUT);
Serial.begin(9600);
}
void loop() {
int Value = analogRead(A0);
Serial.println("OBSTACLE!!, OBSTACLE!!");
Serial.print("Analog read: ");Serial.println(Value);
if(Value < 770)
{
digitalWrite(LED,HIGH);
}
else
{
digitalWrite(LED,LOW);
}
delay(200);
}
Upload the code and make the connections. Then open the serial monitor at 9600 bauds and you will have the analog read printed to the serial monitor. Or go below and downlaod the code with the i2c LCD.
// IR sensor Test
http://www.electronoobs.com/eng_arduino_tut72.php
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 or 0x3f for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
int LED = 11; // Use the onboard Uno LED
int isObstaclePin = 7; // This is our input pin
int isObstacle = HIGH; // HIGH MEANS NO OBSTACLE
void setup() {
lcd.init();
lcd.backlight();
pinMode(LED, OUTPUT);
pinMode(isObstaclePin, INPUT);
Serial.begin(9600);
}
void loop() {
int Value = analogRead(A0);
Serial.println("OBSTACLE!!, OBSTACLE!!");
Serial.print("Analog read: ");Serial.println(Value);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" INFRARED LIGHT ");
lcd.setCursor(5,1);
lcd.print(Value);
if(Value < 770)
{
digitalWrite(LED,HIGH);
}
else
{
digitalWrite(LED,LOW);
}
delay(200);
}
Upload the code and make the connections. Then open the serial monitor at 9600 bauds or just see the results on the LCD screen.