Arduino Book + Projects

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

introduction

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.

what is arduino hardware?


The Arduino board contains the microcontroller and various
input/output devices, like sensors, actuators, and other
electronic components, can connect to the board.

what is arduino software?


Arduino software refers to the set of tools used to program
and control the Arduino hardware. This includes the Arduino
programming language and the Arduino IDE.

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.

The IDE is available for Windows, MacOS, and they can


download Linux and for free from the official Arduino website.

how to install it?


1. Download the latest version of the Arduino IDE from
the official Arduino website.

2. Open the downloaded file and run the installer.


3. Follow the instructions on the screen to complete the
installation process.
4. Once the installation is complete, open the Arduino
IDE.
5. Connect your Arduino board to your computer using a
USB cable.
6. Select the correct board and serial port in the Arduino
IDE.
7. Verify the sketch, this will check the code for any
errors.
8. Click on the upload button, this will upload the sketch
to the Arduino board.

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.

/*…*/ block comments


Block comments, or multi-line comments begin with /* and
end with */ and can span multiple lines.

// 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.

Else can also precede another if test, so multiple, mutually


exclusive tests can be run simultaneously, through the else if
statement. It is even possible to have an unlimited number of
these branches.
for
The for statement is used to repeat a block of statements.
Mostly used for repetitive operations.

Initialization: happens first and exactly once.

Condition: each time through the loop, the condition is tested;


if it’s true, the statement block and the increment are
executed. When the condition becomes false, the loop ends.

Increment: executed each time through the loop when the


condition is true.
while
A while loop will loop continuously, and infinitely until the
expression inside the parenthesis, () becomes false.
Something must change the tested variable, or the while loop
will never exit.

Condition: a boolean expression (true or 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

These constants define pin levels as HIGH or LOW and are


used when reading or writing to digital pins. HIGH is defined
as logic level 1, ON, or 5 volts while LOW is logic level 0,
OFF, or 0 volts.
input/output
Constants are used with the pinMode() function to define the
mode of a digital pin as either INPUT or OUTPUT.

analog-digital functions
digital i/o
pinMode(pin, mode)

pinMode(pin, mode)

pin: the Arduino pin number to set the mode of.

mode: INPUT, OUTPUT.

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)

pin: the Arduino pin number you want to read

Reads the value from a specified digital pin, either HIGH or


LOW.

digitalWrite(pin, value)

Outputs either logic level HIGH or LOW at (turns on or off) a


specified digital pin. The pin can be specified as either a
variable or constant (0-13).

digitalWrite(pin, value);

pin: the Arduino pin number.


value: HIGH or LOW.
analog i/o
analogRead(pin)
Reads the value from a specified analog pin with a 10-bit
resolution. This function only works on the analog in pins
(0-5). The resulting integer values range from 0 to 1023.

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()

Prints data to the serial port, followed by an automatic


carriage return and line feed. This command takes the same
form as Serial.print(), but is easier for reading data on the
Serial Monitor.

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

Arduino Uno (x1)


5 mm LED: Red (x1)
Buzzer (x1)
Ultrasonic Sensor (x1)

apps and online services

Arduino IDE (∞)

about the project


This project is a social distancing alarm using Arduino.

how does the project work


Ultrasonic sensors send waves. These waves are absolutely
invisible and come back after hitting an optical. When the
desired distance is hit, the LED and Buzzer would work.
fritzing diagram

code of the project


intermediate...
smoke detection system
components and supplies
Arduino Uno (x1)
Breadboard (x1)
MQ-2 Smoke detection sensor (x1)
Male/Male Jumper Wires (x6)
5 mm LED: Red (x1)
5 mm LED: Green (x1)
Buzzer (x1)
Resistor 221 Ohm (x3)

apps and online services


Arduino IDE (∞)

about the project


The MQ-2 smoke sensor is sensitive to smoke and to
flammable gases: LPG, Butane, Propane, Methane, Alcohol,
and Hydrogen.
The smoke sensor has a built-in potentiometer that allows you
to adjust the sensor's digital output threshold. If a threshold
passes a certain value, it buzzes.

how does the project work


The voltage that the sensor outputs changes according to the
smoke/gas level that exists in the atmosphere? The sensor
outputs a voltage that is proportional to the concentration of
smoke/gas.

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)

necessary tools and machines


Hot Glue Gun (x1)
Scissors (x1)
Plastic Bottle (x1)
Cardboard (x1)

apps and online services


Arduino IDE (∞)
about the project
This project is a remote controlled pet-feeder where

how does the project work


With this Arduino project, your pet can be fed using a remote
control. Through an IR receiver, remote control, and arduino
board.

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:

● Open Arduino IDE and Upload the code


● Open Serial Monitor
● Aim your remote at the sensor and press each button
● You can see different numbers for each button

fritzing diagram
code of the project
application
why is learning arduino an important life
skill

Learning Arduino can be considered an important life skill


because it provides hands-on experience with electronics and
programming, which can help individuals develop valuable
technical skills and problem-solving abilities. It introduces the
basics of microcontroller programming and physical
computing, allowing individuals to create interactive and
automated devices. Arduino is a widely used platform for
prototyping and building IoT (Internet of Things) devices,
becoming increasingly common in personal and professional
settings. By learning Arduino, individuals can gain a deeper
understanding of how technology works and how it can be
used to solve real-world problems. This knowledge and
experience can be useful in many fields, including
engineering, design, and computer science, making it a
valuable life skill to have.
why should you use arduino?
There are several reasons why you might choose to use
Arduino such as its Ease of use, Low cost, Open source,
Wide community, Versatility, and Interoperability.

how can it help in the future?

Arduino has the potential to play a significant role in shaping


the future of technology in several ways:

Internet of Things (IoT): As the IoT continues to grow and


expand, Arduino is likely to play an increasingly important role
in connecting and controlling devices and systems.

Artificial Intelligence (AI) and Machine Learning: Arduino


boards can be used to develop and test AI and machine
learning algorithms, providing a platform for innovation in
these fields.

Robotics and Automation: As robotics and automation


become increasingly integrated into society, Arduino is likely
to play a role in the development and control of these
systems.

Education: Arduino is well-established as an educational tool,


and its continued use in schools and universities is likely to
ensure that future generations are equipped with the skills
and knowledge needed to shape the future.
Sustainable Technology: Arduino can be used to develop and
test sustainable technology solutions, such as energy-efficient
devices and renewable energy systems.

Medical Applications: Arduino has the potential to be used in


the development of medical devices and systems, such as
wearable health monitors and home-based medical systems.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy