Kilcullen Science and Engineering

What Is a Microcontroller? Programming an Arduino Board

Typical Arduino development board (Arduino Duemilanove)
Typical Arduino development board
H0dges, public domain via Wikimedia Commons

What Is a Microcontroller?

You probably have lots of these in your home, although you don’t know it! A microcontroller is a type of computer in the form of an integrated circuit (IC) or “chip,” which is often used in devices in your home which incorporate electronic circuitry. You have probably heard of microprocessors, e.g. Intel Pentium, and these are used as the CPU (Central Processing Unit), effectively the “brain”, in a computer. Microprocessors are integrated circuits that process the instructions in a computer program, perform calculations and send data to and from memory and disk. A microcontroller is a specific type of microprocessor. It differs from a normal microprocessor in the following ways:

  • It has built-in “I/O” (input/output) capabilities, so it can read and write digital and analogue values/states and connect directly to the “real world”. A microcontroller, unlike a microprocessor, can connect directly to switches, buttons, LCD displays, LEDS, relays and serial ports.
  • Microcontrollers are generally used for low-to-medium complexity specific tasks in equipment. This contrasts with the powerful, number-crunching microprocessors used in PCs, which handle a variety of software applications.
  • Microcontrollers are often used in portable devices which run on batteries, e.g. digital cameras. So they are often low-powered with a small current consumption (unlike the heat-sinked, fan-cooled microprocessor in a desktop computer.)
  • Compared to the microprocessor in a PC, the RAM within a microcontroller can typically range from 64k down to as little as 1k.
  • The program in a microcontroller is usually stored in EPROM or EEPROM. This is a type of nonvolatile (a program that doesn’t disappear when the device is turned off) memory which can be continuously wiped and rewritten.
Three DIL (Dual In Line) integrated circuit chips
DIL (Dual In Line) integrated circuits (ICs) or “chips”
Kimmo Palosaari, public domain image via Wikimedia Commons

Microcontroller Uses

Lots of devices make use of microcontrollers. Some examples:

  • Burglar alarms incorporate a microcontroller chip which is connected to the keypad, display and sensor/contact inputs. Microcontrollers are generally self-contained chips with the ALU (Arithmetic Logic Unit), memory and I/O all contained within one integrated circuit.
  • Older automatic washing machines used a cam switch for sequencing the operations during a wash cycle. This was quite a complex switch and was mounted on the end of the shaft of the knob you used to select a wash program. Newer machines use a microcontroller to sequence operations. Other appliances, such as microwave ovens and dishwashers, may incorporate a microcontroller.
  • TVs use microcontrollers to handle the selection of channels and read the state of buttons on the TV.
  • Microcontrollers are used for engine control and the display of information on the dashboard (fascia) of vehicles.
  • Digital cameras use microcontrollers to handle input from buttons and control image capture and display.

Microcontroller Examples

Some commonly used microcontrollers:

  • Zilog Z8
  • Intel 8051
  • Texax Instruments TIMSP430
  • Atmel AVR

What Is an Arduino?

Arduino is an open-source hardware/software programming platform and brand, based around Atmel microcontrollers. It was a concept developed by a company founded in Italy in 2005. Open source means that circuit schematics and source code of the software used in Arduino modules are freely available and can be modified by enthusiasts. 
The Arduino company, headquartered in Monza, and acquired by Qualcomm in 2025, still produces microcontroller boards which you can buy online. Since Arduino is open source, you can also buy clones of these boards.

Arduino development boards, with their analogue and digital inputs and outputs, are ideal for artists, designers and electronic hobbyists who wish to put together a system without having to know a huge amount about digital design. Input and output signals are made available on the Arduino board using rows of female connectors into which individual leads or single in line (SIL) connectors can be plugged.

An Arduino development board will have at least:

  • Nine digital pins which can be either input/output channels. Some of these can be set up as PWM (Pulse Width Modulation) outputs. A PWM signal is a square wave whose pulse width can be varied. PWM is used for speed and position control of motors and servos in robotics and remote control applications
  • Four analogue input channels
  • At least one serial port which may also be used to download code to the Arduino

Some boards also have a range of analogue output channels.

There is a high degree of flexibility as regards the function of pins, some of which can be configured as either analogue or digital. Digital pins can be configured as either input or output.

Arduino boards sense the environment around them as they receive input from sensors connected to these analogue and digital inputs. They can also control actuators such as motors, alarm sounders and electric valves or switch on LEDS, lamps or other visual indication devices. The output drive capability of outputs is limited, so usually, transistors, FETS, or relays must be used between the Arduino output pin and the driven device. An output is capable, however, of driving LEDs directly.

The connectors on board are arranged in a standard manner so that shields can be connected. Shields are modules with a dedicated function (e,g, infrared output, Bluetooth, GSM, WIFI, Ethernet, motor on/off control using relays, stepper motor control). Depending on the shield type, it may be possible to stack several shields on top of each other and address them individually over an I2C serial bus.

Since the Arduino code and hardware is open source, third-party developers have produced clones of the official Arduino boards.

