The detailed objective of this tutorial is to build and program a system that controls the colors of an RGB LED using an infrared (IR) remote control, with the help of an ESP8266 NodeMCU board and an infrared receiver sensor KY-032.
Through this project, you will learn step-by-step how to:
- discover how an IR remote sends coded signals as pulses of infrared light.
- learn how the KY-032 sensor receives and decodes these signals to be interpreted by the ESP8266 NodeMCU.
- connect the KY-032 sensor to the appropriate GPIO pins of the ESP8266.
- understand the function of each pin (VCC, GND, OUT) and how digital signals are transmitted.
- use the ir_rx library to read and decode signals sent from the remote control.
- assign different IR codes to specific color outputs of the RGB LED (e.g., red, green, blue, or combinations).
- light up the RGB LED in different colors based on the button pressed on the IR remote.
- turn the LED on/off or change brightness and color dynamically.
1- ESP8266 NodeMCU Board
The main microcontroller that receives the IR signals, decodes them, and controls the RGB LED.
2- KY-032 Infrared Receiver Sensor
It detects the infrared signals sent by the IR remote control and sends a digital signal to the ESP8266.
3- IR Remote Control
It is used to send infrared commands (button presses) to the KY-032 sensor. Each button sends a unique signal code.
4- RGB LED module
It is a module containing a common anode or cathode RGB LED with built-in resistors (simplifies wiring).
5- Breadboard
It is used for making temporary connections between components without soldering.
6- Jumper Wires
It is used for connecting the ESP8266 NodeMCU with the RGB LED and the KY-032 sensor on the breadboard.
For RGB LED module :
1- Connect pin R (red) of RGB LED module to D0 (GPIO16) of the ESP8266 board
2- Connect pin G (green) of RGB LED module to D1 (GPIO5) of the ESP8266 board
3- Connect pin B (blue) of RGB LED module to pin D2 (GPIO4) of the ESP8266 board
4- Connect pin GND of RGB LED module to pin GND of the ESP8266 board
For KY-032 sensor :
1- Connect pin OUT of KY-032 sensor to pin D3 (GPIO0) of the ESP8266 board
2- Connect pin VCC(+) of KY-032 sensor to pin 3V of the ESP8266 board
3- Connect pin GND of KY-032 sensor to pin GND of the ESP8266 board
The MicroPython program allows the ESP8266 NodeMCU to receive and decode infrared signals from an IR remote control using the KY-032 infrared sensor and to control the RGB LED colors according to the buttons pressed on the remote.
The MicroPython program:
1- detects IR signals using the KY-032 sensor.
2- decodes the received IR codes through the ESP8266 NodeMCU.
3- matches each code with a predefined LED color.
4- lights the RGB LED in the corresponding color.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# More details can be found in TechToTinker.blogspot.com # George Bantique | tech.to.tinker@gmail.com import machine from ir_rx import NEC_16 led_red=machine.Pin(16, machine.Pin.OUT) led_grenn=machine.Pin(5, machine.Pin.OUT) led_blue=machine.Pin(4, machine.Pin.OUT) ir_gpio=machine.Pin(0, machine.Pin.IN) def ir_callback(data, addr, ctrl): global ir_data global ir_addr if data > 0: ir_data = data ir_addr = addr print('Data {:02x} Addr {:04x}'.format(data, addr)) ir = NEC_16(ir_gpio, ir_callback) ir_data = 0 ir_addr = 0 while True: if ir_data > 0: # if we receive a signal from IR remote if ir_data==0x0C: # press button 1 on the remote control led_red.value(1) # Turn on red LED if ir_data==0x18: # press button 2 on the remote control led_green.value(1) # Turn on green LED if ir_data==0x5E: # press button 3 on the remote control led_blue.value(1) # Turn on blue LED if ir_data==0x08: # press button 4 on the remote control led_red.value(0) # Turn off red LED if ir_data==0x1C: # press button 5 on the remote control led_green.value(0) # Turn off green LED if ir_data==0x5A: # press button 6 on the remote control led_blue.value(0) # Turn off blue LED ir_data = 0 |
Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.
Zaouiet Kontech-Jemmel-Monastir-Tunisia
+216 92 886 231
medaliprof@gmail.com
Robotic site created by MedAli-Teacher info