ElectroBlocks-archive-sept-2025/C2/Control-LED-with-Push-button/English

From Script | Spoken-Tutorial
Jump to: navigation, search

Title of the Script:Control LED with Push button

Author: Pratik Nemane

Keywords: Electroblocks, arduino board, 220 ohm resistor, LEDs, breadboard, Push button, video tutorial, spoken tutorial.


Visual Cue Narration
Slide 1:

Title slide.

Welcome to the Spoken Tutorial on Control LED with Push button using Electroblocks.
Slide 2:

Learning Objective

In this tutorial, we will learn how to,
  1. Build a set of blocks to create a Control LED with Push button.
  2. Check the output of the experiment using the simulator.


Slide 3:

System Requirements

To record this tutorial, I am using:
  • Ubuntu Linux OS version 22.04
  • Google Chrome Browser.

A working internet connection to use Electroblocks.

Slide 4:

Prerequisite


https://spoken-tutorial.org

To follow this tutorial,
  • Learner should have a basic knowledge of Electroblocks interface
  • If not, please visit the relevant tutorials on this website.


Open Google Chrome browser.


In New Tab, type

https://electroblocks.org/


Point towards Default Blink LED circuit.

Let us open the Electroblocks platform using Google Chrome browser.


For that Type this url in the address bar.


You will see the default Blink LED circuit on the screen.

Click on the New File/Blank File icon.


A Pop-up window appears.


Click on the OK button.

Click on the New File/Blank file option available on the toolbar.


A pop-up window appears on the screen.


Click on the OK button to start a new project.

Point towards the loop block.


A default loop block appears on the screen.


Let’s drag the default loop block to a convenient place to insert push buttons.



Add the entire Output video.mp4 in the main video at the 1:29 timestamp. We will create this Control LED with Push Button output.


Let’s get started by building a Control LED with Push Button using Electroblocks.

Main Video.mp4


Click on Logic Block.


Point towards all the six Logic Blocks.


Select If then else block, and drag it in the working area.


Place this block inside the loop block.

First we need an If then else block.


Click on the Logic option on the left panel.


You can see six Logic Blocks.


Click on the If then else block and place it inside the loop block.



Click on Sensor


A new list will appear.


Click on the Button option.

We require a button to control the LED.


Click on the Sensors menu on the left panel.


A new list opens.


Click on the Button option.

Point the cursor towards all three blocks.


Select the Button setup block and drag it in the working area.


Point towards “Button Setup

You will see three blocks.


Select the Button setup block and drag it to the working area.


The Button Setup block is used to configure a push button in the circuit.

Point towards “Connected to PIN#”


Point towards the “USE PULL UP Resistor” checkbox.


Point towards the unchecked checkbox.


Only narration.

By default, this button is connected to pin 2 of Arduino.


Below, you can see the "USE PULLUP Resistor" checkbox.


By default this box is unchecked.


We will leave the box unchecked.


This indicates that an external resistor is connected to the button.

Point the cursor to the “Is Button Pressed” checkbox.


Show the enabled checkbox.

By default, the "Is Button Pressed" checkbox in the button setup is always checked.

It means that the button will be in the pressed state when you run the simulation.

Point towards the “Loop Dropdown”


Point towards

Observe the loop dropdown option in the Button Setup block.


Here, loop 1 is selected.


It indicates that this setting is applied to loop 1 only.

Point to Copy All option.


Check the Copy All checkbox.


Point to button setup block

You can see a checkbox against the Copy all option in the Button setup block.

Check the Copy All checkbox.

This setting ensures that the button setup stays the same, for all the loops in the simulation.

Only narration


Click on the Button option.


Select the Button is pressed? block and drag it in the working area.


Place this block in the If section of the if then else block.

We will add a button block in the loop.


Click on the Button option.


Select the Button is pressed? block.


Place this block in the If section of the if then else block.



Only narration.


Click on Add-ons.


A new list will appear.


Now we will add an LED to the circuit.


Click on the Add-ons menu on the left panel.


A new list appears.

Click on the LED option.


Point to the two blocks.


Click on the Turn on LED block and drag it in the working area.


Place this block in the then section of the If then else block.

Click on the LED option.

You will see that two LED blocks will appear.


Click on the Turn on LED block


Place this block in the then section of the If then else block.



Point to the grey area.


Point to the simulation screen to show the circuit disappeared.

You will see that the LED and button setup block will turn to grey.


Also, the circuit in the simulation is not seen.

Point towards the LED and push button.


This is an error.