Arduino boards have from 32 to 512k of flash memory which can be used for program storage.

Arduino Leonardo board with digital pins configurable as input or output and analog inputs
This is Leonardo, one of the ranges of Arduino boards. Digital pins can be configured as either input or output. Several digital pins can double up as analog inputs in addition to the standard analog inputs
© Eugene Brennan

What Can an Arduino Board Be Used For?

An Arduino board can be used for doing lots of cool stuff. You can easily add LCD displays, a keypad or seven-segment display modules and build a simple system quickly. Lots of information and libraries are available on the Arduino.cc website. You can design your own add-on electronics or use shields to build a modular system. Arduinos, because of their versatility, can be used for simple, mundane tasks or complex applications.

An example of a simple application would be the ability to turn on a device when the temperature in a room falls below a certain level. It wouldn’t be too difficult to extend this application and add a GSM module which could send out a text message when this occurs. Arduino boards can be used to implement a complex home automation system which could be controlled over a smartphone.

They are also used by enthusiasts as the processing and control device in robots, and kits are available for building a simple wheeled robot.

Microcontroller Projects: Programming an Arduino Board

Arduino boards are programmed in C and high-level functions are provided as standard for reading and writing to analogue and digital pins and serial ports. Source code is known as a “sketch”. Standard libraries are also available for tasks such as output to an LCD panel or communication with a GSM module. Lots of other libraries and code have been contributed by enthusiasts and are available on the Arduino website.

A basic code editor/compiler is available on the Arduino website, which can be used for developing programs. However, the editor is basically just like Wordpad and doesn’t provide any colour-coded highlighting or have sophisticated debug features. Atmel Studio, a cut-down, customised version of Visual Studio, is an alternative which provides these features.

Programs are downloaded onto an Arduino board using either a serial port or USB connection. A bootloader then loads the program into memory on reset so that an external programmer isn’t required.

Simple Arduino Sketch

// A simple sketch written in C which can be run on an
// Arduino board. It reads a character from the serial port, echos
// it back to the remote terminal and flashes an LED

void setup()

{
Serial.begin(9600) // Open the port at 9600 baud
pinMode(13,OUTPUT) // Set pin 13 as an output
}

void loop() 
{
char character;

if(Serial.available()) // if there is data in the receive buffer.....
{
character = Serial.read(); // read the character
Serial.write(character); // echo the character to the serial port

// Flash an LED
digitalWrite(13,HIGH); // turn on the LED connected to pin 13
delay(50) // delay 50 mS
digitalWrite(13,LOW); // turn off the LED connected to pin 13

}

Which Arduino to Buy?

For kids and absolute beginners, I recommend the Grove Beginner Kit, available from Amazon. It’s an all-in-one Arduino Uno-compatible board with 10 Sensors & 12 Projects. Interestingly the board is supplied with breakout sections for each transducer which can be detached if desired. Jumper cables are supplied to connect the main controller board to each transducer section:

Arduino Leonardo development board
Grove Beginner Kit
Amazon

Transducers in the Grove Beginner Kit Include:

Sensors

  • Light Sensor
  • Sound Sensor
  • Temperature & Humidity Sensor
  • Air Pressure Sensor
  • 3-Axis Accelerator

Actuators

  • LED
  • Buzzer
  • OLED Display
  • Button
  • Rotary Potentiometer

The first Arduino board I bought was the Arduino Leonardo, also available from Amazon (explained earlier). It has a modest amount of I/O including 20 digital I/O ports, 7 pulse width modulation (PWM) channels, 12 10-bit analogue input channels. Headers are soldered onto the board, but you may be able to find a version without them if you need more space.

Arduino Leonardo
Amazon

In addition to an Arduino board, you need a way of displaying information such as measured values from a sensor, typed text or status messages. Two useful modules are:

16-character by 2-row LCD display module for Arduino
16-character, 2-row display for Arduino
Amazon
4-character 7-segment display module
4-character, 7-segment display
Amazon

Comduino Terminal Application

Comduino Terminal, an example Windows application I wrote for a Leonardo Arduino board. A user can communicate with the board over a USB or serial link, telling it to set digital inputs high or low, set analogue outputs, and read from digital and analogue inputs.

Screenshot of the Comduino Terminal application for reading and writing Arduino I/O pins
This is Comduino Terminal, an application for reading and writing Arduino I/O pins. It is available on my blog (check my profile for the link).
© Eugene Brennan

Disclaimer

This article is accurate and true to the best of the author’s knowledge. Content is for informational or entertainment purposes only and does not substitute for personal counsel or professional advice in business, financial, legal, or technical matters.

© 2014 Eugene Brennan

Comments

zafrinazara on August 16, 2019:

Thank you for giving me a wonderful explanation about Arduino microcontrollers. We also conduct embedded system course in chennai for all streams of engineering students using sensors and microcontrollers.

PDXBuys from Oregon on December 01, 2014:

If I am lucky Santa will bring me one of these for Christmas.

No comments:

Post a Comment

×

Posts by Category