Interface IR distance sensor and RGB LED with NodeMCU
Use distance values from IR sensor and control color of RGB LED
Things
NodeMCU board (quantity: 1 no.)
Micro USB cable A to B (quantity: 1 no.)
Breadboard (quantity: 1 no.)
IR sensor module (quantity: 1 no.)
Common Cathode RGB LED module (quantity: 1 no.)
Jumper wire – male to male (quantity: 8 no.)
Arduino IDE on your computer
Let’s begin!
Since we can get a measure of the distance of the obstacle from the analog value of the IR sensor, we can use these values to make the RGB LED give a certain color for a particular range of distance.
Let’s make the RGB LED green when the obstacle is far, and red when the obstacle comes closer.
Interfacing IR sensor module and Common Cathode (-) RGB LED module with NodeMCU
Interfacing IR sensor module and Common Cathode (-) RGB LED module with NodeMCU
Final Code
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.