Learn how to use Arduino, selection criteria, handling of basic inpunt and output, connection diagrams and some basic programming examples with Facilino.
What is Arduino?
- It’s a open hardware platform with breadboard including ATMEL microcontrollers and a programming environment (Arduino IDE).
- It has been very successful because all the sketches are open and because the simplicity of its API.
- Interacts with physical elements activating and deactivating digital and analog signals (inputs and outputs).
- It works with 5V signals and has a limited processing capability (compared to boards such as Raspberry PI).
- Most well known boards: Arduino Uno, Arduino Mega, Arduino Nano, Arduino Duemilanove, etc…
What we can do with Arduino?
Electronic projects, generally simple projects. There exists many manufacturers which provide electronics ready-to-use with Arduino boards with many sensors, actuators, expansion boards:
- Measuring all kind of electrical signals, biomedical signals, gas sensors, etc…
- Motor control (DC motors, servo motors, stepper motors), etc…
- Communications with sensors and smart devices.
- Screens, LEDs, buttons, accelerometers, digital compass, gyros, etc…
Everything at a very low cost!
Which is the most suitable Arduino platform?
Obviously, this basically depends on the application… We must know in advance how many inputs and outputs are required and their type (digital or analog). It is also very important to know is we need some additional required hardware such bluetooth, zigbee, I2C, SPI, wifi, etc.
One of the most popular Arduino boards is Arduino Uno, designed to create generic basic circuits. Our recommendation is to use Aduino Nano v3.0 together with its expansion board. The main reason is that both together can be even cheaper that the original Arduino Uno with the same electrical characteristics. In addition to this, it has, as main advantage to offer rows with pins connected to +5V and 0V which will allow as to directly connect many sensors and actuators, otherwise we need a breadboard to connect +5V and GND pins.
In particular, Arduino Nano v3.0 has 14 E/S available for digital input and output (numbered from 0 to 13) and 8 Analog Inputs (numbered from A0 to A7). Actually, analog inputs can be used as digital inputs and outputs if required, but pins A6 and A7, so potentially we could have up to 20 digital inputs and outputs. In addition to this, some pins can offer an extended features such pins 0 and 1 which are used for Serial communication with USB (through an FTDI chip in the original Arduino brand and CH340 in the Chinese versions). It also offers features to control motors with PWM signals, interrupts (useful to detect switches or optical sensors), I2C and SPI to communicate with other devices, etc. For more information, it is convenient to see the specifications for Arduino Nano v3.0.
Digital Inputs
Sensors such as buttons, switches, push-buttons, etc are typically connected as a digital input to Arduino. They provide a binary state signal HIGH or LOW depending on the signal level +5V or 0V, respectively.
Here we show an example of a push-button connected to digital input 2 (the push-button module includes a resistor to avoid signal rebounds).
Here you can get the Fritzing diagram:
An example code in Facilino to read the state of the push-button is shown below:
Here you can download Facilino code:
In this code, we read the state of the digital pin 2 and it is compared with the HIGH state. In case both are equal, then we print a message on the serial console indicating the HIGH push-button state, otherwise we show a message showing the LOW state.
Digital outputs
Actuators, such as LEDs, active buzzers, relays, are treated as digital outputs. We can set two possible states: HIGH or LOW.
When connecting a device to a digital output, the current to activate such device is provided by Arduino. The total amount of currents through these pins is very limited and we must avoid to connect directly through these pins devices requiring high current consumption. In this example, we use a LED module, which already includes a current limiting resistor. The pin 13 used in this example is used in Arduino Nano board as a built-in LED, so in this example both LEDs will light up simultaneously.
Here you can get the Fritzing connection diagram:
This code in Facilino allows to toggle the LED, that is, lights on and off alternatively at a frequency of 1Hz (500ms ON state and 500ms OFF state)
Here you can download Facilino code:
Analog Inputs
Most of sensors in Arduino provide analog values, range between 0V and +5V. This signal is converted by a ADC (analog to digital converter) to provide values between 0 and 1023. For instance, sensors measuring the change of a physical magnitude such as light ambient sensors (LDR), potentiometers, electrodes measuring body electrical signals, etc. Here we show how to connect an LDR (light dependent resistor) to analog input A0 (it also works with light sensor TCRT5000). If the light light level increases the value of the resistor decreases.This change is used to activate built-in LED connected to pin 13.
Here you can download Fritzing diagram:
Here you can see a Facilino for this circuit:
Here you can download Facilino code: