You are on page 1of 76

Cartooino

it ve
ac
e r
t
In
T
EN
D INO
T U U
S D
E

AR
N
O

o n
s-
n d
a
H
1
Acknowledgement
GreenLab
Cartooino
Acknowledgement
The cartooino Book is a comical
adaptation of the Arduino Projects Book.
The Book was developed by Greenlab
Microfactory for use for her “One student,
One Arduino” project. The essence of which
is to create a more relatable learning
approach for the participants. Therefore,
the Microfactory would like to acknowledge
Arduino LLC for their selflessness and
contribution to the body of knowledge by
fortifying the open source community
with their products and projects.
Lolia
In addition, Greenlab Microfactory will also
like to acknowledge that some of the content
of this book were derived and adapted from
the online platforms of Tutorials Point etc.
.
Disclaimer
This book was not created for commercial
purposes, and the contents of the cartooino
projects Book are licensed under a Creative
Commons Attribution -ShareAlike (CC BY-SA)
by Greenlab Microfactory. This means that
you can copy, reuse, adapt and build upon
the text of this book non-commercially while
attributing the original work(but not in any
way that suggests that we endorse you or your
use of the work) and only if the result are

Ayomide
transmitted under the same Creative
Common license.

Full license terms: creativecommons.org/license/bu-nc-sa/3.0/


Stack of Content

Getting to know your 01


tools

Building a simple
circuit 02
Understanding the
program interface 03

Spaceship interface
04

YouNiversity 05

Colour mixing lamp 06

GreenLab
Cartooino
02
Introduction

Aliya
A regular pupil and a participant of the
One Student One Arduino Project

divine
A regular pupil and a participant of the
One Student One Arduino Project

Uncle green
Lead facilitator of theOne Student One
Arduino Project

GreenLab
Cartooino
03
Introduction

KunleA regular pupil and a participant of the


One Student One Arduino Project

Faith
A regular pupil and a participant of the
One Student One Arduino Project

Emmanuel
A 400 level Student of computer science at
UNIBEN and a co-facilitator of the One Student
One Arduino Project

GreenLab
Cartooino
04
Maths teacher: X + Y= COS 30

0.324 X + Y=?
Maths class
was
interesting
2 4x but not as
much as the
kite
competition
34
o o l over
sch
school over
school ove
r
Are you not going Kunle I have to
to wait for the
run home because of the Maybe next time
football game?
Kite competition

I can’t wait to get


Stop Running home Aisha will
be waiting already
Ayomide

05
Aisha what’s
that?

Look Over there!!


I think the plane is been
controlled by that
uncle

06
Hi, My Name is And that is called
UNCLE GREEN a Drone Built with
Arduino.

Would You Teach


I really
I Really
wantwant
to Us how To Make
to build
build aa toy
Robot toy A Drone??

07
How high can
your kite
fly?

Nice

08
It will be
stressful
Should we go
join the Arduino
project with
Ayomide

Aliya remember
you have to tell And don’t forget
your mom to do your assignment

This place is
awesome

WOW

At Uncle Green house


Yo
u
to A re
Gr
e e welc
nLa om
b e

09
Meanwhile
Aliya jhorr
Aliya’s House
come and help me
in the kitchen

BUY
YOU
ICE B R
LOC
HER K
E

So ma,
Yesterday I was
introduced Aliya pass me the
to Arduino spoon

Can I stay
a little longer Just don’t
after school? stay too late

10
NEXT DAY

Episode 01

Learn Discover Create

Getting to know your tool

11
Getting to know your tool
Next Day
Hello kids, I am glad that you could
come today, i officially welcome you
to the “One student One Arduino” Project

Electricity is a type of
energy, much like heat,
gravity or light. Electrical
energy flows through conductors
like wire. You can convert
electrical energy into other forms
of energy.
Do you know that
What can electricity be Like In Our
one essential need
used for? Electric Bulb
is electricity

To watch TV

These are examples of electric energy


conversions

Electrical

Heat(thermal) energy

12
Getting to know your tool

More Examples of
Electrical energy Conversion Movement, heat and sound
energy

Light; heat and sound


Electrical Electrical

The components you might use to do Transducers change other types of energy into electrical
this is called electrical transducers. energy and vice versa.

Can we convert other forms of


What are circuits?
energy to electrical energy

Yes you can


Things that convert other forms
of energy into electrical
energy are often called sensors,
And things that convert
electrical energy into other forms
of energy are called actuators.

Circuits are closed loops of wires with a power source (like a battery) and
something to do something useful with the energy, called a load.

So Our Extensions are circuits

In a circuit, electricity from a point of higher potential energy (usually referred


to as power or +) to a point of lower potential energy. Ground(often represented
with. a - or GND) is generally the point of least potential energy in a circuit.
In the circuit you are building, electricity only flows in one direction.
This type of circuit is called direct current, or DC. In alternating current(AC) the
circuit changes its direction 50-60 times a second(depending on where you live).
This type of electricity that comes from your wall socket.

I will give you guys a little assignment.


look up these terms
Current, Voltage
and finally resistance
13
I know you want to start building
toys. But there are few informations
when can we start you need to know about the Arduino
building flying toys in your kit

15 14 13 12

16 11

17

10 9
1
8
3
4
2 6
5 7

1. Power USB- it gives power to the Arduino board power when you
connect the USB cable to the USB connection
2.Power(Barrel jack)
you can also power the board from AC mains power by connecting it to the
barrel jack

14
Getting to know your tool
Other parts of the
Arduino board are

3.Voltage Regulator-The function of the


voltage regulator is to control the
voltage given to the Arduino board
and stabilize the DC voltage used by the
processor and other elements.

4.Crstal Oscillator -The crystal Oscillator helps Arduino in dealing with


time issues. How does Arduino calculate time? The answer is by using the
oscillator. The number printed on top of the Arduino crystal is 16,000H9H.
It tells us the frequency is 16,000,000 Hertz or 16Mhz.

11. Main microcontroller


Each Arduino board has its own microcontroller
The Arduino UNO board has ve analog input A0 through A5. These
pins can read the signal from an analog sensor like the humility sensor
or temperature sensor and convert it into digital value that can be read
by the micro-processopr

12. ICSP pin


Mostly, ICSP(12) is an AVR, a tiny programming header for the
Arduino consisting of MOSI, MISO, SCK, RESET, VCC and GND. It
Is often referred to as an SPI (Serial Peripherial Interface), which
could be considered as an “expression” of the output. Actually,
you are slaving the output device to the master of the SPI bus.

13. Power LED indicator


This LED should light up when you plug your arduino into
a power source to indicate that your board is powered up
correctly. If this light does not turn on, then there is something
wrong with the connection.

15
Getting to know your tool

15. Digital I/O


The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide
PWM (Pulse Width Modulation) output.) These pins can be configured
to work as input digital pins to read logic values (0 or 1) or as digital
output pins to drive different modules like LEDs, relays, etc.
The pins labelled “ “ can be used to generate PWM.
16. AREF
AREF stands for analog Reference. It is sometimes used to set an
external volatge (between 0 and 5 volts) as the upper limit for the
analog input pins.

Arduino Reset -You can reset your Arduino board i.e, start your
program from the beginning. You can reset the UNO board in two
ways. The first, by using the reset buton (17) on the board.
Second you can connect an extenal
reset buttom to the arduino pin labelled RESET(5)

Pins(3.3,5, GND, Vin)

3.3V(6)-supply 3.3 output volt


5V(7)- Supply 5 output volt
Most of the components used with Arduino board
works fine 3.3 volts and 5 volts.

These are the parts with


tag 15-16

16
Getting to know your tool

Before we proceed
further, it is worthwhile
to read a resistor. How can we read
Resistors Let us look below

Resistors are measured in


ohms. The values of resistors
are represented by colour
codes.As Presented as follows
The resistors are of 4-band
(colour) , 5-band or 6-band. In the
4-band resistor,
the first two colours
indicate the first two values,
while the third band indicates the
numbers of Zeros. The last band
represents tolerance in the picture
here, Gold has a value of 5%
which means that the resistor
can tolerate a load of plus or
minus 5%, Therefore, this
For your assignment,
particular 4-band has a value
go through your Arduino project
of 10,000 or 10Kohms +5 kit and perform the following:
1. Identify the resistors in your kit
2. Calculate the values of each type.
Can we do it
Maybe I will come to your together?
house

17
Getting to know your tool

Source:https://electronics.stackexchange.com/questions/119/6
-brand-resistors-which-way-should-the-bands-be-read.

18
We are a step closer to
real Fun. In order
to build your toys,
you will need to download,
install and setup the
ARDUINO IDE on your We are going to use your computer
computer.

Oh I know how to use one


Getting to know your tools

Good Question But Uncle!


IDE means Integrated What is an IDE
Development
Environment, and it is a
software that tells the
Arduino board what
you want to do. As a
developer you will be
writing and testing
software. So the IDE
allows you to write and
test your code

I know you would also like


to know what a code is ?
A code is any collection of
computer instructions,
possibly with comments,
written using human-
readable programming
language.
19
GreenLab
Cartooino

Episode 1.2
Getting to know your tool-
How to Download, Install and set up
the Arduino IDE software

Am
Am
Interested
Interes-
ted

20
How to Download, Install and set up
the Arduino IDE software

Uncle Green How do you send command


to the Arduino board

You can do that using the Arduino IDE

Downloading and Installing Your Arduino


I will show you guys how software
to install the Arduino
software

With internet

STEP 1.
Now we want to download
the IDE, click the link-
https://www.arduino.cc/en/Mai
n/Software

21
How to Download, Install and set up
the Arduino IDE software

Step 2: After the download the next step is to power


your Arduino Board.
The Arduino Uno automatically draw power from either,
the USB extension to the computer or an external power
supply.To power up your Arduino, connect the Arduino
board to your computer using the USB cable. The green
power LED(Labelled PWR)should glow.
Step 3: Now launch the Arduino IDE
After you download your IDE, you need to unzip the folder.
Inside the folder, you would find the application icon with and
infinity( )label(application.exe).Double-click the icon to start the
IDE. As shown

Now it is time to open your first project.


Once the software starts, you have two options,
(1)Create a new project,
or
(2) Open an existing project
example.
The next picture explains how to do these.
But before you can create your project,
you need to do step 5 and 6. So do these
first then create your project.

22
How to Download, Install and set up
the Arduino IDE software

Step 4:1 To create a new project,


Select File New.
As shown

Step 4.2: To open an existing


project example,
select File Example Basics Blink.
Here, you are selecting just one
of the examples with the name
Blink. This turns the LED on and
off with some time delay. If you
like, you can select any other
example from the list.

Go to Tools
Board and select your
board

