Toll-Free Customer Support 24/7

IR AURDUINO code

/*
 * Project name:
     IR sensor  
 * Copyright
     (c) Researchdesignlab.com
 * Description:
    
 * Test configuration:
     MCU:             ATMEGA328
     Dev.Board:       Arduino uno
     Oscillator:      16 MHz
     Software:        Arduino

*/


#include <LiquidCrystal.h>  // initialize the library with the numbers of the                                   

LiquidCrystal lcd(6, 7, 2, 3, 4, 5);            
   
/*
 * LCD RS pin to digital pin 6
 * LCD Enable pin to digital pin 7
 * LCD D4 pin to digital pin 2
 * LCD D5 pin to digital pin 3
 * LCD D6 pin to digital pin 4
 * LCD D7 pin to digital pin 5
 * LCD R/W pin to ground  */

const int irPin = 12; 
int irState = 0;

void setup() 
{ 
  pinMode(irPin, INPUT);            // initialize the IR sensor pin as an input:   
  
  lcd.begin(16, 2);                  // set up the LCD's number of columns and rows:
 
}

void loop() 
{
 irState = digitalRead(irPin);
// if it is, the IR sensor is HIGH:  

 if(irState == LOW)
 { 
   lcd.setCursor(0,1);   
   lcd.print("IR HIGH");            // Print a message to the LCD.
 
 }
 
else
{
  lcd.setCursor(0,1);
  lcd.print("IR LOW");

}
}

Back to top