Any AVR microcontroller based board which follows the standard arduino schematic and is flashed with the arduino boot-loader can be called an arduino board. The arduino is refered to as open source hardware, since the standard schematic is open to everyone and anybody can make their own version of arduino board following the standard schematic. All arduino boards should be compatible with the arduino IDE which can be used to program the arduino boards. The arduino IDE is also open source and anybody can contribute their libraries to the arduino. There is no other tool available which helps in easy prototyping like the arduino does. The arduino board has all the required circuitary to get the built-in AVR microcontroller running. The output or inputs can be taken from the boards or given to the board using convenient connectors. Both digital and analog inputs and outputs are available in all arduino boards. The arduino boards can also communicate with other devices using standard communication ports like USART, IIC, and USB etc. The most impressive thing is that most of the arduino boards are bread-board compatible which makes both the hobbyist and developers happy.
When it comes to programming the arduino board anyone who have basic knowledge of c programming can quickly get started with the arduino IDE. It is very simple to understand and has built-in functions for almost every simple or complex task. There are lots of libraries available which can be used tointerface the arduino board with any other devices. One can hardly find a hardware module of which the interfacing code is not there in the arduino. Moreover there are lots of examples which can help one to get used with the arduino in a very short time.
This article discusses the steps required for getting started with arduino and explains how to code a simple LED blinking code.
The very first thing to do is to select the arduino board which suits the requirement. Visit the website of arduino where one can get all the details about the arduino boards and arduino softwares. Beginners are recommended to use arduino duemilanove board or arduino uno board. Those who are used to with handling the hardware things, soldering etc. can choose arduino pro-mini board. All the details of the available arduino boards can be found from the arduino website itself. This article and the following ones are explained based on the arduino pro-mini board and the IDE version 1.0.3 for windows. The advantage of this board is that it comes in very small in size; bread board compatible burg stick connectors can be soldered according to our requirements. It is very breadboard friendly and occupies very less space of a typical breadboard.
The only difficulty is that it requires another board to load the program into it through USB port. The compatible USB to TTL converter board can be obtained from the nearest vendors or by online purchase. The two boards are so cost efficient that they together cost less than other basic arduino boards.
The latest version of the arduino IDE can be downloaded from the arduino website itself, available for windows, linux, mac etc. One have to simply copy the entire folder into a preferred location in your PC, open the folder click on the arduino icon and that's it, no need to install.
The programing language is based on C and any one has a basic idea can uickly get start with it. Moreover there is a separate page discussing about the programming details only where one can refer all the details onarduino programming language.
If everything has been done in the correct way the arduino IDE opens up and it looks like the following image in windows;
If everything has been done in the correct way the arduino IDE opens up and it looks like the following image in windows;
The first step is to save the project in a folder which is selected to contain all projects and experiments with the arduino. Click file -> save as, select the required folder and give the file name. For all the experiments with the arduino it is recommended to create a folder named "ARDUINO WORKSPACE" and save this particular project as "_1_led_blinking". Sketch names can only consist of ASCII characters and numbers (but cannot start with a number). They should also be less than 64 characters long. The arduino sketch is saved in the file format '.pde'.
Now go to the examples and find the basic led blinking code as shown in the following image;
Now a separate window with the code opens up which is not supposed by the user to edit, since it is a working code and should be kept as such for future references. Select all and copy paste the entire code into the _1_led_blinking window and close the new window with the 'blink code' safely.
All the arduino codes have a small description about it and about the hardware connections at the very beginning of the code file itself as marked inside the green box in the following image.
There is a built-in LED connected to the digital pin number 13 of the arduino pro-mini board and this particular code is for blinking that led with a delay.
An arduino code has two basic functions namely "setup ()" and "loop()". The setup() is the function where all the initial settings like setting the pin as input/output, initializing the serial communication with baud rate etc. The loop() is actually an infinite loop inside which the rest of the code should be written. The user-defined functions if there is any should be written separately outside the setup() and loop() and can be called from inside both of them.
The function pinMode() is a built-in function used to set a particular pin as input or output. The first parameter is pin number and the second parameter suggests whether the pin should be input or output.
For example to make pin number 5 as output
pinMode (5, OUTPUT);
To make pin number 6 as input
pinMode(6, INPUT);
In this particular example the pin13 is already defined as led using the statement
int led = 13
and hence came the following statement
pinMode(led, OUTPUT);
which can make the 13th pin of the arduino board as output.
The digitalWrite() is another function which can be used to write a digital value (logic 0 or logic high) to a particular pin which has already been made as output using the pinMode() function.
For example to make the pin number 5 as logic high
digitalWrite(5, HIGH);
And to make the same pin as logic low
digitalWrite(5, LOW);
The function delay () is a very useful function for almost all the projects and it can generate a delay in milliseconds between the code steps.
For example to generate a delay of 5 seconds,
delay(5000);
Once the coding has been done its time to verify the code and arduino is so user friendly that people won't get too many errors. There is a button for verifying the code at the top left corner of the IDE as shown below;
Once the verification has been done the code is ready to upload to the board. Connect the board to the USB port of the PC and install the driver which comes along with the board. After installing the driver come back to the arduino IDE and select the board from the list using tools>boards>arduino pro mini
After selecting the board, one should also select the COM port on which the board is connected as shown in the following image;
Now try to upload the code to the board by clicking the upload button as shown in the image below;
Now one can try changing the delay or connecting an external LED to another pin and all such basic things. No separate power supply is required as the arduino pro-mini board is USB powered.
Refer to the code and circuit for blinking an external LED connected to the pin number 5 of the arduino board.
Code:
// Pin 5 has an LED connected on it through 1K resistor.
// give it a name:
int led = 5;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
No comments:
Post a Comment