Step 5: Select your Arduino board. To avoid any error when uploading your
program to the board, you must select the correct Arduino board name, which
matches with the board connected to your computer.

23
How to Download, Install and set up
the Arduino IDE software

Step 5: Select your Arduino board. To avoid any error


while uploading your program to the board,
you must select the correct Arduino board name, which
matches with the board connected to your computer.
Go to Tools Board and select your board.
In the picture below, we have
selected Arduino Uno board according to our tutorial,
but if you are using another Arduino board you must
select the name that matches the board you are using.

A- Used to check if there is any compilation error.


B- Used to upload a program to the Arduino board.
C- Shortcut used to create a new sketch.
D- Used to directly open one of the example sketch.
E- Used to save your sketch.
F- Serial monitor used to receive serial data to the
the board.
Now, simply click the “Upload” button in the environment.
Wait a few seconds you will see the RX and TX LEDs on the
board, Flashing if the upload is successful, the
message “Done uploading” will appear in the status bar.
Congratulations! You have
successfully installed your
Arduino IDE. You are now
ready to embark on a
memorable adventure

24
How to Download, Install and set up
the Arduino IDE software

Step 6: Select your serial port

Select the serial device of the Arduino board


Go to Tools--- Serial Port Menu.
This is likely to be COM3 or higher (COM1 and
COM2 are usually reserved for hardware serial
ports). To find out, you can disconnect your Arduino
board and re-open the menu, the entry that
disappears should be the Arduino board. Reconnect
the board and select the serial port.

Read out the next


step lolia

25
How to Download, Install and set up
the Arduino IDE software

Lets look at what we


have here

Resistors
This resist flow of electrical
in a circuit, changing the
Piezo voltage and current as a result.
This is an electrical Resistor values are measured
component that in ohms (represented by the
can be used to greek Omega character: )
detect vibrations The coloured stripes on the
sides of the resistors indicate
and create noises.
their value( see resistor colour
table)

The Arduino Uno is


what we will be using
for our project

So there are other Arduino Uno


types of Arduino This picture shows the Arduino
board Uno microcontroller development
board that will be at the centre
of your projects. It’s a simple
computer, which you will use to
build circuits and interfaces for
interaction, and to tell the micro
controller how to interface with
other components.

What is that?
DC motor:
This converts electrical energy to
mechanical energy when electricity is
applied to its leads. Coils of wire inside
the motor become magnetized when
current flows through them

Light Emitting Diodes(LEDs)


A type of diode that illuminates
when electricity passes through
it.

26
How to Download, Install and set up
the Arduino IDE software

Are we going to Capacitors:


No! just the
use everything These components store and release electrical
tools for our
energy in a circuit. When the circuit’s voltage
project is higher than usual it is then stored in the
capacitor,it allows current to flow in giving
the capacitor a charge. When the circuit’s
voltage is lower, the stored charge is released.

Thi s is called a USB cable Ayomide this is called


it allows you to connect Battery Snap, it is Used to
connect a 9V battery to power
your Arduino Uno to your
leads that can be easily
Personal Computer for plugged into a breadboard or
Programming. your Arduino.

Servo Motor Tilt sensor


A type of geared motor that can only It’s a type of switch that will open
rotate 180 degrees. It is controlled by or close depending on its
sending electrical pulses from your orientation. typically, they are
Arduino. These pulses tell the motor hollow cylinders with a metal ball
what position it should move to power in-side that will make a connection
across two leads when tilted in the
to the Arduino for most of the projects
particular direction.
in the kit.

Breadboard:
Though the name sounds funny but
it is a kind of bread that cannot be
chewed. A board on which you can
build electronic circuits. It’s like a
patch panel

#TIP
A resistor is a device that restrict the
flow of electric current in a system

27
How to Download, Install and set up
the Arduino IDE software

Push Button
It momentary switches that close a
circuit when pressed. They snap into
bread-boards easily. These are good
for detecting on/off signals

Jumper Wires are used


to connect components
to each other on the
Male header pins breadboard, and to
the Arduino.

These fit into female


sockets like those on a Potentiometer
breadboard. They help This is a variable resistor with three
make connecting things pins, Two of the pins are connected to
easy the ends of a fixed# resistor. The middle
pin, or wiper, moves across the resistor,
dividing it into two halves. When the
OHHH!! external sides of the potentiometer are
connected to voltage and ground, the
middle leg will give
the difference in
voltage as you
turn the knob.

Here is a list

Now that
we have
described
each
lets get
started
Now you understand how
potentiometer works

28
How to Download, Install and set up
the Arduino IDE software

We have gotten to the end of this project, you


created your first arduino program to control the
behaviour of some LEDs based on a switch. You
have used variables, and if()...else statements and
functions to read the state of an input and control
outputs.
Uncle! What is
a function? and I
also need more
information
about variables.

Good Question!
When we meet next I will explain
everything better for you

#TIP

29
How to Download, Install and set up
the Arduino IDE software

What about the these two

So we are almost
Done

H-bridge Photoresistors

H-BRIDGE is a circuit that allows you


to control the polarity of the voltage
applied to a load, usually a motor.
The H-bridge in the Kit is an Integrated
circuit, but it could also be constructed
with a number of discrete components

Photo-resistor (also called a


photocell, or Light dependent
resistor). A variable resistor that
changes its resistance based on
the amount of light that falls
on its face.

so we can
start now

It is 4 0 Clock already

30
Practice Question

What does IDE stand for?


answer choices

In Deep Environment
Internal Deep Escape
Integrated Development Environment
Integrated Device Environment

31
Episode 2
Building a simple circuit

32
Building a simple circuit

Hy kids how was school today


School was great, Uncle our
interhouse games starts in a
week. Microfactory

I am sure
that I will win
a medal or two

That Great Remember diligence


and hard work always wins, Now
today we will discover some basic
electrical theory and how to
connect components in series and
parallel. So if you are ready
let’s start.

The Basic Electrical Theory


Electricity is a type of energy, much like heat, gravity or light.
Electrical energy flows through conductors, like wire. You can
convert electrical energy into other forms of energy to do something interesting, like
turn on a light or make some noise out of a speaker. The components you might use to
do this, like speakers or light bulbs, are electrical TRANSDUCERS. Transducers change
other types of energy into electrical energy and vice versa. Things that convert other
forms of energy into electrical energy are often called SENSORS, and things that
convert electrical energy into other forms of energy are sometimes called ACTUATORS.
You will be building circuits to move electricity through different components.
Circuits are closed loops of wire with a power source (like a battery) and something
to do something useful with energy, called a load.
In a circuit, electricity flows from a point of higher potential energy(usuallyreferred to
as power or +) to a point of lower potential energy in a circuit. In the circuits you are
building, electricity only flows in one direction. This type of circuit is called direct
current, or DC. In alternating current (AC) circuit electricity changes its direction 50 or
60 times a second (depending on where you live). This is the type or electricity that
comes from a wall socket.
There are a few terms you should be familiar with when working with electrical
circuits. Current(measured in amperes, or amps: with the A symbol) is the
amount of electrical charge flowing past a specific point in your circuit. Voltage
(measured in volts; with the V symbol) is the difference in energy between one
point in a circuit and another finally, Resistance (measured in ohms, with the
symbol) is how much a component resist the flow of electrical energy.

33
Building a simple circuit

-There needs to be a complete path from the energy source(power) to the


point of least energy (ground) to make a circuit. If there’s no path for the
energy to travel, the circuit won’t work.
-All the electrical energy gets used up in a circuit by the components in
it. Each component converts some of the energy into another form energy.
In any circuit, all of the voltage is converted to another form of energy
(light, heat, sound, etc.)
-The flow of current at a specific point in a circuit will always be same
coming in and going out.
-Electrical current will seek the path of least resistance to ground.
Given two possible paths, more of the electrical current will go down
the path with less resistance. If you have a connection that connects power
and ground together with no resistance, you will cause a short circuit, and
the current will try to follow that path. In a short circuit, the power source
and wires converts the electrical energy into light and heat, usually as sparks
for an explosion. If you’ve ever shorted a battery and seen sparks, you will
know how dangerous a short circuit can be.

The diagram shows a simple


circuit made from three jumper
cables, a 220 ohm resistor
and a LED. Please go to the
information about each of
these components. Don’t
forget that the long leg of the
LED is the positive side(+)
called anode, while the short
leg is the negative (-) side
call cathode
34
Building a simple circuit

One major warning for you to note.


Always unplug your Arduino from the
power source before building the circuit

What Next? Connect the jumper cables, push button,


resistor and LED (with a jumper wire
connect the long leg of the LED to the
anode, and the short leg of the LED to
the ground) from the Arduino board to
the breadboard as shown in this picture.

Once you are done connecting


them, now connect your
Arduino to the computer using
the USB cable. Now press the
push button to switch on the
LED . I the LED lights up then
you have successfully built your
first circuit.
Congratulations

35
Building a simple circuit

Once again do not forget to


unplug the Arduino board from
the computer before making
any changes to the breadboard

Series circuit
- Components in SERIES come one after another

To build this remove your power source, add a with next to the one already on
your breadboard. Wire them together in series as shown below. Connect the
LED cathode to ground, Power up the Arduino again. Now turn on the LED,
you will need to press both switches. Since these are in series, they both
need to be closed for circuit to be completed.

After successfully building


your first circuit. Now you
will learn the differences
between the two types of
circuit you can build. Which
are series circuit and a
parallel circuit.

36
Building a simple circuit

Parallel Circuit
- Component in PARALLEL run side by side
To wire up switches in parallel, keep the
switches and LED where they are, but
remove the connection between the two
switches. Wire both switches to resistor.
Attach the other end of both switches to
the LED, as shown in the diagram on the
right hand side. Now when you press
any of the buttons, the circuit is completed
and the light turns on.

Let me check the


Ayomide what am I going to do ?
next step

OK
What next.. Lolia push the button
if the LED will light up

We have now
gotten to the
end of our
project. During
this project

You have learned about the


basic electrical theory, that is,
properties of voltage, current
and resistance while building a
very simple circuit on a breadboard. With basic components like led, resistor and switches,
you have created the simplest interactive system where the user presses the button in order
to switch on the light. these fundamental knowledge of working with electronics will be built
upon in the following project. in the next project will be building a spaceship interface so you
can explore and discover the galaxy. see you then.

37
Practice Question

How do you give instructions on


what the Arduino should do in an IDE?
answer choices
Editor
Sketches
Console
IDE error

38
GreenLab
Cartooino

Episode 3
Understanding
the program
interface

39
Understanding the Program structure

Yes we have a lot to do today.


Uncle green What
Do you still remember how to
are we doing today setup the Arduino IDE?

Yes,Ayomide said you told


him we will build a robot
today
Yes you have to
download it Nice having a good memory
first will help in today’s project

An electronic circuit is composed


of individual elctronic components,
#TIP suchas resistors, transistors, capacitors
inductors and diodes connected by
conductive wires or traces through

40
Understanding the Program structure

Today I would like you understand the Is it how to use the


program interface and structure Arduino IDE

Uncle you would


also teach us how
to enter the code.

Now kids very soon you will visit the


YouNiversity and so you need a laptop
or phone with internet access.

My Mother has a laptop


at home so I can practice

You see, without all these information,


you will not be able to build your awesome
toys and other prototypes properly.

hmmmm!

41
Understanding the Program structure

Unsigned int
Unsigned ints (unsigned integers) are the same as int in the way that
they store a 2 byte value. Instead of storing negative numbers, however, they
only store positive values, yielding a useful range of 0 to 65,535(2^16)-1). The
Due stores a 4 byte (32 bit) value, ranging from 0 to 4,294,967,295(2^32-1).
example

Unsigned int counter = 60 ; // declaration of variable with type unsigned


int and initialize it with 60
Word
On the Uno and other ATMEGA based boards, a word stores a 16-bit
unsigned number. On the Due and Zero, it stores a 32-bit unsigned
number.
Example
word w = 1000 ;//declaration of variable with type word and initialize
it with 1000
Long
Long variables are extended size variables for number storage, and
store 32 bit (4 bytes), from - 2,147,483,647.
Example
Long Velocity = 102346 ;//declaration of variable with type long and
initialize it with 102346
Unsigned long
Unsigned long variables are extended size variables for number storage
and store 32 bits (4 bytes). Unlike standard longs, unsigned longs will
not store negative numbers, making their range from 0 to 4,294,967,295
(2^32-1).
Example
Unsigned long Velocity = 101006 ;// declaration of variable with
type Unsigned Long and intialize it with 101006
short
A short is a 16-bit data-type. On all Arduinos (ATMega and ARM based),
a short stores a 16-bit(2-byte) value. This yields a range 0f -32,768 to
32,767(minimum value of -2^15 and a maximum value of (2^15)-1).
Example
short val = 13 ;//declaration of variable with type short and initialize it
with 13

42
Understanding the Program structure

Char
A data type that takes up one byte of memory that stores a character value.
Character literals are written in single quotes like this ‘A’ and for multiple
characters , strings use double quotes: “ABC”. However, character are
stored as numbers. You can see the specific encoding in the ASCII chart.
This means that is possible to do arithemic operations on characters, in
which the ASCII value of the character is used. For example, ‘A’ +1 has
the value 66, since the ASCII value of the capital letter A is 65.
Example
Char chr _a = ‘a’ ://declaration of variable with type char and initialize it
with character a
Char chr_c = 97://declaration of variable with type char and initialize it
with characecter

Unsigned char
Unsigned char is an unsigned data type that occupies one byte of memory.
The unsigned char data type encodes numbers from 0 to 255.
Example
Unisigned Char chr _y = 121://decalaration of values with type Unsigned char
and initialize it with character y

Byte
A byte stores an 8-bit unsigned number from 0 to 255.
Example
Byte m=25;//declaration of variab;e with type byte and inialize it with 25

int
Intergers are the primary data-type for number storage int stores a 16-bit
(2-byte) value. This yields a range of -32,768 to 3,767(minimum value
of -2^15 and a minimum. value of (2^15)-1):
The int size varies from board to board. On the Arduino Due, for example,
an int stores a 32-bit(4-byte)value. This yields a range of -2,147,483,648 to
2,147,483,647 (minimum value of -2^31 and a maximum value of (2^31)-1).
Example
int counter =32 ;//declaration of variable with type int and initialize it with 32.

43
Understanding the Program structure
Operators
An Operator is symbol that tells the compiler to perform specific
mathematical or logical functions. The following are the types
of operators.
Arithmetic Operators
Assume variable A holds 10 and variable B holds holds 20 then-
Example
void loop () {
int a = 9,b = 4,c;
c = a + b;
c = a - b;
c = a * b;
c = a / b;
c = a % b;
}
Result

a + b = 13
a - b= 5
a * b = 36
a/b=2
Remainder when a divided by = 1

operator Operator Description Example


name Symbol

assignment Stores the value to the right of the


= sign in the variable to the left of A=B
operator
the equal sign.
A + B will
addition + Adds two operands
give 30

A - B will
subtraction - Subtracts second operand from
give -10
the first

% A * B will
multiplication Multiply both operands
give 200

B / A will
division / Divide numerator by denominator
an integer division give 2

modulo Modulus Operator and remainder B % A will


%
of after an integer division give 0

Comparison Operators
Operator table

44
Understanding the Program structure

operator Operator Description Example


name Symbol

equal Checks if the value of two operand


= is equal or not, if yes then (A == B) is
to not true
condition becomes true.
Checks if the value of two operand
not != is equal or not, if values are not equal (A != B) is
equal to then condition becomes true. true
condition becomes true.
Checks if the value of left operand (A < B) is
less than < is less than the value of right true
operand,- if yes then condition
becomes true
greater Checks if the value of left operand (A > B) is
>
than is greater than the value of right not true
operand, if yes then condition
becomes true
less than or Checks if the value of left operand (A <= B) is
<=
equals to is less than or equal to the true
value of right operand, if yes then
condition becomes true
greater than Checks if the value of left operand (A >= B) is
>= is greater than or equal to the
or equals to not true
value of right operand, if yes then
condition becomes true

operator Operator Description Example


name Symbol

equal Checks if the value of two operand


= is equal or not, if yes then (A == B) is
to not true
condition becomes true.
Checks if the value of two operand
not != is equal or not, if values are not equal (A != B) is
equal to then condition becomes true. true
condition becomes true.
Checks if the value of left operand
less than < is less than the value of right (A < B) is
- if yes then condition
operand, true
becomes true
greater Checks if the value of left operand
> (A > B) is
than is greater than the value of right
operand, if yes then condition not true
becomes true
less than or <= Checks if the value of left operand
(A <= B) is
equals to is less than or equal to the
true
value of right operand, if yes then
condition becomes true
greater than Checks if the value of left operand
>= is greater than or equal to the (A >= B) is
or equals to
value of right operand, if yes then not true
condition becomes true

45
Understanding the Program structure
Bitwise Operators
Assume variable A holds 60 and variable B holds 13 then-
operator Operator Description Example
name Symbol

(A & B) will give


& Binary AND operator copies a bit to the 12 which is 0000
and result if it exists in both operands 1100

(A l B) will give
Binary OR Operator copies a bit if it
or l exists in either operand
61 which is 0011
1101

(A ^ B) will give
Binary XOR Operator copies the bit if is
xor ^ 49 which is 0011
set in one operand but not both.
0001

Binary Ones Complement Operator is (~A) will give -60


not ~ which is 1100
unary and has the effect of ‘flipping’
bits. 0011

Binary Left Shift Operator. The left A << 2 will give


shift left << operands value is moved left by the 240 which is 1111
number of bits specified by the right 0000
operand.

Binary Right Shift Operator. The left A >> 2 will give


operands value is moved right by the 15 which is 0000
shift left >>
number of bits specified by the right 1111
operand.

Example
void loop(){ Result
int a =10, b = 20; c=12
int c = 0; c=61
c = a & b; c=49
c = a l b; c=-60
c = a ^ b; c=240
c = a ~ b; c=15 Example
void loop(){ Result
c = a << b; int a =10, b = 20; c=12
c = a >> b; int c = 0; c=61
c = a & b; c=49
} c = a l b; c=-60
c = a ^ b; c=240
c = a ~ b; c=15
c = a << b;
c = a >> b;
}

46
Understanding the Program structure

What is a variable a scope?

Variable in Arduino has a property called scope. A scope is a region of the


program and there are three places where variables can be declared. They are -

# inside a function or a block, whixh is called LOCAL VARIABLES.


# Inside the definition of function parameters, which is called FORMAL PARAMETERS.
# Outside of all functions, which is called GLOBAL VARIABLES.

Local Variables
These are variables that are declared inside a function or block. They can be used only by
the statement that are inside that function or block of code. Local variable are known to
function outside their own. Following is the example using local variables -

Void setup(){
}
Void loop(){
int x, y ;
int z ; Local variable declaration
x = 0;
y = 0; actual initialization
z = 10;
}

Global varibles
These variabls are defined outside of all the functions, usually at the top of the
program. The global variable will hold their value throughout life-time of your program.
A global variable can be accessed by any information. That is, a global variable is
available for use throughout your entire program after its declaration.

The following examples uses global and local variables-


int T , S ;

float c = 0 ; Global variable declaration

Void setup(){

}
Void loop(){
float c = 0 ; Global variable declaration
int x, y ; Void setup(){
int z ; Local variable declaration
}
x = 0; Void loop(){
y = 0; actual initialization int x, y ;
int z ; Local variable declaration
z = 10; x = 0;
} y = 0; actual initialization
z = 10;
}

47
Understanding the Program structure

When input the comparison


operator take note the of
curly and normal brackets
as they affect you code.

{} ()

48
Understanding the Program structure

Boolean Operators
Assume variable A holds 10 and variable B holds 20 then-

Operator Operator Description Example


name symbol

Called Logical AND operator. If both the


and && (A-&& B) is
operands are non-zero then then condition
true
becomes true
Called Logical OR operator .If any of the two (A II B) is
or ll operands is non-zero then then condition true
becomes true.
Called Logical NOT Operator. Use to reverses
the logical state of operand. If a condition is !(A II B) is
not !
true then Logical NOT operator will make false.false

Example
void loop(){
int a=9,b=4
bool c=false,
if((a > b)&& (b > a))

c= true;
else
c= false;

if((a== b)l l (b < a))


c= true;
else
c= false;

if( !(a == b)&&(b < a))


c= true;
else
c=fasle;
if( !(a == b)&&(b < a))
}
c= true;
Result else
c=fasle;
c=true }
Result
c= true
c= true c=true
c= true
c= true

49
Understanding the Program structure

Compound Operators
Assume variable A holds 10 and variable B holds 20 then-

Operator Operator Description Example


name symbol

increment operator, increases


increment ++ integer value by one A- - will give 9

Decrement operator, decreases A- - will give 9


decrement –
integer value by one

Add AND assignment operator. It B +=A is


compound adds right operand to the left
+= equivalent to B =
addition operand and assign the result to left B+ A
operand
Subtract AND assignment operator. It B*=A is
compound ++ subtracts the right operand from the equivalent to B =
subtraction left operand and assign the result to B* A
the left operand.

Multiply AND assignment operator. It


B*=A is
compound multiples right operand with the left
*= equivalent to B =
multiplication operand and assign the result to the
B* A
left operand.

Divide AND assignment operator. it B/=A is


compound divides left operand with the right
/= equivalent to B =
division operand and assign the result to the B/ A
left operand
Modulus AND assignment operator. B %=A is
compound
%= it takes modulus using two operands equivalent to B =
modulo
and assign the result to the left B %A
operand
compound bitwise inclusive OR and assignment A I=2 is same as
I= operator A=AI2
bitwise or

compound A &=2 is same as


bitwise and &= Bitwise AND assignment operator
A=A&2

50
Understanding the Program structure
Example
void loop(){
int a= 10, =20

int c= 0; Booleans
a++;
a--;
b += a;
b -= a;
b*= a;
b /= a;
a %= b;
a l= b;
a &= b;
}
Result

a + 11
a=9
b=30
b=10
b=200
b=2
a=0
a=61
a=12

51
Understanding the Program structure

S/NO.

Control Statement & Description.

1. If statement
It takes an expression in parenthesis and a statement or block of statements. If the
expression is true then the statement or block of statemnt gets executed otherwies.
these statement are skipped.
2. If ...else statement
An if statement can be followed by an optional else statement, which executes
when the expression is false

3. If ...else if ...else statement

The if staement can be followed by an optional else if..else statement, which


is very useful to test various conditions using single if...else if statement.

4. switch case statement


Similar to the if statments, switch...case controls the flow of progress by allowing the
programmers to specify different codes that should be executed in verious conditions.

5.
Conditional Operator ?:

The conditional operator ?: is the only ternary operator in C.

Control Statement & Description.

If statement
It takes an expression in parenthesis and a statement or block of statements. If the
expression is true then the statement or block of statemnt gets executed otherwies.
these statement are skipped.

If ...else statement
An if statement can be followed by an optional else statement, which executes
when the expression is false

If ...else if ...else statement

The if staement can be followed by an optional else if..else statement, which


is very useful to test various conditions using single if...else if statement.

switch case statement


Similar to the if statments, switch...case controls the flow of progress by allowing the
programmers to specify different codes that should be executed in verious conditions.

Conditional Operator ?:

The conditional operator ?: is the only ternary operator in C.

52
Understanding the Program structure

Finally you will need


access to the internet
will at home to practice

#TAG
RESISTANCE (R)
IS A MATERIAL’S
OPPOSITION TO
THE FLOW OF
ELECTRIC CURRENT.
IT IS MEASURED My Elder brother has a laptop
IN OHMS. I will use it

So you could invite your


friends to come learn with you

Servo Motor is an electrical device


that can push or rotate an object with
great precision.

When
When we meet
we meet nextnext
time we would build a
we would
spaceship be building
interface, and see how it works.
a spaceship interface

Hurray thank you uncle

53
s 4
paceship interface

54
Spaceship Interface

A spaceship is a craft, vehicle


vessel or machine designed to take
humans or things deep into the sky.
just like the one here.

So in today’s class, we will learn how to build


Uncle yesterday you said we will
build a spaceship interface today. an interface to send signals deep into the galaxy.
But what is a spaceship?

The connection diagram here


shows how you will build and
connect the circuit from the
Arduino
board to the bread board.

Arduino Uno is an open source


micro-controller board based
on the microchip ATmega328P
micro-controller and developed
by Arduino.cc.
It has digital and analog input &
output pins that may be linked
with various other circuits.

In this class, you will learn about digital


input and output, write your first code,
and also about variables.

To complete this project, you will need one


switch, two red LEDs and one green LED, with
three 220ohms and 10kilo-ohms resistor.
Lastly , you will need at least 45minutes
to complete this task.

55
Spaceship Interface

GreenLab
Microfactory This is going to be our
virtual lab where major
project will be carried out

This place looks


Arduino
Toolkits like Dexter
Here lab in Cartoon
Uncle please show
network us round

Some of our activities


will involve us stopping evil
villians with Arduino
We will make use
of a candance

what is a candence

It is a watch like
device that allows
change into your
What is a candence superhero outfits

Oh

56
Spaceship Interface
kids you will learn in this project how to to control things
with your Arduino. You will be making a control panel with a universal
switch and light that would be used to stop General ZOD With this
interface a green LED will be on until you press a button.
When the Ardiuno gets the signal from the button the
green light will turn off and two
others will start blinking this should
disable his plans
General ZOD
is evil inventor
that creates
mind freak robots.
His latest invention
I s set to hit lagos.
Who is general ZOD we have to stop his
plan.

The Arduino digital pins can read only two states: when there is voltage on an input pin and
when there’s not. This kind of input is normally called digital(or sometimes binary, for two-
stats). These states are commonly referred to as HIGH and LOW. HIGH is the same as saying
“there is voltage here!” and LOW means “there is no voltage on this pin!”. When you turn an
OUTPUT pin HIGH using a command called digitalWrite(). you are turning it on. Measure the
voltage between the pin and the ground, you will get 5 volts. When you turn an OUTPUT pin
LOW, you are turning it off. The Arduino’s digital pins can act as both inputs and outputs. In
your code, you will configure them depending on what you want their function to be. When the
pins are output, you can turn on components like LEDS, if you configure the pins as inputs,
you can check if a switch is being pressed or not. Since pins 0 and 1 are used for
communicating with the computer, it is best to start with pin2.
To proceed, follow the connection diagram above, wire up your breadboard to the Arduino’s
5V and ground (GND) connections, just like the previous project. Place the two red LEDs and
one green LED on the breadboard. Attach the cathode (short leg) of each LED to ground
through a 220-ohm resistor. Connect the annode (long leg) of the green LED to pin 3. Connect
the red LEDs’ anodes to pin 4 and 5, respectively.
Place the switch on the breadboard just as you did in the previous project. Attach one side to
power, and the other side to digital pin 2 on the Arduino. You will also need to add a 10k-ohm
resistor from ground to the switch pin that connect to the Arduino. That pull down resistor
connects the pin to ground when the switch is open, so it reads LOW when there is no voltage
coming in through the switch.

