Wednesday 28 October 2015



                                          Getting Acquainted With Arduino

Many of you must be reading this after referring other websites but still I expect you to go through this "story" as if you are hearing it for the first time. Please be patient till then :). Also suggestions are welcome if you think something is not correct.

Arduino is a tool that allows you to make projects with simple coding that would else require a complex programming and circuitry. To start with imagine arduino as a box that has some inputs and some outputs. What arduino does is it fetches inputs, manipulates them and gives outputs according to the code that it has. Thats arduino in a nutshell. We will get into the details after checking out its various parts (I prefer using Arduino UNO but little things change with different models) :-



                                                                                      
1. USB Plug:- This port is used for uploading programs or commonly called "Sketches" on your Arduino. This can also be used for powering Arduino from your PC.
2. Digital I/O pins: Pin 2-13 as labelled in the picture are used for taking digital inputs(0s and 1s or to be practical 0 volts or 5 volts) and for giving digital outputs ( Though Arduino comes with a function to mimic analog outputs that is almost continuous voltages from 0 to 5 volts).
3.Reset Button:- As the name suggests this button when pressed forces the arduino board to restart itself resetting the program and memory content of variables (we'll discuss all about it :P).
4.Serial Programmer:- These pins allows arduino to "communicate" with your PC. For many basic applications you won't need them.
5.ATmega328 Microcontroller:- This is the "heart and brain" of the Arduino. All the operations, decisions and manipulations are done in this IC. It is a single package microprocessor with Memory for the program instructions and data in it along with other resources like input output memory blocks, timers etc. To conclude it is a tiny computer.
6.Analog in pins:- These pins are the most useful pins onboard on the Arduino because these help us to communicate with analog sensors that sense features of physical world( light, temperature , humidity etc.).
7. The Pins next to analog pins are the so called Power Pins. I will describe each one of them below:-
            a)Voltage in:-This pin can be used to supply voltages ranging from 7-12 volts (to be on the safer side and ensure that under no case you end up burning something) that is regulated to 5 volts and fed to the ATmega chip.
            b)Ground Pins:- These pins are connected to zero volt reference or the "Ground". Any voltage read by or returned by Arduino is with respect to these pins.
            c)5 Volt pin:- This pin is 5 volts above the ground pins. These oins can source upto       200 mA of current but it is better to be within 100 mA and not test the boards limits.
            d)3.3 volt pin:- This pin is 3.3 volt above the ground and is ideal for powering MOSFET based devices and lightning LEDs.


            e)The Reset Pin:- This pin resets the arduino board whenever it sees a high or 5 volt above the ground.
            f)The power port:- This can be used for powering the board with unregulated dc voltage of 7- 12 volts.(Again little less than its tolerance to be safe).

Don'ts Associated with Arduino

Before actually making the Arduino work I stress on what is not to be done with an Arduino. Arduino is meant for digital programming and processing and so you can't expect huge power from it. There are certain limits to the current that can be drawn from the board. The limits depend on the atMEGA chip on board. The chip mounted on Arduino UNO is atMEGA 328 and this chip can take/give a maximum of 20.0 mA and the Vcc=5 volts and ground can give a maximum of 200.0 mA while the ground can take a limiting 400.0 mA current. But still I advise you not to drive loads that take more than 10 mA of current to be on the safer side. !!WARNING: DON'T EVER TRY TO DRIVE MOTORS OR SOLENOIDS OR SPEAKERS WITH ARDUINO!!. To be clear I am posting the technical specifications associated with Arduino UNO board (Credits arduino.cc):


Coding Time

Yes so as now we are well aware of  the don'ts lets start coding and programming. To program an arduino board you will eed a special softawre called Arduino IDE (Interactive Development Enviornment). You can download it from the official website or simply follow this link. Keep on visiting the webpage in case there might be some updates in the software. Follow the installation procedure and complete the installation. After this open the Arduino IDE and you should see a window like this.



Now head over to the file option and go to examples and select the file as shown below:

Open the Blink sketch because it will test if your board is able to communicate with your PC or not.
Connect you Arduino Board to you PC, Wait for some time. 
Now follow the intructions as in videos.
And when you are done uploading this is what you will get. Arduino program to blink the on board LED.


Thats it for now. If your Arduino doesn't  start then head on to this Guy's Video. He has done a nice video on trouble shooting Arduino connection with PC.

The Functions in ARDUINO IDE

Well the last post was more of first connection and didn't include any explanation of the program (I'll be using sketch instead of program from now on) itself. Apologies for that but now I am going to discuss the functions used in basic Arduino programming. Let us start with the structure of an Arduino IDE sketch:
As you can see the code is divided into two parts. Both have their own significance as discussed below:-
Part I (void setup())
In this part you write commands that are to be executed only once after the Arduino is powered or RESET. Generally different digital pins are assigned as input/output pins and some variables (if required) are initialized. As the name suggests this function setups the Arduino ready for work.
Part II (void loop)
This part consist of repetitive program that keeps on executing till any of the program statement stops the execution. The name itself proclaims that the code in it will continue looping.
If you go back to our very basic BLINK program then you will find some basic functions which are discussed below:

1. pinMode():-This function tells the Arduino which Digital pins are Input or Output. For using it in IDE you will have to use 2 essential elements along it namely the pin which is being designated a position and the work it is supposed to do (Take input or give output). Statement 1 in the program above declares digital pin 13 as output.
2. digitalWrite():-This function tells the micro controller to output +5 volts on any given pin (Namely pin 13 in above statement). This function needs to be used along with two values : first the pin number on which output signal is to be given and whether the output is to be a +5 volt or 0 volt.
3. delay():-This function instructs the arduino board to let a given amount of time pass before executing the next instruction. The value entered in the  () brackets is the time delay in milliseconds.
4. digitalRead():-This function (not used above) tells the board to input the signal at a given pin. Its syntax is as :
                                digitalRead("pin_number");
5. analogRead():- This function reads the analog voltage from the required analog input pin. Its syntax is same as digitalRead.
6. analogWrite():- This function allows you to write an analog voltage in the range 0-5 volts.
NOTE!@!@!@~Arduino IDE is case sensitive so Delay() or digitalwrite() will not work@!@!@!. Also all the lines written between these fancy symbol combo(/*  */) are nothing but multi line comments to make the sketch more user friendly. Also // bull.......hit is a single line comment and does not bothers the IDE.
                       The last two functions will be discussed later in detail with examples. Well that's all for now. Stay tuned...


                               analogRead() and analogWrite()

To start with analogRead(PIN_NAME) allows you to read a voltage from 0-5 volts (default) and gives a value from 0-1023. This means for every 4.9 millivolt (approximately) you get one from analogRead().
analogWrite() is a function available only on certain digital pins called the PWM pins. If you look closely to the digital pins you will find some ports with "~" symbol before them. Only these pins support analogWrite(). The syntax for using analogRead() is analogRead(PIN, VALUE) where value is an integer from 0-255 (0 for 0 volts and 255 for 5 volts). analogRead() can be used to control brightness of L.E.Ds, speed of motors etc.