Project 1 : LED Blink


In this project we will switch on and switch off an led connected to the Arduino.
Note: Keep in mind that, this simple switching is what we are going to do always, so this is the basic thing that anyone must know to work with a microcontroller.

Lets move on to the project.

Components Required:

1. Arduino Board
2. USB Cable that will connect the Arduino Board to the PC or your Laptop.
3. Breadboard ( if available )
4. LED
5. Resistor ( 1K ohm)

Circuit Diagram:

Connect the led as shown in above diagram with the Arduino Board. 

Code:

For LED blink without delay:

int ledpin=13 //set the pin to which the led is connected
void setup()
{
pinMode(ledpin, OUTPUT); // set the led pin as output pin
}
void loop()
{
digitalWrite(ledpin, HIGH); // set the output as high
}

For LED blink with delay:

int ledpin=13
void setup()
{
pinMode(ledpin, OUTPUT);
}
void loop()
{
digitalWrite(ledpin, HIGH); // set output high
delay(3000); //delay of 3seconds
digitalWrite(ledpin, LOW); // set output low
delay(3000); //delay of 3 seconds
}

Post your queries in the comments section.

No comments: