Arduino beginner series: Project 3: Varying Brightness LED

Hello everyone!! Welcome to this post on Arduino Projects!!
Need a short introduction to what the Arduino is then click on LINK
Check out the breadboard intro right HERE

So till now we could only send a digital signal to the LED: keeping it either at 0 volt or 5 volts. But in this project we’ll program the LED to glow between the 0 and 5 volts.

Demo:

This is what project looks like and you can build it too!

Things you will need:

  1. Arduino UNO
  2. LED (any colour)
  3. 220 ohm resistor
  4. jumper wires
  5. Breadboard
  6. Arduino IDE on your computer

Functions that we’ll be using:

  1. pinMode()
  2. analogWrite()
  3. delay()

Some important concepts + Video tutorial:

  1. analogWrite() command: Here’s where you can better understand this function (LINK).<—- My project is based on this video.
  2. Pulse Width Modulation: A fancy term for a digital signal. While the signal can only be high (usually 5V) or low (ground) at any time, we can change the proportion of time the signal is high compared to when it is low over a consistent time interval.
    (LINK1) (LINK2) theses two videos will help you better understand PWM

Code:

int led=9;
int bright=0;
int wait=500;

void setup() {
  // put your setup code here, to run once:
  pinMode(led, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  for (int i=0; i<4; i++){
    bright+=63;
    if(bright>253){
      bright=0;
    }
    analogWrite(led, bright);
    delay(wait);
  }
}

Stay Tuned for upcoming posts on Arduino Projects! We’re on the basic newbie projects right now and slowly, gradually move on to those cool, ultra techy projects!! Want to be the first to know when a new and amazing post comes up?? Then feel free to subscribe!

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: