In this
post i will explain how to write a basic code of led blinking and upload it to
Arduino Uno. First of all download Arduino IDE it is open source. Open it you
will find two function already there void
setup and void loop all the
declaration of pins as input/output eg.pinMode(13,OUTPUT) and declaration of
baud rate e.g Serial.begin(9600) or part of code that you want to run only once
is defined under setup function and a part of code that you want to run again
and again is defined under loop function. Below is the code of led blinking.
Code-
int
led=13; // we have connected the led at pin 13 of arduino uno
void
setup() {
pinMode(led,OUTPUT);
//declaration of 13 pins as output pin
}
void
loop() {
digitalWrite(led,HIGH); /// it will set led
pin at high state(1)
delay(1000); // delay of one second
digitalWrite(led,LOW); /// it will set led pin at low state(0)
delay(1000);
}
pinMode function is used to define the corresponding pin of Arduino as input or output pin. for example pinMode(13,OUTPUT) to set the 13 pin as output and pinMode(13,INPUT) to set the 13 pin as input.
digitalWrite function is used to set the
corresponding pin either at High state
or Low state for example digitalWrite(13,HIGH) to set 13 pin at high state and digitalWrite(13,LOW) to set 13 pin at low state. Delay of 1 second is given using delay(1000) function between high and low state of led to
observe the blinking otherwise it is too fast we can’t observe the blinking of
led.
Write
this code into Arduino IDE then compile it and follow the given steps-
- Connect the Arduino Uno with PC/laptop using USB cable.
- Go
to tool>board and select Arduino Uno board.
- Your computer will detect the board and a com port will assign. To know the com port go to control panel of your computer then device manager then under port you will find port of Arduino Uno.
- .. To select the com port in Arduino IDE go to Tool then port and select the right port.
- Now upload the code into board using upload menu in Arduino IDE.
- Design the circuit as given below.
- . . After uploading code you can give power to board through USB or through power adapter(9V/1A).
Comments
Post a Comment