Introduction To Arduino Ide
Introduction To Arduino Ide
Launch the Arduino IDE. Connect the Arduino board to your computer using the USB cable.
Some power LED should be ON.
To create a new project, select File → New. And then edit the file.
To open an existing project example, select File → Example → Basics → (select the example
from the list).
For explanation, we will take one of the simplest of examples named "AnalogReadSerial". It
reads a value from analog pin A0 and print it.
Arduino programs can be divided in three main parts: Structure, Values (variables and
constants), and Functions.
Let us start with the Structure. Software structure consist of two main functions:
Setup() function
The setup() function is called when a sketch starts. It is used to initialize the variables, pin
modes, start using libraries, etc. The setup function will only run once, after each power up
or reset of the Arduino board. Here, you can see the Serial.begin(9600); statement which
opens the serial port to allow the board to send output for display by the serial monitor (see
"Output" sub-section below).
Loop() function
After calling the setup() function, which initializes and sets the initial values,
the loop() function does precisely what its name suggests, and loops consecutively, allowing
your program to change and respond. It is used to actively control the Arduino board. Here,
you can see how a value is read from an analog pin (see "Understanding microcontroller
pins" sub-section below), then displayed with the Serial.println(sensorValue); statement.
Most of the information on this page is taken from here. There are other tutorials which one
might find interesting for understanding the electronics and programming an arduino board
like the one here on Sparkfun.
In the figure below is illustrated the popular ATmega328P 8-bit microcontroller that is used
to equip the Arduino Uno, Nano and ProMini boards. You can see, from left to right, the real
chip, then the schematic with the pin layout, and finally the Arduino Uno and ProMini
boards that expose the microcontroller pins on header pins.
If you have an analog physical sensor such as an analog LM35DZ temperature sensor, then
you need to connect it to an analog pin. If you have a digital sensor, it means that the
sensed value is not represented by a linear function of the voltage, but with an appropriate
digital coding of the value. Depending on the coding, you have to drive (e.g. read) the digital
pin accordingly in order to determine the numerical value. But, usually, this is done through
already written sensor or communication libraries such as the OneWire library for digital
sensors using the OneWire format. A digital sensor can be connected to an analog pin if only
LOW and HIGH level are used. However, it is a safe habit to use a digital pin for digital
sensors, unless specified differently by the sensor or communication library.