Table of Contents

How to Control LED Brightness with Arduino Using PictoBlox

Arduino LED Brightness Control
Example Description
Learn how to create a smooth LED fading effect using Arduino Uno and PictoBlox! In this project, an LED connected to a PWM pin gradually increases and decreases in brightness, creating a breathing or glowing effect. This activity introduces students to PWM (Pulse Width Modulation), variables, loops, and hardware control using PictoBlox.

Introduction

LEDs are everywhere, but did you know you can control their brightness to create stunning smooth glowing effects? Pulse Width Modulation (PWM) is an incredibly powerful technique used to fade LEDs, control motor speeds, and much more by rapidly switching digital signals ON and OFF! Learn what PWM is, how duty cycles control power, how to interface an LED with Arduino, and program it 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 variables, loops, and hardware repetition, we’ll show you how to generate a smooth fade-in and fade-out effect and build exciting DIY lighting projects.

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

How to Connect with Arduino Uno

  1. Connect Uno to your computer and open PictoBlox.
  2. In PictoBlox, go to the toolbar and click on the Board menu. Select Arduino Uno.
  3. Next, click on the Connect button, 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.Port Connection
  4. 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.
  5. Switch to Upload mode by toggling this button. You’ll observe some changes in the UI.

Circuit Connections

LED Connection

  1. Connect the longer leg (Anode) of the LED to Digital PWM Pin 3 through a 220Ω resistor.
  2. Connect the shorter leg (Cathode) of the LED to GND.
  3. Connect Arduino GND to the breadboard’s negative rail.

Step-by-Step Block Coding Guide

Let’s create a script that makes the LED glow brighter and dimmer continuously.

  1. Go to the Arduino Uno palette and drag the when Arduino Uno starts up’ block into the scripting area.
  2. Create a variable from the Variables palette named ‘Brightness’ as a Number. This variable will be used to determine the Brightness of the LED.
  3. From the Variables palette, add the ‘set ( ) to ( )’ block. Use the “Brightness” variable and set its value to “0”.
  4. From the Arduino Uno palette, add the set PWM pin () output as ()’ block. Use Pin 3 and add the Brightness variable from Variables palette for the Output.Set PWM pin with Variable Output
  5. From the Control palette, add the forever’ block.
  6. From the Control palette, add the ‘repeat ()’ block inside the forever block. Set its value to 10.
  7. From the Variables palette, add the ‘change () by ()’ block inside the ‘repeat ()’ block. Use the ‘Brightness’ variable and change its value by 25.
  8. From the Arduino Uno palette, add the ‘set PWM pin () output as ()’ block. Use Pin 3 and add the Brightness variable from Variables palette for the Output.
  9. From the Control palette, add the ‘wait () seconds’ block. Set its value to 1.Update PWM pin with Variable Output
  10. Inside the forever block and after the repeat () block. Add another ‘repeat ()’ block from the Variables palette. Use the ‘Brightness’ variable and change its value by -25.
  11. From the Arduino Uno palette, add the set PWM pin () output as ()’ block. Use Pin 3 and add the Brightness variable from the Variables palette for the output.
  12. From the Control palette, add the ‘wait () seconds’ block. Set its value to 1.

Final Code - Arduino LED Brightness Control

Now it’s time to upload the script to the Arduino Uno! For that, click on the Upload Code button, and voila!

Output

Output - Arduino LED Brightness Control

Conclusion

This project demonstrates how PWM can be used to control LED brightness using Arduino and PictoBlox. Students learn how variables, loops, and PWM outputs work together to create smooth lighting effects. The LED Fade Effect is an excellent beginner project for understanding real-world hardware control. It also serves as a foundation for advanced projects involving lighting systems, automation, and interactive electronics.