Introduction
Push buttons are incredibly popular electronic components found in everything from your TV remote to gaming controllers! Learn what a push button is, how state-toggling logic works, how to interface an LED and a push button with Arduino, and program them with ease in PictoBlox – our Scratch blocks-based graphical programming platform with advanced hardware interaction abilities. Once you’re equipped with the basic knowledge of tracking variable states and hardware debouncing, we’ll show you how to build a smart light switch and other exciting DIY projects using the push button.
To work in PictoBlox, you’ll first need to download it from HERE.
Ready? Set. Go!
Prerequisites
- Arduino Uno R3 Board
- 220Ω Resistor
- Breadboard
- LED
- Laptop or Computer
- PictoBlox installed on the system
- Jumper Wires
- Push Button
How to Connect with Arduino Uno
- Connect Uno to your computer and open PictoBlox.
- In PictoBlox, go to the toolbar and click on the Board menu. Select Arduino Uno.
- Next, click on the Connect menu, select the Port to which Arduino Uno is connected e.g. COMXX or ttyXX. Once you select the port, the icon beside the Connect tab will become connected.

- On the top right corner, there is a toggle button named Mode. This button is used to switch between the two working modes of PictoBlox, namely the stage mode and the upload mode.
- Switch to Upload mode by toggling this button. You’ll observe some changes in the UI.

Connection

Step-by-Step Block Coding Guide
- Go to the Arduino Uno palette and drag the ‘when arduino starts up’ block into the scripting area.
- Create Two Variables from the Variables palette. Label one as ‘Switch pressed’ and the other as ‘Switch State’. Make sure both of the Variables are of number type.
- From the Variables palette, add the ‘set ( ) to ( )’ block. Use the ‘Switch pressed’ variable and set its value to “0”.
- From the Variables palette, add the ‘set ( ) to ( )’ block. Use the ‘Switch state’ variable and set its value to “0”.

- Create a custom block from the My Blocks palette. Label it as ‘Toggle Switch’.
- A new ‘define Toggle Switch’ will appear in your script area. From Control palette, add the “if () then else” block underneath it.
- From the Operators palette, add the “() = ()” block inside the if condition. From the Variables Palette, add the “Switch state” block in the first operand. For the second operand, use “0“.
- Finish the ‘define Toggle Switch’ block as follows:

- Finish the earlier script as follows:

To upload the code, click on the Upload Code button.
Output

Conclusion
In this lesson, we explored how to create a toggle system using an Arduino Uno, a push button, and PictoBlox. We learned how to write conditional logic that detects a button press to switch and hold the state of an LED, moving beyond a simple momentary switch to a functional, real-time toggle interface. By interacting with the digital pins, we visualized how physical inputs can reliably control hardware states. With this fundamental concept mastered, you can now apply state-toggling logic to control more advanced actuators, switches, and components in your future DIY automation projects!


