This week's task what to use some of electronics in our kits to make a smart circuit with inputs and action outputs. I decided to make a garage door that opens on its own and closes on its own.
no particular reason why I care about this idea, it just seemed fun to try and make it work with the components I have.
For the software I used TinkerCAD to make and test the electric circuit online.
Materials and components used
Glue gun and glue sticks to fix pieces to cardboard
Sheesh Tawok sticks to add support and extend motor shaft
Cutter to cut cardboard and sticks
Cardboard to make the chassis of the project
Electrical components
Used various electrical components:
2x - 330 ohm resistor - Limit current across LED
1x - IR Sensor - Detects objects in-front of it
DC 9 Volt power supply - Power up everything
Jumper wires - Connect components on the breadboard
1x - Small breadboard - Acts as the common connection between components
2x - LEDs - Output to indicate the device is working
1x - Stepper Motor - Open and close the gate
1x - 5V Buzzer
1x HC-SR04 ultrasonic - Check if a car is waiting in-front of the gate
Arduino Uno - Main brain of the circuit
330 ohm Resistor
IR Sensor
DC 9 Volt power supply
Jumper Wires
Mini Breadboard
LEDs
HC-SR04 ultrasonic
5V Buzzer
Stepper Motor
Arduino Uno
Circuit Documentation
This project uses a IR sensor, an ultrasonic sensor, and a servo motor to make an automatic gate system. The servo acts as the gate, and it opens or closes depending on the sensor readings.
The ultrasonic sensor measures distance. If something is closer than 15 cm, the servo turns to open the gate by rotating the servo from 100 degrees to 180 degrees. At the same time, the green LED turns ON and the buzzer goes off to indicate that the gate is open.
Once the car goes in The IR sensor checks for movement when the car reaches the sensor the gate closes and stays closed till the car starts leaving and the red LED is ON. When motion is detected of the car leaving the gate opens for 5 seconds, then closes again and waits 3 seconds before checking for new cars.
1 × Ultrasonic Sensor – measures distance of objects (like cars) near the gate to open it.
1 × IR Sensor – detects motion to decide when the gate should open or close.
1 × Servo Motor – acts as the gate, moving between open and closed positions.
1 × LEDs – green LEDs that turn ON when the gate is open.
1 × LED – red LED that lights up when the gate is closed.
1 × Arduino Board – controls the whole system.
Code Blocks Explaination
forever loop keeps program running
pir sensor on pin 3 reads if motion is detected or not
ultrasonic sensor on trigger pin 7 and echo pin 6 measures distance in cm if object is 15 cm or less it rotates servo to 180 and sets pin 10 and 11 high and pin 8 low
if pir sensor equals 1 then servo rotates to 100 degrees gate opens it keeps checking until pir sensor goes back to 0 during this time pin 10 and 11 are set low and pin 8 high
after motion detected gate stays open for 5 seconds servo goes to 180 then gate closes servo back to 100 waits 3 seconds before checking again
on start servo is set to 100 degrees as default closed position
Connections:
Ultrasonic Sensor
VCC → 5V on Arduino
GND → GND on Arduino
TRIG → Pin 7 on Arduino
ECHO → Pin 6 on Arduino
PIR Sensor
VCC → 5V on Arduino
GND → GND on Arduino
OUT → Pin 3 on Arduino
Servo Motor
Signal (yellow/orange wire) → Pin 0 on Arduino
VCC (red wire) → 5V on Arduino
GND (brown/black wire) → GND on Arduino
LEDs
Green LED #1 → Pin 10 (with resistor to GND)
Red LED #2 → Pin 8 (with resistor to GND)
Buzzer
Positive (+) → Pin 11 on Arduino
Negative (–) → GND on Arduino
Power Supply
Arduino powered by USB or 9V battery (through barrel jack).
Very important note:
To make this code work in real life you need to do a simple change in the arduino ide, due to how IR sensor is different from PIR sensor. The IR sensor sends HIGH all the time on its output pin but once an object is detected it sends LOW
Simulation of the circuit: (noise alert)
I started the project by debugging each component on its own and after confirming everything works as expected I started grouping everything on the mini breadboard
But before I connected everything I had to make some extensions like we were taught before, using jumpers.
I am not any good at making cardboard chassis so I just made a box and made holes where due for components
most complicated part was fixing the servo motor, I had to do multiple joints and interactions to keep it fixed to the cardboard
I made some small sticks and fixed them using double tab to the servo, after that I made a slit for the servo wing and used double face to fix it to the front of the garage.
And to finish the garage entrance I spiked the door into the rotor of the servo.
The holes for the ultrasonic, using more double tape I fixed it to the front door.
I had many issues connecting the servo to the cardboard but after many tries and bruteforcing I manage to fix it and attach the door
The IR sensor is fixed down in the middle of the garage using tape
Finishing pictures of this wires mess:
Demonstration video
While looking for the components in tinkerCAD I did not find IR sensor when I asked one of my instructors they told me to use PIR sensor instead
I had an issue when I used the PIR sensor on Tinkercad because it didn’t act the same as the real IR sensor I had. My actual IR sensor stayed high all the time when nothing was detected, and it only went low when something was detected. Because of that, I had to change the code in the .ino file since the simulation didn’t match reality.
Learning from my mistakes I would try to test every component on its own first before connecting them to the full circuit or before assuming how they work.
We had