🚗 Automatic toy garage (Arduino project)

🚗 Automatic toy garage (Arduino project)

Daniil Zhuk
Hello to all. In this project, we will make a toy automatic garage with the help of Arduino. This toy is unusual and will be very interesting to your kid. Thanks to the HC-SR04 ultrasonic sensor, the garage will automatically open when a car passes in front of it at a distance of about 30 cm and closes after 4 seconds. The toy can be improved. For example: add lights in the garage when opening, add sounds warning of closing or opening of the garage or use the TV remote control to open, close the garage, or set the password with the console on the garage ... In general, there are a lot of interesting modernization options.

The process of making a toy garage on the Arduino
For the project we need:
  • Arduino UNO or any other modification,
  • SG90 servo,
  • ultrasonic range finder HC-SR04,
  • breadboard,
  • wires dad-dad, dad-mom,
  • charging from a mobile phone 5V, 2A, or a portable power bank, or a Krona battery,
  • The USB cable for Arduino firmware,
  • a cardboard box,

First of all, according to your sketch, we make the base of the garage:

Making the markup on the box, cut and glue everything in the right places.

At the top of the garage above the gate, we make a hole for the distance sensor.

We make the gate with a height of 9 cm and a width of 7 cm and glue in its place.

Install the servomotor inside the garage on the ceiling, the wires are brought out into the hole. We also try on and cut out small cardboard strips, with the help of which the gates will open when the servomotor turns.

Electric circuit toy garage
Now consider the scheme of our toys.

The scheme is simple. For the assembly, we need several wires to connect the range finder to the pin D12 on the Arduino. We connect the Trig contact to the D11 Echo, and the servomotor is connected to the digital pin D0.

Sketch for managing a toy garage

After collecting the scheme and before uploading the sketch to Arduino, you need to install the library NewPing_v1.8. It works a little faster with the distance sensor and simplifies the sketch code.

#include <NewPing.h>
#include <Servo.h>
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200
int clo = 15; 
int ope = 140; 
Servo servo;  


void setup() {

void loop() {

  if (sonar.ping_cm() < 30) 
    delay (3000);
    delay (1000); 

The program constantly calls the HC-SR04 sensor, and if an obstacle appears in front of it at a distance of 30 cm, it opens the gate at a given angle, and the program stops for 3 seconds. After 3 seconds, the sensor is polled again. If there is no obstacle, then the servo turns to a given angle and closes the gate.

Add a comment

* Comments must be approved before being displayed.