Pages

Monday, 16 September 2019

ESP32-IR(Infrared) SENSOR

ESP32-IR(Infrared) SENSOR

Aim:
To extract information from IR sensor.

Description:

To learn how to read values from an IR sensor using ESP32-Microcontroller.

Hardware required:

ESP32-Microcontroller Development board,
IR sensor 

Pin connection:

Pin Mapping:

IR SENSOR
ESP32
5V
5V
GND
GND
A/O
IO12

Procedure:
1.        The above pin connection shows how to read values from a IR sensor using ESP32 board.
2.        Do the connections as shown in the pin diagram and pin mapping.
3.        Connect the USB cable to the board.
4.        Open Arduino IDE .Select DOIT ESP32 DEVKIT V1 in boards and select COM port.
5.        Verify the program and upload it.
6.        Now you can see the output on the serial monitor.


Program:

/* the setup function runs once when you press reset or power the board */ 
void setup(void)
{
/* initialize digital pin 12 as an input */ pinMode(12,INPUT);
Serial.begin(9600);
}

/* the loop function runs over and over again forever */ 
void loop(void)
{
int value=digitalRead(12); if(digitalRead(12)==HIGH)
{
Serial.print("no obstacle:"); Serial.println(value); delay(1000);
}
else if(digitalRead(12)==LOW)
{
Serial.print("obstacle present:"); Serial.println(value); delay(1000);
}
}

Output:

No comments:

Post a Comment