Lesson 19 Smart Garage Door

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp

Introduction

In this lesson, an intelligent garage system will be simulated. In front of the garage, open the garage door through the Switch on the IoT Control page. When the car  goes out to the set distance, the garage door automatically closes.

Components

Programming Steps

Step 1

Enter the Simulation page, then connect the SIG of servo to P0 of the Ezblock Pi, the VCC to 3.3V and the GND to GND. Ultrasonic Trig pins are connected to D1; Echo to D0, VCC and GND to 3.3v and GND respectively.

Step 2

Return to the Programming page, and click the IoT Control icon to enter the IoT Control page.

Step 3

Click the ‘+’ button to add function blocks.

Step 4

Create a Ultrasonic sensor and a Switch actuator.

Step 5

Go back to the Programming page. Under the Raspberry Pi category, get a Connect WiFi block and put it into Start block.

Step 6

Click Variables to create a variable called distance.

Step 7

The value of the ultrasonic wave is read and stored in the variable, distance.

Step 8

Select the if do block and the Comparison Operator ( = ) block in the Logic category to set a judgement condition.

Step 9

If get Switch-1 value is equal to 1, the Switch state is ON.

Step 10

When the Switch state is ON, turn the servo to 90 degrees to simulate opening the garage door.

Step 11

Set a judging condition again. When the distance is greater than 50cm, set the servo to 0 degrees to close the garage door.

Step 12

Now save your project, connect the Bluetooth and click Flash to compile and download the code.

Step 13

Re-enter the IoT Control page and click the Run button. When you click the Switch, the garage door will open. When the car is 50cm away from the door, the garage door will close automatically.