Circuit 3D

What is Arduino

Arduino is an open-source family of microcontroller boards, with free software to program them over USB. A board reads inputs such as buttons and sensors and controls outputs such as LEDs and motors, and its analog pins turn a voltage into a number, so 2.5 V reads 512 on a 5 V Uno.

reading = V ÷ 5 V × 1,024

rounded down and at most 1,023, on a 5 V board such as the Uno, so 2.5 V reads 512.

The board’s brain is its microcontroller, a small computer on one chip.

What is Arduino?

Arduino is an open-source electronics platform: a range of small boards built round a microcontroller, plus free software for writing programs and uploading them over USB.

It was made in Italy in 2005 so that students and artists could build interactive projects without an engineering degree, and its open designs mean many compatible boards now exist, from clones to the Wi-Fi ESP32. Figure 1 shows the pins of the best-known board, the Uno.

ATmega328P 012~34~5~678~9~10~111213 3.3V5VGNDGNDVIN A0A1A2A3A4A5 USB

Digital pins 0 to 13: each reads or writes HIGH, 5 V, or LOW, 0 V, and can supply about 20 mA. Pins 0 and 1 also carry the USB serial link, so keep them free while uploading.

Figure 1. An Arduino Uno R3, simplified: its ATmega328P microcontroller, the digital header along the top, and the main power pins and analog inputs along the bottom.

What is a microcontroller?

A microcontroller is a small computer on a single chip, with a processor, memory and input and output pins, made to run one program that controls a device.

The Uno’s ATmega328P runs at 16 MHz with 32 KB of program memory and 2 KB of working memory: tiny next to a laptop, but plenty to read sensors and switch outputs. Microcontrollers sit inside microwaves, washing machines, toys and cars.

What do the pins on an Arduino Uno do?

The Arduino Uno has 14 digital pins, 6 of which can give PWM, 6 analog inputs that measure voltages, and 5 V, 3.3 V and ground pins to power what you connect.

A pin can supply about 20 mA, enough for an LED through a resistor but not for a motor or relay, which need a transistor. A button needs a pull-up resistor so its pin never floats.

How does an Arduino read a sensor?

An Arduino reads a sensor through an analog pin, whose analog-to-digital converter turns the voltage into a number from 0 to 1,023, in steps of about 4.9 mV on a 5 V board.

Most sensors give a voltage from a voltage divider, such as a light sensor or a thermistor with a fixed resistor. Figure 2 shows the reading for each voltage. Digital sensors and displays send numbers instead, over I2C, SPI or UART.

0 1,023 512

2.5 V on A0: reading = 2.5 V ÷ 5 V × 1,024 = 512, one of 1,024 steps about 4.9 mV apart.

Figure 2. The Uno’s 10-bit analog-to-digital converter, using its 5 V supply as the reference.

How do you program an Arduino?

To program an Arduino, write a sketch in the free Arduino IDE, in C++ with Arduino’s simple functions, and upload it to the board over USB with one click.

Every sketch has setup(), which runs once at power-up, and loop(), which repeats for ever. Commands such as pinMode(), digitalWrite(), analogRead() and delay() do most of the work. Figure 3 times the Blink sketch.

HIGH LOW 2 seconds of pin 13

delay(500): loop() sets pin 13 HIGH, waits 500 ms, sets it LOW and waits again, so one blink takes 1000 ms: 1,000 ÷ 1,000 = 1 blinks a second.

Figure 3. The classic Blink sketch: setup() makes pin 13 an output once, then loop() repeats HIGH, delay, LOW, delay for ever.

Which Arduino board should you start with?

The Uno is the usual first board: 5 V, sturdy, with the most tutorials and add-on boards, called shields.

The Nano packs the same chip into a breadboard-friendly strip, and the Mega adds many more pins. Newer boards run at 3.3 V, so check a sensor’s voltage before connecting it. For a full computer instead, compare Raspberry Pi vs Arduino.

How do you work out Arduino readings and resistors?

To turn an Arduino reading into volts, scale it by 5 V ÷ 1,024, so 512 is 2.5 V, and size an LED’s resistor from the 5 V a pin gives.

Example 1: a reading to volts

analogRead(A0) returns 512. What voltage is on the pin?

Given
analogRead(A0) returns 512 on a 5 V Uno
Find
the voltage on A0
Solution
V = reading × 5 V ÷ 1,024 = 512 × 5 ÷ 1,024 = 2.5 V
Answer
About 2.5 V

Example 2: an LED on a pin

What resistor does a red LED need on a 5 V Uno pin for 10 mA?

Given
a red LED, about 2 V, on a 5 V Uno pin at 10 mA
Find
its series resistor
Solution
R = (5 V − 2 V) ÷ 10 mA = 300 ΩThe next standard size up is 330 Ω, giving 9.09 mA, within the pin’s 20 mA
Answer
330 Ω between the pin and the LED

Summary

Key equations

  • reading = V ÷ 5 V × 1,024 analogRead, at most 1,023
  • V = reading × 5 V ÷ 1,024 back to volts
  • blinks a second = 1,000 ÷ (2 × delay) a blink sketch

Key terms

Microcontroller
A computer on one chip.
Sketch
An Arduino program.
PWM
Fast on-off switching.
IDE
The editor that uploads it.

Practice problems

  1. What is the heart of an Arduino board?

  2. What does analogRead give for 2.5 V on a 5 V Uno?

  3. Which Uno pins can make PWM?

  4. What does loop() do in an Arduino sketch?

  5. About how much current should one Uno pin supply?

FAQ

Is Arduino a microcontroller?

Arduino is the board and its software; the microcontroller is the chip on the board, such as the Uno’s ATmega328P.

What language does Arduino use?

C++, with Arduino’s own library of simple functions such as digitalWrite() and analogRead().

Is Arduino free?

The software is free and open source, and the board designs are open, so many compatible boards exist. The boards themselves cost money.

What is the difference between Arduino and Raspberry Pi?

An Arduino runs one program on its pins; a Raspberry Pi is a small computer with an operating system.

What voltage does an Arduino Uno use?

It works at 5 V, powered over USB or from 7 to 12 V on its barrel jack or VIN pin. Many newer boards use 3.3 V.

Can an Arduino power a motor directly?

No. A motor needs more current than a pin gives and makes voltage spikes, so drive it through a transistor or motor driver with a flyback diode.

What can you make with an Arduino?

Anything that reads inputs and controls outputs: temperature loggers, robots, LED displays, alarms, timers and home automation.

What is the difference between a microcontroller and a microprocessor?

A microcontroller is a small computer on one chip, with processor, memory and pins, made to run one device; a microprocessor is just the processor, needing separate memory and chips, as in a PC.