In this blog we will cover very basics of Arduino UNO you need to know to start doing some cool stuff with this small yet very amazing microcontroller. In this whole article we will try to explain how digital I/O pins work in Arduino UNO and what amazing things can we do with it etc.
First things first.
What is an Arduino UNO ?
It is one of the very classic and famous product from Arduino. It is a small microcontroller board with:
14 Digital I/O pins (& 6 PWM’s)
6 Analog Inputs
16 MHz ceramic resonator
A USB port
A power jack
An ICSP header
And a reset button
Image source: https://store.arduino.cc/products/arduino-uno-rev3
But today we will try to cover basics so we won’t be talking much about couple of things in the list instead we will cover only these things:
14 Digital I/O pins (& PWM’s)
6 Analog Inputs
A USB port
And a reset button
And believe me these are the things which can cover up to 90-95 percent of things which you are willing to do with your little UNO board.
So, lets learn more things about Arduino UNO by doing it.
First, take your Arduino board and connect it to you PC or laptop using USB 2.0 Type A/B cable.
Now to begin doing things with Arduino we need to have an interface in our computer that can talk to Arduino UNO board. To do so go to the link (https://www.arduino.cc/en/software) and download the latest version of Arduino IDE. At the time of this video, we had the following version:
After you have downloaded it follow the guided instructions in the setup. If you get any problem, write it in comment section and I will try to give solution to that.
As soon as you run the IDE it will show something like notepad very simple. Where some commands are already written. We press a “Ctrl+A” and then "del" just to remove all the lines of code.
Now we got an empty screen like below:
Before we start writing the code, go to Tools-> Board and select Arduino UNO there or any other Arduino board you are using.
Next go to Tools -> Port and select the Port showing your board name.
If you have done these steps correctly it means we are communication to right Arduino board at right address.
Now,
First we can setup a pin as we want to make an LED glow using Arduino we need to tell the controller which pin we have LED located (for our case it is PIN 13 as it is locate to closest GND pin and we won’t have to add a breadboard). Also, we want to give output from controller to the LED so we will have possibility to use any Digital I/O pin.
To setup the pin we need to write
void setup(){
pinMode(13,OUTPUT);
}
Where 13 is the pin number and OUTPUT is the functionality. Until now we have directed and informed the controller that we are interested in pin 13 but now we should tell the controller what to do with pin 13 to see an action. So, lets try to turn the LED ON which is hanging in between our pin 13 and GND.
So now, we write:
void loop(){
digitalWrite(13,1);
}
Where 13 is again pin number and 1 means ON or HIGH whereas 0 means OFF or LOW. We want to see the LED working so let’s make it ON.
To ensure no compilation errors we can first click on Verify . If it goes well, we can click on Upload then these lines of code will be uploaded to our microcontroller memory, and it will run this code for infinite number of times as we have used “void loop”.
As soon as upload is successful we will see the LED on PIN 13 turns ON. Now to turn it OFF just write the same code but instead on “1” in digitalWrite we will write “0” there.
void setup(){
pinMode(13,OUTPUT);
}
void loop(){
digitalWrite(13,0);
}
Now, your LED has turned OFF. Lets try blinking it we will add a little pause between lines by using delay.
void setup(){
pinMode(13,OUTPUT);
}
void loop(){
digitalWrite(13,1);
delay(500);
digitalWrite(13,0);
delay(500);
}
So, we have written the code just for blinking once but it’s been written in the loop so it will keep on repeating the pattern forever. I really hope this video have given you good insights of how things work on digital I/O pins. But in next video we will cover about PWM pins. These PWM pins give us major advantages when it comes to voltage control and stuff like that. We will try to understand PWM by using very classic way that is dimming and brightening the LED.
Stay tuned 😊
No comments:
Post a Comment