In this lesson, you will learn how to change the brightness of an LED by using different values of resistor. The Arduino Uno will control the LED by making the output ports high and low.


 

Parts list
1x Arduino Board arduino uno blink
1x  breadboard breadboard
1x 5mm Red LED  arduino_lesson3_red_led_5mm.jpg
1x 270 Ω Resistor red, purple, brown  arduino lesson3 R270
1x 470 Ω Resistor yellow, purple, brown  arduino_lesson3_R470.jpg
1x 2.2 kΩ Resistor red, red, red  arduino lesson3 R2k2
1x 10 kΩ Resistor brown, black, orange   arduino lesson3 R10k

 

 


 

The four resistors are connected to the LED and the Arduino board

 arduino lesson 3 sch

The circuit is build on a breadboard

arduino lesson3 board


 

The skecth is made with Arduino 1.6.7

/*
LED Brightness
Turns on an LED on for one second, 4 with different resistors so the LED brightess will change.

This example code is in the public domain.

modified 28 feb 2016
by www.avrprojects.net
*/

// the setup function runs once when you press reset or power the board
void setup()
{
for(int a=0;a<13;) pinMode(a++,OUTPUT); // set all pins to output
}

// the loop function runs over and over again forever
void loop()
{
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait ms
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait ms
digitalWrite(3, LOW); // turn the LED off by making the voltage LOW
digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait ms
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait ms
digitalWrite(5, LOW); // turn the LED off by making the voltage LOW
}