0% found this document useful (0 votes)
622 views100 pages

Arduino For Beginners

The document provides an introduction to Arduino programming for beginners. It discusses what Arduino is, including its history as an open-source hardware platform. It also outlines some commonly used Arduino boards and their basic specifications.

Uploaded by

Maria Bunea
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
622 views100 pages

Arduino For Beginners

The document provides an introduction to Arduino programming for beginners. It discusses what Arduino is, including its history as an open-source hardware platform. It also outlines some commonly used Arduino boards and their basic specifications.

Uploaded by

Maria Bunea
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 100

Arduino

Programming for Beginners


Comprehensive Beginners Guide to Learn Arduino
Programming Step by Step
© Copyright 2019 Ethan Thorpe - All rights reserved.
This document is geared towards providing exact and reliable information in regards to the topic and issue
covered. The publication is sold with the idea that the publisher is not required to render accounting,
officially permitted, or otherwise, qualified services. If advice is necessary, legal or professional, a practiced
individual in the profession should be ordered.
- From a Declaration of Principles which was accepted and approved equally by a Committee of the
American Bar Association and a Committee of Publishers and Associations.
In no way is it legal to reproduce, duplicate, or transmit any part of this document in either electronic means
or in printed format. Recording of this publication is strictly prohibited and any storage of this document is
not allowed unless with written permission from the publisher. All rights reserved.
The information provided herein is stated to be truthful and consistent, in that any liability, in terms of
inattention or otherwise, by any usage or abuse of any policies, processes, or directions contained within is
the solitary and utter responsibility of the recipient reader. Under no circumstances will any legal
responsibility or blame be held against the publisher for any reparation, damages, or monetary loss due to
the information herein, either directly or indirectly.
Respective authors own all copyrights not held by the publisher.
The information herein is offered for informational purposes solely, and is universal as so. The presentation
of the information is without contract or any type of guarantee assurance.
The trademarks that are used are without any consent, and the publication of the trademark is without
permission or backing by the trademark owner. All trademarks and brands within this book are for
clarifying purposes only and are the owned by the owners themselves, not affiliated with this document.
Table of Contents
Introduction
Chapter 1: Diving into the World of Arduino
Chapter 2: Hardware and Tools
Chapter 3: Working with Arduino
Chapter 4: Exploring Arduino
Chapter 5: Circuits, Arduino Shields and Library
Chapter 6: Practical Projects
Chapter 7: Smart Appliances and The Power of the Web
Chapter 8: Troubleshooting Common Problems
Conclusion
Appendix
URL
Reference
Introduction

This book will act as a starting point for all you need to learn about Arduino
programming. We will provide links to all the software you may need to learn
Arduino programming.
This book will seek to teach all aspects of Arduino Programming to a complete
beginner with absolutely no experience writing programs. So, for those who fear
programming as head-cracking work, we will seek to dissuade you from such as
you read through this course.
Makerspaces the world over are increasingly interested in including electronics
and programming into their education. Integration of Arduino boards into their
lessons and projects is often the way they go about doing this. A lot of maker
educators often avoid Arduino because they fear programming is a difficult thing
to learn. We are here to prove them wrong.
For those more familiar with Arduino programming, there is still much you
could learn from reading this book. Each step in the programming steps will be
explained to carry everyone along.
This book will act as a starting point for all you will need to know about Arduino
programming. We will provide links to the software you may need to learn
Arduino programming.
Chapter 1: Diving into the World of Arduino

A Brief History
Ivrea is a small town that sits across the Dora Baltea River in Italia. Famous for
its underdog kings, one of which was King Arduin who was eventually deposed
by King Henry II, of Germany.
We take the name of the platform from Bar di Re Arduino, a bar popularly
frequented by Massimo Banzi. The bar’s name was inherited from the Italian
king of 1002, King Arduin.
Arduino was introduced by Massimo Banzi, David Mellis and David Cuartielles
in Italia in 2005 at the Interaction Design Institute Ivrea (IDII) to provide access
to a cheap and simple tool for creating hardware for non-engineers.
It was forked from the work of Hernando Barragán , a student at the IDII who
had created a language called Wiring for his master’s thesis. Wiring was
designed to simplify the creation of interactive electronics for artists and
designers.
What Is Arduino?
Arduino can best be described as an easy to use open-source electronic
prototyping platform based on very flexible hardware and software. Arduino
boards have a microcontroller which can be programmed to do various tasks.
They can to read various different type inputs such as; read mail, light on a
photocell, wind change, a specific sound and turn it into an output; publish a
book, turn off the light, open the door, start the coffee machine.

The Microcontroller Chip


A microcontroller is an Embedded System , which means it is many units
embedded into one chip: Microprocessor, Memory units (RAM, ROM, FLASH),
Input/Output Ports, and other peripherals.
Microcontrollers are impressive because they allow non-developers and
developers to build a functioning electrical system in a short amount of time.
Since you need not choose several parts and make sure that they are compatible
with each other.
The microcontroller chip of the Arduino makes it a truly special resource.
Arduino Uno comes with a microprocessor that has 32KB of storage, 2KB of
RAM and has an eight-bit processor that runs at only 16MHZ. It is light and
capable of handling anything you may want to do with Arduino.
Note: some boards have higher storage/RAM/processor.
There are exceptions, some chips are built with larger RAM, storage and
processor. But, most Arduino within the common price range will be within the
above specifications with some deviations allowed.

Discovering Other Arduino Board


Arduino is released under a creative commons license (open source), which
means that anyone can produce their own board. There are many different
Arduino compatible clones on the open market but only official boards have
Arduino included in their names.
Most people buy clones of Arduino because they are less expensive than official
Arduino boards. We will warn you to be careful about buying boards from
companies you are not familiar with. If you do not want to buy from Arduino,
these companies are recommended http://www.adafruit.com/ and
http://www.sparkfun.com/ . Their products are less pricy but also of similar
quality to official boards.
The board you buy should depend closely on the type of project you want to
undertake. For a small form project, you should consider Arduino pro mini and
for a wearable one, you should consider Sparkfun’s LilyPad board.

Official Arduino Boards


There are many types of Arduino as we have mentioned earlier. The Arduino
you will buy depends on what you want to do with it.
Below are a few examples of the Arduino boards that you will easily find out
there.

Arduino Uno
Arduino can best be described as an easy to use open-source electronic
prototyping platform based on very flexible hardware and software. Arduino
boards have a microcontroller which can be programmed to do various tasks.
They can to read various different type inputs such as; read mail, light on a
photocell, wind change, a specific sound and turn it into an output; publish a
book, turn off the light, open the door, start the coffee machine.
Because of its cheap price and ease of use, Arduino has become very popular for
makers that want to dabble in the creation of interactive hardware.
Unlike most previous programmable circuit boards, Arduino does not require
any extra hardware (Programmer) to load new code into the board.
You can buy Arduino directly from https://store.arduino.cc/ or from retail for a
price range of $22-$24.
The Board usually appears as a blue circuit board the size of a credit card
although varying models come in varying sizes. It comes with an Atmel
microcontroller which is a tiny computer, a USB connector, a power connector
and two rows of headers. The pins of the connectors are connected to the headers
which can be connected to virtually any electronics you can imagine.
There are usually 9 digital pins (I/O) and 4 analogue input channels. The I/O
pins can be used as input pins – to connect light sensors, temperature sensors,
sound sensors, keyboard or mouse, buttons… or they can be used as output pins
– to drive motors, control lights, connect displays, LED’s, check mail…The
USB also allows you to control your Arduino with your computer or control
your computer with the Arduino.
Arduino Leonardo
Arduino Leonardo is based on the ATmega32u. It has 20 digital I/O pins. It
contains everything you will need to support the microcontroller.

Arduino Ethernet
Arduino Ethernet is based on the ATmega328. It has 14 digital
Input/Output pins, six analog inputs and a 16 MHz crystal oscillator.

Arduino Due
Souped-up clock speed and ridiculous amounts of memory are the two things
that truly make the Due stand separate from the others.

Arduino Yun
Arduino Yun is the first of a new line of Wi-Fi products that seek to combine the
power Linux with the ease of use of Arduino. Arduino Yun is the combination of
an Arduino Leonardo (based on the Atmega32U4 processor) board with a Wi-Fi
system-ona-chip that runs Linino.

Arduino Mega 2560


Mega is a special class of Arduino. Renowned for its large number of I/O pins,
the Arduino mega is the go-to for complex electronic work. It has a very much
larger memory space.

Arduino Mini
If you need to pack electronics into space not much larger than a postage stamp,
then the Arduino Mini is probably what you want.
And many other models
For this lesson, we will use the Arduino Uno model as a sample.

Arduino Clones
Some Arduino clones that you may also desire to purchase include:

NodeMCU
NodeMCU is one of a kind. It is one of the most favorite alternatives to Arduino
available right now. It has a similar size to the Arduino mini and Nano, but it
packs a meaner punch.

Teensy 3
Teensy is one of the best Arduino alternatives available right now. They are very
similar to Arduino micro and Nano, much like NodeMCU. And much like the
lauded Node, they are even better than the official Arduino versions. A little bit
more expensive at $30, its processing power surpasses almost every other
microprocessor.

MSP430 Launchpad
Power consumption often proves to be the problem of most DIY builds, this is
why the MSP430 boards are impressive. Drawing in current claimed to be three
times as low as most other Arduino boards, it is exactly what is needed for builds
meant to run for long periods.
There are many Arduino clone other types; The STM32, PocketBeagle, DIY
(Homemade)…
Caution!
Do not fry your Arduino!
It might be a good idea to read this chapter before you actually unpack your
Arduino, Bad things may happen if you do not.

1. An Arduino can only supply 40mA output per pin, so you may not
want to drive a speaker or motor directly and you cannot directly
connect a LED without a resistor.
2. Do not short an output at +5v, +3.3v or the ground pins. The amount
of current drawn from an output pin at +5v connected to the ground
will fry the board.
3. Do not put Arduino on a metal surface, it will short out the pins.
4. Do not draw more than 200mA from the total output pins altogether.
The ATmega chip supplies only 200mA total, so driving 10LED’s
will eventually kill your board.
5. Do not supply more than +5v to your input pins. Even a +0.5v excess
charge may damage your board. This also applies to sensors… always
check your voltages carefully before connecting anything.
6. Do not supply more than the accepted voltage to the input pins. A +5v
ATmega chip has an absolute limit of +6v and +5v for a +3.3v one.
7. The vin chip will fry if it takes in more than +12v. There is an
onboard voltage regulator that will fry if it takes more than +12v.
8. When running on external power, do not draw more than 500mA
from the +5v pin.
9. Do not draw more than 50mA from the +3.3v pin.
10. Be careful of reverse polarity. Swapping in a GND pin for the
vin or +5v pin will kill the board.
11. Do not connect a load to the vin pin while you are using USB
power.
12. Remove the carpet under your work desk to protect against
static charge.
If this seems needlessly complicated, but do not worry. Just pay special attention
to 1-5 and 10 and you will be fine.
Chapter 2: Hardware and Tools
For you to begin practicing with Arduino, you will probably need a few things to
get started with.
While you can learn Arduino programming with only the contents of your
Arduino Uno Budget Pack, please do make sure you have all the materials listed
below within the pack:

A computer running Arduino IDE


USB A-B cable, Breadboard not less than half-size and Breadboard
wires
10K potentiometer and 2 push-buttons
Bright RBG LED and 5 red diffused LEDs
10K ohm resistors and 220 to 1K ohm resistors
Plastic mounting plate for the board
Flathead screwdriver
You will also need some of the following materials:

PN2222 transistor, 1N4001 diode and a small DC motor


Precision screwdriver set
Solder and soldering iron
Wire strippers, tweezers and a multimeter
A small needle-nose plier and flush diagonal cutters
60/m RGBW NeoPixel strip (1 meter)
Solder sucker
Scientific calculator
Components of whatever device you wish to operate the Arduino
with
Some/All the above are components you will need if you are to master Arduino
programming.
The function of the above-named components if not immediately stated below,
will be described as we get further into programming your board.

Power Supply
Arduino rarely comes with a power pack. For most projects, you will use the
USB cable to draw power from your computer. However, for any mobile project,
you will need to consider a 9V AC power supply to make it independent.
The Breadboard
The breadboard is a revolutionary design when it comes to programming a
board. Before its invention, it was necessary for an engineer to perfect his entire
board design on paper before doing any form of prototyping, or spend ruinous
amounts of money soldering and unsoldering the board (the board may get
damaged). The breadboard eliminated that limitation entirely by allowing its
users to program their circuits without permanently soldering anything until they
have perfected their designs.
A breadboard allows the user to prototype and experiment with different circuit
designs before doing any permanent soldering of the board.
The breadboard contains metal clips in the holes on their plastic housing which
are connected to each other by thin strips of conductive materials. These allow
currents to flow freely between one hole to the next, mimicking a circuit.
However, since the breadboard on its own is not self-powered, it requires power
to be sent through jumper wires from the Arduino. These wires are also
sometimes used to form circuits by connecting switches, resistors and other
components.
The jump cables are connected to the breadboard through two power rails clearly
visible on it, for both power and ground connections. The rail in between the
breadboard is to enable circuits to be more easily mounted on it.

Jump Wires
Jumper wires serve the very simple function of connecting your Arduino header
pins to the breadboard. As already stated above, using these to test-drive your
circuit allows you to see if your circuit is accurate without having to solder
Arduino. You will need jumper wires, if you want to use the breadboard.

Needle Nose Pliers


This is a vital component for any electrical and computer work. It is, in fact, vital
even to non-electricians like artisans, jewellery designers… these pliers are used
to re-position, snip and bend wires and to insert them into the breadboard. They
are also used to hold wires and circuits in place while working.

Multimeter
A multimeter is a very vital part of working with electronics. It is a combination
of a voltmeter (measures voltage {AC and DC}), an ohmmeter (measures
resistance) and an ammeter (measures current). Because of the precision
required when working with Arduino, it becomes almost vital if you are to work
required when working with Arduino, it becomes almost vital if you are to work
on the board without blowing out your board at the first attempt. It will solve a
lot of the Mathematical issues you will face when learning Arduino
Working on Arduino without a multimeter is possible. But it is not advised if
you are not already proficient in working with other electronics with tight
tolerance ranges.

Solder and Soldering Iron


These are vital for any circuit work. Maybe even more vital than anything on
this list. Solder is a small wire of metal. It has a very low melting point, which
means that it can be very quickly melted and solidified.
The soldering iron is a piece of electrical equipment that heats up rapidly to just
the right temperature to melt solder. The process of melting the solder and
cooling it in order to cement a wirehead into a circuit is called Soldering .
Soldering is done to fix the wire onto the circuit so that it is not easily removed,
as shown below.
The process is very simple,

The end of the solder wire is carefully placed on the wire


The wire is placed in the location it is to be held
The soldering iron is applied (the solder melts onto the wire) and
removed swiftly
The wire is held in position until the solder solidifies
The soldering is done.
Although soldering the way I described above is sufficient for your needs, it is
not necessarily the best way to go about it. There are a lot of different ways to
perform soldering, you will find that the method I will describe below will be the
best way to come out of the process with a functional, undamaged, neat and
well-done board.

Get a soldering station. This will allow you a certain degree of


precision when working with delicate components, and a certain
safety of temperature control over your soldering iron.
Get a brass sponge. This allows you to prevent the degradation of
your soldering iron’s tip by removing oxidation due to left-over
pieces of solder. You may also choose to simply use a wet sponge to
perform the same task, although this may shorten the lifespan of your
soldering iron tip.
Please, stick with lead-free rosin core solder if you are majorly
concerned about your health. While the lead solder is significantly
cheaper, for health reasons, it has become fairly unpopular. If you are
using a lead solder, ensure proper ventilation of your work place.
It is advised that you tin the tip of and keep your soldering iron hot
for about 20 to 30 seconds before starting with any form of soldering.
The temperature should hover around 573K.
Tinning the tip of the soldering iron involves covering the tip of the
soldering iron (360 degrees) with solder.
Once your circuit is set and your soldering iron is ready, place your
solder along the tip of your soldering iron (use a copper wire to keep
the solder stable if you wish) and after about 1 to 2 seconds it should
have melted unto the tip.
Hold the solder on the tip and support it with wire, if you need to.
Now, place the tip containing the solder on the joint between your
two circuit components. Ensure the solder is well placed and remove
your soldering tip in a move that should not take more than 3 to 4
seconds. The solder should have been left between the joint.
Wait for a few minutes for the solder to cool and check it to see if the
soldered joint is solid. Do not attempt to blow wind unto the joint in
an attempt to make it cool rapidly. Once the soldered joint is
confirmed solid and good, you may proceed.

Diode
Diodes are like transistors, a semiconductor device. One of the many interesting
properties of the diode is that they conduct electrons only in one direction.
Arduino boards have a diode in series (directly connected one after the other)
with their power input jack to prevent you from reversing the power, which will
damage the chip.
Diodes are generally built with a forward voltage drop that ranges from 0.5v to
0.7v. If you measure the voltage before the diode and after the diode, the voltage
will be 600mV higher before the diode as compared to after it.
This, of course, has its limits, if the reverse voltage surpasses the diodes limit,
This, of course, has its limits, if the reverse voltage surpasses the diodes limit,
the diode will break, which will cause current to flow freely in the wrong
direction. In some diodes called zener diodes, this will be controlled. Zener
diodes only conduct current if the voltage exceeds a certain value.
This value is specific and constant, so zener diodes can act as a reference in
voltage regulators.

LED
The LED is much like a diode, this means that it will connect electricity only in
one direction. This is an internal limitation deliberately built into its function.
LEDs have both a cathode (negative) and an anode (positive).
The cathode is usually the flat and shorter leg side, while the anode often acts as
the round and longer leg.
LEDs often come in various color, Red, Green Orange, Blue… and with various
forward voltages often written as VL (This will become significant later on).
Since they emit low energy light, their voltage drop is much lower than light
sources that emit UV, Blue… light.
Color Forward voltage (V L )
Red 1.7v - 2.2v
Orange 2.0v
Yellow 2.1v
Green 2.2v
Blue 3.2v - 3.8v
White 3.2v - 3.8v

This is an assumption that may not always be true for LED forward voltages.
Always confirm what your LED’s forward voltage is before using it.

Electronics and Physics


Before you begin using Arduino, there are some physics you need to know. If
you already know this, skip this topic.
Electricity is the flow of electrons (electric charge carriers) from one point to
another.
Electrons are the negatively charged sub-components of an atom.
Electrons are the negatively charged sub-components of an atom.
Electrons move easily through certain materials called conductors (copper,
silver, gold). These materials themselves contain free moving electrons
Certain materials like wood, plastic, rubber… are called insulators because they
don’t have free electrons and thus cannot conduct electricity.
Any material with more electrons than protons (positively charged sub-particles)
is negatively charged, and any material with more protons than electrons is
positively charged.
Much like magnets, opposite sides attract. Electrons in a negatively charged
materials will flow freely into a positively charged material as long as a
conductor is present between the two materials. This is called an electric current.
An electric current can best be described as the quantifying value of charge per
unit of time, flowing through a medium that conducts electricity. In physics, it is
denoted by the symbol “A”, which stands for Ampere and can be denoted by:
I = C/t
Where: C is charge (C) and t is time (s).
A battery is a device that possesses potential energy due to an imbalance of
electrons within one of it’s component.
Batteries have two sides, a cathode (the negative side that contains a lot of
electrons) and an anode (the positive side that contains very few electrons).
Since electrons generally seek to move to regions that lack them in sufficient
numbers, the electrons in the cathode will seek to move to the anode, which will
generate an electromotive potential (EMF).
The EMF stored in a battery is what lites an LED and rotates a motor. This EMF
is also called the potential difference, or more popularly Voltage (V/U) and is
represented as J/C.
The amount of energy a battery can release per second varies from one design to
another. This peculiarity of batteries and other voltage generation units is
described as Power and is designated by the unit J/s, which is generally referred
to as Wattage.
When drawing a circuit, the power will be drawn as if it flows from the Anode to
the cathode for convenience. In reality, the current will flow from the cathode to
the anode (due to the difference in the number of electrons on both sides of the
divide).
Most Batteries, are built to regulate how fast this happens, and that determines
Most Batteries, are built to regulate how fast this happens, and that determines
their wattage.
Resistors are represented by the symbol “Ω”. They are best described as
electronic components that limit the free-flow of electrons within themselves.
This is useful in reducing the discharge rate, which is how fast electrons move
from cathode to anode. Its also for limiting how strongly (voltage) electrons flow
through the circuit.
It is ideal for most circuits that these values (Voltage/Discharge rate) be limited
because of the delicate nature of most circuit components that come with
Arduino.
They are labelled with prefixes K “kilo”, n “Nano” …
Resistors color code :
Resistors come designed in 4 to 5 bands, all of which spots different color
combinations.
To understand the value of the resistor (1000 Ω, 200 Ω, 0.3 Ω…), it is necessary
to calculate for them using the color code.
The first 2 (or 3) bands are the 2 (or 3) first digits of the value, and the 3rd (or
4th) band is the power of ten that comes after those 2 (or 3) digits.
This is sometimes called the multiplier; it is just the number of zeros you have to
add.
The last band is the tolerance and is usually silver or gold.

An example is; red, red, red, gold (22 x 100Ω = 2,200Ω = 22 x 10² Ω = 2.2kΩ
with a tolerance of 5%).
Another example will be; green, blue, black, brown, red (560 x 10Ω = 5,600Ω =
5.6kΩ, with a tolerance of 2%).
There exists a relationship between the resistance, the voltage and the current
which can be calculated using Ohm's Law.
I = V/R
where I is the current (Amps), V the voltage (Volts), and R the resistance
(Ohms).
This is the most important formula in any electronic calculation you will do for
Arduino, so please remember it!

The Capacitor
A capacitor is a small electronic component that stores electric charges for a
circuit. Capacitors are used in Arduino to give the programmer more control
circuit. Capacitors are used in Arduino to give the programmer more control
over how power flows in the circuit.
Since, the capacitor is capable of storing electronic charge in an electric field, by
using them within the circuit, you can generate analogue voltages under the
program’s control with a simple “analogWrite(){” function.
Capacitors, like resistors, are by themselves useless as a part of the circuit. They
are often referred to as passive components. However, when combined with
other circuit components, they become immensely useful.
The capacitor also provides protection from overfiring relays.

Arduino IDE (Software)


Programming can generally be done with a simple notepad. It is in fact often
recommended you learn with it. We are not going to do that here.
Arduino programming is done with Arduino IDE (Integrated Development
Environment).
Download it here ( https://www.arduino.cc/en/Main/Software )
Installation:
For Windows:
Go to https://www.arduino.cc/en/Main/Software , select download
and click on Windows installer.
Click download.
Click the downloaded file to run it.
Grant administrator permission.
Agree to the License Agreement.
Select the appropriate boxes (you will need the Arduino Software and
the USB driver).
An installation folder will be requested, click on next or type in
another folder.
Click install.
You will be prompted on whether or not you wish to install the
Arduino USB Driver (device software), select install.
You will need to wait for a few minutes, and when the installion is
complete, launch the Arduino IDE.
For Ubuntu:
Go to the site, go to Download, and select the Linux version.
Click download.
Open a terminal window using this command: CTRL+ALT+T, then
run the following commands. Change the file names as appropriate
cd Downloads
run after that: tar xf arduino-1.6.11-linux64.tar.xz
run this after: sudo mv arduino-1.6.11/ /opt/arduino-1.6.11/
then run this: /opt/arduino-1.6.11/install.sh
this will add the dailout: sudo usermod -a -G dialout $USER

What the above commands do is: opens the Downloads folder, then unzip the
downloaded file, it then moves the unzipped file to “/opt/” folder, and finally, it
will run the install script.
The install script will then create a desktop file, and a MIME type file will also
be created to associate “.ino” files with the IDE. Finally, add “a = append” user
to the 'dialout' group (-G). This will allow the IDE to access the serial ports.
Upon opening the IDE, you will notice the greyed out “Tools > Port”. Upon
successfully adding your chosen ‘dailout’ group to the IDE, the option will
become enabled. You will have to close the IDE and reopen it for this to happen.
Or you can look at the installation steps as provided here:
(https://tutorials.ubuntu.com/tutorial/install-the-arduino-ide#0 ).
Arduino IDE + Teensyduino:
You will need the Teensyduino add-on for the Arduino IDE if you have a
Teensy board. A comprehensive installation guide can be found here
https://www.pjrc.com/teensy/td_download.html/ .
Teensyduino does not support the latest versions (1.6.10 & 1.6.11) of the
Arduino IDE, for now, so you will have to download this version (1.6.9).
You may come across an error while installing Arduino: If this is the case, try
running the command
sudo chmod +x /opt/arduino-1.6.6/install.sh
This adds (+) the permission to be executed (x).
Then from the above installation steps for ubuntu, try running: /opt/arduino-
1.6.6/install.sh again.
Chapter 3: Working with Arduino

Preparing Your Workspace


Arduino is usually done on a carpet free table, but your choice of workspace also
depends on how your Arduino is to be powered. For work powered by the USB
cord, it might make sense to use your computer table. For work powered with a
battery it will make more sense to use a dry plastic/rubber covered table with
only the flooring underneath. Like I had mentioned earlier, please keep away
from materials that can generate a static charge from your workplace.
To begin using Arduino, please make sure you have all the above listed vital
components, and that you have followed the necessary steps to download the
IDE onto your computer.
Once you have done that, you may proceed to the next topic.

Working with Your First Arduino


For your first work operating your Arduino,

1. Open your Arduino IDE by double-clicking on it. There are several


options listed on the header of the application, select File , then hover
on Examples and hover over 01.Basics . From the provided options,
select Blink .
2. The next step is to tell the software the type of Arduino you will be
working with. On the header, select Tools, then hover over the Board
option and select Arduino Uno (or whatever other board you
bought).
3. The next step is to plug in your Arduino using the USB cable that was
illustrated above. Please do note carefully the port through which
your Arduino was connected. It will become relevant shortly. The
boards LED will light up upon you doing this.
4. Then you will need to select the communication port the Arduino is
connected to. Do this by selecting Tool s from the header and then
clicking on Port . If your port is not already labelled with the Arduino
Uno, please unplug your Arduino from the computer, and plug it back
in again. Once your Board shows up, select the port containing the
Arduino. It should be labelled as “Arduino/Genuino Uno ”. On
windows, the port will likely be labelled as “COM3” and may be
labelled as “dev/cu.usbmodem1461” on OS X.
5. Click on Upload in order to transfer the simple Blink program to the
Arduino Board. You may also use CTRL+U to upload the code.
6. This will make the Board LEDs labelled TX and RX to blink, and the
software will display the message “Done Uploading ”.
7. The LED labelled as L will then begin blinking as it initially did upon
plugging in the Arduino.
8. Congratulations, you have just told your board what to do for the very
first time.
9. The Next step is thus to alter the code a little bit and see how the
modifications influence what the LED does and how it blinks.
10. The term compiling is often used to describe how the human-
readable code that you wrote is converted to a binary numbers file.
This is how Arduino reads your program (in binary). The binary file
is then uploaded to the Arduino’s memory during the upload.
Note: If the Port selected is not the one connected to the Arduino, an error
message will be displayed once you try uploading the Blink code. Refer to this
for a list of common errors on Arduino and how to solve them “
https://www.arduino.cc/en/Guide/Troubleshooting ”.

The Simple Blink Code


Here, we will explain the various things that make up the code you just uploaded
and how you can alter what your board does by changing things in it.
Now to examine the code. One thing easily noted when you clicked on your
code is that some texts show up on your workspace (the wide typing space that
covers your screen when you open the software). This is the code that tells the
Board what to do.
Arduino has no programming language of its own. The codes you will write to
use your Arduino are simply combinations of the C and C++ programming
languages.
The first 14 or so lines will be lighter than the rest, and examining them closely
will show that they are placed within these signs “*/” and “/*”. This is what is
called a comment: A comment is a line of words that come before or after a code
describing what the code does or other important things to the coder, yet does
not influence what the code does.
A comment can either be multi-line or single-line, and they are almost
universally lighter in color than the actual code. The example above was a multi-
line comment, single-line comments exist and is also illustrated in line 17.
line comment, single-line comments exist and is also illustrated in line 17.
Single-line comments use the operator “//comment:” instead of “*/comment/*”,
everything on that line will be a comment, and everything after it will be normal
code again.
Comments may also be used to temporarily disable a code by simple encoding
the code in the comment tag, this allows the programmer to prevent the code
from being executed without having to delete it. Since comments are not
executed, they do not take up space on the Arduino’s limited memory and thus
only exist on your hard disk.
“void setup(){” is what we will examine next.
This is a setup routine thus it will only run once every single time the Arduino is
started.
Void is a data type whereby is no information is returned by the setup.
The two brackets shown above are something used to pass data every function.
Since setup requires no data, the brackets are empty (This will be covered better
later into the book).
Everything that exists between curly brackets in the code is code that executes
while setup itself is running. Brackets in Arduino sketches are meant to be
closed, please always make sure you do this if you do not want to get error
messages. The software should normally notify you of any unclosed code, by
highlighting the piece for you or simply highlighting the closing bracket.
“pinMode(13, OUTPUT);” The command is the first command within the code
that alters the way your board works.
You might be able to guess by the name; it has to do with the rows of pins on
your board. These pins can either be output or input as described above. We will
want to make out pin number 13 an output. The pinMode is a value already
described by the software itself, thus it is a constant. It designates that what the
values within the brackets change is the mode of the pins (output or input).
Constants are designated with a blue color in the software (if it is not modified).
The first number designates the pin number you are modifying as 13 because the
blinking LED is connected to pin number 13. The comma is to make way for
another constant to be added (the software will treat the comma as a break
between two values describing pinMode).
The output value changes the pin number 13 to an output. The value is 1 as
opposed to input, which has a value of 0. Thus “pinMode(13, OUTPUT)” can
be written as “pinMode(13,1)” .
Every Arduino IDE statement is ended with a semicolon (;) , as can be noticed
in the above statement.
“voidloop(){” is the next function to be executed after the above-described setup
has finished running.
Voidloop is a little different from void setup because unlike the latter, it runs
continuously, and will repeat forever until the Arduino is restarted or another
program is uploaded.
“digitalWrite(13, HIGH)” is a command that like the similar example above
describes something that is to be done to pin 13.
What this does is designate the pin number 13 as high, therefore writing
something digitally onto the board. The high value makes pin 13 connect
internally to the 5V pin. Since the LED is now connected across the ground and
to pin 13, there will now be a 5v current passing through the LED, which makes
it light up.
Note: Do not ground the pin 13 once this command has executed. It will fry
your board.
This complimentary value to the “ HIGH” value is “ LOW” . This value can
also be written as “1” for the former and “0” for the latter or “true” and “false”
for the same. Should the value be “low”, this sets the pin 13 to ground, meaning
no current will now pass through it and the LED will switch off.
“delay(1000)” is the last function.
The “delay” function, like its name implies, delays the code for exactly the
stated amount of time (in milliseconds: 1000 = 1sec), before allowing the
Arduino to execute the next command.
Once the Arduino reads to line 29 (the end of the “void loop(){” ), it starts over
at line 25 again because of the loop you have created.
Interpreting the code shows that we are telling the LED to switch on and the
switch off for 1second (delay), before coming on again and repeat the steps
again. This causes the witnessed blinking that happens.
Note: if the position of “13” within the code is instead written as “led” , you will
see the variable “int led = 13;” written before the rest of the code. This tells the
IDE to let you code “13” as “led” . Therefore, for the rest of the code “led” will
mean “13” . This line of code is called a declaration.

Altering the Blink Code


You will be able to alter what the Arduino does by doing small modifications to
your code by altering the value in the “delay” function. By altering it from say
1000 to a value like 500 (or 200 or 2000). Uploading the new code will change
how fast your Arduino blinks from once about every second to once about every
0.5seconds (or 0.2seconds or 2seconds).

Sketch
On Arduino, A sketch is just another name used to describe what might be a
code when working with anything else, not Arduino. The sketch tells the board
how to behave, and what functions it needs to perform.

Using a Resistor
As you really get into Arduino programming, it gets more complicated. To be
honest, making what passes for a small bulb blink is not something really
impressive. That’s why you will learn how to add a resistor here.

The Physics Behind It


Before you begin connecting anything to your board, you should probably
unplug it from your computer. Next, you will need to know some things about
your board. You’ll need to know: your total resistance, the voltage of your LED,
and its current.

Using this formula R = .


The more LEDs you connect to your Arduino, the greater the true value of your
current and power distorts. This means you will need to know the total resistance
your LEDs will give the Electricity flow within the board.
You will connect the resistor in series with the LED (one resistor connected
directly to the LED). Since we know the voltage of the Arduino output pin is
+5V, adding the voltage of the LEDs to that of the resistors (VL + VR ) should
give a value not exceeding 5V.
This means VR = 5V – VL .
Since the current passing through the resistor is equal to the one through the
LED; IL = IR .
This means that we can say: R = VR /IR = (5V – VL )/IL .
This will let us calculate the value of the resistor that should be connected to the
LED (R).
LED (R).
Most Arduino work uses a 10K ohms resistor.
Note: substitute 5V for 3.3V if you happen to be using a 3.3V Arduino. Your LED
datasheet will tell you what your LEDs voltage and amperage is (V L and I L ).
Your amperage must not exceed 20mA, anything higher will fry your LED as
cautioned in chapter 1. Your calculated R will not be exactly what you have, so
take the resistor with the next higher value to it (it should not exceed +1Ω, or
your LED may light up weakly).
You will also calculate the resistance of your LED using the above method or
online using this application (https://play.google.com/store/apps/details?
id=it.android.demi.elettronica&hl=en ) or this tool
(http://led.linear1.org/1led.wiz ).

Continuing
The resistor can be connected to either the anode or cathode of the LED without
affecting the circuit, as long as it is in series with the LED.

You will now need to connect a red jumper cable from pin labelled as
5v to the positive horizontal rail on the breadboard.
Similarly, a blue cable will be used to connect from a pin labelled
ground to the negative breadboard horizontal rail. This is a
configuration you will use again and again for Arduino work.
Your next step is to plug a yellow pin into pin 13 and the other end
should be plugged in any of the labelled 10 rows on the breadboard
(c10).
You will next need to connect another blue wire from your negative
ground rail to any other row on the breadboard (c18).
The next step is now for you to plug your resistor into row d18 (the
row next to the one you chose above), with the other leg plugged just
under your yellow cable in c11.
Finally, you will need to connect your LED’s cathode to the resistor
at d11 and connect the Anode to the yellow wire at d10.
Uploading your new program will light up your LED again. The
current runs through the resistor, into your LED and back into the
Arduino in a loop with a delay value (????).
Arduino sketch examples in your Arduino IDE are a great way to learn
Arduino programming. Just load the examples, and compare it to your own
code (debugging) to fix any problems that may come up.
code (debugging) to fix any problems that may come up.
Note: You may need to trim the legs of your resistor in order to reduce the
chances of any open leg coming in contact with other wires and shorting the
board.

More LEDs
This is something very easily done with Arduino and a small breadboard. This
will be done similarly to what was done with the resistor, but a little differently.

Connect the two pair of rails on the breadboard together using jumper
cables. (positive to positive and negative to negative). The widely
used method is using a red cable for the positive rail and a blue cable
for the negative rail. This makes it easy to distinguish which is which
without retracing your steps. It allows power to flow to both sides of
the breadboard.
The next step is similar to what you did in the one LED example
(connect the 5V pin to the bottom of the first positive rail using the
red wire, connect the ground pin to the bottom of the first negative
rail using the blue cord. Connect pin 13 with the yellow cable as
shown before). Repeat the rest of the first tutorial to add the other
blue cable, resistor and LED.
We start adding more LEDs by connecting a resistor from the ground
(the other negative rail) to h12, and a LED with the shorter end
(negative) at g12 (same row as a resistor) and the longer one
(positive) at g11.
Add the remaining LEDs with the same pattern as the first slowly
going down.
Now you are to change the position of the yellow wire on pin 13 to
pin 6 and add another yellow connecting from pin 5 to f11 on the
breadboard.
Do the same for the remaining pins, slowly going from pin 4 – 3.
Congratulations, you are finished with your Arduino board. Now it’s
time to code.

Coding
The first step to coding is to perform certain declarations you may need to use in
the rest of your code.

You can start by declaring “int timer = 200;” , this tells the compiler
that an integer called “timer” should have a value of “200” .
Declare the “void setup() {” , then unlike before within the “{”, you
will declare;

for (int thisPin = 3; thisPin < 8; thisPin++) {


pinMode(thisPin, OUTPUT);
} and close it with another “}” .

What this means is that the setup will configure the pins 3 to 7 as
output, as the code had declared that “let “thisPin” be 3, let
“thisPin” be < 8, let “thisPin” be all values (integers) greater or
equal to 3 but less than 8, now set “thisPin” as output.
This short piece of code together with the set the code into a changing
mini loop. Each time the loop repeats, the value of “thisPin” is
increased by 1. Thus, by the next loop instead of 3, the value of
“thisPin” will now be set to 4. This will repeat itself over and over
again until the loop is complete.
To continue with the rest of the code, you will now need to set the
digitalwrite(thisPin, HIGH);” together with the rest of the blink
code. If you followed the blink example, then you already know what
that does.
There is an inclusion though. Since the “void loop(){”s “for”
declaration changes value, you will need to declare

“for (int = thisPin = 3; thisPin < 8; thisPin++) {”


This tells the loop to execute the command once before changing the value
of “thisPin” to the next one.

Since we don’t want to have the LEDs turn on one after the other
before turning off, we will include “digitalwrite(thisPin, LOW);”
after declaring the “delay(timer)” . This makes the LED turn off
after the delay.
However, since the value of “thisPin” changes as the loop repeats,
the LED changes as the light flashes. This causes the LEDs to flash
one after the other in a smooth row, from the one connected to pin 3
to the one connected to pin 7.
This is a simple method of connecting multiple LEDs and an example
of how to code such a thing. We will explain more as we cover more
topics.
Note: this code can also be done by writing it as:
Note: this code can also be done by writing it as:
for (int thisPin = 7; thisPin >= 3; thisPin- -) {
pinMode(thisPin, OUTPUT);
} .
This does exactly what the above code does, but instead of increasing the value
of “thisPin” as the mini-loop runs, it decreases it till it gets to 3, before starting
again. “>=” means greater or equal to (the value will include the integer),
“<=” means lower than or equal to (the value will include the integer), “<”
means less than ( the value does not include the integer), “>” means greater
than (the value does not include the integer).

Optimizing
The above code is an example of optimized code. It does everything you need it
to do while requiring only the shortest amount of code.
Optimization in coding is the process of reducing the code to the bare minimum
required for it to carry out the exact function needed. An optimized code is one
containing no extra words that can be done in another way to make it a shorter
code.
There are many ways to write code. The blink code for multiple LEDs, as shown
above, could be written in a different way. Another way to write this code is:
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {
for (int thisPin = 3; thisPin < 8; thisPin++) {
digitalWrite(thisPin, HIGH);
delay(timer);
digitalWrite(thisPin, LOW);
}
}
This does exactly what the above code does. However, it is almost twice as long.
This is an unoptimized code.
The mark of a good programmer is the ability to write a code in the shortest
amount of words possible without affecting its action.
Another advantage of optimized codes is that they run faster than normal code
since the computer reads all the declarations faster. This might have no effect on
the speed of the light coming on, but as the code gets larger, the effect slowly
compounds and the code runs slower.
Chapter 4: Exploring Arduino

Further Simple Sketches


Fade
Turning on multiple LEDs is a little bit more impressive than doing so with a
single LED. How about something more challenging, like making the LED fade
out? This is possible to do with Arduino. We will be using the function:
“analogwrite() ;” . What this does is simulate the appearance of brightness
between the on and off stage using something called a PWM (pulse width
modulation).

Connect the LED again much like when you practised the blink
example, but change the pin position of the yellow cable to pin 9
from pin 13. Everything else will be the same. Connect you Arduino
back into the system and make sure your port is selected correctly.
int led = 9;

int brightness = 0;
int fadeAmount = 5;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30);
}

What the code does is:

1. Set the value of led to represent 9, the value of brightness as 0


and the value of fadeAmount as 5
2. The void setup declares pin number 9 as an output.
3. analogWrite then sets up pin 9 to whatever brightness is given
at the time
4. Next is the fadeAmoun t function that sets how much the
brightness increases as 5
5. Next, the if statement checks if the brightness is less or equal to
zero or if it is greater or equal to 255
6. Thus, the code executes to increase the brightness until it
reaches 255
7. Once this is done, the code again increases the brightness by a
negative 5, until it reaches zero
8. The delay declaration is to prevent the code from running so
fast that you do not see the fading effect

Upload your code and restart your Arduino. The LED will start
fading in and out.
Like we mentioned earlier, this is in truth a manipulation of how the Arduino
interprets the code. Arduino can normally only generate digital signals.

Button
Connecting a button to Arduino is not very difficult. It is different from what
you have been doing so far because instead of just doing output code, for the
Arduino to function, you will need to do input. The Arduino will read the input
from the Button and interpret what to do based on the code you uploaded.

Much like you did with your first Arduino, connect the blue and red
cables to the power rails of your breadboard. Then connect the yellow
cable to pin 13 and d6.
Connect both rail sides of your breadboard together, connecting two
positive sides together and two negative sides together.
Connect your resistor to the negative rail (we are not using another
cable to connect to the breadboard) and to d5.
Connect your LED to e5 and e6 using what you have learned so far.
Another Yellow wire will be used to connect pin 2 to b18 and a
resistor will lie between a18 and a positive breadboard rail.
Finally, the button should lie between e16-e18 depending on your
button type and f16-f18. Then g16 will be connected to the negative
power rail on the other side as illustrated above.
Now that you have to code what your board looks like into your IDE
const int buttonPin = 2; // declaration of “buttonPin” {it is connected to pin
2} to represent the value 2:
const int ledPin = 13; // declaration of “ledPin” to represent the value 13:
int buttonState = 0; // declaration of “buttonState” to represent the value 0:

void setup() {
pinMode(ledPin, OUTPUT); // declares the LED as an output:
pinMode(buttonPin, INPUT); // declares the pushbutton as an input:
}

void loop() {
​ buttonState = digitalRead(buttonPin); // reads the state of the
pushbutton:
​ if (buttonState == LOW) // checks if pushbutton is currently pressed:
{
​ ​ digitalWrite(ledPin, HIGH); // The LED turns on:
​ ​ }
else // if the pushbutton is not pressed”:
{
​ ​ digitalWrite(ledPin, LOW); // The LED turns off:
​ }
}
The interpretation for this code is fairly obvious. The Arduino reads the code
top-down, so if the button is pressed (current flows through the button, thus, it is
called HIGH), the LED turns on. If it is not pressed (no current flows through
the button, thus, it is called LOW), the LED goes off. This is the function of the
attributes “if” and “else” .

The Serial Monitor


This is a tool used by programmers used to check in on different spots of their
This is a tool used by programmers used to check in on different spots of their
code on the computer. It uses the same circuit build like that of the previous
button tutorial, without the LED. The code has the following design:
int pushButton = 2; // the name pushbutton is given to pin 2:
void setup() {
​ Serial.begin(9600); // initializes serial communication at 9600 b/s:
pinMode(pushButton, INPUT); // declares the pushbutton pin as an
input:
}
void loop() {
​ int buttonState = digitalRead(pushButton);
//reads the state of the pushbutton:
​ Serial.println(buttonState); // prints out the state of the button:
​ Delay(3); //this is purely for stability:
}
}
Once the code is uploaded and the Arduino compiles it.
You can also do this by opening your file header link in the IDE following these
steps:
File -> Examples -> 01.Basics -> DigitalReadSerial. This opens a similar code to
the one above.
Once this has been done, a window opens up on your IDE at the upper right
corner. The number within the code “serial.begin();” is called the data speed in
bits per seconds.
By changing the values described, you can easily see what is actually happening
on the board, whether the pin 2 is actually HIGH or if it is LOW or if pin 13 is
actually output or input. This makes the serial monitor code a very handy thing
when troubleshooting your Arduino.

Sensors and Input


Configuring the LEDs was a simple function of output. To use input, we need a
set of components called sensors.

Sensors and Actuators


Sensors and Actuators
A good definition for a sensor would be “an object with the purpose of detecting
events and changes in the environment while producing a corresponding output

A sensor can thus “listen” to the physical environment and interpret it in order to
produce digital data. The actuator on, the other hand, is a device that converts
energy into movement. Both devices are just two sides of a coin. An actuator
converts digital data into output and a sensor converts environmental factors into
an input.
Using the example of a heater, the heater will be designed to increase the
temperature to say “300K”. How does the heater however, know when the
temperature is 300K? This is done by a sensor that will have been included in
the heater’s design.
Arduino is capable of dealing with both Analog and Digital inputs but can only
handle digital outputs. Sensors usually communicate in analog, but most have a
small circuit that is capable of translating analogue into a digital value. This is
because while digital information is presented in binary, analog information is
presented as amplitude variations. Thus, analog pins on Arduino are input.

Temperature Sensor
A temperature sensor does as its name implies; it senses changes in temperature.
A popular basic program is to connect a temperature sensor to an LCD and
Arduino to make it display the current temperature. Most large appliances use it
to monitor their own internal temperature changes to prevent damaging rises in
temperature.

Infrared Emission Sensor


This is used to transmit light at a frequency of 38KHZ (infrared). The actual
emission frequency depends mostly on the model. It is used to send code from
one Arduino to another or to even control a TV. It is also referred to as an
“infrared emitting diode”.

Photoresistor
This is basically a light-dependent resistor. Its resistance varies with the intensity
of the light to which it is exposed. This is used as a sensor to build equipment
that only works when there is light, or that shuts down when there is light, like a
light-sensitive coffeemaker.
light-sensitive coffeemaker.

Sound Sensor
This has proven to be very popular with makers of voice changers. The sensor is
capable of detecting changes in the surrounding sound, and it interprets these
changes as data. It usually has adjustable sensitivity.

Knock Sensor
This is used to build knock sensitive locks. They detect the sound of a knock.
For most builds, they are connected to LEDs that turn on when the sensor detects
someone knocking.
There are many other sensor types available, and we cannot list them all.

Pulse-Width Modulation
Pulse-Width Modulation is a type of digital signaling that has proven incredibly
useful to programmers everywhere. It is used by engineers and circuit designers
to create circuitry with sophisticated controls.
It is very common and useful to people who work with Arduino.
PWM allows the programmer to change how long Arduino pin spends at HIGH
in analog at a consistent interval.
PWM is used by Arduino programmers to effect fine control over circuit
components that cannot normally perform at such fine levels. It is especially
popular for controlling the brightness of display units (RGB LED, LCD…), fine-
tuning the grip of a robot arms, etc.
The term duty cycle is generally used to describe this difference in the amount of
time a signal is high compared to when it is low. This is calculated in
percentages. The “on-time” describes when the signal is high.
Thus, if a signal (5V) has a duty cycle of 50%, ​ you are getting only 2.5V of
electricity in reality.
Apart from dimming LEDs, this is also used to the reduce power consumption of
Arduino by altering digitally how much current is supplied without actually
touching the board.

Switches
A switch is a mechanical device that is capable of either breaking a circuit or
connecting it. It is just one small pushbutton in a completed board. However, its
importance is not depicted by its small size. Any Arduino board that was built
importance is not depicted by its small size. Any Arduino board that was built
for use must have a switch, this is to give a degree of control to the user,
allowing him/her to control whether the device should be currently working or
not.

A Sensor Sketch
This will be an example using an actual sensor. We will be demonstrating this
using a potentiometer. The attempt is to build Arduino that is capable of sensing
sound waves.
An ultrasonic sensor emits sound at a frequency of 40,000HZ. This sound
bounces back to the sensor, which records the time as data. The sensor interprets
the data using the relationship between time and velocity.
VCC, Echo, Ground and Trig are the four pins that can be found in an HC-SR04
Ultrasonic module. To make Arduino that can sense distance, we connect the
shields VCC pin to the 5V pin on Arduino, the Ground pin connects to the other
Ground pin, while the Trig and Echo pins connect to pin 9 and 10 on the
Arduino.
The code will be found here. The comments within the code explain what the
various code sections do.
https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/
The distance is calculated by multiplying the duration by 0.034 and dividing the
result by 2. This is a fairly simple example of a sensor sketch.
You can freely experiment by using different sensor types.

Arduino Logic
void setup( ){
statements-1;
.
.
.
statement-n;
}
void loop ( ){
statement-1;
.
.
.
.
statement-n;
}
The above is a simple example of what an Arduino code should look like. Most
Arduino codes will follow this simple basic design. There are two blocks to
Arduino programming, the Preparation and the Execution. Each block is
always enclosed in curly braces. The setup (), is the preparation block. Loop () is
the execution block, and everything contained within it is what the Arduino
reads to determine its function.
The setup function starts serial communication. It is where you declare whether
your pin is to be output or input as we had explained above. Once setup has been
declared the board starts reading pin numbers and setting them as input/output.
void setup ( )
{
pinMode (pin-number, OUTPUT); // this will set the ‘pin-number’ as
an output
pinMode (pin-number, INPUT); // this will set the ‘pin-number’ as
an input
}
The codes in-between the loop are executed continuously. The code runs from
the beginning of the curly bracket to the end of it, before returning to the
beginning to start again, until the Arduino is switched off.
Void loop ( ){
digitalWrite (pin-number,HIGH); // this will turn ON the component
connected to the ‘pin-number’
delay (500); // this makes the board keep its current configuration
for 0.5s
digitalWrite (pin-number, LOW); // this will turn OFF the component
connected to the ‘pin-number’
delay (500); // this makes the board keep its current configuration
for 0.5s
}
}
Declaration sometimes comes before the setup, but it is always read as part of
the setup. These usually take the form of the int attribute, which means integer.
They are used to change certain functions about how the code is interpreted once
it starts executing.
All statements in a code ends with a semicolon.
int led = 9;
int brightness = 0;
int fade = 3;
void setup( ){
}

There are literarily thousands of Arduino syntaxes out there. It is impossible for
us to go through them all. We will examine some, however.

Variables

Constants
Floating Point Constants: This variable is similar to integer constants. They
are used to make code readable. They allow the use of scientific variables like e
and E.
Integer Constants: This variable consists of numbers. They are automatically
treated as base 10 but can be modified with modifiers like; 10 (decimal), 2
(binary), 8 octal.
HIGH | LOW: These variables specify the two values of a pin (HIGH/LOW).
For Input : HIGH is reported when the voltage at the pin is greater than 3.0V for
5V boards and 2.0V for 3.3V boards OR for Output : HIGH is reported at 5V
for 5V boards and 3.3V for 3.3V boards.
For Input : LOW is reported when the voltage is at 1.5V for 5V boards and 1.0V
for 3.3V boards OR for Output : LOW is reported as 0V for both 5V and 3.3V
boards.
INPUT | OUTPUT | INPUT_PULLUP: This function changes the electrical
behaviour of a pin with “pinMode()” . Pins configured as INPUT; make
extremely small demands on the circuit they are on. For INPUT_PULLUP;
This is the same as input, but instead of external resistors being used to reduce
voltage demands, the circuit will use its own internal pull-up resistor. For
OUTPUT; This makes the pin into power demanding conductors on the circuit,
allowing the board’s full voltage to flow into them.
LED_BUILTIN ; This variable stipulates the pin to which the on-board LED is
connected to. This is usually pin 13.
true | false ; These are Boolean constants. False is defined as 0 and true is
defined as 1. Any integer that is non-zero is true, but true is often used to
represent a true statement. It is typed in lower case, unlike the other variables.

Data Types
Variable datatypes that exceed their maximum or minimum capacity are said to
overflow . This causes unpredictable results. To avoid this problem, some
programmers use unsigned datatypes like “unsigned int, unsigned long,
unsigned char ”.
String(val); String(val, base); String(val, decimalPlaces); This constructs an
instance of the string class. It will return a single instance of the string class. It
allows multiple data types.
array ; This is variables in a collection that can be accessed with an index
number. Examples are;
int my[6];
int myT[] = {2,4,6,8};
int myTs[6] = {2,4,-8,3,
Char message[6] = “hello”;
All the above methods are valid for the declaration of an array.
Arrays are accessed by declaring;
myT[0] == 2, myT[4] ==8,…
This means that the last declarable index for an array is “n-1”. C++ does not
check if the array you declared is legal or not. Be careful not to exceed the
number of arrays you declared if you do not want errors.
bool: This holds one of two values (true/false).
boolean: This is a non-standard term for bool in Arduino
byte: This stores an 8-bit unasigned number. It is from 0-255.
char: This is used to store character values. Only use this datatype to store
characters. It occupies 8 bytes
double: It is implemented like float and occupies 4 bytes. It is a double-
precision floating number.
float : This is a datatype for numbers with decimal points. It is popularly used to
approximate analog and continuous values due to their greater resolution as
compared to integers.
Float should be avoided in mathematical calculations because they can only
contain 6-7 characters, their absolute values are different and they run slower
when compared to integer math. Float will be treated as integer unless you add a
decimal point.
int: These are the primary datatype. It is a number storage and stores a 2-byte (2
bit) value. They store negative numbers by “2’s complement math” and the
highest bit is called the “sign” bit.
long: these are variables that store 4-byte (32 bit), they are extended size
variables for number storage. L is added to at least a number when doing real
math with integers.
short: This datatype is 16 bit.
string: There are multiple versions string constructs but they can all be
represented in two ways. A string can be made out of a datatype or from an array
(made from type char) and simply null-terminate it. Examples for the first type
will be described in function . Strings are normally automatically terminated
with a null character “ASCII code 0”. This allows the function “serialPrintln() ”
and others like it to tell where a string ends and terminate it there. Strings have
one more character than the text it contains.
char str1[15];
char Str1[8] = {‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’};
char str7[8] = {‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘\g’};
char str8[] = “Arduino”;
char str9[8] = “Arduino”;
char str5[15] = “Arduino”;
All the above strings are correct and will run without error.
Note: Strings are always defined in a double quote (“bvc”) while characters are
in a single quote (‘fds’).
void: This is used only for function declarations. They signify that the function
is not to return any information to the function it was called from.
word: This datatype stores unsigned number of 16 bits (2-byte).

Structures
Structures
Sketch
setup(): This is what is called to start a sketch. It is used to initialize variables,
pinModes… It runs only once.
loop(): This does exactly what its name says. It runs after setup and does so
forever and without end. It is what actively controls the board.

Arithmetic Operators
% (remainder) : This calculates the remainder after an arithmetic division
operation. It does not work on floats and is useful in keeping variables within
range. If its first value is negative, the result will be negative.
* (multiplication) : This operator multiplies two values together. It often causes
an overflow because it is easy for the result to exceed the datatype in this type of
operation.
Should any of its datatype be float or double, floating point math will be used to
obtain the result.
+ (addition) :
- (subtraction) : This operator finds the difference between two datatypes. It can
easily overflow should the result be smaller than the datatypes range. Much like
with multiplication, floating point math is used should one of the data be of type
float or double.
/ (division) : This operates on two datatypes to produce a division of the lower
data from the upper data. Float point math will also be used for the result if one
of the datatype is floator double.
= (assignment operator) : This tells the microcontroller to evaluate the variable
or datatype on the right of the assignment operator and store said data on the left.

Control Structures
break : This is a structure used to exit conditional statements. It can also be used
to exit a switch case. The break statement bypasses the normal loop condition.
continue : This structure skips the rest of the loops current iteration. It is a
conditional statement containing conditions like (for, while…). The Arduino
checks the condition and proceeds if said condition is met.
do...while : This does the same thing as the while structure, but it will run after
the loop, thus, making the loop run at least once even if it does not meet the
required condition.
else : This allows for the grouping of multiple tests. It will only be executed if
the “if” statement result yields “false”. The tests will carry on until it yields
“true”. If none of the conditions report “true”, the default operation is carried
out. It is normally used with the “if” statement, to grant a bit more control to the
statement.
for : This statement repeats a block of statements. It uses an increment counter
to terminate the loop. It is useful for any repetitive operation and often appears
with arrays operating on collections of data.
goto : This will transfer the program flow to a specified point in the program. It
allows the Arduino to skip certain codes. It lets the programmer place his code
without having to worry about where it is.
if : This structure is used to check for a condition and the proceeding statement
will be executed if the condition is “true”.
return : This is used to terminate a function and return the value of that function
should it be called.
while : This is used to loop a statement infinitely until the statement condition
eventually proves “false”. It only applies to test variables that changes while the
code is running.

Boolean Operators
! (logical not) : This reports as “true” only if the operator is “false” and “false”
only if the operator is “true”
&& (logical and) : This is a logic operator that reports “true” only if both
conditions are “true”.
|| (logical or) : This reports as “true” if even one of the 2 operator is “true”.

Comparison Operators
!= (not equal to) : It compares variables from both sides and reports “true” if
they are not the same, otherwise it reports “false”. You should only compare
variables of the same datatype, otherwise you may get unpredictable results.
Negative numbers are less than positive ones.
< (less than) : This compares variables on both sides of the operator. It will
return “true” if the operator on the left is less than that on the right. Negative
numbers are less than positive ones. You should only compare variables of the
same datatype, otherwise you may get unpredictable results.
<= (less than or equal to) : This compares variables on both sides of the
operator. It will return “true” if the operator on the left is less than or equal to
that on the right. Negative numbers are less than positive ones. You should only
compare variables of the same datatype, otherwise you may get unpredictable
results.
== (equal to) : It compares variables from both sides and reports “true” if they
are the same, otherwise it reports “false”. You should only compare variables of
the same datatype, otherwise you may get unpredictable results. Negative
numbers are less than positive ones.
> (greater than) : This compares variables on both sides of the operator. It will
return “true” if the operator on the left is greater than that on the right. Positive
numbers are greater than negative ones. You should only compare variables of
the same datatype, otherwise you may get unpredictable results.
>= (greater than or equal to) : This compares variables on both sides of the
operator. It will return “true” if the operator on the left is greater or equal to the
operator to the right. Positive numbers are greater than negative ones. You
should only compare variables of the same datatype, otherwise you may get
unpredictable results.
For further reading on the types of functions and syntaxes in Arduino, please
visit (http://arduino.cc/en/Reference/HomePage/ ). This is an Arduino reference
page that lists all the different types of functions for controlling the Arduino
board. Use this to code when coming up with your own projects that may not
have functions already listed in this book.

Functions
Functions in Arduino represent a modular series of code that performs a defined
task and then returns to the area of code from which the function was called. It is
like writing a mathematical equation in the code. For programmers
accomplished in the use of BASIC, functions allow the utility of subroutines.
Functions codify one action in a single place so that, the code only has to be
perfected once. This allows you to debug a single code and use that function an
unlimited amount of times without having to worry about errors.
Functions also influence your coding by making it modular. This makes the
program more readable and gives the programmer significant freedom in time
program more readable and gives the programmer significant freedom in time
when coding, since a large part of the code would have been done as functions in
a previous work.
There are two required functions for Arduino to work, “setup()” and “loop()” .
All other functions must be created outside the curly brackets of these two
functions.

Examples:
int myMultiplyFunction(int x, int y) {
​ int result;
​ result = x * y;
​ return result;
}
The above code is a function. It allows for the multiplication of two integers “x”
and “y” and save the result into memory. We declared “myMultiplyFunction”
to be an integer containing two values “x” and “y” . Then, within the
declaration, we declare another integer “result” . By giving result a value of “x
* y” (a multiplication of “x” and “y”), the function is to return the result of that
multiplication and assign it to whatever contains the “myMultiplyFunction” .
To use the function, we can do this:
Voidloop() {
​ int h = 2;
​ int g = 3;
​ int z;
​ z = myMultiplyFunction(h, g);
​ serial.print(z);
​ delay(3);
}
In the above code, we use the function we had declared by equating “z” to be
“myMultiplyFunction” , this mean that the values of “g” and “h” will
substitute for “x” and “y” in the above declared function and return “z as 6” .
The remaining code does serial print for the Arduino so that we can physically
observe the result.
The “myMultiply function can be declared above or below the rest of the code.
The “myMultiply function can be declared above or below the rest of the code.
While it is preferable to declare a function before you use the function, it is not a
rule.
A complete code will look like this:
int myMultiplyFunction(int x, int y){
​ int result;
​ result = x * y;
​ return result;
}
void setup(){
​ Serial.begin(9600);
}
void loop() {
​ int g = 2;
​ int h = 3;
​ int z;
​ k = myMultiplyFunction(g, h);
​ Serial.print(z);
​ delay(500);
}
Do not leave spaces in the declaration of names within your function. Arduino
will only accept 0-9, A-Z and the underscore (_), a function is not allowed to
start with a number.
A functions body must be contained within braces as we have seen with the
“voidloop(){” and “void setup(){” examples. The type of function is declared
first (int, void, const). The name of the function usually follows
(myMultiplyFunction, setup, loop). After this is to be the body of the function
contained within curly braces.
Within a functions body, a return type must always be present, even if it is void
like in “void loop” . The function must be called within the “void setup()” body,
by either simply declaring the name as in the above example or for those that are
not integers;
void DashedLine() {
​ serial.println( “----------” );
}
}
void loop() {
}
void setup() {
​ serial.begin(9600);
​ DashedLine();
}
As you will notice the function is called without any preceding “int” call. This is
because so far, we had been dealing with integers (numbers), but because the
new function is simply letters, we can call on it without preceding it with any
data type.
Note: we used “serial.println” and “serial.print” , both attributes do the same
thing, with the exemption that “serial.println” does this on a new line while
“serial.print” does it on the same line.
There are many different functions out there, we will list a few.
Digital I/O
digitalRead(pin, value) : This function reads the value of a specified digital pin
(HIGH/LOW).
digitalWrite(pin, value) : This function writes a value (HIGH/LOW) to a
digital pin.
pinMode(pin, mode) : This function configures the specified pin to behave as
either input or output.
Analog I/O
analogRead(pin) : This function reads the value from the specified analog pin.
analogReference(type) : This function configures the reference voltage for
analog input (DEFAULT/INTERNAL/EXTERNAL/INTERNAL1V1…)
analogWrite(pin, value) : This function writes an analog value to the specific
pin (PWM pins).
Math
abs(x) : This calculates the absolute value of a number. It returns +x if >= 0 and
-x if < 0.
constrain(x, a, b) : This function constrains a number within range. X will be
the constrained number (all data types), a is the lower end of the range (all data
types) and b will be the upper range (all data types). It will return x - if within
range, a – if less than a and b – if greater than b.
map(value, fromLow, fromHigh, toLow, toHigh) : This re-maps a number
from one range to another. It returns the mapped value
max(x, y) : This calculates the maxima of two numbers. It returns the larger of
the two numbers
min(x, y) : This calculates the minimum of two numbers. It will return the
smaller of the numbers.
pow(base, exponent) : It calculates the value of a number raised to a power.
Used to generate curves… It returns the exponent result. The data type for
exponent is float, for base is float and for return is double.
sq(x) : This will calculate the square root of a number. It returns the number’s
square root as data type double.
sqrt(x) : This calculates the square of a number. The datatype of the return is
double.

Random Numbers
random(min, max) ; or random(max) : This will generate pseudo random
numbers. It will return a number between min and max-1 with datatype long.
randomSeed(seed) : It initializes pseudo random number generator. The seed
data type is usually unsigned long.

Bit and Bytes


bit(n) : This computes the value of a specified bit. It returns the value.
bitClear(x, n) : This clears a bit of an assigned numeric variable.
bitRead(x, n) : This reads a bit of a number. It returns the bit’s value.
bitSet(x, n) : This will write a 1 to a bit of variable.
bitWrite(x, n, b) : This will write a bit of a numeric variable.
highByte(x) : This will extract the leftmost byte of a word. It will return the data
type byte.
lowByte() : This extracts the rightmost byte of a word. It returns data type byte.
There are hundreds of other functions that can be found at
(http://arduino.cc/reference/HomePage/ ). Please visit at your discretion.
Chapter 5: Circuits, Arduino Shields and Library

Circuit Diagrams

We discussed resistors and voltages earlier. There is a lot more to learn if you
are to become proficient in Arduino.
A simple electric circuit, as can be seen, has a battery (supplies power), a resistor
(controls the current) and a LED (lights up to signify the circuit is on. More
components can be easily added to this circuit, like more resistors, LED, a
capacitor, a potentiometer, a switch…
The load of a circuit is the total amount of power all the components of the
circuit will need to function. If the power supplied to the circuit is smaller its
load, the circuit will not work (or will work slowly/weakly).
Arduino circuit diagrams looks a little different however.
The large rectangles represent the Arduino
The labels had already been explained in a previous topic, please
refer to it.
The “-/\/\/\/\-” represents the power source (battery)
The lines represent cables and connections linking to each other. Any
label not linking to another represents a label that was not employed
The “-/ -” represents the switch and the rest of the symbols represent
what they stand in for in a normal circuit.

Shields
They are modular circuits that can piggyback on your Arduino to give it extra
functions. Arduino shields are a must if you want to do something more than
light up a LED and print a few things on your computer. While you may be able
to rotate a motor with your Arduino, what if you wanted to connect to twitter
with it?
Shield were built in the same spirit as that of Arduino. Easy to use, cheap, small
and functional are the best words to describe Arduino shields. Much like
Arduino itself, they come in various shapes, sizes and functionalities.
It is possible to add more than one shield to Arduino, in fact, the only thing that
limits the number of shields that can be added to Arduino is the circuit load.
Shields often come with a library or an example sketch. This makes working
with shields a very easy thing to do. For an experienced Arduino user, it is
possible to connect Arduino to a shield and get it working in just 5 minutes.
possible to connect Arduino to a shield and get it working in just 5 minutes.

Arduino shields are built with a similar form as Arduino boards themselves.
Power and ground pins will be on one eight pin header, and there will be other
analog pins on a six-pin header next to the eight pins. Digital pins will usually
occupy the other side, an eight-pin header that is seperate from another ten-pin
by some spacing.
Some shields will require another connection to the Arduino's ICSP header as
shown above (the2- 3 pins at the vertical left). Most Arduino shields will use
every pin available on the board, although some take only a few.
Some shields are capable of communication using SPI, I2 C or serial, while
others use analog inputs or Arduino’s interrupts.
Note: Do not use overlapping pins when using multiple Arduino shields.

Types of Shields
Prototyping Shields and Others
Protoshield Kit
This Shield works as a big prototyping area. It is the most popular prototyping
shield. A breadboard can be connected to it, or you can just solder directly to the
board.
Go-Between Shield
This shield solves the issue of overlapping pins by sitting between two shields
and swapping the pins of the top shield.

ProtoSrew Shield
This is a useful tool for linking Arduino to external motors and heavy-duty
sensors. It is similar to the ProtoShield, but each pin is linked to a new screw
terminal.

Danger Shield
This shield typically contains everything from potentiometers, to display, to a
couple of other impressive sensors. The danger shield allows you to mess around
with your Arduino by warning you of danger. It is very important when learning
the ins and outs of using Arduino.

Joystick Shield
This is used to turn the Arduino into a control tool. It contains what might be a
controller, thus allowing you to use your Arduino to control things like robots.

MicroSD Shield
Because of the limited space typical in most Arduino, it might make sense to
connect a microSD shield to the board. This will allow you to input a microSD
in your board and use its memory space for extra storage functions. It typically
comes with an SD library.

Ethernet, Wi-Fi, GPS… Shields


WiFly Shield
Called Wifly shield by SparkFun, this is a mainstay shield that equips your
Arduino with the ability to connect to wireless networks (802.11b/g). It is
capable of acting as both the web client or server and even both.

Arduino Wi-Fi Shield


This is one of the classic shields. It allows the Arduino to connect to a Wi-Fi
router and allow it to host web pages and surf the web.

Arduino Ethernet Shield


Arduino Ethernet Shield
This is just Arduino Wi-fi with wires. It is a bit more popular than the Wi-fi
shield though, because of its ease of use. It imbibes your Arduino with the
capability to surf the world wide web freely and comes with a very large library.

XBee Shield
XBee provides Arduino with the ability to communicate wirelessly. While it
cannot connect to world wide web, it can be used to wirelessly start sprinklers,
lights, and coffee machines. It is also very cheap and easy to use.

w/ SM5100B Cellular Shield


This basically turns your Arduino into a cellular phone. It allows you to send
text messages and receive messages. Just connect a microphone and speaker to it
and you may just have yourself another phone.

GPS Shield
Like its name suggests, this shield allows you to use the Global Positioning
system with Arduino. With this, you will always know where you Arduino is.

Electric Imp Shield


This is quite a unique shield, and doesn’t deserve its low position on this list at
all. It looks like a microSD. This shield also allows the programmer to use Wi-Fi
(host web pages, surf the net, etc), but it is significantly more powerful than
anything else on this list.
Sound Shields
VoiceBox Shield
This is a sound alteration Shield capable of altering the voice of anyone speaking
to it. It is used to give the user’s voice a robotic, mechanical sound.

Music Instrument Shield


This shield was designed to be able to make a variety of sounds. It uses the
MIDI protocol to, when connected to Arduino, turn it into a bank of musical
instruments. It is capable of making a library of sound effects like piano sounds,
drums, etc.

Mp3 Player Shield


Mp3 Player Shield
This turns Arduino into an Mp3 player. It comes with a library. By simply
adding speakers, microSD you can transform your Arduino into a sound machine
of whatever specificity you want.

Spectrum Shield
This allows Arduino to listen to various sounds and turn them into frequencies,
before presenting it in a graphic equalizer display.

Display Shields
Color LCD Shield
This is a small screen component that allows you to display text and pictures
with a 128x128 cell phone color LCD.

CMUCam Shield
This will turn Arduino into a camera. This component is a small camera that
allows the user the option of vision. It is especially useful to users who may be
using their Arduino to control small robots by allowing the user to visually track
it.

Motorz! Shields!
PWM Shield
As I had mentioned earlier, pulse-width modulation can also be used to drive
servo-motors, beyond just dimming LEDs. This shield allows Arduino a fine
range of control over servo motors.

Monster Moto Shield


This allows the user to drive servo motors much like the PWM shield, but this
shield can handle much beefier ones than the other shields could handle.

Ardumoto Motor Driver Shield


This is the most popular of its class. It is the classic when it comes to driving
servo motors with Arduino.
Installing Shields
Preparations
Many shields are made without headers attached. This allows the user a degree
of freedom to alter how the headers are used (Straight male headers rather than
stackable headers or the other way around).
Attaching a header is a simple process with very few steps. You will need a few
things from your kit however. You will need solder, soldering iron, wet sponge,
Arduino board and 4 headers (the original ones or the new R3 ones). You may
also optionally have a soldering iron stand, solder wick and maybe a third hand.

Before you begin, make sure the headers you have match your Arduino footprint
(use the new shield header for R3 layouts and the old headers for Arduino with
that type of header layout).
There are two types of headers. If you will be stacking shields, it is advisable to
use the stackable header and the male header tor single shield works. Male
headers make a lower-profile stack when used to stack shields compared to
stackable headers, but, stackable headers allow you to still insert jumper cables
into the Arduino when the shields are stacked.
Note: stick to headers that have straight, rectangular and male pins for now.
They are easier to work with, and most Arduino components come adapted for
male header pins.

Assembly
Attaching the Header
Headers should be inserted into the shield first. Orientation is of utmost
importance . The headers should face the correct direction. Male pin headers
should enter the top of the shield and extend downwards. Solder the pins only
once you have the header facing the right direction.
Once the headers are inserted properly, flip the board so that the female side
Once the headers are inserted properly, flip the board so that the female side
rests on the flat work-table. Align all headers carefully so that they rest
perpendicular to the Shield.

Soldering
Carefully solder a single pin on each inserted header, this ensures that the
headers remain perpendicular to the shield (in the event of a shake). Ensure the
solder is not too much for each pin.

Testing
Carefully Align the Shield with Arduino and plug it in. This ensures that your
Shield headers are properly aligned. If it is not an immediate fit, please realign
the board and perform the above steps again until the fit is exact.

Soldering
Once your shield headers pass the above test, then solder the rest of the pins to
the shield. Once all your pins are soldered, please check for bad solder joints.

Bad Joints
There are possible mistakes when soldering. Please check that your solder
doesn’t link two pins together if you do not want a short-circuit. Also check for
cold solder joints (they are not soldered but look like they are).

Plug in
It is good practice to disconnect your Arduino before working on it. Now plug in
the Shield by matching Arduino headers to the ones on your shield. Please be
careful not to bend your header pin while doing this.
Congratulations, you have connected your shield to Arduino.

Tricks
A known trick is to use an old shield to aid in aligning the header.
Aligning a male header is significantly easier to align than stackable headers.
This is because you can just plug your pin directly into the Arduino first before
carefully laying your shield on it.
Solder away.
Be careful not to burn your header by leaving the soldering iron on the pins for
Be careful not to burn your header by leaving the soldering iron on the pins for
too long.

Library
Arduino libraries are useful when a programmer needs to make a complex task
as simple as possible. These are contained as part of the extensive add-ons
available to all Arduino users. An example is writing a code to capacitive touch
sensing, while we could spend a few days writing and perfecting the code on our
own, we could just get a code from a great library and implement it into our
Arduino.
You can learn all about how to download and install libraries at the official
Arduino library website. It comes with great instructions about using the
Arduino IDE library manager. (https://www.arduino.cc/en/Guide/Libraries/ ).

Using Library Manager


Already listed in Arduino 1.5 version and greater is a large collection of
libraries. It contains almost anything you may need to use your Arduino for.
Open the library manager and install any library you want to use with a single
click.
You may also click on “Add .ZIP library” to install any “.zip” library you have
from elsewhere.
Users of older versions of Arduino may follow these steps:
Manual Installation

First, you will have to download the library from the web
Locate the “.zip” file on the computer and double-click to open it and
extract the folder contained inside
In most library folders, there will be a “.h” and a “.cpp” file.
Copy the whole file.
Open your Documents folder, in it will be an Arduino folder, open it.
Navigate to libraries and past your copied file in that folder.
Edit the name of your pasted folder to remove any symbol that is not
A-Z and 0-9. If you do not do this, you will not be able to use it.
Restart your Arduino if it was already open and by navigating to the
examples folder, you will see the contents of your library there. You
may now open it.
Chapter 6: Practical Projects

LED Cube with Arduino


The aim is to make a LED cube that pulsates at regular intervals and while
visually compelling, it is a simple project. We’ll will need to utilize multiplexing
to reduce the power draw.
This is a very good project where you will get the much-needed practice on
soldering.
You will need to obtain the following hardware:

Arduino UNO
64 LEDs (3.3V)
10 resistors (the resistor value will depend on the voltage of your
LED)
Craft wire
Prototyping board
Drill of the same size as LED
Crocodile clips
A wooden holder in a 4x4x4 cubic configuration
Because of the limited number of pins available on Arduino UNO, we will
build the 4x4x4 cube using multiplexing. This allows us to break down to 4
layers. This means that we only need to control just 16 LEDs directly.

We simply need to activate a layer and the control pin to light a specific LED,
meaning that we can control all the 64 LEDs with just 20 pins total.
Each layer will be built with a common cathode which will lead to a single pin.
Each LED will be linked to the one above and below it, and since we have 16
layers of positive and 4 layers of negative LED pins, we can do this easily.
The directions are:

Fold the LEDs short leg and drill the needed holes in your wooden
placeholder. It needs to be very tight. The holes should be equidistant
from each other and the folded legs should be of the same size.
Follow the directions as shown in the picture.
Solder the short legs (cathode) on a thin craft wire as shown above.
Test the above configuration using the blink code by connecting a
resistor and ground to cathode (1 pin for all four), and 5V to each
anode and run it. It should light up all the LEDs. If not, all LEDs light
up, check your connections again.
Now do the same for all the remaining 60 LEDs and ensure the
connections are solid.
Then arrange all the 4 LEDs in a cube configuration and ensure the
vertical legs (anode) are soldered together while the cathode is
similarly linked per layer.
If you cannot get a perfect fit for anodes, use a clip to hold them
together and keep them at appropriate height. And ensure anode only
connects to anode. You may snip any out of place wire/leg to ensure a
smoother build.
Once you have your cube, connect the resistors to your prototyping
board and your board to the cube wire frame in what order you want
(LED to board first before resistor or resistor to board first before
LED).
Once your pins are finally connected (the 4 cathode layers to analog
pins 2 to 5, 16 LED anode pins to digital pin 0 to 13 and analog 0 and
1), and we are done.
Upload your code:
https://github.com/brucetsao/eLedCube/blob/master/LED_1cube_4x4x4_Blank_Show_/LED_
Now you can see what it does. You can modify the code by using
“plane(layer)number ” to choose the LED you want to command. Ensure that
all other planes are HIGH before commanding a LED otherwise everything will
light up.

GPS Tracking with LoRa Shield


With the proliferation of satellites in todays’ world, the ability to know where
someone is, is in popular demand. Are you the suspicious husband, the worried
father, the sophisticated stalker…? the GPS has become an asset everyone
wants.
As an Arduino fan, the question should be, can you can build your own GPS
tracker with Arduino? Yes, you can. In this project, our aim is to build an
Arduino based GPS tracker.
We are using LoRa because of its low power requirement and long-distance
operation.
operation.
To build this, we will need the following Hardware:
NEO-6M GPS module, a transmitter, a 16x2 LCD, 433MHZ LoRa module (or
whichever one is legalized in your locale), 433MHZ LoRa antenna, connecting
wires, Arduino Uno and the Arduino LoRa shield.
To build the LoRa shield we will be using this circuit diagram:

The Arduino shield consists of a 12V jack whose purpose will be to regulate the
3.3V pin for the LoRa module and to power Arduino through the vin pin. The
regulated 5V will thus be used in powering the 12x6 LCD. The two resistors R1
and R2 will act to fix the voltage of the LM317 regulator. An external regulator
is more reliable than the Arduino’s own internal voltage regulator. Included
within the shield will be a potentiometer with the purpose of regulating the
LCD’s brightness.
To design your own PCB:
Download the PCB design software, install it, open it and format your
PCB tracks.
Go to (https://www.pcbgogo.com/?code=t ) and log in or sign up.
Enter your PCB dimensions in the prototyping tab.
Select “quote now ” and change whatever parameters you want. It
costs about $5 and will be delivered in 2-3 days.
Upload the Gaber file generated by the PCB software and once your
file has been verified, you may use whichever payment option you
want.
Once you get the PCB, you may start assembling the board.
Download the LoRa library (https://github.com/sandeepmistry/arduino-LoRa ).
You will need two shields for this project, one for transmission and the other as a
receiver. The receiver will be the one with the LCD attached.
Now that you have the transmitter module ready, you may connect your GPS
module.
Connect the pins D4 to RX and D3 to TX, and ppower it with the 5V pin.
You will need to download the TinyGPS++
(https://github.com/mikalhart/TinyGPSPlus/archive/master.zip ) Library to
interprete the data sent from the GPS module (NMEA sentence).

Coding:
Ensure that you have downloaded and installed the two libraries in your IDE
before proceeding.
To program the transmitter, we use the following code:
https://circuitdigest.com/microcontroller-projects/lora-based-gps-tracker-using-
arduino-and-lora-shield
Once our codes are uploaded, power up the transmitter and the LED on the PCB
will start blinking. The receiver will similarly turn on and display the welcome
message we typed in the above code.
Once the transmitter receives data from the satellite, the LCD will immediately
display it.
The next step is to put the transmitter where you want; car, bag, etc. and you will
be able to track whoever is currently carrying the transmitter with the receiver.

Motion Sensitive Light Switch


Motion Sensitive Light Switch
This type of project has many advantages. Using a motion sensitive light, it can
be a security system that detects intruders in the compound to wake up the
resident, it can be used as a responsive night light (lights on when the resident is
wake) or any other number of ways.
The motion sensor will detect the movement of a trespasser and automatically
switch on for 40 seconds. How you code it depends mostly on how you want to
use it.
The hardware we will need are:
Arduino Uno, PIR motion sensor, a 5V relay module, a breadboard, a 100Ω
resistor, a power supply and LED.
***Note: you will be connecting your project directly to the mains (230-240V).
Touching any live wire directly will can kill you. Be extra careful.***

The circuit diagram will follow these steps:

We will connect an LED to Arduino’s pin 13 and the PIR data OUT
pin to Arduino’s pin 8. The LED will indicate that the light has turned
on or off.
Pin 9 of Arduino will connect to IN1 pin of the relay module and a
bulb will be connected to the mains of the Relay (one to mains supply
and the other wire to NO relay contact).
COM of the relay will link up with the other wire of main.
The sensor will link up with pin 8 on Arduino and its ground pin to
ground. Its main pin must be connected to the Arduino’s pin 13
through the breadboard.
Please be careful when connecting to mains (240V AC), if you are
not sure, examine the circuit diagram again.
The code below will then be loaded into the Arduino IDE:
https://www.maxphi.com/pir-motion-sensor-light
Once someone enters the range of the sensor, the sensor detects the movement
through infrared, it’s OUT pin changes from LOW to HIGH, and alerts the
Arduino which changes its configuration from relay pin HIGH to LOW.
This will cause the light to come on.
Once the intruder leaves, the sensor no longer detects motion and changes its
configuration back to LOW from HIGH. This in turn causes Arduino to assume
a HIGH command at the relay pin.
This design is easily applicable as: Garage Lights, Bathroom Lights and Security
Lights.

Build a Personalized Alarm System


The previous project was about making use of a light bulb to warn you of an
intruder in your home, and its numerous other uses. This new project will make
use of a buzzer to make a fully functional home alarm system to keep you safe at
night.
This project will make use of:
Arduino UNO, buzzer and PIR motion sensor.
From the short list of required hardware, this may very well be the easiest and
least demanding project you will do in this chapter.

From your Arduino board to your sensor, connect VCC to 5V pin and
GND to the GND pin.
Connect the Arduino’s pin 2 (digital) to the output signal pin on the
sensor.
Connect Arduino’s GND pin through a breadboard or directly to the
buzzer’s negative terminal.
Connect Arduino’s digital pin 9 to the positive terminal of the buzzer.
The circuit follows the diagram below.

We can then upload our code:


https://maker.pro/arduino/tutorial/how-to-build-an-arduino-powered-motion-
sensor-alarm
The above code, once uploaded and the Arduino, sensor and buzzer set in a
position of our choice, will make the buzzer sound whenever someone is within
6-7m of the sensor.
The Arduino’s digital pin 2 is written as HIGH OUTPUT and this will cause the
condition for “intruder_detect() ” to start running.
The “siren()” code functions using PWM signals of varying frequency to
simulate an alarm sound.
Intruder detected will be printed on the serial monitor and after a minute of the
intruder leaving the sensor range, the buzzer shuts down.
Sensitivity and time can be modified as liked within the code based on the sensor
type being used and its range.

Arduino Digital Clock with RTC


Much like the above project, we will need a few things:
Much like the above project, we will need a few things:

Arduino UNO
2 LED
DS1307 RTC
330K and 4 120K resistor
The circuit uses a multiplexing technique to reduce the number of wires that are
used to link with Arduino while similarly reducing the power consumption
significantly.
The RTC module, keeps track of the time and compensates for drifts like leap
years. We only need hour and minute information though, so that is all we will
extract from it.
The circuit makes extensive use of the breadboard to link multiple pins to the
same Arduino pin. The colored chart describes what is linked to what.
To set the time, open the IDE include the library “DS1307RTC ” you have
downloaded, ensure the time is correct and run the serial monitor.
Once that is done, we upload the code found here:
https://electronics-project-hub.com/arduino-7-segment-display-clock-with-and-
without-rtc/
The libraries can be found here: (https://github.com/PaulStoffregen/Time )
(https://github.com/PaulStoffregen/DS1307RTC )
(https://github.com/DeanIsMe/SevSeg ).
The next thing to do is to power up the module and watch it display the time.
The RTC though, is still vulnerable to temperature variations. For high accuracy,
you will need an RTC with inbuilt temperature compensated crystal.

Game Controller with Unity


The aim is to design an awesome game controller with very few steps. This
tutorial seeks to design a game controller powered by Arduino UNO with the
Unity game engine. The controller will be tested by using it to avoid objects.
For this project we will need the following hardware:

A breadboard
Arduino Uno
Unity game engine
An Uniduino plugin
10K resistor and potentiometer
Hook-up wires
You may purchase an Arduino starter kit that contains most of this from here
(https://www.makeuseof.com/tag/4-best-starter-kits-arduino-beginners/ ).
Building the controller will follow this circuit diagram:

Once you have your circuit built as described above, open the code
StandardFirmata<Firmata<Examples found in files of your IDE.

Upload what you get and open Unity.


Look for the plugin in the asset store and buy it. It is fairly cheap.
While it can be done without the plugin, you may want to go
(http://www.alanzucconi.com/2015/10/07/how-to-integrate-arduino-
with-unity/ ) here for that.
Follow the video to make sure everything is working right.
Now, set digital pin 2 to INPUT and analog pin 5 to ANALOG.
You can use unity to program a simple game that you can test your
controller with.
Go to Assets>Uniduino>Prefabs and drag the prefab into your
hierarchy on a new scene.
Choose in your hierarchy Create>Sphere and transform it to the
bottom of the game.
You will now need add a new script into the hierarchy by heading into Add
Component < New Script.
Next, you should rename the C Sharp object and add the new script to the
GameObject by clicking on Create < Add.
Type in the codes in the link into your new script:
https://www.makeuseof.com/tag/make-custom-game-controller-arduino-unity/
Read the above code and note the comments to understand what it does.
Save the script and exit back to editor. There you will change the values for pot
pin number to 5, button pin number to 2, left edge to -9.5 and right edge to
9.5.
Add:
void Update ()
{
//We assign the value the arduino is reading from our potentionmeter to our
potValue variable
potValue = arduino.analogRead(potPinNumber);
}
To SphereMover script’s update. Check back to the Uniduino option in
Hierarchy and ensure the port is still accurate/there. If not, change port name
to that of the Arduino.
Now select play for the sphere in hierarchy.
So that we will not have to calibrate and calculate out potentiometer values, we
can add:
https://www.makeuseof.com/tag/make-custom-game-controller-arduino-unity/
To the C#Script<Create<Project panel . This is an extension method built into
the Unity plugin.
Heading back to the script, we will use the remap functions to convert the pot
values into useable ones for our game.
Under our typed in pot value, add:
mappedPot = potValue.Remap();
and we can enter our values into the code by:
mappedPot = potValue.Remap(0, 1023, leftEdge, rightEdge);
Click on save and the Mapped Pot values will now change with movement of
the potentiometer.
Now, open the script and assign your new values thus;
//Assign the mapped pot value to the sphere's x position
transform.position = new Vector3(mappedPot, transform.position.y,
transform.position.z);
Now, you can click on play and the movement of your potentiometer will
correspond to your game character.

Traffic Light Controller


Our last project will be the very simple traffic light controller. Like it’s name
suggests, our aim is to build an Arduino that can control signal lights.
Hardware components:

10K resistor
Breadboard and Arduino UNO
Connecting wires and three LEDs (green, red and yellow)
A pushbutton switch
Six 220Ω resistor
Below is the circuit diagram we will be using for this project.

The resistors will connect to the LEDs cathode on one end and to D8 to D10 on
the other end. The LEDs on the other end are connected to both the resistor and
ground (cathode), and also connected to the 5V pin on the anode leg.
Once we have our circuit up and running, you can find the code here:
https://www.makeuseof.com/tag/arduino-traffic-light-controller/
As can be seen from the code, it is very similar to blink a single LED.
With the exception of the “changelights() ” function, the rest of the code is
almost the same.
The traffic lights can be changed in several ways to satisfy our own timing by
simply changing the values in the code.
And now, we have our traffic light controller.
A fairly nice way to round off right? Wrong .
Why don’t we alter the code to allow someone else to choose when it turns
RED without altering the code?
You would have noticed from the above that you did not use all the hardware
you were told to get.
Follow the circuit below:

The difference between the two circuits is academic. The button in this circuit is
connected to pin D12 and the switch now has a resistor attached to it (10K).
The code can be found here:
https://www.makeuseof.com/tag/arduino-traffic-light-controller/
What the new code does is wait for 15 seconds after the button is pushed before
the light changes. This allows someone to control the lights by pushing the
button.
Why don’t we also add a junction to our traffic lights controller?
Just follow the circuit below:
The original LEDs are connected as in the previous examples and the
pushbuttons have been removed. The new LED sets are connected to D11- D13
using a similar method to the earlier examples.
Upload the following code:
https://www.makeuseof.com/tag/arduino-traffic-light-controller/
Unlike the previous examples, when one set of lights is red, the other will turn
green and vice versa.
This is the same method that most street traffic controllers use.
However, since they do this over a large area without any wired input, they must
be communicating over the web.
Arduino can also do this. We will explore this avenue in our next chapter.
Chapter 7: Smart Appliances and The Power of the
Web

Connecting Arduino to the Web


With the rapid adoption of internet services around the world, it has become
necessary for new electronics producer to make products that can be used
wirelessly. It is almost impossible for a single person to learn the limits of what
is possible with Arduino. We will be practicing connecting Arduino to the
internet by converting it into a weather monitoring station that can upload data to
an online cloud service.
We will be using Arduino boards and the free web services (http://freeboard.io/ )
and (http://dweet.io ). After this lesson, you should be able to build your own
internet of things dashboard for household automation applications.
You will need; Arduino Uno, DHT11 sensor (or DHT22), 4.7K resistor,
photocell (with 10K resistor), CC300 Wi-Fi chip (Adafruit CC300),
breadboard and finally, jumper cables.
You will also need to get the following libraries:
DHT sensor library (https://github.com/adafruit/DHT-sensor-library )
Adafruit CC300 library (https://github.com/adafruit/Adafruit_CC3000_Library )
Finally, create an account on freeboard using the earlier link.
Install the library using the methods you learned above.

Hardware Install
Connect the Arduino 5V pin to the positive rail on the breadboard,
and ground the board by connecting the ground pin to the negative
rail.
Place the CC300 board and the DHT sensor on the breadboard.
Connect pin 1 of DHT to the positive rail on the breadboard and pin 4
to the negative one.
Connect the sensor’s pin 2 to Arduino’s pin 7, and connect the 4.7K
resistor between pin1 and pin 2 of the sensor to complete that part of
the circuit.
Connect the cell in series with the 10K resistor on the breadboard and
connect the ground the other end of the resistor.
The common pin on the photocell should then connect to analog pin
A0.
Connect the Wi-Fi module by linking it’s IRQ pin to Arduino pin 3,
CS to pin 10 and VBAT to pin 5.
Connect SPI pins to Arduino by linking MOSI to pin 11, MISO to pin
12 and CLK to pin 13.
Finally connect Vin to Arduino 5V (positive rail) and ground to
ground (negative rail).
Testing the sensors:
// Libraries
#include "DHT.h"
// DHT sensor
#define DHTPIN 7
#define DHTTYPE DHT11
// DHT instance
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
// Initialize the Serial port
Serial.begin(9600);

// Init DHT
dht.begin();
}
void loop()
{
// Measure from DHT
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Measure light level
float sensor_reading = analogRead(A0);
float light = sensor_reading/1024*100;
// Display temperature
Serial.print("Temperature: ");
Serial.print((int)temperature);
Serial.println(" C");
// Display humidity
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println("%");
// Display light level
Serial.print("Light: ");
Serial.print(light);
Serial.println("%");
Serial.println("");
// Wait 500 ms
delay(500);

}
The above code is a simple one designed to test if the sensors are working or not.
As you can see, the code is explained using comments. The complete code is in
the library mentioned earlier.
Upload the sketch and the data will display something like:
Temperature: 25 C
Humidity: 36.00%
Light: 83.79%
Now that the sensors are working, we need to make it capable of connecting
electronically to Wi-Fi. Dweet has “things”, this is a place where you upload
data through http requests. Should you upload data to a new thing that has not
been created before, it would be instantly created.
The code below automatically connects to the freeboard server and uploads the
data.
data.

// we state the Libraries we want to use


#include
#include
#include "DHT.h"
#include
// Define pins that CC3000 are connected to
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// DHT sensor
#define DHTPIN 7
#define DHTTYPE DHT11
// Create an CC3000 instance for the chip
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,
ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2);
// DHT instance
DHT dht(DHTPIN, DHTTYPE);
// WLAN parameters enter your own details into all parameters
#define WLAN_SSID "yourWiFiNetwork"
#define WLAN_PASS "yourPassword"
#define WLAN_SECURITY WLAN_SEC_WPA2
// give a name to your thing, it’s advised to used a very complicated one
#define thing_name "yourThingName"
// Variables to be sent
int temperature;
int humidity;
int light;
uint32_t ip;
uint32_t ip;
void setup(void)
{
// We initialize the CC300 chip
Serial.begin(115200);

Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
// Connect to local WiFi network
Serial.print(F("Connecting to WiFi network ..."));
cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
Serial.println(F("done!"));
// if the sketch hangs, this code will reset it. It is called a watchdog
wdt_reset();
/* Wait for DHCP to complete */
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100);
}
}
void loop(void)
{
// Measure from DHT
float t = dht.readTemperature();
float h = dht.readHumidity();
float h = dht.readHumidity();
temperature = (int)t;
humidity = (int)h;
// Measure light level
float sensor_reading = analogRead(A0);
light = (int)(sensor_reading/1024*100);
Serial.println(F("Measurements done"));
// Start watchdog
wdt_enable(WDTO_8S);
// Get IP
uint32_t ip = 0;
Serial.print(F("www.dweet.io -> "));
while (ip == 0) {
if (! cc3000.getHostByName("www.dweet.io", &ip)) {
Serial.println(F("Couldn't resolve!"));
}
delay(500);
}
cc3000.printIPdotsRev(ip);
Serial.println(F(""));
// Reset watchdog
wdt_reset();
// Check connection to WiFi
Serial.print(F("Checking WiFi connection ..."));
if(!cc3000.checkConnected()){while(1){}}
Serial.println(F("done."));
wdt_reset();
// Send request
Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
if (client.connected()) {
Serial.print(F("Sending request... "));
client.fastrprint(F("GET /dweet/for/"));
client.print(thing_name);
client.fastrprint(F("?temperature="));
client.print(temperature);
client.fastrprint(F("&humidity="));
client.print(humidity);
client.fastrprint(F("&light="));
client.print(light);
client.fastrprintln(F(" HTTP/1.1"));
client.fastrprintln(F("Host: dweet.io"));
client.fastrprintln(F("Connection: close"));
client.fastrprintln(F(""));
Serial.println(F("done."));
} else {
Serial.println(F("Connection failed"));
return;
}
// Reset watchdog
wdt_reset();
Serial.println(F("Reading answer..."));
while (client.connected()) {
while (client.available()) {
char c = client.read();
Serial.print(c);
}
}
Serial.println(F(""));
// Reset watchdog
wdt_reset();
wdt_reset();
// Close connection and disconnect
client.close();
Serial.println(F("Closing connection"));
Serial.println(F(""));
// Reset watchdog & disable
wdt_reset();
wdt_disable();
// Wait 60 seconds until next update
wait(60000);
}
// Wait for a given time using the watchdog
void wait(int total_delay) {
int number_steps = (int)(total_delay/5000);
wdt_enable(WDTO_8S);
for (int i = 0; i < number_steps; i++){
//Serial.println(F("Waiting for 5 seconds ..."));
delay(5000);
wdt_reset();
}
wdt_disable();
}
Let’s now go into the details of the code. It starts by importing the required
libraries:
#include
#include
#include
#include "DHT.h"
#include
The above code can be modified to suite our own needs as noted by the
The above code can be modified to suite our own needs as noted by the
comments scattered through it. Now that the data has been sent to freeboard,
Arduino will consistently send code over to the server.
To display the data graphically, we use freeboard.io to create a new dashboard
and display our data in human understandable visuals.

Making Household Appliances Smart


A possible use of the above topic, is the ability to switch on or off household
appliances without having to physically touch it. We will demonstrate below.
We will be doing this using a 5V relay to switch a power outlet on and off. The
Arduino will use a sensor to determine when to switch the relay.
While it is possible to switch on the device alone directly, due to the dangers of
leaving an unmonitored switch on, it is always better to just control the switch
relay alone. Not to mention, the ability to use a single Arduino to switch on
multiple devices.
The plan is to install a 5V relay inside a power outlet box using a grounded
extension cord.
We will need the following hardware parts for this project:
Arduino UNO, electrical outlet box, electrical outlet, power strip, Signal, VCC
and ground wires, SRD-05VDC-SL-C 5V relay, electrical outlet box cover plate
and a 3/8” NM/SE connector.

Now for the assembly:

Cut the power strip to determine which of the three wires in it connect
to each prong on its plug (ground, live and neutral). You may use a
continuity tester to determine this.
Remove a knock out plugs from the outlet box, and install the NM/SE
connector in its place.
Remove some of the outer sheathing of the cord and feed it into the
electric outlet box through the connector (3-4”).
Carefully off 4” of the live wire and remove about ¼” of the cut off
live wire insulator and insert it in the NO terminal of the relay, and
connect the ground, signal and VCC wires to the relay.
Connect the remaining live wire into the C terminal of the relay and
ensure it is a fit.
Secure all the wires and the relay in the box and make sure they can
all fit well.
Secure the live wire from the NO relay terminal to the hot terminal of
the power outlet (the one with the smaller slot) with the gold screws.
The neutral wire from the power cord should also be secured to the
neutral terminal of the outlet (left side with larger slots) with the
silver screw.
Also, secure the ground wire to the ground terminal outlet (D-shaped)
with the green screw.
Screw the outlet into the box and ensure it fits, then cover it up and
screw in the cover.
We now have an outlet that can be easily controlled by Arduino. All that
remains, is to connect the pins to your Arduino and upload code, and we are
done.

The connections should follow the above design. The USB will lead to the
computer, or you may attach a battery to it using one of the examples given
previously. The bulb can be anything, from your coffee machine to your washing
machine.

We will connect a DHT11 humidity and temperature sensor to Arduino so that


the bulb turns off when humidity exceeds a certain level. To upload the code,
connect Arduino to your computer, and upload this code.
#include <dht.h>
#include <dht.h>

dht DHT;

#defines DHT11_PIN 7
int pinOut = 8;

void setup(){
Serial.begin(9600);
pinMode(8, OUTPUT);
}

void loop()
{
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
// DHT.humidity can be changed to DHT.temperature
if (DHT.humidity <= 40){
// the value <= 40 can be changed to any humidity or temperature
digitalWrite(pinOut, HIGH);
} // tells the pin to allow current flow. The bulb turns on
else {
digitalWrite(pinOut, LOW);
} // tells the pin to prevent current flow. The bulb goes off
delay(500);
}
The above code is similar to the one we uploaded previously to send data to the
web. It takes in the humidity and temperature data and tells the power outlet to
switch on when humidity reaches 40%. This can also be done to tell the bulb to
turn on when temperature is below 300K by changing the values as noted in the
turn on when temperature is below 300K by changing the values as noted in the
code.

Controlling Arduino with a Smartphone


We talked about getting Arduino to send data to the web in the previous topic,
now we will talk about using your android phone to control a higher voltage
device.
We will explain in this tutorial, how to control Arduino directly from your phone
and with a web browser
To accomplish this task, we will need to purchase or build the following:

An Arduino robot
HC-05 Bluetooth Module
Android with OS 2.2 or 2.1 and above.
A Google account and a Bluetooth controller App.
The Bluetooth Module will have its 5V pin connected to Arduino’s
5V pin and it’s ground pin connected to that of Arduino.
You may connect the Bluetooth TX pin to Arduino’s RX pin only
since there is no data to be received from Arduino.
You may completely remove the distance sensor from the Arduino if
you wish and connect pin 9-12 of Arduino to IN1-IN4 of the Motor
module as above, and the Enable pins should connect to 5V using a
jumper.
The Bluetooth module may be placed above or below the chasis.
The following code will then be uploaded.
You may download the code here .
The code is explained using comments. From what we had done above and a
little experimentation, the code becomes clearer still.
The next step is to open the Bluetooth controller application. The application can
be gotten on google play.
Configure the control keys in app paying attention to how you configured it in
code.
When say the forward key is pressed, Arduino receives the data through
Bluetooth communication as 1 and Arduino will thus make IN1 and IN3 HIGH
while IN2 and IN4 will become LOW. This achieves a forward motion. The
same system will be used for the other motions, granting free command over the
same system will be used for the other motions, granting free command over the
motions of the robot.
This is unfortunately not as useful as a Wi-Fi module because, the range is 10
meters. There must also be sufficient power provided to the Bluetooth module to
prevent it from shutting down.