It occurs because both the LED and push button are connected to pin 2 of the arduino.


To resolve this error, we will assign a different pin number to the LED.



Click on the dropdown arrow in the LED block.


Change the pin number to pin 4.


Point towards the block to show their changes.

Click on the dropdown arrow in the LED block.


Change the pin number to pin 4.


Now, all the blocks appear in normal condition.



Only narration.


Only narration


Click on the Time section.

Let’s make sure that the LED remains turned ON for a sufficient amount of time.


For this, we must add a delay block.


Click on Time on the left panel.

Drag and drop the Wait block for 0.2 second block in the working area.


Place this block below the turn ON LED block.


HaChange the time to 2 seconds in the block.


Drag and drop the Wait block for 0.2 second block to the working area.


Place this block below the turn ON LED block


Change the time to 2 seconds in the block.



Only narration.


Right click on the Turn on LED block and select the Duplicate option.


Now we will turn OFF the LED.


Right click on the Turn on LED block and select the Duplicate option.


A new Turn on LED block will be created in the working space.



Drag and place this new block inside the else section of If then else block.


Click on the dropdown arrow and select OFF


Drag and place this new block inside the else section of If then else block.


Change the state to OFF.


This block turns OFF the LED connected to pin 4.

Only narration.


Click on the Code Icon.

Now we will see the arduino code generated by electroblocks.


Click on the Code Icon.

Highlight Pin 4 line of code. In the void setup function, you will see pin 2 and pin 4 are mentioned.


Pin 4 is assigned to the LED.

Point to OUTPUT


Highlight Pin 2 line of code.


It is termed as OUTPUT because the arduino gives a value to the LED.


Pin 2 is assigned to the push button.


It is termed as INPUT because the arduino takes a value from the push button.



Point to the void loop function.


Highlight the if ((digitalRead(2) == HIGH))


Highlight LED turned HIGH line of code.


This is the void loop function.


It shows the action performed by components and sensors in the experiment.


if ((digitalRead(2) == HIGH))

This line checks if the button connected to pin 2 is pressed or not.


digitalWrite(4, HIGH)

This line describes the LED connected to pin 4 turn ON.



Highlight delay(2000) line of code.


Arduino narration.


Highlight LED turned LOW line of commands.


delay(2000)

This line makes sure that the LED is turned ON for 2 seconds.


In the arduino syntax, 2000 milliseconds represent 2 seconds.

If the condition is false, the code inside the else block will execute


digitalWrite(4, LOW)

This line describes the LED connected to pin 4 turns OFF.



Let’s check the desired result using the simulator.
Click on Home page


Click on the play button

Click on the Home page option from the toolbar.


Click on the Play button to start the simulation.

Show the LED is turned ON.


The visual representation of the simulation shows that:

When the push button is pressed, the LED is turned ON for 2 seconds.


Let us check the output of the LED if we don’t press the pushbutton.

Only narration


Uncheck the Is button is pressed box in the button setup


Click on the play button again.


For this condition, uncheck the Is button pressed checkbox in the button setup block.


Start the simulation again.


Notice that when the push button is not pressed, the LED remains OFF.



Only narration.


check the Is button pressed box in the button setup block.


Click on the Previous Step button to return to the beginning of Step 1.

To see the simulation in the step by step manner.


First check the Is button pressed box in the button setup block.


Then click on the Previous Step button to return to the beginning of Step 1.



Click on the Next step


Point the cursor to the yellow colour outline


Click on the Next Step button and notice the blocks in the working area.


The execution state of the block is highlighted with a yellow colour outline.

Add the entire Output video.mp4 in the main video at the 10:21 timestamp. Notice the output of the experiment.
This brings us to the end of this tutorial.


Let us summarise.

Slide 5:

Summary


In this tutorial, we will learnt how to,

  1. Build a set of blocks to create a Control LED with Push button.
  2. Check the output of the experiment using the simulator


Slide 6:

Assignment


  1. Pressing the first button turns the LED on.
  2. Pressing the second button turns the LED off.

Hint- Don't use a time block.


As an assignment, please do the following:
  1. Add two buttons and one LED in ElectroBlocks.
  2. Connect the first button to pin 3, the second button to pin 4, and the LED to pin 2.
  3. Create a project with the following functionality:


Add the Assignment video.mp4 in the main video at 10:54 timestamp. Notice the output of the assignment shown in the video.
Slide 7:

Thank you

This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.

Thank you for watching.

Contributors and Content Editors

Madhurig, PratikNemane, Pratiknemane