The KY-032 Infrared Sensor is a module that is commonly used in electronics and robotics projects for detecting the presence of infrared signals. It is also known as an infrared obstacle avoidance sensor module. The module consists of an infrared emitter (LED) and an infrared receiver (phototransistor) placed side by side.
Here are some key features and characteristics of the KY-032 Infrared Sensor:
1- Detection Method: The sensor module detects infrared light by emitting a modulated infrared signal and measuring the reflection. When an object is present in front of the module, the infrared light emitted by the LED bounces off the object and is detected by the phototransistor.
2- Operating Voltage: The KY-032 module typically operates at a voltage range of 3.3V to 5V, making it compatible with most microcontrollers and development boards.
3- Digital Output: The module provides a digital output that can be easily interfaced with microcontrollers or other digital circuits. It produces a HIGH (logic 1) output when no obstacle is detected and a LOW (logic 0) output when an obstacle is detected within its detection range.
4- Adjustable Detection Range: The detection range of the KY-032 sensor can be adjusted using a potentiometer on the module. This allows you to fine-tune the sensitivity of the sensor according to your specific requirements.
5- Applications: The KY-032 Infrared Sensor can be used in various applications, including obstacle detection and avoidance in robotics, line following robots, proximity sensing, object detection, and security systems.
When using the KY-032 Infrared Sensor, it's important to keep in mind that it primarily detects the presence of objects based on their reflective properties rather than their distance. The effectiveness of the sensor can be affected by factors such as ambient light and the reflective properties of the objects being detected.
To use the KY-032 infrared sensor, a lamp and a relay with the Arduin UNO, you will need a few components and connections. Here's a list of the required items:
ESP32 Board:
The ESP32 is a microcontroller board that features built-in WiFi and Bluetooth capabilities. It can be programmed and used to control the lamp.
KY-032 Infrared Sensor:
This sensor detects infrared signals and can be used to detect objects or receive signals from a remote control.
Relay Module:
A relay module is an electronic device used to control high-power circuits with low-power signals. It consists of a relay, which is essentially an electromagnetically operated switch, and typically includes additional components like transistors, diodes, and optocouplers for protection and isolation.
You'll need a relay module that is compatible with the ESP32 board and can switch the high-voltage lamp. Ensure it's rated for the voltage and current required for your lamp.
Lamp (220V):
The lamp you want to control, which is rated for 220V. Ensure it's in working condition and safe to use.
Power Supply for the Lamp:
You'll need a power source for the lamp, typically a 220V AC power supply.
Wiring:
Various wires and cables for connecting the components in your circuit.
Breadboard:
A breadboard is a prototyping board that allows you to build circuits without soldering. It provides a convenient way to connect the components together.
Jumper Wires:
You'll need jumper wires to make connections between the ESP32 board, lamp, relay, and breadboard. Ensure you have male-to-male jumper wires or a mix of male-to-male and male-to-female wires, depending on your specific needs.
To mount the ESP32 board with the KY-032 infrared sensor, a lamp and a relay, you can follow these steps:
1- Connect the KY-032 infrared sensor to the ESP32 board:
- Connect the VCC pin of the KY-032 sensor to the 3.3V pin on the ESP32 board.
- Connect the GND pin of the KY-032 sensor to the GND pin on the ESP32 board.
- Connect the OUT pin of the KY-032 sensor to a digital pin 22 on the ESP32 board.
2- Connect the Relay to the ESP32 board:
- Connect the relay's control pin (S) to pin 23 of ESP32 board.
- Connect the pin (+) of relay to pin 3.3V of ESP32 board.
- Connect the relay's ground pin (GND) to the ESP32 board's GND.
3- Connect the Lamp and the power supply to the Relay:
- Connect one of the power supply's wires to the relay's common (COM) terminal.
- Connect the phase wire of the the lamp to the normally open (NO) terminal of the relay.
- Connect the neutral wire of the power supply directly to the neutral wire of the lamp.
To program the ESP32 board to receive data from the KY-032 infrared sensor and light up a lamp using MicroPython, you'll need to follow these steps:
Step 1: Install MicroPython on ESP32 If you haven't installed MicroPython on your ESP32 board, you'll need to do that first. You can find the MicroPython firmware for ESP32 on the official MicroPython website (https://micropython.org/download/esp32/). Follow the instructions to flash the firmware onto your ESP32 board.
Step 2: Install Required Library You'll need to install the ir_rx library to work with the KY-032 infrared sensor. This library is compatible with the ESP32 and works with MicroPython. You can find the library and instructions on how to install it here: ir_rx
Step 3: Writing the MicroPython Code Next, you'll need to write the MicroPython code.
Here's a sample MicroPython code to read data from the KY-032 sensor and control the lamp based on its output:
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 |
import machine <span class="crayon-e">from </span><span class="crayon-e">ir_rx </span><span class="crayon-e">import </span><span class="crayon-e">NEC_16</span> # Define the GPIO pins for the sensor and relay ir_sensor_pin = 22 # Connect KY-032 OUT pin to GPIO 22 relay_pin = 23 # Connect the relay to GPIO 23 # Set up the relay pin ir_sensor = machine.Pin(ir_sensor_pin, machine.Pin.IN) relay = machine.Pin(relay_pin, machine.Pin.OUT) # Function to capture and map IR codes 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)) # Create the IR receiver object ir = NEC_16(ir_sensor, ir_callback) ir_data = 0 ir_addr = 0 # Main loop while True: if ir_data > 0: if ir_data==0x0C: # if you press button 1 on the remote control relay.value(1) # Turn on the lamp if ir_data==0x18: # if you press button 2 on the remote control relay.value(0) # Turn off the lamp ir_data = 0 |
Step 4: Transfer the Code to ESP32 Transfer the updated MicroPython code, which includes IR code mapping, to your ESP32 board using ampy or Thonny IDE (as described in the previous answer).
Step 5: Test Now, when you use the specific buttons on the remote control associated with the mapped IR codes, the lamp should turn on and off accordingly.
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