Login

Interface IR sensor with NodeMCU

Objectives

  • Learn to interface the IR sensor with NodeMCU
  • View digital and analog outputs of the sensor on the Serial Monitor

Things

  1. NodeMCU board (quantity: 1 no.)
  2. Micro USB cable A to B (quantity: 1 no.)
  3. Breadboard (quantity: 1 no.)
  4. IR sensor module (quantity: 1 no.)
  5. Jumper wire – male to male (quantity: 5 no.)
  6. Arduino IDE on your computer

Let’s begin!

An IR sensor has two bulbs on its head. The transparent one is an IR LED and the darkened one is an IR photo-diode. The LED sends a beam of IR light and the photo-diode receives reflected beams of IR light. The amount of reflected light gives an idea of the distance of an obstacle.

Most IR sensors have only a digital output. This output gives either a HIGH or LOW signal depending on whether the obstacle is close or far from a certain threshold. This threshold is set using a potentiometer present on the sensor.

A few IR sensors also come with an additional analog output. This gives a measure of how much reflected light is actually being received by the IR photo-diode.

 

IR sensor

 

Interfacing IR sensor module‘s digital pin with NodeMCU

 

Interfacing IR digital sensor module with NodeMCU

 

Final Code – Digital IR sensor

To copy the code, right click on view raw at the bottom of the code, click on open link in new tab and then copy the code.

Interfacing IR sensor module‘s analog pin with NodeMCU

 

Interfacing IR digital sensor module with NodeMCU

 

Final Code – Analog IR sensor

To copy the code, right click on view raw at the bottom of the code, click on open link in new tab and then copy the code.

There you go!

Takeaway

Loader Loading...
EAD Logo Taking too long?
Reload Reload document
| Open Open in new tab

We would love to see what you build out of these learnings!

Click here to submit your projects, share it with the world and stand a chance to be rewarded.

top

Knowledge and Content by Li2 Technologies | © 2021 NASSCOM Foundation | All rights reserved

X