Table of Contents

How to Control an Arduino LED Using a Switch

Arduino LED using switch
Example Description
Learn how to control an LED using a push button switch with Arduino and PictoBlox block coding! In this activity, students will create a simple circuit where pressing a switch turns an LED ON and releasing the switch turns it OFF. This project introduces digital input and output concepts and helps learners understand how Arduino interacts with external components.

Introduction

Switches are commonly used in electronic devices to provide user input. In this activity, we will use a push button switch to control an LED connected to an Arduino board. Using PictoBlox block coding, students will learn how to read the state of a switch and control an output device based on the input received 

Setting Up the Hardware

  1. Open PictoBlox 
  2. create a new project in Block coding
  3. Keep the default sprite tobi on the stage
  4. Go for the board and select the board Arduino UNO
    Arduino Connect
  5. Connect the Arduino board to the computer using a USB cable. 
  6. Connect an LED to Digital Pin 13 of the Arduino.
  7. onnect a push button switch to Digital Pin 2 of the Arduino.
    Circuit Connection
  8. Complete the circuit using appropriate jumper wires and a breadboard. 
  9. Ensure all connections are secure before uploading the program. 

Step-by-Step Block Coding Guide 

  1. Add the Arduino Start Block
    Arduino-UNO-Starts-Up
  2. Add a Forever Loop from the control palette
    add forever loop
  3. Add the If-Else Block from the control pallet
    if else add in forever loop
  4. From the Arduino category, drag the “read status of digital pin” block and set the pin number to 2. Place this block in the condition section of the if-else block.
    add status of digital pin 2
  5. From the Arduino category, drag the “set digital pin output as” block. 
  1. Digital Pin – 13
  2. Output – High
    When the switch is pressed, the LED connected to Pin 13 turns ON.
    set digital pin 13 with high  6.Again from the Arduino category, drag the “set digital pin output as” block.
  1. Digital Pin – 13
  2. Output – LOW
    When the switch is not pressed, the LED connected to Pin 13 turns OFF.
    set digital pin 13 with low7.Connect the Arduino board to the computer and upload the block code.
  1. Press the switch to turn the LED ON.
  2. Release the switch to turn the LED OFF.

Conclusion

In this activity, we learned how to use a push-button switch as an input device and an LED as an output device. By reading the switch status and controlling the LED using block coding, we understood the basic concept of digital input and output in Arduino.