0% found this document useful (0 votes)
5 views65 pages

Arduino Lending Basic Kit

Uploaded by

Dmdhinesh
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)
5 views65 pages

Arduino Lending Basic Kit

Uploaded by

Dmdhinesh
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/ 65

Arduino Basic Projects

for Absolute Beginners

Created as a companion manual to the Toronto Public Library Arduino Kits.

Arduino Basic Projects for Absolute Beginners

Copyright © 2018 Toronto Public Library. All rights reserved.

The Toronto Public Library is not responsible for personal injury or damage to property
that occurs with use of the Toronto Public Library’s Arduino Kits and the Arduino Kit
Manual. Images created using Fritzing software.

1
Table of Contents

PREFACE................................................................................................................................................. 3

INTRODUCTION ..................................................................................................................................... 5

SAFETY TIPS ........................................................................................................................................... 9

ABOUT THE ARDUINO STARTER KIT ................................................................................................... 11

ARDUINO UNO TOUR .......................................................................................................................... 13

GETTING TO KNOW YOUR BREADBOARD .......................................................................................... 14

FIRST ELECTRONICS ............................................................................................................................. 16

GETTING TO KNOW THE ARDUINO SOFTWARE ................................................................................ 20

THE “MINIMUM” PROGRAM .............................................................................................................. 24

BLINK MY INTERNAL LIGHT: PROJECT 1 ............................................................................................. 28

BLINK AN EXTERNAL LED: PROJECT 2 ................................................................................................. 32

BRIGHTER LIGHT: PROJECT 3 .............................................................................................................. 36

TRAFFIC LIGHT SIMULATOR: PROJECT 4 ............................................................................................ 37

BUTTONS: PROJECT 5.......................................................................................................................... 45

TONE CREATOR: PROJECT 6................................................................................................................ 49

MY FIRST INSTRUMENT: PROJECT 7 ................................................................................................... 51

RECOMMENDED RESOURCES............................................................................................................. 63

2
Preface
Time Required: 5 minutes

Thank you for borrowing Toronto Public Library’s Arduino Kit. Please return this kit to
the Digital Innovation Hub from which it was borrowed.

3
Borrowing Arduino Kits
 Arduino Kits are available to Toronto Public Library customers with a valid Teen
(13-17), Adult – Under 25 (18 – 24), or Adult (25+) library card.

 Holds cannot be placed on the Arduino Kits.

 You can only borrow one Arduino Kit at a time. Each kit can be borrowed for 21
days and cannot be renewed.

Fines Per Day and Maximum Fines for Arduino Kits

CARD TYPE FINE AMOUNT MAXIMUM YOU WILL


PER DAY BE CHARGED FOR
EACH LOAN PERIOD
Adult $0.35 $14.00
Adult Under 25 (18-24) $0.15 $6.00
Teen (13-17) $0.15 $6.00

 If you lose an Arduino Kit, you will be charged the purchase price of the Arduino
($50). The library does not accept a replacement Arduino or an item of equal value.

 If the Arduino Kit is overdue by more than 40 days, the library considers it lost. If
you find the kit within 6 months of paying the replacement cost you can get a
refund, minus any overdue fines so please keep your receipt.

 Please report damaged equipment or missing parts to the Digital Innovation Hub
staff from which it was borrowed. Damaged Arduino boards and kits are subject
to replacement purchase fees.

4
Introduction
Time Required: 5 minutes

An Arduino is a microcontroller; a small, simple computer on a single integrated circuit.


It is designed specifically for beginners who are new to coding and electronics. You can
learn more about the Arduino at https://www.arduino.cc/en/Guide/Introduction.

There are thousands of projects you can build with an Arduino.

Parts In This Kit


Your assembled kit includes all the parts you will need for the Arduino projects outlined
in this manual. When you are done with your projects, please return the parts to their
proper slots for the next person to enjoy.

There are different types of Arduinos. This kit uses a blue


Arduino Uno board. The different parts on the Arduino are
labelled in white.

5
The USB cable is used to connect the Arduino to your
computer.

The breadboard lets you build circuits. It has a series of holes


where you can insert wires to create circuits. The magic of a
breadboard is that it’s reusable, and you don’t need to solder
(permanently joining components together to form a circuit
by melting metals).
6
Jumper wires are used to create electric circuits and can be
inserted into the breadboard.

LEDs (light-emitting diodes) are electronic devices that emit


light when an electrical current passes through them.

Resistors help control the flow of electricity in your circuit by


limiting the current. They come in different values measured
in ohms (Ω). Using the correct value resistor is important
because they protect the LEDs and other parts from being
damaged by too much current. They have different colour
bands on them to tell you what kind of resistance it is.

7
Before you can use the Arduino, you will need to set up the
Arduino IDE software on your computer. You’ll be using the
IDE (Integrated Development Environment) to write code
and upload it to your Arduino. The code for the Arduino is
called a Sketch.

8
Safety Tips
Toronto Public Library’s Arduino Kits use low voltage electricity and are not inherently
dangerous. However, safety is always important when working with electrical circuits.
Please follow the safety tips and instructions in this manual at all times.

Expert Tip: Always treat electronic projects as if they could


have potentially dangerous voltages.

Each project has been planned and mapped out for you. Please take the time to read and
thoroughly review the project instructions from beginning to end before you begin.
Ensure that wires are connected accurately and in accordance with the diagrams
provided. Not following the instructions as specified may result in personal injury or
damage to the equipment.

Expert Tip: Turn off all power sources before modifying the
circuit. Keep your Arduino unplugged while you are
connecting wires and parts. Only connect it to the computer
after your setup matches the diagram provided.

Keep your work surface clear when using this kit and maintain an orderly and safe work
environment. Keep food and drinks away from the work area while working with your
Arduino kit. Always unplug the Arduino when not in use. After using the kit, return all
the parts to their proper storage place.

Expert Tip: Place the Arduino on a non-metal surface and


refrain from working on metallic surfaces.

9
Warnings
 This kit is not a toy and is not appropriate for small children. Small parts may present
a choking hazard. Not for children under 3.

 Avoid touching the exposed end of ground and power wires when connected to the
Arduino.

 Use only the materials provided in the Arduino Kit.

 Do not make alterations or perform major repairs on the Arduino Kit.

 No soldering with the TPL Arduino Kit.

 Do not use lithium ion batteries, they may explode when shorted

 Do not use on metallic surfaces, such as your Macbook. Place the Arduino on a non-
metal surface and refrain from working on the surface of your Macbook.

 The library is not responsible for damage to any equipment and hardware used with
the kit, including personal computers, laptops or tablets.

 Unplug the Arduino when not in use.

 Turn off/disconnect all power sources before modifying a circuit. While you’re
connecting components, keep your Arduino unplugged. Only connect it to a computer
or power source after the circuit is complete.

10
About the Arduino Kit
Time Required: 10 minutes

The basic kit includes all the parts you’ll need to get you started in the wonderful world
of Arduino!

If you get stuck or have any issues or questions with this Arduino Kit, feel free to ask
any of our Digital Innovation Hub staff. We also have Arduino classes that will teach
you all the basics, and Arduino Clubs for free-form learning with staff support.

An Arduino is a low-cost microcontroller that is designed for


beginners and is easy to learn.

Now you’re ready to unpack your kit. Take a look inside and make sure you have all
the necessary parts, listed on the following page.

11
Part Inventory for the Basic Kit

1x Arduino 1x Breadboard 16x Jumper Wires 6x 220ohm


Resistors (red, red,
The Arduino is the The breadboard is Jumper wires connect brown, gold bands
microcontroller and used to temporarily the components on resistor)
brains of our project. connect multiple completing a circuit.
It stores programs components and Note: The colour of Resistors are used to
and processes inputs wires together during the wires do not reduce the flow of
and outputs. prototyping. matter when building electric current in a
the projects. circuit. This prevents
damage to LEDs that
require a lower
voltage.

1x Piezo 6x 10kohm 5x Pushbuttons 6x LEDs


Resistors (brown,
The piezo is used to black, orange, gold Used to interrupt a LED stands for Light
create sound for the bands on resistor) circuit. When you Emitting Diode and
projects. push and hold the is used to create light.
Used in a circuit for button, it completes These LEDs typically
the switches. the circuit. require around 1 volt.

12
Arduino Uno Tour
Time Required: 10 minutes

Spend a few moments looking at the diagram below and compare it to the Arduino
included in your kit.

The Arduino has been labeled to help you learn all the different connectors and parts.

DC Power Jack
USB Port
Used to power the
Arduino with an Used to power the Arduino
external DC power with 5 volts. Also used to
supply (7-12volts only). upload code to the Arduino.

Reset button

Used to reset the Arduino.

RX and TX LED

Tells you when your Arduino


is sending or receiving
commands to your computer.
Usually will blink when
uploading a sketch or using
5v and GND Power serial communication.

Used to provide 5 volts of Digital pins (pins 2-13)


positive power, and GND
Use these pins with
to ground your circuit.
digitalWrite(), digitalRead()
and analogWrite() functions.
Analog in analogWrite() works with
pins that have a ~ beside the
Used as inputs with the
number.
analogRead() command.
Built-in LED

A built-in LED that you


ATmega328P can control. It shares
digital pin 13.
This microcontroller is
the brains of the Power LED
Arduino. 13
When lit, it means the
Arduino is powered on.
Getting to Know your Breadboard
Time Required: 20 minutes

Video resources about breadboards: http://goo.gl/6HPHbg

In order for us to connect our tiny components together, we need our breadboard. A
breadboard is great for prototyping since it does not create a permanent connection
between components like soldering does. Everything is held together by friction when
you insert them into those tiny holes inside your breadboard.

Remember: If you have any questions, or need some extra


help, feel free to visit a Digital Innovation Hub at the Toronto
Public Library for classes or assistance.

Power rails

All the power rails have invisible wires


under that run vertically.

Connectors
Five holes in each of
the horizontal rows
are connected.

What a breadboard looks like if we could see the wires under the breadboard

14
Above is an example of how a breadboard usually looks; on the right is how a breadboard
would look if we could see the wires that connect all of the holes together. Those hidden
wires are used to connect all your components to each other while you prototype.

Take a look at your breadboard. You may have noticed that the breadboard holes are all
labeled A to J (vertically) and from 1-30 (horizontally). This is used to indicate where to
place your components.

Throughout this guide, we will be asking you to place your components in very specific
holes within your breadboard. For example, we might ask you to put a wire into hole 3E.
Now is the time to get familiar with the layout of your breadboard.

15
First electronics
Time Required: 30 minutes

For this first project, we’ll be creating a very basic circuit that can power an LED light
when a switch is pressed on the breadboard. We will not need to program our Arduino.

It does not matter what colour the wires you use compared to the wiring diagram. All
wires will conduct the same electricity.

Required Components

1x 220ohm
Resistors
1x 2x Jumper 1x
1x Arduino (red, red, 1x LED
Breadboard Wires Pushbutton
brown,
gold)

Make sure you use the correct resistor! Each resistor has a
value, in ohms, that tells you how strongly it resists the flow
of current. To tell the resistors apart, note the coloured bands,
and the order in which they are arranged. The basic kit
includes three 220ohm resistors, and three 10kohm resistors.

16
For this project we will only be using the Arduino to power for our LED. At this time, we
won’t need to write any Arduino code.

Step 1
Whenever you work on your Arduino, make sure you disconnect it from any power
source while connecting the components. Always double check that everything is
connected correctly, so you don’t short-circuit your Arduino.

Step 2
Time to plug our components into the breadboard!

Find a pushbutton and plug it into the breadboard as shown. There are four pins for this
component. Plug the pins from the switch into the breadboard holes E1, F1, E3 and F3.

17
Step 3

Find the 220ohm resistor (the resistor with the colour bands red, red, brown and gold) included
in your kit. Plug one side of the resistor into the breadboard hole G3 and the other side
into the hole G7.

Step 4

Find your red LED. Take note that the LED has one leg that’s longer than the other. The
longer leg is our positive anode and the shorter is the negative cathode. Plug in the shorter
leg into the breadboard hole H7 and the longer leg into the hole the H8.

LED stands for Light Emitting Diode. What is a diode you might ask?

A diode is an electrical component that allows electricity to flow in only one


direction from positive to negative. That is why our LED has a positive (the longer
wire) and negative side wire.

18
Step 5

To give the LED power, we will need to connect the jumper wire from the Arduino’s 5V
pin to the breadboard's hole F8.

Step 6

Lastly, we need to complete the circuit. Plug in a jumper wire from any of the Arduino’s
available GND pins to the breadboard at G1.

Step 7
That’s it! We are now done our first project. Just plug in your Arduino to your
computer using the USB cable (USB-A to USB-B).

Once powered, your LED will turn on whenever you push the switch. When you push
the button, it completes the circuit. Power flows from the 5V pin on the Arduino, to
the LED, then to the resistor, and then to the switch. When pushed, current flows
finally back to the Arduino’s GND pin.

19
Getting to know the Arduino Software
Time Required: 25 minutes

Arduino IDE (Integrated Development Environment)

The Arduino IDE is a software used to write, test, and upload programs to the Arduino.
Windows, Mac OS and Linux each have their own version of Arduino IDE available for
download at http://arduino.cc/en/main/software

Installing Arduino IDE

Windows
1. Open the Arduino downloads page at http://arduino.cc/en/main/software and
click the Windows link. This will download the .zip file of the Arduino application.
2. Unzip the downloaded folder by right clicking it and selecting “Extract All”.
3. To connect the Arduino to the computer, plug the square end of the USB into the
Arduino and the flat end into the computer. On the Arduino, the green LED will
turn on and Windows will try to find drivers. If drivers are found, skip to step
five.
4. If it fails to find drivers, close the window and install drivers manually.
a. Open the Start menu and in the Search Programs and Files box, type
devmgmt.msc. Press Enter to open the Device Manager window.
b. Click Browse to find your Arduino folder from where you saved it in Step
one.
c. In the Arduino folder, click the Drivers folder and then the Arduino Uno file
d. Click Next, and Windows completes the installation.
5. Now that you installed the software and drivers, you can open it by clicking the
arduino.exe file in the Arduino folder. You can also make a desktop shortcut for
convenient access to the Arduino IDE software.
6. Double click the icon to launch the application.

20
Mac OS
1. Open the Arduino downloads page at http://arduino.cc/en/main/software and
click the MAC OS link.
2. Double click the app and place it in the applications folder.
3. To connect the Arduino to the computer, plug the square end of the USB into the
Arduino and the flat end into the computer.
4. A dialogue box will appear on screen with a message “A new network interface
has been detected”.
5. Click Network Preferences, then click Apply. Even if the left side of the window
displays the Arduino as “not configured”, it will work.
6. Close the Network Preferences window.
7. To launch the Arduino application, go to the Applications folder and select the
Arduino app.

Arduino IDE Software Environment

Programs written for Arduino are called “Sketches”. It is recommended to explore the
Arduino software environment before you start your first sketch.

The Arduino software is presented as a GUI (Graphical User Interface), which provides
a visual way of interacting with a computer. The turquoise coloured window is
Arduino’s GUI, and it is divided into four main areas.

21
Arduino IDE as viewed in Mac OS 11

Menu Bar
The menu bar contains dropdown menus of all the tools, settings and
information relevant to the software. For Windows, the menu bar is located at
the top of the Arduino window and in Mac OS, the menu bar is located at the top
of the screen.

Toolbar
The toolbar contains common buttons for writing sketches for Arduino.

 Verify – The Verify function is used to check that the written code does
not have obvious mistakes. However, it doesn’t guarantee the code works
as intended.

22
 Upload - The Upload function sends the sketch to the connected Arduino
board.

 New - The New function is used to create a new sketch.

 Open - The Open function is used to open an existing sketch.

 Save - The Save function is used to save the current sketch.

 Serial Monitor - The Serial Monitor function is used to view data sent to
or received by the Arduino board. Unlike other toolbar functions, it is
located on the far right of the toolbar.

Text Editor
The text editor displays the sketch as text. It has Arduino sketch feature like
colour codes and auto formatting.

Message Area
The message area notifies you of common errors with the Arduino.

23
The “Minimum” Program
Time Required: 15 minutes

Plug in your Arduino to the computer and launch the Arduino IDE software or web
interface.

Load the bare minimum example from the Arduino software to test if we can upload
this sketch.

Go to File -> Examples -> 01.Basics -> BareMinimum to load the bare minimum example
from the Arduino software to test if we can upload this sketch. First let us just go over
what is in the BareMinimum sketch.

24
Any code inside void
setup() runs only when
the Arduino first turns
on or restarts.

Runs any code inside


void loop() after
running code inside
setup(). After running
all commands inside
void loop(), it will go
back to the first
command inside void
loop() and keep looping
until the Arduino is
turned off or new code
is uploaded to it. That’s
why it is called loop!

That is the bare minimum code you must have to be able to upload to the Arduino.
When you start a new project, always load the BareMinimium so you never forget the
required commands.

Now, upload the BareMinimium sketch to test if you can communicate with your
Arduino.

Under the menu “Tools”, double check that your Board setting is set to the Arduino Uno
and your serial port is selected correctly.

25
Next, we have to select the Serial Port to say how to communicate with our Arduino.
Click the menu Tools -> Port.

On Windows machines, they will be listed as COM1, COM2, COM3, COM4 and etc.
Unfortunately, you have to guess which COM port it is so start with the highest
number. There is no harm in selecting the wrong COM port, so see if it will connect.
You could also disconnect the Arduino and see which COM port disappears and
reappears when you plug it back in.

On macOS, your Arduino Serial Port is usually called “dev/cu.usbmodem####” where the
# could be a random number. Like the Windows serial port if there is more than one,
there is no harm in guessing which “dev/cu.usbmodem####” it could be. In the example
above, it would be “/dev/cu.usbmodem1413” for the Arduino.

Now we can click the upload button to see if the sketch can be
uploaded to the Arduino.

26
If all goes well, you should
see no errors on the bottom
debug screen. It should also
say “Done uploading”.

As you can see on the


example screenshot on the
left, an error has occurred.
The Arduino software gave
an “Problem uploading to
board” which means it was
unable to properly talk with
the Arduino.

In the debug information


you can see it also tells us
“avrdude: ser_open(): can't
open device "\\.\COM1": The
system cannot find the file
specified.”. This is telling us
our COM port was incorrect or the Arduino is not plugged in correctly. If you have any
issues call a TPL Digital Innovation Hub for assistance, come to one of our Arduino
courses or talk to staff directly at a Digital Innovation Hub.

27
Blink my Internal Light: Project 1
Time Required: 20 minutes

Now that we have a basic understanding of what an Arduino is and how to get started,
let us program something very simple. This project is the one most people like to start
with, as it is simple and easy to understand. If you have any trouble getting started or
wish to have more assistance, we highly recommend you come to one of the Toronto
Public Library’s introductory Arduino courses.

For this project, we do not require you to wire anything as we will be using the built-in
LED.

Built-in LED
for this project.

28
Coding the project
Time to code the project and enable the built-in LED to blink. In order to call on the
internal LED we will use the name LED_BUILTIN, which will automatically use the
correct Arduino pin on the board that controls that light. Below is the completed code we
will be typing in.

Line 1. void setup() {


Line 2. pinMode(LED_BUILTIN, OUTPUT);
Line 3. }
Line 4.
Line 5. void loop() {
Line 6. digitalWrite(LED_BUILTIN, HIGH);
Line 7. delay(1000);
Line 8. digitalWrite(LED_BUILTIN, LOW);
Line 9. delay(1000);
Line 10. }

Inside our void setup() function we have a command on Line 2 called pinMode which
tells the Arduino if it is an input or output. Inside the brackets of the function pinMode
we pass two parameters. The first tells pinMode what pin to select (in our case
LED_BUILTIN), and the second tells the Arduino if it is an INPUT or an OUTPUT (we
have ours set as an output).

Coding Accuracy
Be careful typing in correctly. Forgetting to put in a semi-colon or
writing digtalwrite instead of digitalWrite is a big deal. Accuracy is
important making sure your code will run on the Arduino. Talk to
Digital Innovation Hub staff for assistance if you have any questions.

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {

29
The Arduino will now process the command “pinMode(LED_BUILTIN, OUTPUT)”
whenever the device turns on and reboots only, as this command is in the setup()
function. This is only needed to run one time because our LED will never change from an
OUTPUT to an INPUT, so running the command again is not needed.

Inside our loop() function is where we will place the remainder of our code. Remember
any command you put inside the loop() function will repeat the command forever until
you turn off the device or reprogram it.

Line 6 uses the command digitalWrite(LED_BUILTIN, HIGH) which is used to tell the
built-in LED to turn on. Just like pinMode, digitalWrite also needs two parameters to be
passed to it. First parameter tells what Arduino pin to control, the second parameter says
what to do with the pin, if it is either on (HIGH) or off (LOW). We want to turn it on, so
we will use HIGH.

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
digitalWrite(LED_BUILTIN, HIGH);
}

Now upload this program to the Arduino, to see if our LED will turn on. If the LED
doesn’t turn on, double check that the program uploaded correctly and your code is
accurate. If it continues to not light up your LED and everything is connected accurately,
then your computer might be having issues uploading to your Arduino. Please refer to
the troubleshooting guide.

As you can see, the LED remains on when we upload or power our Arduino on with our
code. It is essentially asking the built-in LED to turn on a hundred or more times a second.
That is not very fun so we need to make our LED blink. We first need to tell the Arduino
to wait one second after turning on the LED, before we turn it off. To do this we will add
the command delay() on Line 7.

30
The delay command tells the brains of our Arduino to stop and wait. We pass one
parameter with the command delay to say how many microseconds to pause. In our case
we used delay(1000) which will equal to a one second pause.

Next on Line 8 we add our digitalWrite command for the built-in LED, but this time
asking it to turn off (notice we are using LOW instead of HIGH). Adding the command
digitalWrite(LED_BUILTIN, LOW) will turn off our LED light.

Our last piece of code on line 9, is to pause the Arduino again, so it will turn off the LED
and wait one second.

Line 1. void setup() {


Line 2. pinMode(LED_BUILTIN, OUTPUT);
Line 3. }
Line 4.
Line 5. void loop() {
Line 6. digitalWrite(LED_BUILTIN, HIGH);
Line 7. delay(1000);
Line 8. digitalWrite(LED_BUILTIN, LOW);
Line 9. delay(1000);
Line 10. }

Upload and we should now have a beacon light that turns on for one second and then
turns off for one second.

31
Blink an External LED: Project 2
Time Required: 30 – 40 minutes

Use the LED included in the kit and make it blink. The code will be very similar to Project
1, but with some modifications.

Required Components

1x 220ohm
2x Jumper Resistors (red,
1x Arduino 1x Breadboard 1x LED
Wires red, brown,
gold)

Our goal is to tell our Arduino to blink the external LED forever (when powered on and
until we reprogram our Arduino). The LED light will turn on, wait for one second, turn
off the LED, wait for one second and repeat.

Let us start by connecting our components together on the breadboard and to the
Arduino. You should only power up your Arduino when you are confident it is
connected correctly.

32
Wiring the project

Always make sure your Arduino is disconnected from any power source while
you work on it. This should always be your first step for every project, even
when the instructions do not tell you to do so.

Step 1
Connect the following as shown by starting with the LED (Light Emitting Diode).

Connect the short leg of the LED into the breadboard hole 1E and the longer leg of the
LED into 2E.

33
Step 2
We need to connect our resistor into the breadboard. Unlike the LED which is a type of
diode, the resistor does not have a positive or negative leg.

Connect one leg of the resistor to the breadboard in the hole 2D and the other leg into 6D

Step 3
All that is left is connecting two jumper wires from the Arduino to the breadboard.

Connect a jumper wire from any of the available GND headers to the breadboard 1A (this
will connect the ground from the Arduino to the negative leg of the LED)

34
Step 4

Connect a jumper wire from pin 9 of the Arduino to the breadboard hole 6A. This will
connect pin 9 of our Arduino to the resistor which then connects to the LED’s positive leg
to complete the circuit. We can control pin 9 of the Arduino by telling it to blink on and off.

Coding the project


Time to code the project and enable the external LED on the Arduino pin 9 to blink. Very
similar to blinking the internal LED, but now we replaced LED_BUILTIN with our
Arduino pin connected to our LED which is pin #9.

Line 1. void setup() {


Line 2. pinMode(9, OUTPUT);
Line 3. }
Line 4.
Line 5. void loop() {
Line 6. digitalWrite(9, HIGH);
Line 7. delay(1000);
Line 8. digitalWrite(9, LOW);
Line 9. delay(1000);
Line 10. }

Upload the code to the Arduino to see the project blink the external LED.

35
Brighter Light: Project 3
Time Required: 20-40 minutes

For this project, we need the same components as Project 2. If you have taken a break or
want to just jump into Project 3 please refer to Project 2 for wiring instructions, as the
code will be the only thing different in this project.

Coding
Take a quick review of the final code for a fade light. Instead of digitalWrite (used to turn
things on or off) we will be using analogWrite which allows us to control how bright the
LED is. You can set the value of analogWrite between 0-255 (0 turns off the pin, 255 turns
on full power, and 130 is about half the maximum brightness or speed of the motor).
Upload the code to the Arduino to see the LED fade in.

Create an integer variable called


ledPin which will hold the value 9.
Line 1. int ledPin = 9;
Line 2. Setup ledPin (Arduino pin #9) as
Line 3. void setup() {
an output.
Line 4. pinMode(ledPin, OUTPUT);
Line 5. }
Output as an analog output to
Line 6.
Line 7. void loop() { ledPin (Pin #9). Set value to 0
Line 8. analogWrite(ledPin, 0); which means turn the LED off.
Line 9. delay(300);
Line 10. analogWrite(ledPin, 90); Set the output of ledPin as 130.
Line 11. delay(300); That is 130 out of 255, which
Line 12. analogWrite(ledPin, 130); would make it half the maximum
Line 13. delay(300); brightness.
Line 14. analogWrite(ledPin, 190);
Line 15. delay(300);
Output as an analog output to
Line 16. analogWrite(ledPin, 255);
ledPin (Pin #9). Set value to 255
Line 17. delay(300);
Line 18. } which mean maximum brightness.

Use delay to pause the code for


300 milliseconds so we can see
the different brightness.

36
Traffic Light Simulator: Project 4
Time Required: 45 minutes

We only have had one LED connected at any time, so it is time to expand and make a
simple traffic light.

Required Components

3x 220ohm 3x LED (1x


7x Jumper Resistors Green LED, 1x
1x Arduino 1x Breadboard
Wires (red, red, Yellow LED, 1x
brown, gold) Red LED)

Wiring the project

37
Step 1

Connect your red LED shorter pin (cathode) into the breadboard hole E1 and
the longer LED pin (anode) into the breadboard pin E2.

Step 2

Connect one pin of the 220ohm resistor into the breadboard hole C1 and the
other side of the resistor into the breadboard hole C5.

Step 3

Connect your yellow LED short leg (cathode) into the breadboard hole E7 and
the long leg (anode) into the breadboard hole E8.
38
Step 4

Connect another 220ohm resistor into the breadboard hole C7 and C11.

Step 5

Connect your green LED short leg (cathode) into the breadboard hole E13 and
the long leg (anode) into the breadboard hole E14.

39
Step 6

Connect another 220ohm resistor into the breadboard hole C13 and C17.

Step 7

Connect a jumper wire from the breadboard hole A17 to any of the available
breadboard left negative power rail holes.

40
Step 8

Connect a jumper wire from the breadboard hole A11 to any of the available
breadboard left negative power rail holes.

Step 9

Connect a jumper wire from the breadboard hole A5 to any of the available
breadboard left negative power rail holes.

41
Step 10

Connect a jumper wire from the any of the Arduino GND pins to any of the
available breadboard left negative power rail holes.

Step 11
We now have all the lights grounded (connected by the negative power rail), so we now
need to send power to them. We will be using three digital output pins to control the
three lights.

Connect a jumper wire from the Arduino pin #2 to the breadboard hole A14
(this will power our green LED).

42
Step 12

Connect a jumper wire from the Arduino pin #3 to the breadboard hole A8
(this will power our yellow LED).

Step 13

Connect a jumper wire from the Arduino pin #4 to the breadboard hole A2
(this will power our red LED).

43
Coding
Now that everything is wired up, we can start to work on the code. We want our red
LED to turn on with the yellow and green off. Upload the code to the Arduino.

Line 1. int greenLED = 2; Set variables to store the


Line 2. int yellowLED = 3; pin numbers of the green,
Line 3. int redLED = 4; yellow and red LEDs.
Line 4.
Line 5. void setup() {
Line 6. pinMode(greenLED, OUTPUT); Set the pins (2,3,4) used for
Line 7. pinMode(yellowLED, OUTPUT); our LEDs as OUTPUTs
Line 8. pinMode(redLED, OUTPUT); when the Arduino boots or
Line 9. } restarts since inside setup().
Line 10.
Line 11. void loop() {
Line 12. digitalWrite(greenLED, HIGH); First the Arduino will turn
Line 13. digitalWrite(yellowLED, LOW); on the green LED, turn off
Line 14. digitalWrite(redLED, LOW); the yellow and red LED,
Line 15. delay(8000); and pause for 8 seconds.
Line 16.
Line 17. digitalWrite(greenLED, LOW); Then, turn off green and
Line 18. digitalWrite(yellowLED, HIGH);
red LED, turn on the
Line 19. digitalWrite(redLED, LOW);
Line 20. delay(2000); yellow LED, and pause.
Line 21.
Line 22. digitalWrite(greenLED, LOW); Turn off the green and
Line 23. digitalWrite(yellowLED, LOW); yellow LED, turn on the red
Line 24. digitalWrite(redLED, HIGH); LED, pause for 8 seconds.
Line 25. delay(8000); e for 2
Since no other commands
Line 26. } seconds.
are here, repeat at the start
of the loop() function.

44
Buttons: Project 5
Time Required: 30 minutes

So far, we have only created projects that use outputs but no inputs. The most basic way
to get user input is by using a pushbutton. We can have our Arduino read the state of a
pushbutton, which will be used to tell the internal LED of the Arduino to turn on when
it is pressed.

Required Components

1x 10kohm
3x Jumper Resistors
1x Arduino 1x Breadboard 1x Pushbutton
Wires (brown, black,
orange, gold)

Wiring the project

Step 1

Your pushbutton has


four legs that need to fit
into the breadboard.
Insert the button as
shown with the legs in
the breadboard holes
E1, E3, F1, F3.

45
Step 2

Insert your 10kohm


resistor into the
breadboard hole G3
and the other side
into G7.

Step 3
Connect a jumper wire
from the Arduino’s 5v
pin to the breadboard
hole J1.

(The 5v pin of the


Arduino continuously
sends 5v power out. You
cannot turn it off or on
by code. Used for
powering external IC
chips, buttons, and
sensors.)

46
Step 4

Connect a jumper wire


from the Arduino’s GND
pin to the breadboard hole
J7.

Step 5
Connect a jumper
wire from the
Arduino’s A0 pin to
the breadboard hole
J3.

(This will be an input


to detect the button
being pressed. It will
read that power is
flowing from 5V to
GND when it is
pressed.

We have a 10kohm
resistor so we don’t
short out the 5V to
GND connection.)

47
Coding
Create an integer variable called buttonPin to store
Line 1. int buttonPin = A0; the value A0 (the pin our button is connected to).

Create an integer variable called buttonState. This


Line 2. int buttonState;
will be used to store if the button is HIGH or LOW
when we check using digitalRead() function.
Line 3.

Line 4. void setup() {


Set the built-in LED on the Arduino
called LED_BUILTIN as an output.
Line 5. pinMode(LED_BUILTIN, OUTPUT);
Set the button on the Arduino called
Line 6. pinMode(buttonPin, INPUT);
buttonPin (Pin A0) as an input.

Line 7. }

Line 8. Use digitalRead to see if


buttonPin (Pin A0) is pressed
Line 9. void loop() { or not and store if it is HIGH
or LOW in our variable
Line 10. buttonState = digitalRead(buttonPin); buttonState.

Line 11. if(buttonState == HIGH) { Check our variable buttonState


if the button is pressed. If it is,
Line 12. digitalWrite(LED_BUILTIN, HIGH); turn on the built-in LED
(LED_BUILTIN).
Line 13. } else {
If the button is not pressed
Line 14. digitalWrite(LED_BUILTIN, LOW); then turn off the LED
(LED_BUILTIN).
Line 15. }

Line 16. }

Upload the code to the Arduino and try the button.

48
Tone Creator: Project 6
Time Required: < 25 minutes

Required Components

1x Arduino 1x Piezo Speaker

Wiring the project

Step 1

Connect the Piezo speaker pins


directly to the GND pin and PIN
10 of the Arduino. (It does not
matter what pins go to GND or
pin 10. There is no positive or
negative on the Piezo included)

Be careful! The pins are


delicate and might bend if you
push too hard.

49
Coding
Create an integer variable called
SpeakerPin which will hold the
number 10.

Line 1. int SpeakerPin = 10;


Line 2. Setup SpeakerPin (Arduino pin
Line 3. void setup() { #10) as an output.
Line 4. pinMode(SpeakerPin, OUTPUT);
Line 5. }
Create a tone to our SpeakerPin, at
Line 6.
Line 7. void loop() { a tone of 300hz. Then wait for one
Line 8. tone(SpeakerPin, 300); second.
Line 9. delay(1000);
Line 10. Create a tone to our SpeakerPin, at
Line 11. tone(SpeakerPin, 700); a tone of 700hz. Then wait for one
Line 12. delay(1000);
second.
Line 13.
Line 14. tone(SpeakerPin, 999);
Create a tone to our SpeakerPin, at
Line 15. delay(1000);
Line 16. a tone of 999hz. Then wait for one
Line 17. noTone(SpeakerPin); second.
Line 18. delay(1000);
Line 19. } Stop all tones for SpeakerPin (pin
#9) and wait for one second.

Upload the code to the Arduino to hear the tones.

50
My First Instrument: Project 7
Time Required: 45 minutes

In this project, we will combine our knowledge of switches and using the piezo speaker
to create a super basic instrument. We will assign a different tone() function to the
speaker whenever one of the switches is pressed.

Required Components

3x 10kohm
1x 11x Jumper Resistors 1x Piezo
1x Arduino 3x Pushbuttons
Breadboard Wires (brown, black, Speaker
orange, gold)

51
Wiring the project

Connect a jumper wire from


Step 1 the Arduino’s 5v pin to one
of the breadboard right
positive power rail holes.

52
Step 2

Connect a jumper wire from


the Arduino’s GND pin to
one of the breadboards right
negative power rail holes.

Step 3

Your pushbutton has


four legs that need to fit
into the breadboard.
Insert the button as
shown with the legs in
the breadboard holes E1,
E3, F1, F3.

Step 4

Connect a jumper wire from


an available breadboard
positive rail hole to the
breadboards hole J1.

53
Step 5

Insert your 10kohm


resistor into the
breadboard hole H3 and
the other side into H7.

Step 6

Connect a jumper wire


from an available hole on
the breadboard right
negative power rail to the
breadboard J7 hole.

54
Step 7 Connect a jumper wire from
the Arduino’s A1 (analog in)
pin to the breadboard hole J3.

(This will be an input to


detect the button being
pressed. It will read that
power is flowing from 5V to
GND when it is pressed.

We have a 10kohm resistor so


it won’t short out the 5V to
GND connection.)

Step 8

Your pushbutton has


four legs that need to fit
into the breadboard.
Insert the button as
shown with the legs in
the breadboard holes E8,
E10, F8, F10.

55
Step 9

Connect a jumper wire from


an available breadboard
positive rail hole to the
breadboard hole J8.

Step 10

Insert your 10kohm resistor into


the breadboard hole H10 and the
other side into H14.

56
Step 11

Connect a jumper wire


from an available hole on
the breadboard right
negative power rail to the
breadboard J14 hole.

Step 12

Connect a jumper wire from


the Arduino’s A2 (analog in)
pin to the breadboard hole
J10.

(This will be an input to


detect the button being
pressed. It will read that
power is flowing from 5V to
GND when it is pressed.

We have a 10kohm resistor


so it won’t short out the 5V
to GND connection.)

57
Step 13

Your pushbutton has


four legs that need to fit
into the breadboard.
Insert the button as
shown with the legs in
the breadboard holes
E15, E17, F15, F17.

Step 14

Connect a jumper wire from


an available breadboard
positive rail hole to the
breadboards hole J15.

58
Step 15

Insert your 10kohm resistor into


the breadboard hole H17 and the
other side into H21.

Step 16

Connect a jumper wire


from an available hole on
the breadboards right
negative power rail to the
breadboards J21 hole.

59
Step 17

Connect a jumper wire from the Arduino’s A3 (analog in) pin to the breadboard
hole J17.

(This will be an input to detect the button being pressed. It will read that power is
flowing from 5V to GND when it is pressed.

We have a 10kohm resistor so don’t short out the 5V to GND connection.)

60
Step 18

Connect the Piezo speaker pins


directly to the GND pin and PIN
10 of the Arduino. (It does not
matter what pins go to GND or
pin 10. There is no positive or
negative on the Piezo included).

Be careful! The pins are


delicate and might bend if you
push too hard or misalign it
when inserting into the
Arduino.

Upload the code to the Arduino and try pressing each button for a different tone.

61
Coding Create three integer variables to store
our analog input pins. (We will have
inputs for a low, medium and high
Line 1. int lowNotePin = A3; note the user can push.)
Line 2. int medNotePin = A2;
Line 3. int highNotePin = A1;
Line 4. Create three integer variables that
Line 5. int highNote = 0; will hold the state of our buttons. (0
Line 6. int medNote = 0; means not pushed, 1 means pushed).
Line 7. int lowNote = 0;
Create an integer variable called
Line 8.
SpeakerPin to store what Arduino
Line 9. int SpeakerPin = 10;
pin we will be using (pin #10).
Line 10.
Line 11. void setup() {
Set our lowNotePin (A3),
Line 12. pinMode(lowNotePin, INPUT); medNotePin (A2) and highNotePin
Line 13. pinMode(medNotePin, INPUT); (A3) as inputs.
Line 14. pinMode(highNotePin, INPUT);
Line 15.
Line 16. pinMode(SpeakerPin, OUTPUT); Set SpeakerPin (#9) as an OUTPUT.
Line 17. }
Line 18.
Store the states of our
Line 19. void loop() {
buttons in our variables
Line 20. highNote = digitalRead(highNotePin); called highNote, medNote
Line 21. medNote = digitalRead(medNotePin); and lowNote.
Line 22. lowNote = digitalRead(lowNotePin);
Line 23. If lowNote button is pressed
Line 24. if(lowNote == HIGH) { (HIGH) then make a tone to
Line 25. tone(SpeakerPin, 300); SpeakerPin (#9) at 300 hz.
Line 26. }
Line 27.
If lowNote was not pressed,
Line 28. else if(medNote == HIGH) {
check if medNote is (HIGH).
Line 29. tone(SpeakerPin, 700);
If so make a tone to
Line 30. } SpeakerPin (#9) at 700hz.
Line 31.
Line 32. else if(highNote == HIGH) { If lowNote and medNote were
Line 33. tone(SpeakerPin, 900); not pressed, check if highNote
Line 34. } is (HIGH). If so make a tone to
Line 35. SpeakerPin (#9) at 900hz.
Line 36. else { noTone(SpeakerPin); }
Else if no other button is pressed,
Line 37. }
tell SpeakerPin (#9) to stop all
tones.
62
Recommended Resources
Get these for free at the Toronto Public Library

Want to learn more about Arduinos? Here is a list of our favourite Toronto Public
Library books and resources. When using the Arduino Kit, please stick to the projects
outlined in this manual. Additional projects found in the recommended resources are
for educational and entertainment purposes and are only intended for use with your
personal Arduino.

http://www.Arduino.cc
The official website has great tutorials and
reference resources. The website includes
information on all commands you can do for the
Arduino programming language and examples on
how to use them.

Learning Arduino with Peggy Fisher


This beginner course consists of two hours of
video and can be accessed for free from
Lynda.com (via tpl.ca/elearning with a valid Toronto
Public Library card).

63
Adventures in Arduino by Becky Stewart
This book provides simple, easy-to-follow
introductions to the Arduino. It is written for 11 to
15 year olds, but we’ve found the concepts,
content, and language engaging and applicable to
adult Arduino users. Available from Safari (via
tpl.ca/elearning with a valid Toronto Public Library
card).

Arduino for Kids (2017) by Priya Kuber, Rishi


Gaurav Bhatnagar, Vijay Varada
This book is intended for children (ages 9 and up)
and their parents. It includes a series of fun, easy
projects that don’t require any knowledge of
electronics. Available from Safari (via tpl.ca/elearning
with a valid Toronto Public Library card).

The Maker's Guide to the Zombie Apocalypse:


Defend Your Base with Simple Circuits, Arduino,
and Raspberry Pi (2016) by Simon Monk
No one knows what the future holds, so we can’t
definitively say whether or not the Arduino
projects in this book will come in handy. What we
can guarantee is that you’ll have fun learning
about Arduinos in a unique and creative way.
Available in regular print.

64
Make: Drones: Teach an Arduino to Fly by David
McGriffy
Have you ever wondered how drones work? This
book reveals drone building secrets and explains
how you can get your Arduino to fly. Available in
regular print and as an eBook from Safari (via
tpl.ca/elearning with a valid Toronto Public Library
card).

The Arduino Inventor's Guide (2017) by Derek


Runberg and Brian Huang
Ready to move on from the Arduino kits and start
working on some more advanced projects? Why
not build a tiny electric piano, a desktop
greenhouse, or a colour-mixing night light? You’ll
find ten fun Arduino projects in this new eBook,
available from Safari (via tpl.ca/elearning with a valid
Toronto Public Library card)

Arduino Playground : Geeky Projects for the


Experienced Maker (2017) by Warren Andrews
This is the perfect resource for more advanced
Arduino projects. One of our favourites is the
Garage Sentry Parking Assistant, a project that can
help you pull into your garage by setting off an
alarm when you’ve gone far enough and need to
hit the brakes. Available in regular print and as an
eBook from Safari (via tpl.ca/elearning with a valid
Toronto Public Library card)

65

You might also like