Interfacing Ultrasonic Sensor, Relay Module, and 16x2 I2C LCD with Arduino
- Get link
- X
- Other Apps
Introduction
In this tutorial, we'll explore how to interface an ultrasonic sensor, a relay module, and a 16x2 I2C LCD with an Arduino board. This project allows you to measure distance using the ultrasonic sensor, control a relay based on the distance, and power on the STM32 module when the distance is above 5cm. The distance and relay status are displayed on a 16x2 I2C LCD.
Components Needed
- Arduino board
- Ultrasonic sensor
- Relay module
- 16x2 I2C LCD
- STM32 module
- Jumper wires
Wiring Connections
Follow these wiring instructions to connect the components:
Ultrasonic Sensor:
- VCC → +5V on Arduino
- GND → GND on Arduino
- Trig → Digital Pin 2 on Arduino
- Echo → Digital Pin 3 on Arduino
Relay Module:
- VCC → +5V on Arduino
- GND → GND on Arduino
- Control → Digital Pin 4 on Arduino
STM32 Module:
- Power → Relay Common Pin (NO) on Relay Module
- GND → GND on Arduino
16x2 I2C LCD:
- VCC → +5V on Arduino
- GND → GND on Arduino
- SDA → SDA on Arduino
- SCL → SCL on Arduino
Arduino Code
Explanation
In the Arduino code, the relay Pin
is utilized to control the relay module. When the ultrasonic sensor detects a distance greater than 5cm, the relay is activated (digital Write(relayPin, LOW)
), completing the circuit and providing power to the STM32 module. Conversely, when the distance is 5cm or less, the relay is deactivated (digital Write(relayPin, HIGH)
), cutting off power to the STM32 module. This mechanism allows you to remotely power on or off the STM32 module based on the proximity detected by the ultrasonic sensor.
Conclusion
This project not only demonstrates the integration of an ultrasonic sensor, a relay module, and a 16x2 I2C LCD but also showcases how these components can be used to automate the power control of external devices, such as the STM32 module. As always, feel free to experiment and modify the code to suit your specific requirements.
If any project requirement Contact me on +918973147676 Thank you.
- Get link
- X
- Other Apps
Comments
Post a Comment