Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸšͺ Ultrasonic Sensor Gate Controller

This Arduino project controls a servo-operated gate using an HC-SR04 ultrasonic sensor. When an object (e.g., a person) is detected within 50cm, the gate opens (servo rotates), a blue LED lights up, and a gentle buzzer beeps. After 5 seconds of no detection, the gate closes, and a red LED turns on.


πŸ“¦ Hardware Setup

Components Required

  • Arduino (Uno/Nano)
  • HC-SR04 Ultrasonic Sensor
  • SG90 Servo Motor
  • Red & Blue LEDs (with resistors, ~220Ξ©)
  • Buzzer (passive)
  • Jumper Wires

Wiring Guide

Component Arduino Pin
HC-SR04 Trigger D2
HC-SR04 Echo D3
Red LED (Anode) D4
Red LED (Cathode) D8
Blue LED (Cathode) D7
Blue LED (Anode) D5
Servo Signal D6
Buzzer (+) D12

Note: Ensure proper grounding (GND) for all components.


βš™οΈ Software Setup

1. Install Required Library

This code uses the Servo library, which comes pre-installed with Arduino IDE. If missing:

  • Open Arduino IDE β†’ Sketch β†’ Include Library β†’ Manage Libraries β†’ Search for "Servo" β†’ Install.

2. Upload the Code

  1. Copy the provided code into a new Arduino sketch.
  2. Select the correct board (Tools β†’ Board β†’ Arduino Uno/Nano).
  3. Select the correct port (Tools β†’ Port).
  4. Click Upload (▢️).

πŸŽ›οΈ How It Works

  • Detection: Ultrasonic sensor measures distance (object within 50cm triggers the gate).
  • Gate Control:
    • Open: Servo moves to 90Β°, blue LED on, buzzer beeps gently.
    • Close: After 5 seconds of no detection, servo returns to 0Β°, red LED on.
  • Buzzer: Short beeps (50ms ON, 500ms cycle) while gate is open.

πŸ”§ Troubleshooting

  • Servo jitters? Check power supply (use external power if needed).
  • Sensor not working? Verify wiring (Trigger β†’ D2, Echo β†’ D3).
  • LEDs not lighting? Confirm correct polarity and resistor values.

πŸ“œ License

MIT License – Free to use, modify, and distribute.

Happy Coding! πŸ’»βš‘


πŸ”— Need Help?

Open an issue or contribute on GitHub.

"Born to Code" – Because every great project starts with a single line. πŸš€

About

An automatic gate that is operated by an ultrasonic sensor and a servo motor.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages