Arduino Book + Projects
Arduino Book + Projects
Arduino Book + Projects
what is arduino?
Arduino is an open-source electronics platform. You can use it
to create interactive electronic projects, robots, and other
devices that you can control using a computer.
installation
what is arduino ide?
Arduino IDE is a software that allows users to write, upload
and run code on Arduino boards. It is a simple program that
helps users write code in the Arduino programming language
and upload it to the board. There is a text editor and a tool for
uploading the code. It also includes pre-written code called
sketches to control various functions of the Arduino hardware.
hardware
arduino uno
The Arduino UNO (microcontroller board) is one of the most
widely used and easily accessible boards among the Arduino
family, making it a popular choice for beginners and hobbyists
to start building projects with.
vcc
“VCC" stands for Voltage Common Collector, it is the voltage
source that provides power to the microcontroller.
gnd
"GND" stands for Ground. It is a reference voltage or a
common return path for electrical current.
5v
"5V" is the output voltage of the onboard voltage regulator,
which is used to power the microcontroller and other
components on the board.
usb cable
"USB" is the Universal Serial Bus port, which is used to
connect the board to a computer for programming and power
supply.
breadboard
A breadboard allows you to easily connect electronic
components together without the need for soldering.
servo
Servo motors are great devices that can turn to a specified
position.
led
An LED (light-emitting diode) is a small light source that can
be used as an indicator or visual output.
buzzer
A Buzzer is basically a beeper (emits sound).
jumper wires
Jumper wires are used for making connections between items
on the breadboard and Arduino board header pins.
resistors
Resistors are to limit the current flowing through a circuit and
protect other components from damage.
sensors
Sensors are electronic devices that are used to measure
various physical properties, such as temperature, light, sound,
etc.
code
fundamental structure
There are two required functions in an Arduino sketch,
setup() and loop(). Other functions must be created outside
the brackets of those two functions.
setup()
It is the first function to run in the program is the setup ()
function, which is run one time, and is used to set pinMode or
initialize serial communication.
It must be included in a program even if there is no code to
run.
loop()
After calling the setup() function, the loop() function loops
consecutively, allowing the program to change, respond and
control the Arduino board – reading inputs, triggering outputs,
etc.
This function is the core of all Arduino programs and does the
bulk of the work.
further syntax
{ } curly braces
An opening curly brace { must always be followed by a closing
curly brace } If not followed would leave an error.
; semicolon
A semicolon must be used to end a statement and separate
elements of the program.
comments
Comments are ignored by the program and take no memory
space.
// line comments
Single-line comments begin with // and end with the next line
of code.
operator structure
arithmetic operators
% (remainder or modulus)
* (multiplication)
+ (addition)
- (subtraction)
/ (division)
= (assignment operator)
comparison operators
!= (not equal to)
< (less than)
<= (less than or equal to)
== (equal to)
> (greater than)
>= (greater than or equal to)
compound operators
++ (increment)
-- (decrement)
+= (compound addition)
-= (compound subtraction)
*= (compound multiplication)
/= (compound division)
boolean operators
! (logical not)
&& (logical and)
|| (logical or)
control structure
control flow
if
The if statement checks for a condition and executes the
following statement or set of statements if the condition is
'true'. If not, the program skips over them and continues on
after the brackets.
if… else
An else statement will be executed if the condition in the if
statement results in false.
fundamental variables
variables
A variable is a way of naming and storing a numerical value
for later use by the program.
variable declaration
All variables have to be declared before they can be used.
Declaring a variable means defining its value type, as in int,
long, float, etc., setting a specified name, and optionally
assigning an initial value. This only needs to be done once in
a program but we can change the value at any time using
arithmetic and various assignments.
other variables
datatypes
byte
Byte stores an 8-Bit numerical value without decimal points.
They have a range of 0-255.
int
Integers are the primary data type for the storage of numbers
without decimal points, with a range of 32,767 to -32,768.
long
The extended size data type for long integers, without decimal
points with a range of 2,147,483,647 to -2,147,483,648
float
A data type for floating-point numbers, a number that has a
decimal point. Floating-point numbers are often used to
approximate analog and continuous values because they
have greater resolution than integers. Floating-point numbers
can be as large as 3.4028235E+38 and as low as
-3.4028235E+38.
arrays
An array is a collection of values that are accessed with an
index number.
Any value in the array may be called upon by calling the name
of the array and the index number of the value. Arrays are
zero-indexed, with the first value in the array
beginning at index number 0. An array needs to be declared
and optionally assigned values before they can be used.
bool
A bool holds one of two values, true or false.
constants
The Arduino language has a few predefined values, which are
called constants. They are used to make the programs easier
to read. Constants are classified into groups.
true/false
These are Boolean constants that define logic levels. FALSE
is easily defined as 0 (zero) while TRUE is often defined as 1,
but can also be anything else except zero. So in a Boolean
sense, -1, 2, and -200 are all also defined as TRUE.
high/low
analog-digital functions
digital i/o
pinMode(pin, mode)
pinMode(pin, mode)
digitalRead(pin)
Reads the value from a specified digital pin with the result
either HIGH or LOW. The pin can be specified as either a
variable or constant (0-13).
digitalRead(pin)
digitalWrite(pin, value)
digitalWrite(pin, value);
analogWrite(pin, value)
analogWrite(pin, value)
pin: the Arduino pin to write to. Allowed data types: int.
value: the duty cycle: between 0 (always off) and 255 (always
on). Allowed data types: int.
other functions
math
max()
Calculates the minimum of two numbers of any data type and
returns the smaller number.
min()
Calculates the maximum of two numbers of any data type and
returns the larger number.
time
delay()
Pauses a program for the amount of time as specified in
milliseconds, where 1000 equals 1 second.
millis()
Returns the number of milliseconds since the Arduino board
began running the current program as an unsigned long
value.
serial
serialprintln()
serial.begin()
Opens serial port and sets the baud rate for serial data
transmission. The typical baud rate for communicating with
the computer is 9600 although other speeds are supported.
projects
beginner...
automatic social
distancing protocol
components and supplies
fritzing diagram
code of the project
advanced...
remote controlled
pet-feeder
components and supplies
Arduino Uno (x1)
Breadboard (x1)
SG-90 Micro-Servo Motor (x1)
IR Reciever Generic (x1)
IR Remote (x1)
Male/Male Jumper Wires (x1)
preparation steps
Installing the IR Library:
The first thing we need to do to associate with Arduino is to
download the IR library.
Decoding IR Signals:
First, you need to connect the parts as per the given circuit
diagram:
Use the following code to decode the IR remote:
fritzing diagram
code of the project
application
why is learning arduino an important life
skill