Automated Garage Gate Control Using Arduino UNO and HC-SR04 Ultrasonic sensor - Python Language

Here is an example code for detecting a car entering a garage using an Arduino UNO and an ultrasonic sensor:

This code uses an ultrasonic sensor to detect the distance of an object (car) in front of the sensor. The sensor sends out a pulse of ultrasonic sound and then measures the time it takes for the sound to bounce back. The distance of the object is calculated using the time and the speed of sound. The code checks if the distance is less than 20 cm, which is the threshold for detecting a car entering the garage. If a car is detected, the code sets the gatePin to LOW, which will close the garage gate. The code also includes a delay of 3 seconds to prevent the gate from closing too quickly and damaging the car.

For this project, you will need the following electronic items that can be bought from amazon:

  1. An Arduino UNO
  2. Ultrasonic sensor (HC-SR04)
  3. Relay module (e.g. SainSmart 4-Channel)
  4. Jumper wires
  5. Power Supply

The ultrasonic sensor is a device that can measure the distance of an object using ultrasonic sound waves. It has four pins: VCC, GND, TRIG and ECHO. The VCC pin needs to be connected to the 5V pin on the Arduino UNO, the GND pin needs to be connected to the GND pin on the Arduino UNO, the TRIG pin needs to be connected to a digital pin on the Arduino UNO (in this example it is pin 9) and the ECHO pin needs to be connected to a digital pin on the Arduino UNO (in this example it is pin 10).

The relay module is a device that can be controlled by the Arduino UNO to turn on or off an electrical circuit. It has several pins such as VCC, GND, IN1, IN2, IN3, IN4. The VCC pin needs to be connected to the 5V pin on the Arduino UNO, the GND pin needs to be connected to the GND pin on the Arduino UNO and the IN1 pin needs to be connected to a digital pin on the Arduino UNO (in this example it is pin 8).

Here is a sample circuit diagram explanation for the setup:

In the circuit diagram, the ultrasonic sensor is connected to the Arduino UNO using jumper wires, the VCC pin is connected to the 5V pin, the GND pin is connected to the GND pin, the TRIG pin is connected to digital pin 9 and the ECHO pin is connected to digital pin 10. The relay module is connected to the Arduino UNO using jumper wires and the VCC pin is connected to the 5V pin, the GND pin is connected to the GND pin and the IN1 pin is connected to digital pin 8.

Please note that this is just a sample code and circuit diagram, you may need to adjust the code and circuit to suit your specific requirements and hardware. Also, you will need to check the compatibility of the relay module with the microcontroller and also the voltage rating of the relay module and match it with the voltage rating of the microcontroller.

You can also add more functionality to the code such as sending an alert message or a notification when a car is detected, or integrating it with other devices such as a camera to capture an image of the car when it enters the garage.

Additionally, you will need to ensure that the garage gate is properly aligned and calibrated with the sensor to avoid any potential damage to the car.

Please do check the compatibility and voltage rating of these module with your microcontroller and also the pinout of the module.

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.