Introduction
In this lesson, you will learn how to use the SunFounder Uno board by turning on an LED and making it blink once per second.
Components
– 1 * SunFounder Uno board
– 1 * USB cable
– 1 * Resistor (220Ω)
– 1 * 1 LED
– Jumper wires
– 1 * Breadboard
Principle
LED
A light-emitting diode (LED) is a semiconductor device which can turn electric energy into light energy via PN junctions. By wavelength, it can be categorized into laser diode, infrared light-emitting diode and visible light-emitting diode which is usually known as light-emitting diode (LED). LEDs are usually red, yellow, green, blue, or color-changing. Color-changing LEDs can change their color with different voltages.
Before building any circuit, you should know the parameters of the components in the circuit, such as their operating voltage, operating circuit, etc. You should connect a current-limiting resistor when an LED is used or else the LED can become burned due to excessive current. In this experiment, the operating voltage of the LED is between 1.5V and 2.0V and the operating current is between 10mA and 20mA. The SunFounder Uno board can supply 5V power, the LED we choose works at 1.7V, 15mA. The current-limiting resistance equals total voltage subtracted by LED voltage, then divided by current. In this case, that would be (5-1.7)/0.015. Thus, the current-limiting resistance equals 220Ω.
Experimental Procedures
Step 1: Build the circuit
The schematic diagram
Step 2: Program (please go to our official website www.sunfounder.com to download related code by clicking LEARN -> Get Tutorials)
Step 3: Compile the code
Step 4: Upload the sketch to the SunFounder Uno board
You should now see the LED blinking.
Experimental Summary
Through this experiment, you have learned how to turn on an LED. You can also change the blinking frequency of the LED by changing the num value in the delay function delay (num). For example, if the function is changed to delay (250), you will find that the LED blinks more quickly.
Code
//Blinking_LED //turn on the LED for half a second,then off for half a second,repeatedly //support@sunfounder.com //www.sunfounder.com //2015.5.7 /************************************************/ const int ledPin = 9;//the number of the LED pin /************************************************/ void setup() { pinMode(ledPin,OUTPUT);//initialize the digital pin as an output } /************************************************/ //the loop routine runs over and over again forever void loop() { digitalWrite(ledPin,HIGH);//turn the LED on delay(500); //wait for half a second digitalWrite(ledPin,LOW); //turn the LED off delay(500); //wait for half a second } /*************************************************/ |
Video