Arduino Uno is an open-source hardware development board designed by Arduino company and user community that designs and manufactures single-board microcontrollers and microcontroller kits for building digital devices.
Arduino has Development board and IDE(integrated development environment).
Arduino Uno development board is an 8-bit microcontroller embedded in a single board. Arduino Uno Board looks likes as bellow image.
Board itself has:
Arduino IDE
Arduino has its own integrated development environment (IDE). It is a software environment, you can write code there, compile your code and upload code in the board. You can download Arduino IDE from arduino.cc. After downloading the IDE, you can install it on your host machine laptop or computer. Arduino IDE looks like as below image.
Let's try some code to understand better
Project 1: Blinking LED. (For this example you don't need to connect external LED because the board itself has built-in LED L at the top left of the board below GND pin)
Step 1: Install the Arduino IDE to your host machine.
Step 2: Connect Arduino Board with the USB cable to your host machine.
Step 3: Write the following code to the IDE.
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
Step 4: Click on the Upload button at the top left of the IDE. After uploading the code LED will start blinking.
Let's try to break the code
void setup()
The setup function will execute only ones after pressing the reset button or power the board. You can initialize input-output pins in this function.
pinMode(LED_BUILTIN, OUTPUT);
First of all, we need to define input-output pins. In this code, the output pin is LED_BUILTIN.
Most Arduinos have an onboard LED you can control. On the UNO, it is attached to digital pin 13. LED_BUILTIN is set to the correct LED pin.
It is set to OUTPUT so, LED_BUILTIN becomes output pin.
Please note that every statement must end with a semicolon ';'.
void loop()
The loop function runs over and over again forever.
digitalWrite(LED_BUILTIN, HIGH);
The digitalWrite statement is used to send the digital bit on the selected pin. HIGH for digital 1 and LOW for digital 0. In Arduino Uno HIGH is equal to 5V and LOW is equal to 0V. So, this statement means to send digital bit 1 at LED_BUILTIN to turn on the LED.
delay(1000);
This statement is used to provide the delay. Value is set to 1000 so, this will provide approximately 1 second of delay.
digitalWrite(LED_BUILTIN, LOW);
This statement is used to turn the LED off by making the voltage LOW.
Let's try another example for the same project i.e blinking led.
We want to turn on the led for half second and after that led will turn off for a second and this process will run over and over.
First of all, we need to define the output pin. As I mentioned earlier, in Arduino Uno built-in LED is connected to the pin 13. So, we define pin 13 as output. Let's do it.
Write the following line before void setup()int led = 13;
We take a variable led which is an integer and the value of the integer is 13.
void setup()
{
pinMode(led, OUTPUT);
}
In this statement, we initilize the pin led as OUTPUT.
void loop()
{
digitalWrite(led, HIGH); //trun on the led
delay(500); //delay of half second
digitalWrite(led, LOW); //turn off the led
delay(1000); //delay of 1 second
}
Like this post