Project Two: Blink led using Arduino board
Project Two: Blink led using Arduino board will basically get you up and blink led using Arduino board. We assume you already understand project one: Light led using Arduino board.
Components
Quantity | Module/component | Description | price Range |
1 | Arduino board (Uno)+Cable | more | 1200-2500/= |
1 | Resistor | Any electronics supply store | 10-20/= |
1 | LED | From 1k Ω to 2KΩ | 10-20/= |
3 | Connecting Wires (Jumpers) | learn more | 50/= |
1 | Breadboard | learn more | 150/= |
Send us a request using the contact section if you don't have any.
1. From led Anode pin (longer leg)
led Anode pin >>>Resistor end >>> then the other side of the resistor end to Pin 7(Arduino)
2. From led cathode (shorter leg)
led cathode >>>Ground pin (Arduino GND)
3. Plug the power into the Arduino.
Now copy the code below and paste it Arduino IDE and upload to Arduino 4. After successful upload led should blink The LED should light up.
Note: Will be using /*comment goes here*/ or //comment goes here as comment
More about comment
Comments are lines in the program that are used to inform developer or others about the way the program works. Comments are ignored by the compiler, in this case, we are using Arduino IDE as a compiler.
project code
/*Author: orengo Dickson */
/* Date Written: 17 March 2020 *
Description: *Turns an LED on for one half second, then off for one-half second repeatedly*/
const PinLed = 7; // Pin Definitions
/**Function Name: setup */
*Purpose: Run once when the system powers up.*/
void setup()
{
pinMode(PinLed, OUTPUT);
}
/**Function name: loop
*Purpose: Runs over and over again, as long as the Arduino has power*/
void loop()
{
digitalWrite(PinLed, HIGH);
delay(500);
digitalWrite(PinLed, LOW);
delay(500);
Your final code without comments should look like as follows:
const PinLed = 7;
void setup()
{
pinMode(PinLed, OUTPUT);
}
void loop()
{
digitalWrite(PinLed, HIGH);
delay(500);
digitalWrite(PinLed, LOW);
delay(500);
altering the code
By altering the code for the delay you can create something a little more interesting
You can also replace above code with this one
/*blinks faster, then slower.*/
const int PinLed = 7; // led connected to pin 7
voidsetup()
{
pinMode(PinLed, OUTPUT);
}
int delayTime = 1000;
void loop()
{
while(delayTime > 0)
{
// while delayTime is greater than 0
digitalWrite(PinLed, HIGH);
delay(delayTime);
digitalWrite(PinLed, LOW);
delay(delayTime);
delayTime = delayTime - 100;
}
while(delayTime < 1000)
{
// while delayTime is less than 1000
delayTime = delayTime + 100;
// do this first so we don?t have a loop with delayTime = 0
digitalWrite(PinLed, HIGH);
delay(delayTime);
digitalWrite(PinLed, LOW);
delay(delayTime);
}
}
Need help? please contact us
Comments
Post a Comment