1.13 Doorbell

Today we will make a doorbell, click the button3 sprite on the stage, the buzzer will sound; click again, the buzzer will stop sounding.

../_images/1.13_header.png

Required Components

In this project, we need the following components.

../_images/1.13_list.png

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Raphael Kit

337

Raphael Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

GPIO Extension Board

BUY

Breadboard

BUY

Jumper Wires

BUY

Resistor

BUY

Buzzer

-

Transistor

BUY

Build the Circuit

../_images/1.13_image106.png

Load the Code and See What Happens

Load the code file (1.13_doorbell.sb3) to Scratch 3.

Click on the green flag on the stage. When we click on the Button 3 sprite, it will turn blue and then the buzzer will sound; when we click again, the Button3 sprite reverts to gray and the buzzer stops sounding.

Tips on Sprite

Delete the default sprite, then choose the Button 3 sprite.

../_images/1.13_scratch_button3.png

Then set the size to 200.

../_images/1.13_scratch_button3_size.png

Tips on Codes

../_images/1.13_buzzer4.png

This block allows you to switch the sprite’s costume.

../_images/1.13_buzzer5.png

Set gpio17 to low to make the buzzer sound; set it to high and the buzzer will not sound.

The status switch is used here, and we will use a flowchart to help you understand the whole code.

When the green flag is clicked, the status will be set to 0 first, and wait for the sprite to be clicked at this time; if button3 sprite is clicked, it will switch to costume as button-b costume (blue) and the status will be set to 1. When the main program receives the status as 1, it will let the buzzer sound at 0.1s interval. If button3 is clicked again, it will switch to button-a costume (gray) and status will be set to 0 again.

../_images/1.13_scratch_code.png