Who’s in for some


adventure

Yeah!!
57
Spaceship Interface

For you to be able to control things with your


Arduino you will need to write some codes to
instruct the Arduino. Below, we will be talking
about how to write the “codes”.

Understanding the code


The source code in Arduino is called “Sketch”
Arduino programs can be divided in three main part:
Structure, Values (variables and constants) and
Functions. In tutorial, we will learn about the
Arduino software program, step by step and how
we can write the program without any syntax or
compilation error.
Lets start with the Structure. Software structure
consist of two main functions:-
-Setup( ) function
-Loop( ) function

58
Spaceship Interface
Lets look carefully at
the codes

59
Spaceship Interface

My name I will control


is General All Lagos
with my AI
ZOD!!

NOT even the


government
can stop me

Check if GreenLab
Launching Codes is on to us

Set our perimetre to


25

#TIP
Capacitor is a device used to
store electric charge, consisting
of one or more pairs of
conductors separated by an
insulator

60
Spaceship Interface
Meanwhile...
Let check our space interface
code, shall we?...
Divine you are welcome

Ayomide has told a lot about


Yes you
uncle

61
Spaceship Interface

its almost
time kids

Dress Room Ayomide Do


not forget
to push
the button

Kids change into your hero outfits


62
Spaceship Interface

Destroy

terminant

Lets show

them who’s
boss

63
Spaceship Interface

Be
careful

Push the
button

Ok

WINNER

64
#TIP

How to use a Breadboard


You already used the breadboard but we totally forgot to talk about it. We can use a
breadboard
(protoboard) to connect electrical components. Inside the breadboard are metal clamps.
Since metal conducts electricity, components in the same clamps are connected. In that
illustration
you can see which holes of a breadboard are connected internally.
Do you see that the resistor sticks with one leg in the same column like the green LED?
That is the point where they are connected.
Expert Knowledge: Conductors and Insulators

Why does the metal clamps make a connection, but not the plastic of the breadboard?
There are electrical conducting materials. They are called conductors. Metalls, for instance
silver, copper or aluminium are very good conductors. They conduct, because they’ve got so
called freely moving electrons. This is actually what current consists of.
Materials without the ability of conducting electricity are called insulators. Plastic, ceramic
and glas belonging to the group of insulators. Maybe you’ve already seen the large insulators
on high-tension power lines? They hold the cables to the high-voltage poles. Usually they are
made of ceramic.

65
Episode 05- GreenLab
Your Rights to Innovat Welcome to YouNiversity Cartooino
Your Rights to Innovate

YouNiversity

66
Welcome to YouNiversity

Guys welcome to YouNiversity,


You have the following task
- Goto You tube
-Find an Arduino project
-Follow how it was built and build it
-Then present your project to your friends
explaning to them why you selected the project
,what you have learnt, and how others can learn
from the project.

67
M O N D AY

Guys I made simple circuit How did you do that?

Ayomide teach us Come to my house


tomorrow Oh yes!
how to make toys

TIP
What is AI
The full meaning of AI is
Artificial Intelligence

68
GreenLab
Cartooino

EPISODE 6 -
Colour mixing lamp

69
Colour mixing lamp
Uncle Green how Hello kids, welcome back from
was your day? YouNiversity! Aliya what did you learn?

I could not finish That is ok today we will


the YouTube videos create a lamp that changes
colour depending on the
I slept off
room lighting conditions.
Shine red and blue light on a
set of three light sensors,
and the LED will turn purple!
This project uses three
analog inputs and you will
watch data from the sensor
in the “serial monitor”

Ayo we want to create You will need the


Disco light following components
for this project:

1.One RBG LED


2.three 220ohms resistors
3.three 10kilo-ohms resistors
4.three photoresistors
and at least 45minutes of
work time. Using a tri-color
LED and three photo-resistors,
you will be creating a lamp
that smoothly changes colors
depending on external
lighting conditions. So if you
are ready, connect your
components as shown in
the image

70
Colour mixing lamp
Please note that the RGB LED you
will use for this project has four
pins instead of two pins LED you
have been using before

LEDs

#TIP
LED(Light emitting diode) is a semi conductor device that emits light when
an electric current is passed through it. Light is produced when the particles
that carry the current known as electrons and holes combine together within
the semiconductor material.
71
Colour mixing lamp
Yes Aliya if carefully written

So uncle
will the
Arduino
tell the
lamp what
colour to
display?

72
Colour mixing lamp

Connecting your
Arduino Board to
your IDE

We have now come to the end of today’s project.


Uncle when can we Lolia why are you coming now?
practice on our own.
By next week I
will introduce
Yeah I went you to my very
to the good friend
market with Daniel
He will help us
my mum. with some of
our projects.

Ayomide we have to worked Since today is Friday I will give you kids a
together quick assignment

Ok then

73
A rear picture of kids doing their project

Cartooino
Book 2

74
Cartooino
Project
Book
2020
Thank You

GreenLab
Cartooino

You might also like