Are you ready to make your house and office space an uber cool space without having to shell out tons of money?

Turning the lights off can be something most of us forget a lot of times. Not only does it waste more energy but also seems like a waste of money and no doubt harming the environment. The era of smart homes has got us a little extra creative and we decided to turn our house and office manual light switches into motion sensing light switch.

Things used in this project

Hardware components

Raspberry Pi (You can use RPi 4B, 3B+ or 3B) x 1

Ezblock Pi Board x 1

Ultrasonic Sensor Module x 1

Servo x 2

Double Sided Foam Tape x 1

LEGO Brick x 2

Glue Gun x 1

Apps/ Software used

http://ezblock.cc/

Operations

Step 1: Create a new project

Go to the home page of Ezblock Studio and click the Products button in the top right corner of the page and then you will enter the product selection page.

Choose the product under Kits category: SensorKit for Pi.

Then select the programming environment, Block.

Click the New Project button on the left side of main page to create a new project.

Then input the project name.

Step 2: Build the Circuit

After creating a new project, click on the Simulation icon on the left side of the page to enter the Simulation page.

Drag the 2 Servo and 1 ultrasonic sensor module to the right area. DO NOT close the Ezblock APP, and you will need to use it in later steps.

Note: You can click the + icon in the bottom left corner to unfold the module category.

Step 3: Hardware Connection

Plug the Ezblcok Pi into the Raspberry Pi , then follow the circuit in the Step 2 to connect the hardwares, finally power the Raspberry Pi.

Step 4: Program

Back to the Ezblock APP, then program according to the figure below. You can find the block you need in the Basic, Logic, loops, Math, Variables and Sensor Kit categories.

Note: Click the Settings icon in the upper left corner of the if do block, place the else block below the if  block to convert to the if do else block.

Step 5: Connect Bluetooth & Flash Code

Click the Bluetooth connection button on the left function area. Then, in device select prompt, choose your device and click on Done, waiting for "Connected" to appear.

In case of cross connection between several Raspberry Pi boards, Ezblock Pi decrease its Bluetooth signal strength while it is being connected. You need to put it as close as possible to your device. As long as they are connected, the signal strength will be normal.

After the connection is done, click the Flash button to compile and download the code to the Raspberry Pi.

Step 6: Fix the Auto-switch Device

Use the glue gun to stick the LEGO bricks to the servo rocker, and then fix the 2 servos to the upper and lower sides of the switch. Finally, use double-sided foam tape to fix the Raspberry Pi and the ultrasonic module beside the switch.

Note: You need to fix the rocker arm into the servo with the smallest screws in the servo package.