ElectroBlocks-archive-sept-2025/C2/Control-RGB-LED-with-Push-button/English
Title of the Script: Control RGB LED with Push button
Author: Pratik Nemane
Keywords: Electroblocks, arduino board, 220 ohm resistor, RGB LED, breadboard, Push button, video tutorial, spoken tutorial.
| Visual Cue | Narration |
| Slide 1
Title Slide |
Welcome to the Spoken Tutorial on Control RGB LED with Push Button using Electroblocks. |
| Slide 2
Learning Objectives |
In this tutorial, we will learn how to,
|
| Slide 3
System requirement |
To record this tutorial, I am using
A working internet connection to use Electroblocks. |
| Slide 4
Prerequisite |
To follow this tutorial,
|
| Type https://electroblocks.org/
Highlight the link in the search tab |
Let us open the Electroblocks platform using Google Chrome browser.
In the address bar, type this URL and press Enter. You will see the default Blink LED circuit on the screen. |
| Click on the New File/Blank file option to open a new blank file. | Let us open a new file. |
| Click on the code option available on the left hand side of the screen.
Drag and drop the setup block to a convenient place to the working area. Highlight setup block |
Click on the Code option available on the left panel of the screen.
Drag and drop the Setup block in the working area. This block will execute only once during runtime. |
| Click on Variables
Click on the Create number variable option. Point to pop up window Type Count in pop up window Click on the ok button. |
Click on the Variables option from the left panel of your screen.
Now click the Create Number Variable option. A pop-up window will appear on the screen. Type Count as the variable name. Click the OK button to continue. |
| Highlight the two new generated blocks in the list.
Click in the working area Point to the variable block. Point to variable number block. Click on the variable number block and change the number to 0. |
You will see the two variable blocks generated in the list.
Click on the working area to close the list. In the working area, a variable block is generated inside the Setup block. By default the variable value is set to 33. Click on the variable number block and change the number to 0. |
| Click on Logic Block
Select If then block, and place this block in the loop block. |
Click on the Logic option.
Click on the If then block and place this block inside the loop block. |
| Click on Sensor
A new list will appear. Click on the Button option. |
Let us add a button to control the RGB LED.
Click on the Sensors menu on the left panel. A new list opens. Click on the Button option. |
| Select the Button setup block and drag it to the working area. | Select the Button setup block and drag it to the working area. |
| Point towards “Connected to PIN#” | By default, this button is connected to pin 2 of Arduino. |
| Point to Copy All option.
Check the Copy All checkbox. |
Click on the checkbox against the Copy all option in the Button setup block
It ensures that button setup remains unchanged throughout the simulation process. |
| Click on the Button option.
Drag the Button is pressed block and place it in the If section of the If then block. |
Click on the Button option from the list
Drag the Button is pressed block, place it in the If section of the If then block. |
| Only narration
Click on the variable option and select the number count equal to 10 block. Place this block in the then section of the if then block. Point to default value . Drag and drop the number block to the dustbin area. |
Let's add a variable block to update the variable value.
Click on the variables option and select the number count equal to 10 block. Place this block in the then section of the if then block. Here the default value of the variable is 10. Drag and drop the number block to the dustbin to delete the block. |
| Click on the Math option.
Drag Return the sum of the two numbers block and place it inside the number count variable block. (where 10 was removed) |
Click on the Math option.
Drag and place the third block in the number count variable block. |
| Delete the first number block.
1+ 1 |
Delete the first number block from the arithmetic math block. |
| Click on the Variable option.
Drag and drop the Count block in the arithmetic math block. |
Click on the Variables option.
Drag and drop the count block in the first section of the arithmetic math block. |
| Point to dropdown option
Point to plus option |
By default the plus option is selected in the block.
It indicates that the addition operation will be performed with this block. |
| Point to the arithmetic block | The overall setup of this block is designed to increment the variable value by 1. |
| Select If then block, and drag it to the working area.
Place this block inside the loop block. |
From the Logic option, drag and drop the If then block in the working area.
Place the If then block below the number count = count + 1 block. |
| Only narration.
Click on the Logic option available on the left hand Side of the screen. Point to third block(= Return true if both inputs equal each other) Select the comparison block. Place this block in the if section of the if then block. |
Let us add a comparison block to compare button count value.
Click on the Logic option. The third block represents the Comparison block Select the Comparison block. Place this block in the if section of the if then block. |
| Only narration
Click on the variable option. Drag the count block to the working area. Place this block in the first section of the comparison logic block. |
Let us add a count block.
Click on the Variables option. Select the count block and drag it in the first section of the comparison block. |
| Click on the math option
Select the first block and place this block in the second section of the comparison block |
Now, click on the Math option.
Select the first block and move it to the second section of the comparison block. |
| Click on the number block and change to 1. | By default the number is set to 123.
Double click on the value and change this value to 1. |
| Only Narration.
Click on Add-ons. A new list appears. Click on the RGB LED option. Click on the Setup RGB LED block and drag it to the working area. |
Let us add a RGB LED to the circuit.
Click on the Add-ons menu from the left panel. Click on the RGB LED option from the list. Select the Setup RGB LED block and drag it to the working area. The Setup RGB LED block is used to configure a RGB LED in the circuit. |
| Highlight setup RGB block
Red LED is connected to pin 11 of the arduino. Green LED is connected to pin 10 of the arduino. Blue LED is connected to pin 9 of the arduino. Point to RGB LED on simulation window |
Observe the LEDs connected to their respectives pins.
The RGB LED appears on the simulation window on the right side of the screen. |
| Click on the RGB LED option.
Click the Set RGB LEDs colour block Place this block in the then section of the If then block. Point to if then block. |
Click on the RGB LED option.
Select the Simple RGB LEDs colour block. Drag and place this block inside then block. This setup indicates that if the count is 1, then the red led of RGB will turn on. |
| Highlight the entire set of blocks for count 2 and count 3 | Similarly, design the blocks for the following conditions:
Pause the video and set-up the blocks in order as shown here. Hint - Duplicate the count and RGB LED block placed inside the if then block. |
| Add number count equal to zero block.
Click on Variables, select Number count =10 block Place it under the blue RGB block. Change 10 to 0. |
Notice that I have added the number count equal to zero block below the Blue colour RGB LED block.
This condition resets the counter to zero. |
| Use wait block to give 1 second delay
In the left panel,go to Time option. Select wait for 0.2 seconds block and place it inside the main if then block. Change the value to 1. |
We will keep the LED turned ON for 1 second.
Use the wait block to give a 1 second delay. |
| Click on Sensor option.
Click on the Button option. Select the “Button is Released” block and drag it to the working area. Place this block below the wait for 1 second block. |
Let's add a Release button block in the loop.
Click on the Sensors menus and select the Button option. Select the Button is Released block and place it below the wait block. |
| Only narration.
Right click on the Simple RGB LEDs colour block. Select the Duplicate option. Drag and place this block below the Button is released block. Select the black colour to turn off the LED |
Let us add Turn off the RGB LED block.
Duplicate the Simple RGB led block and place it below the button release block. Change the colour of the LED to black to turn OFF the RGB LED. |
| Click on the code section.
Highlight void setup function |
Click on the Code section.
Here, the RGB LED connected to arduino pins are defined. Also the variable for the counter is defined and set to 0. The void setup function defines the push button and RGB LED as INPUT and OUTPUT components. |
| Highlight void loop
Highlight if condition |
Let us understand the void loop function.
Whenever the push button is pressed, the counter value increases by 1. And this new value will be stored as a counter. For counter = 1 condition, RGB led emits red colour for 1 second. For counter = 2 condition, RGB led emits green colour for 1 second. For counter = 3 condition, RGB led emits blue colour for 1 second. After this condition, the counter gets reset to 0 again. Click on the Home option to start the simulation. |
| Click on the Play button | Click on the Play button to start the simulation. |
| Point to simulation window. | The visual representation of the simulation shows that:
When the button is pressed for the first time, the red LED turns ON for 1 second and then turns OFF. When the button is pressed for the second time, the green LED turns ON for 1 second and then turns OFF. When the button is pressed for the third time, the blue LED turns ON for 1 second and then turns OFF. |
| Slide 5
Summary In this tutorial, we will learnt how
|
This brings us to the end of this tutorial.
Let us summarise. |
| Slide 6
Assignment When you press the button for the, Fourth time, blue LED has to turn on and turn off Fifth time, green LED has to turn on and turn off. Sixth time, red LED has to turn on and turn off. |
As an assignment, please do the following |
| Point to the output of the assignmentAdd the Assignment video.mp4 in the main video | Notice the output of the assignment. |
| Slide 7
Thank you |
Thank you for watching. |