Wi-Fi Remote Control Using ESP8266


Controlling Arduino with Wi-Fi is a very straightforward process. You will hope
to learn how to use the Wi-Fi module under this topic. As can be seen from
examples in the previous tutorials, there has been a certain common method to
codes and circuits we have been building. From the examples above, we know
which pins transfer which information.
As with the Bluetooth example where we did not connect the TX pin because it
was not needed, the same is true for all modules. The circuit you will build with
a module is highly dependent on what you want to do with it, and thus, the kind
of information it will transmit.
The plan for this last project of ours is to build a Wi-Fi controller to any device
with Wi-Fi access using a Wi-Fi nunchuk that has been made from an ESP8266.
While it is possible to program the ESP8266 itself, it is generally preferable to
program Arduino and have it control the Wi-Fi module.
While the aim of this tutorial is to produce a serial terminal data, it is very easy
to use another Arduino to read the serial string output and act on it.
We will need the following hardware:
Arduino Mega (this is because it has two serial ports, since using UNO might
make the Arduino impossible to reprogram as the module will assume control of
the programing port once it is running), ESP8266 Wi-Fi module, jumper wires,
breadboard, FTDI chip or another Arduino and battery.
There are many ways of connecting ESP8266 to Arduino, however, we will be
using the following method:

Connect a red jumper to the 3.3V power pin, a brown one to the 3.3V
pin (enables chip), a white one to TX, a grey one to RX and a black
one to ground.
The TX jumper cable will be connected to RX1 on ArduinoMega and
the RX cable will lead into TX1 on ArduinoMega.
Since nunchuk communicates using i2c, most Arduino will come
with an inbuilt i2c bus (they also have their own connection plugs,
but you can just use jumper wires and A breadboard or jumper wires
only). Connect the nunchuk. SDA pin - analog 4 and SCK - analog 5.
(Do not buy off-brand ones, stick to Nintendo nunchuk.
To set up a server to communicate with the ESP8266, we use the code on this
instructable page (https://github.com/splatspace/esprelay/ ). It allows the
communication of two devices to log on to any computer that is running the
code.
You will need to install Python 2.7 on your PC in order to run the code.

Follow the above steps to setup a receiving ESP8266. It will


diagnosis if the Wi-Fi module is not running well. An FTDI chip is
connected to the model so that a USB port can be used to receive
serial data. This data is then examined on the PC.
Add a battery to the model because the FTDI module is not built with
a sufficient power source. This will cause the ESP8266 to restart
regularly if it isn’t fixed.
You may add another Arduino in the place of an FTDI chip if you
wish to use the Arduino to control something.
Load the terminal program you are using. The strings from the
nunchuk will be seen scrolling down the screen as they are received.
Use the code below to setup the ESP8266 typ:

AT+RST
AT+CWJAP="this will be occupied by your Wi-Fi’s SSID", "This
will be occupied by the password of your Wi-Fi"
AT+CIPCLOSE
Type the codes below to enable communication with the transmitter of the
nunchuk;

AT+CIPSTART="TCP", "This will be your IP", 54321


AT+CIPSEND=n (this tells the ESP8266 that ascii characters should
be expected. The n represents the number of characters to accept.)
ascii string with no quotes\r\n
AT+CIPCLOSE
You can now control what you want over the Wi-Fi.
You can now control what you want over the Wi-Fi.
Chapter 8: Troubleshooting Common Problems
There are a lot of steps to getting Arduino to do what you want, and should any
step be done wrong, it might fail to work/upload. There are a variety of problems
that crop up when using Arduino, yet, most of these problems can often be
traced to a handful of root causes.

The boards physical connections


Microcontroller fuse settings
Access to the serial ports by the code
The drivers for the board
Firmware on 8U2
The bootloader
The board itself
The list of problems that may arise while using your Arduino is too long to list.
So, we will try to go through the most common problems that occur and
recommend ways with which you may quickly fix these issues.
Here are a couple of things to check first, if your Arduino is messing up.
Arduino IDE
The first step to dealing with any problem is to just reinstall Arduino IDE and
reupload your code. If this doesn’t work, you may check the following within
your IDE:

Ensure you correctly selected the right board in the Tools > Board
menu. This is because of differences in the ATmega chips in differing
Arduino types. See (https://www.arduino.cc/en/Guide/Environment )
for more information on properly selecting your Arduino type.
Make sure that you selected the correct port to which you connected
Arduino. As I had mentioned earlier, unplug and re-plug Arduino to
the computer and carefully monitor the option that appears, if you did
not initially see your Arduino listed under Tools > Serial Port .
If you cannot find Arduino still, then follow the next steps.

Drivers
Drivers are what allows the IDE on your computer to communicate with the
Arduino. What happens when a USB cable is plugged into a system for the first
time is that, the computer accepts drivers that are stored on the board and installs
time is that, the computer accepts drivers that are stored on the board and installs
them. These drivers provide a virtual serial port. Most Arduino use USB CDC
(standard drivers) provided by the operating system while some use FTDI.
If your Arduino type does not appear in the Tools > Serial port menu, then the
driver was not installed.

For windows 7, connect the board again, open the device manager
and update your drivers for Arduino. Right click on the board and
point windows to the “.inf” file. It will be in the drivers/directory of
the IDE file.
For Linux, symlink from /dev/tty/ACM0 to dev/tty/USB0. Then you
may run

sudo usermod -a -G tty yourUserName


sudo usermod -a -G dialout yourUserName
After which you should logout and login for the changes to occur. Open
Arduino again and your port should appear.

Crash
Should the software crash at launch or work unnaturally slowly, or the Tools
menu seems to open too slowly.

Disable Bluetooth serial ports and that of any other networked COM
ports using Device Manager. Since Arduino IDE scans all the COM
ports on the computer upon startup and whenever the Tools menu is
open, these networked ports often cause delays and crashes
Ensure that the only program that scans all serial ports currently open
on your task manager is Arduino IDE. Some Applications that do this
are; virtual daemon tools, BlueSoleil, PDA sync apps…
Ensure the computer is not running a firmware that disables access to
serial ports (ZoneAlarm)
Quit processing, vvv… should you be using them to read data from
the USB cable to Arduino
For Linux, you can try to run the IDE as a root file, and see what
changes
If this doesn’t fix the issue, proceed to the next step.

Direct Connection
Sometimes, the problem arises from physical disconnections from the
board.
Ensure that the Arduino LED is on.
Ensure you are connected directly to both Arduino and the computer.
It there is a USB hub connection, please connect the two directly and
test for changes.
Change the USB cord. Sometimes, this works.
While the code is uploading, disconnect digital pins 0 and 1, and
reconnect them after the upload.
Try disconnecting everything else from the board and uploading the
code.
Ensure Arduino is not touching anything metallic or conductive. As
we had earlier explained, it may ground the board.
The above steps should solve your problems. If they do not, proceed to the next
step.

Auto-Reset and Bootloader


Please do note that some boards do not support this function. On some
computers, you may need to physically press the reset button before uploading,
while on others you will need to upload before pressing reset. It is advised that
you press reset with two to 10 seconds interval using both ways to see which one
your Arduino supports.
This error may be displayed on the IDE.
[VP 1] Device is not responding correctly
This means that you need to try again.
The best way to check if your Arduino comes with a bootloader is to press reset.
If your Arduino LED blinks when you plug it in again, you have a bootloader. If
it doesn’t, then you do not have one.
If none of the above options work for you, the you may need to visit the Arduino
help Forum (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?board=troubleshoot
). Please use the code tags in the forum toolbar to ensure the output is in the
proper format.
You will need to know, your operating system, Arduino type (with a picture if
possible), your exact problem (can’t upload to the board) and the error message
you receive when you try to upload after enabling verbose output (File >
Preferences > Show verbose output ).
Syntax in Arduino
The most common error in Arduino syntax is due to the semicolon at the end of
a statement. The second most common error is due to a missing curly bracket.
Look for incorrect spellings, typos, wrong names for declared values, unallowed
lettering uses and wrong cases. Arduino code is case sensitive. If there’s an error
in your code, the software usually highlights the lines with such errors.
“java.lang.StackOverflowError”
This error often occurs because certain strings can confuse the IDE. Arduino
IDE does preliminary processing by manipulating code on the sketch using
regular expressions.
Look for certain sequences that have certain functions like double quotes, single
quotes, comments or backslashes. Some of these codes, while correct, may
confuse the IDE. An example is ‘“/’ , or /” .
at com.oroinc.text.regex.Perl5Matcher._match(Perl5Matcher.java)
​ at com.oroinc.text.regex.Perl5Matcher._match(Perl5Matcher.java)
or
java.lang.StackOverflowError
at java.util.Vector.addElement(Unknown Source)
at java.util.Stack.push(Unknown Source)
at
com.oroinc.text.regex.Perl5Matcher._pushState(Perl5Matcher.java)
Sketch does not start while you’re powering the board while using
an external power supply
This happens most often because of the disconnection of the RX pin. The
bootloader will see garbage data inflowing without end, thus, it never actually
gets to running your sketch.
Try connecting the TX pin directly to RX, or ground it with a 10K resistor.

Arduino IDE freezes when you attempt uploading a program


Open Task Manager and check if “LVPrcSrv.exe” is running, if it is, kill it and
reupload the program. This is because the Logitech process sometimes conflict
with Arduino IDE.
Arduino does not light up (the power LED) when plugged in
Make sure the jumper is on the correct pins.
For the external battery, the jumper should lie on 2 pins closest that are closest
the power plug.
For USB powered projects, it should be the 2 pins that are closest to the USB
plug.

Error launching Arduino on Windows


Arduino has encountered a problem and needs to close.
Should you get the above message when trying to run Arduino.exe on windows,
please try launching with the “.bat” file (It may take a few minutes).

"Could not find the main class." error


Java Virtual Machine Launcher: Could not find the main class.
Program will exit.
If you get the above error on your attempt to launch Arduino, ensure the
“Arduino.zip” files were correctly extracted. The lib directory should contain
“pde.jar ” and be directly inside the Arduino directory.

“UnsatisfiedLinkError” in Arduino Library


Uncaught exception in main method: java.lang.UnsatisfiedLinkError:
Native Library /Users/anu/Desktop/arduino-0002/librxtxSerial.jnilib
already loaded in another classloader
The above is an error caused by loading an old version of Arduino
communications library.
Find “comm.jar or jcl.jar ” in the directories in your CLASSPATH or PATH
environment variables (“/System/Library/Frameworks/JavaVM.framework/
”).

Cygwin conflicts
6 [main] ? (3512) C:\Dev\arduino-0006\tools\avr\bin\avr-gcc.exe: *** fatal
error - C:\Dev\arduino-0006\tools\avr\bin\avr-gcc.exe: *** system shared
memory version mismatch detected - 0x75BE0084/0x75BE009C.
The above error displays when you have “Cygwin ” running while you are using
Arduino. You can also just delete “cygwin1.dll ” from your Arduino directory
and then replace it with “c:\cygwin\bin\ ”.

Sketch too big


The most common causes of large code is the use of floating point calculations.
We had stated earlier that you should be careful to use as much integer math as
you can get away with in your code. Also you can delete any “#include”
statements made in your code to libraries you will not use for the code. Go
through your code again and look for any code that can be written in shorter
ways. Your chip can only contain 16KB of code.
Advanced troubleshooting problems can be solved by visiting
(https://www.arduino.cc/en/Guide/Troubleshooting ).
Conclusion
This may be the end of this book, but it is just a beginning in your journey to
learn Arduino programming.
Are you interested in learning more?
Are you hungry to handle more Arduino projects?
Do you wish we had added more practical examples?
Arduino is the new kid in town, and everybody wants to know how it works. It is
our hope therefore, that having read through this book and participated in most if
not all of the projects, that you would have grasped what Arduino is all about.
Stay tuned for more on Arduino programming.
Appendix
This Appendix contains a list of URLs referenced in this book, and a list of
reference materials that were used to complete this work. You may find them
useful.
To learn more about Arduino, you may visit the following websites:
Arduino’s official site: https://www.arduino.cc/en
Autodesk, Inc: https://www.instructables.com/
URL
Arduino’s official site for buying boards: https://store.arduino.cc/
Adafruit (Arduino clones): http://www.adafruit.com/
SparkFun (Arduino clones): http://www.sparkfun.com/
Arduino IDE (Download): https://www.arduino.cc/en/Main/Software
Ubuntu Arduino IDE installation guide:
https://tutorials.ubuntu.com/tutorial/install-the-arduino-ide#0
Teensy Board installation guide:
https://www.pjrc.com/teensy/td_download.html/
Arduino Troubleshooting: https://www.arduino.cc/en/Guide/Troubleshooting
Electrodroid Application to calculate resistance:
https://play.google.com/store/apps/details?id=it.android.demi.elettronica&hl=en
LED Calculator Tool to calculate resistance: http://led.linear1.org/1led.wiz
Arduino syntax and function homepage:
http://arduino.cc/en/Reference/HomePage/
Arduino library for capacitive sensor:
http://playground.arduino.cc/Main/CapacitiveSensor/
Arduino libraries: https://www.arduino.cc/en/Guide/Libraries/
Arduino guide on Arduino types: https://www.arduino.cc/en/Guide/Environment
Arduino troubleshooting forum: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?
board=troubleshoot
Common Arduino troubleshooting problems:
https://www.arduino.cc/en/Guide/Troubleshooting
DHT sensor library (https://github.com/adafruit/DHT-sensor-library )
Adafruit CC300 library (https://github.com/adafruit/Adafruit_CC3000_Library )
Turn PC into server: (https://github.com/splatspace/esprelay/ )
TinyGPS++ library:
(https://github.com/mikalhart/TinyGPSPlus/archive/master.zip )
LoRa library: (https://github.com/sandeepmistry/arduino-LoRa )
PCB order page: (https://easyeda.com/order )
Smoke detector shield PCB design:
(https://easyeda.com/circuitdigest/Smoke_Detector_Arduino_Shield-kEQca75rN
)
Digital clock libraries: (https://github.com/DeanIsMe/SevSeg )
(https://github.com/PaulStoffregen/DS1307RTC )
(https://github.com/PaulStoffregen/Time )
Uniduino plugin: (https://www.assetstore.unity3d.com/en/#!/content/6804 )
A sensor sketch code:
(https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/ )
Self-controlled robot code:
(https://gist.githubusercontent.com/jamesabruce/b2eb4698754ae10e492e/raw/de60648a33a37
robot-test.ino )
LED 4x4x4 code: (
https://github.com/brucetsao/eLedCube/blob/master/LED_1cube_4x4x4_Blank_Show_/LED_
)
LoRa code: (https://circuitdigest.com/microcontroller-projects/lora-based-gps-
tracker-using-arduino-and-lora-shield )
Motion sensor code: (https://www.maxphi.com/pir-motion-sensor-light )
Alarm code: (https://maker.pro/arduino/tutorial/how-to-build-an-arduino-
powered-motion-sensor-alarm )
Smoke detector code: (https://lastminuteengineers.com/mq2-gas-senser-arduino-
tutorial/ )
Game controller code: (https://www.makeuseof.com/tag/make-custom-game-
controller-arduino-unity/ )
Traffic controller code: (https://www.makeuseof.com/tag/arduino-traffic-light-
controller/ )
Reference
Build an Arduino controlled power outlet; (http://www.circuitbasics.com/build-
an-arduino-controlled-power-outlet/ ).
Gerald Recktenwald, EAS 199A, Lecture 5: Arduino Programming Part 1 ,
Portland State University (2010).
Rudra P. S. Celebrating Arduino Day (2014)
Tttapa, A Beginner’s Guide to Arduino , Autodesk, Inc (2019).
Bekathwia, Arduino Class , Autodesk Inc (2019).
Miguel Grinberg, Building an Arduino Robot, Part VI: Remote Control,
https://blog.miguelgrinberg.com/post/ (2013).
RAVI, Bluetooth Controlled Robot using Arduino,
https://www.electronicshub.org/ (2018).
RAVI, Automatic Room Lights using Arduino and PIR Sensor,
https://www.electronicshub.org/ (2018).
NCKiwi, Wi-Fi Remote Control Using ESP8266, Instructable circuits (2019).
Aswinth Raj, Lora Based GPS Tracker using Arduino and LoRa
Shield, CircuitDigest (2019)
Ryan Turner, Arduino Programming: The Ultimate Beginner's Guide
to Learn Arduino Programming Step by Step, Kindle (2019).
https://blogs.umass.edu/Techbytes/2014/01/14/turkeybytes-arduino/
Arvind Sanjeev, use a PIR motion sensor to build your own intruder
detection system (2018).
Vividz, Make Your Own Smoke Detector Circuit Using Arduino,
Autodesk Inc (2017).
https://electronics-project-hub.com/arduino-7-segment-display-clock-
with-and-without-rtc/ .
James Bruce, How To Make a Pulsating Arduino LED Cube That
Looks Like It Came From The Future, Makeuseof (2012).
Ian Buckley, How to Make a Custom Game Controller With Arduino
and Unity, Makeuseof (2016).
Joe Coburn, Arduino Programming for Beginners: Traffic Light
Controller Project Tutorial, Makeuseof (2019).

You might also like