Introduction: Interface InfraRed Sensor Using NodeMCU

Hello Makers,

I'm back with another simple Instructable.

In this Instructable we will learn how to interface IR (InfraRed) sensor with NodeMCU.

Step 1: Things Needed

All you need to get started with this instructables is,

Hardware Required

  • NodeMCU
  • Bread Board
  • IR sensor
  • 100 ohm Resistor
  • LED
  • Jumper Wires

Software Required

  • Arduino IDE

Step 2: Description

An infrared sensor is an electronic instrument which is used to sense certain characteristics of its surroundings by either emitting and/or detecting infrared radiation. Usually in the infrared spectrum, all the objects radiate some form of thermal radiations. These types of radiations are invisible to our eyes, that can be detected by an infrared sensor.

Step 3: Connections

Connecting IR sensors to a NodeMCU is really simple. The IR acts as a digital output so all you need to do is operate the pin to flip high (detected) or low (not detected). Check out the images for more details.

Power is usually 3-5v DC input. Every IR modules have a 3-pin connection.

The circuit connections are made as follows:

Vcc pin of the IR module is connected to +3v of the NodeMCU.

Output pin of the IR module is connected to Digital pin D7 of the NodeMCU.

GND pin of the IR module is connected to Ground pin (GND) of the NodeMCU.

In this example we'll connect Anode pin of the LED to Digital pin D6 and Cathode pin to GND pin of NodeMCU.

Before you get started with coding you need Arduino IDE. To download Arduino IDE and for NodeMCU setup, you can check my previous instructacle.

Interfacing Servo Motor With NodeMCU

Step 4: Distinguish Between LEDs

IR Transmitter

Infrared Transmitter is a light emitting diode (LED) which emits infrared radiations. Hence, they are called IR LED’s. Even though an IR LED looks like a normal LED, the radiation emitted by it is invisible to the human eye.

IR Receiver

Infrared receivers are also called as infrared sensors as they detect the radiation from an IR transmitter. IR receivers come in the form of photodiodes and phototransistors. Infrared Photodiodes are different from normal photo diodes as they detect only infrared radiation. The picture of a typical IR receiver or a photodiode is shown below.

Step 5: Let's Start Coding

The code is very simple, and is basically just keeps track of whether the input to Digital pin D7 is HIGH or LOW. It also tracks the state of the pin, so that it prints out a message when Object has detected or not.

int ledPin = 12; // choose pin for the LED
int inputPin = 13; // choose input pin (for Infrared sensor) int val = 0; // variable for reading the pin status

void setup()
{ pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inputPin, INPUT); // declare Infrared sensor as input }

void loop()
{ val = digitalRead(inputPin); // read input value if (val == HIGH) { // check if the input is HIGH digitalWrite(ledPin, LOW); // turn LED OFF } else { digitalWrite(ledPin, HIGH); // turn LED ON } }

Download the "IR.ino" file and open it up in the Arduino IDE.
Then Create a new sketch and paste the code below in the Arduino IDE and hit Upload You can tinker with the code to make it more useful or just use it as it is.

Step 6: That's It Enjoy

It takes less time to create this instructable, and its fun too.

Thank you Makers!!

For taking your time to read my instructable. I hope you enjoy it as I enjoy making it and documenting it to show and tell to other fellow makers here.

CIAO!! with another interesting Instructables!

Comments

About This Instructable

578views

18favorites

License:

Bio: Work until you no longer have to introduce yourself.
More by TheCircuit:Carrot Almond MilkshakeDIY - Flower VasePotato Stuffing - Who's Hungry
Add instructable to: