Arduino ZERO To HERO - 30+ Arduino Projects Learn by Doing - Arsath Natheem S - 2021 - Anna's Archive
Arduino ZERO To HERO - 30+ Arduino Projects Learn by Doing - Arsath Natheem S - 2021 - Anna's Archive
ZERO TO HERO
FAST TRACK YOUR LEARNING
(New Edition)
ARSATH NATHEEM S
Copyright © 2021-2022 by ARSATH NATHEEM S
All rights Reserved.
Imprint: Independently published
Author Name: Arsath Natheem S
2022 Edition
This Arduino Project book is geared towards given that exact and reliable
data in respects to the subject and issue covered. The publication is marketed
with the concept that the publisher is not necessary to render or else, any
qualified services.
In no way is it valid to reproduce, duplicate, or spread any part of this book in
either digital e-format, eBook means or in printed format. Make a Re-
documenting of this text book is strictly prohibited and any storage of this
manuscript is not allowed except with written approval from the publisher.
All rights reserved.
Respective authors own all rights not held by the publisher. The attributes
that are used are without any consent, and the book of the trademark is
without permission or backing by the brand owner. All trademarks and
brands within this book are for descriptive purposes only and are the owned
by the owners themselves, not associated with this textbook.
When we think about the word ‘Education’, we often think of the formal
schooling that happens in primary, secondary and high schools and colleges.
Although, this is not the only way of education, tacit and practical knowledge
is something that we often can’t learn by reading books; it is achieved by
addressing real world problems and practice, it relates to experience,
intuition, ideals, creative thinking, emotions, values, skills and attitudes.
Arduino Education makes the next generation of STEAM programs and tacit
knowledge that empower schoolchildren on their creative learning journey
through secondary school, high school, and university and help them succeed.
This Arduino Project book will help you learn all about making projects with
Arduino, and beneficial for novice to expert level students, and research
scholars. This handbook is written for those who is enthusiastic in innovative
projects with the help of open source tools and technique, and it is a huge
collection of ideas to do some creative projects, to create something new to
society, This book consists of six chapters starting from Arduino basics,
electronic components, Arduino boards and their sensors, to getting started
with Arduino programming, then you can practice 33 step by step projects by
doing, and the book ends with more than 100 fascinating project-ideas and
finally Troubleshooting Arduino. I believe this Arduino handbook will be
helpful for students and research scholars for their mini projects. Also
includes operative basics in case of open-source electronics, for college,
school students and hobbyists to learn Arduino from the basic to expert level
through practical schematic diagrams. I hope this would be a wonderful
project guide for science fair projects and their new innovative works.
TABLE OF CONTENTS
ARDUINO: EVERYONE NEED TO KNOW
Introduction
Microcontroller
Development Board
What is the Arduino?
Why Was Arduino Developed?
What can Arduino be used to Teach?
DIFFERENT TYPES OF ARDUINOS
Why use Arduino UNO?
GETTING STARTED WITH ARDUINO
Installing Arduino IDE with Arduino Uno R3 board
Arduino Libraries
How to add library files
Hello World of Arduino (Blink an LED):
Basic Arduino C functions:
Uploading the Sketches
Arduino Q & A Section
Summary
CHAPTER 2:
BASIC ELECTRONIC COMPONENTS
Resistors
Capacitors
Inductors
Transformer
Diode
Light emitting diode (LED)
Variable resistor (Potentiometer)
Transistors
Integrated circuit (IC)
IC Terminology: Op-amp
H-bridge
Printed Circuit Board (PCB)
WHAT ARE SOME GOOD COMPONENTS TO START WITH?
LED (Light Emitting Diode)
LCD (Liquid Crystal Display)
DC Motor
Servo Motor
Stepper Motor
LIST OF ARDUINO SENSORS AND MODULES
Ultrasonic Sensor Module
IR Infrared Obstacle Avoidance Sensor Module
IR Infrared Fire/Flame Detection sensor
Soil Hygrometer Detection or Soil Moisture Sensor
Humidity and Rain Detection Sensor
Microphone Sensor or Sound Sensor
Digital Barometric Pressure Sensor
Photoresistor Sensor (LDR)
Digital Thermal Sensor - Humidity Sensor
DHT11 Temperature and Humidity Sensor
Rotary Encoder Module
SW-420 Motion Sensor or Vibration Sensor
Passive Buzzer Module
Speed Sensor Module LM393
Relay Module
HC- SR501 Pyroelectric Infrared Sensor (PIR)
Accelerometer Module
Arduino Joystick Module
Piezo buzzer Sensor
Water Flow Sensor
Arduino Color Sensor
Optical Fingerprint Sensor
Heart Rate or Pulse Sensor
Capacitive Touch Sensor
Arduino Bluetooth Module HC-05 or HC-06
Arduino GPS Module (NEO-6M)
RFID
Turbidity Sensor
Load cell Module
PH Sensor Module
Pressure Sensor or Force Sensitive Resister (FSR)
Flex Sensor
CHAPTER 3
ARDUINO PROGRAMMING
Structure of an Arduino Code:
Bare minimum code
Arduino Data Types
Analog to Digital Conversion
ARDUINO PROGRAMMING BASICS
Structure
setup()
loop()
functions
{} Curly braces
; Semicolon
/*...*/ block comments
// line comments
Variables
Variable scope
byte
int
long
float
Arrays
Arithmetic
Compound Assignments
Comparison Operators
Logical operators
Constants
True/false
High/low
Input/output
if
if... else
for
while
do... while
pinMode(pin, mode)
digitalRead(pin)
digitalWrite(pin, value)
analogRead(pin)
analogWrite(pin, value)
delay(ms)
millis()
min(x, y)
max(x, y)
randomSeed(seed)
random(max)
random(min, max)
Serial.begin(rate)
Serial.printin(data)
Digital output
Digital input
High current output
PWM output
Variable resistor input
Servo output
Using Libraries
Summary
CHAPTER 4
ARDUINO PROJECTS LEARN BY DOING
Project 1: Blink an LED
Project 2: Traffic Light 3 Way Controller
Project 3: Push button - LED Blinking
Project 4: RGB Blinking LED (Common Anode)
Project 5: Interfacing with Keypad Module
Project 6: Control LED Blink Rate with Potentiometer
Project 7: Multiple tones with one Piezo Buzzer
Project 8: Seeing the light using Photo resistor with an Arduino
Project 9: Arduino Flame Sensor
Project 10: LED Matrix display 8 x 8 dots (MAX7219)
Project 11: Interfacing with LCD 1602 Display
Project 12: HC-SR04 Ultrasonic Distance Sensor with Arduino
Project 13: Touch Sensor Arduino Interface
Project 14: Relay Module interface with an Arduino
Project 15: Control Servo Motor with Arduino
Project 16: Stepper Motor Control with Arduino
Project 17: Interfacing Soil Moisture Sensor with an Arduino
Project 18: Water Level Monitoring Experiments
Project 19: Vibration Sensor Module
Project: 20: Infrared Sensor Receiver Module with an Arduino
Project 21: IR Remote Control Experiment with Arduino
Project 22: Interfacing Sound Sensor Module with Arduino
Project 23: Analog Joystick Module with Arduino
Project 24: Interfacing DHT11 Sensor with Arduino
Project 25: Temperature and Humidity Monitoring Experiment
Project 26: One digit 7 Segment Displays with an Arduino
Project 27: Four Digit 7 Segment Display Module (TM1637)
Project 28: Heart-shaped display experiment with Arduino
Project 29: Interfacing tilt sensor with Arduino
Project 30: Interfacing RC522 RFID Module with Arduino
Project 31: Interfacing Bluetooth module HC-05 with Arduino
Project 32: Interfacing Thermistor Module with Arduino - To
measure Temperature
Project: 33: DC Motor Direction Control
Summary
CHAPTER 5
How to Troubleshoot and Fix Arduino Issues
Can’t Load Programs on Arduino
Solution: Verify that the board model is compatible with the
configured model
Solution: Ensure a Functioning Arduino
Solution: Reset the Device
Solution: Diagnose USB Connection Problem
Arduino Software is Not Working
Arduino Software is Freezing and Crashing
Don’t Throw Damaged Arduino
Essential Resources
Bibliography
CHAPTER 1:
ARDUINO: EVERYONE NEED TO KNOW
Introduction
The first ever Arduino controller board was born in 2005, at the teaching
space of the Interactive Design Institute in Ivrea, Italy. An article about a
wiring design submitted by a Colombian scholar named Hernando Barragan
can be found in the Interactive Design Institute. The name of the proposal
thesis was “Arduino - The Revolution of Open Hardware”. Of course, it
sounded a slightly different from the typical proposal but nobody would have
make-believe that it would be carve a niche in the domain of electronics.
The Arduino software IDE was developed by David Mellis and was based on
Wiring. Previously, Gianluca Martino and Tom Igoe joined the development
of Arduino mission, as well as the five are well-known as the actual creators
of Arduino board. They needed a controller should be straightforward, easy
to associate with different kind of module and components (such as LED,
motors, relays, and sensors), considerably weightless, also easy to accessible
in the open-source community, and simple to program. It also wanted to be
cost efficient, easy to available, because as students and artists aren’t known
for rich in cash. They choose the AVR type of 8-bit microcontroller (MCU or
µC) devices from Atmel and aimed a self-sufficient circuit board with easy-
to-use connections, put pen to paper bootloader firmware for the
microcontroller, and finished it all into a basic integrated development
environment (IDE) which used programs entitled as “sketches.” The result
was the Arduino Hardware.
Microcontroller
With an internet accessible PC, open up your default browser and type in the
below URL into the web search bar: Download the newest version of Free
Arduino IDE from this page: http://arduino.cc/en/Main/Software
For dissimilar OS platforms, the method of using Arduino IDE is not the
same. Kindly ensuring to the following links:
Windows User: http://www.arduino.cc/en/Guide/Windows
Mac or Linux User:
http://www.arduino.cc/en/Guide/MacOSXLinuxUser
http://playground.arduino.cc/Learning/Linux
For learn more about Arduino IDE, Kindly checkout to the Link:
http://www.arduino.cc/en/Guide/HomePage
Arduino UNO SMD R3
Arduino Uno is one of the most widely used microcontroller boards, powered
by the ATmega328. Its wide range of support network and versatility are the
primary reasons for its popularity. In addition to the 14 digital I/O pins, the
Arduino UNO board has 6 analog inputs, six of which should be PWM (Pulse
Width Modulation) outputs. An ICSP (In-circuit serial programming) header,
a 16 MHz crystal oscillator, a USB A/B port, and a reset button. It's all right,
you'll understand later.
STEP-2: Connect your
Arduino Uno to your PC or Laptop via Arduino cable, use the Type A/B
cable to connect to one of your Laptop’s USB inputs.
Select the tools or components to install and click “next” button to continue
Browse and Select
Destination folder or the installation directory
The procedure will extract and install all the necessary files to execute
accurately the Arduino Software (IDE) on system.
Step 4: How to open examples sketches or program on Arduino IDE.
Open Arduino IDE Software >File >Examples >Basics > Blink
Step 5: Choose your Controller board
For choosing board, you have to follow this entry in the Tools > Board list of
options which match up to your Arduino board.
Step 7:
Upload the program
Here and now, just click the "Upload" button in the Header IDE Icons. Wait
just a second - you can see the RX and TX leds on the board flashing. Once
the upload is finished, you may see the message "Done uploading." will
seem in the status bar.
Step 8: Result
A couple of seconds later once the upload done, you could be able to see the
pin 13 (L) LED built-in on the Arduino board, it will ready to start blink (in
orange color), If it done… well done! You've understood basic Arduino
interface.
Arduino Libraries
The Arduino platform can be emerging into the next level through the
utilization of libraries, much like most programming environment.
Libraries offer an additional value meant for benefit in programming,
e.g., functioning with hardware or handling data. Large number of
Arduino libraries comes with built-in the software IDE, nevertheless
you can be able to download on websites or make your own.
You can express an Arduino Library is such a Class with
Methods/Functions. This is a great method to construct your sketches
There are three places where Arduino libraries are stored: inside the
IDE installation folder, inside the core folder, and inside your
sketchbook's libraries folder. Libraries selected during compilation
are designed to allow for updating of libraries present in the
distribution
For Instances:
v Stepper Motor Library for an Arduino is written like
#include <Stepper.h> ‘.h’ is an extension for the library
header.
v SD card library: Which means permits for reading from and writing
to the SD cards, for example on the Arduino shield for an Ethernet
and Wi-Fi modules
1. Ethernet Library for the Arduino is #include <Ethernet.h>
2. Wi-Fi library for the Arduino is #include <WiFi.h>
For writing your own libraries refer here:
Writing a good library is not an easy task. Developers have different
perceptions about what the appearance of a library like this should be. In my
opinion, developers should cover robust libraries with unit tests, as well as
provide detailed documentation. In addition, an intuitive and easy-to-use
interface is crucial for any decent library.
I have worked on several large software development projects most of my
career. The frameworks we used were robust, and we wrote proper unit tests
and integration tests for most of them. You'd probably spend more time
debugging if you didn't have well-written tests.
The Arduino kit I have been using for about a year and a half is very intuitive
to me. Aimed at hobbyists and self-taught programmers, Arduino was
developed by its creators. The community of people interested in electronics
is large; however, the quality of the published code is often very variable. I
often check the code on GitHub for Arduino libraries I need, but the code is
frequently unmaintained. Library materials were often not properly
documented, even when they were maintained. Unit tests weren't present in
most of them.
https://www.arduino.cc/en/Hacking/LibraryTutorial
https://www.arduino.cc/en/Reference/Libraries
How to add library files
Installing or adding Arduino libraries would be done by three different types
of steps:
1. Manually Adding the Library files,
2. Importing a ZIP compression file,
3. Adding Libraries with the library manager.
These Two approaches should be done with drop down menu options. On the
other hand, for the manual installation, we need to choose the libraries and
place that into the Arduino “libraries” folder.
Principle:
In this project, we will program the Arduino's General-Purpose Input Output
(GPIO) HIGH level (+5V) and LOW level (0V), and before make sure the
LED that is linked to the Arduino’s GPIO, which is blink by a certain
frequency.
What is the LED?
The LED is stand for Light Emitting Diode. LED is generally made with
gallium arsenide, gallium phosphide both are semiconducting materials. The
LED consist of two electrodes: a positive and a negative electrode. This is
illuminating only after a forward current passes, then it will glow red, green,
blue, yellow, etc. The color of the LED is depending on the material that is
used.
Generally, 5-20mA is drive current of the LED. So in actuality, it generally
require more resistor for limiting current, because of protect the LED from
the high current.
What is resistor?
The important role of the resistor is used to limit currents. In general,
electronic circuit, the letter ‘R’ denotes resistor, moreover the unit of resistor
is ohm (Ω).
Writing an Arduino sketch
Before developing an Arduino code, we have understood some basic Arduino
C functions, we may learn in upcoming lesions…
Basic Arduino C functions:
Here is some essential Arduino functions, and commands everyone need to
know before write a code.
setup()
The setup() function is known for what time a code starts. Useful to initialize
variables, start utilizing libraries, pin modes, and more… The setup function
may simply run once at a time, afterward to each activate or reset of the
Arduino microcontroller.
loop()
When making a setup() function, that initializes and use the initial values, the
loop() function do from exactly what its label recommends, in addition, loops
repeatedly, letting your sketch to change and respond. Utilize it to
dynamically regulate the Arduino board.
pinMode() / pinMode(var1, var2)
Arranges the definite pin to work each as an input or an output. Set the mode
of assumed pin is pinMode functions. Var1 is known as the number of the
pin and var2 is known as mode (I/O).
digitalWrite() / digitalWrite(var1, var2)
digitalWrite alters the status of the pin. Var1 is known as the number of the
pin and var2 is the status (HIGH, LOW).
delay()
delay() Function can be used for pauses the codes for the certain amount of
duration (in milliseconds) stated as parameter. (1 seconds is equal to 1000
milliseconds.)
Pin definition
LED UNO R3
Long pin -> +5V (D13)
Short pin -> GND
Note: The lengthy LED pin is linked to the digital signal port 13(D13).
Step 2: LED Blink: Write your first code on Arduino IDE.
Uploading the Sketches
Before Uploading sketches make sure you are connected your
Arduino board to the USB cable (Types A/B).
Make sure if you choose right Arduino Board on tools menu follow
these steps to choose desired controller board Select
Tools→Board→Arduino Uno to find your board in the drop-down
menu. You be able to choose various types of microcontroller boards
from this list, such as the Arduino Nano, Arduino Uno and Arduino
Mega.
Also, the essential stages are select the right serial port for your
Arduino board. You can see all the existing COM serial ports by
selecting Tools→Serial Port→ comX, In IDE, once you have
recently connected your Board to Computer, the COM port may
typically be the bigger number, for e.g. COM 3 or COM 15.
Click Verify Button for the code is checked once before uploading
Click Upload Once Click the upload button, then the code is dump to
the Arduino Microcontroller board.
Step 3: Compile the sketch and upload to Arduino
board. Congrats! Finally, you finished your
Arduino Project Blink an LED. Let’s see the Question-and-Answer Session
about Arduino Platform.
Arduino Q & A Section
1) What is the Arduino used for?
Arduino is an open-source electronic prototyping boards utilized for flexible
easy to practice hardware and software. An Arduino microcontroller board
can read inputs (a light on a sensor module, a tweet on Twitter, a finger
touched a switch), and use that data to trigger a motor, blink an LED, and
broadcast data to the internet.
2) Who invented Arduino?
Massimo Banzi
In 2005, Hernando Barragán (maker of wiring), Massimo Banzi and David
Cuartielles are building upon the work on developing open-source
microcontroller, finally Arduino born. Their goal was to develop a
collaborating art design module that could be easily accessed via a
programmable interface at the Interaction Design Institute Ivrea in Ivrea,
Italy.
3) Who uses Arduino?
Arduino developed for student, hobbyists, artists, designers and any person
fascinated in building interactive project or environments.
4) Is Arduino based on C or C++?
Primarily, the Arduino IDE or compiler support C and C++. Actually, most
of the Arduino libraries are written by C++ Programming. Most of the
fundamental structure is not object oriented, however it could be. Therefore,
"The Arduino IDE language" is C++ or C.
5) Is Arduino good for beginners?
Yes, Arduino is good for beginners, which they able to buy on a budget, an
Arduino Uno is a worthy choice. There are several basic programming/
sketches that will support on the Uno, Novice learner also allowing to
evaluate Arduino and practice as a wonderful knowledge gaining platform,
and most of the mini projects can be designed with an Arduino Uno.
6) How does the Arduino work?
An Arduino board is connected to your laptop by a USB type A/B cable, in
order to connect with the Arduino software since it's nothing but the Arduino
IDE (Integrated Development Environment). This is done using an IDE that
creates sketches and code, which is then sent to the Arduino microcontroller
for execution. Afterwards, the application interacts with sensors, electronic
components, motors, and lights.
7) What is the difference between Arduino and microcontroller?
Many of the board often use Atmel types of AVR microcontrollers. Arduino
UNO is an ATMEGA 328 based microcontroller series. Most commonly
Microcontroller is a well suited than a microprocessor to whatever needs the
recognizing of inputs.
8) How do I start Arduino?
Use your Arduino on the Desktop software IDE. Install or choose the
board drivers. Start your initial sketch. Choose your controller board type
and port. Upload the Sketch/program, furthermore study on the Software
IDE Tutorials.
9) Is Arduino software free?
Yes, Arduino is an open-source hardware and software, almost all the open-
source product is free, and Therefore Arduino is a free platform, we can able
to modifying Arduino module without getting any license from Arduino
developers.
10) How do I power an Arduino?
We able to power-up the Arduino with power supplied from the
laptop through a USB type A/B cable or by utilizing external power
sources, such as power bank, li-ion batteries up to the 12V.
Plugged into the barrel connector with Arduino by using an AC to
DC adapter.
Powering up Arduino by using all types of 5V DC input. ...
Moreover, we can use batteries higher than 5V.
11) What is the programming language of Arduino?
The Arduino language is just a set of C/C++ functions which can be so-called
from your sketch. Your code feels minor modifications (e.g., automatic
creations of function prototypes) as well as then is accept straightly to a
C/C++ compiler (avr-g++).
12) What chip does Arduino use?
Arduino uses ATMEGA328 Microchip, which contain 14 digital
input/output pins, 6 analog inputs, 6 pins can be utilized for Pulse-width
Modulation (PWM) outputs, also includes a 16 MHz quartz crystal, a power
jack, a USB connection support, an ICSP (In-Circuit Serial Programming)
header, and a reset push button.
13) Does Arduino have a CPU?
The Arduino Uno doesn’t have a CPU, but it uses a microcontroller named
ATMEGA328. In an Atmega328 microcontroller include the processor core,
programmable I/O and memory, peripherals are incorporated into a single
System on Chip (SoC). However, the microprocessors possibly will have
integrated registers, nevertheless it will depend on outward RAMs and
peripherals.
14) Which is better Arduino or Raspberry Pi?
A microcontroller is a portable easy-to-use computer which be able to run
one sketch/program at that moment, over and over again. Microcontroller is
extremely straightforward to use. A Raspberry Pi is a general-purpose credit
card sized motherboard, also utilized as a portable computer, generally
Raspberry Pi is support by Linux OS, and it have the capability to run various
programs. It is further more complicated to learn than an Arduino.
15) How is Arduino different from C?
The primary dissimilarity of Arduino vs Traditional C would be the file
associations. An Arduino software development is associated to the IDE
(Integrated Development Environment) of Arduino, which is ultimately a
C/C++ compiler that creates machine sketch for the Arduino boards.
16) Can an Arduino run 12v?
Arduino Power pin labeled as Vin, it is a input voltage in Arduino board (As
an alternative of utilizing the barrel adaptor or USB cable). The Arduino
voltage should be 9V to 12V, and which is regulated inside by the board to
5V.
17) What is the best Arduino?
Arduino Uno: Provided you are a novice learner, entering into the field of
Arduino, the great choice for you would be the Arduino Uno R3, which costs
around $20. Moreover, you can also buy clone boards such as Freeduino
which cost around $5, you may also get started from this too.
18) Why Arduino Uno is best for beginners?
Arduino Uno is the most popular and standard board available in the market
and most likely the primary option for the student. For the reason that, it has a
major benefit is, that we able to use the board to the computer through a USB
cable which does a dual purpose of delivering power to the board and
performing as a Serial port to interface the Arduino microcontroller and the
laptop.
19) Is Arduino difficult to learn?
The worthy information is that Arduino programming is merciful. It still has
a learning curve, and writing an Arduino code it's not just simple, however it
will be much simple than write sketches for your initial projects, to be sure,
Arduino should be a stress-free technique to wet your feet in coding.
20) Is Arduino a PCB?
For dumping code to microcontrollers, for simple user interface the Arduino
Environment provides an IDE, which is created for making right code for
project, Arduino IDE integrated with C and C++, that’s to say, a PCB is not
the similar as an Arduino, but a PCB is portion of Arduino.
21) Can Arduino run without computer?
So, we have a query… Can we run Arduino as a portable device and no
computer needed? Yes, Laptop only sufficient to program it, after dumbing
the code, Arduino can work as portable device with power source. Yes, Here
Wi-Fi module and Ethernet also existing for connecting it to a network. ...
But the Arduino is not effective to run software for that.
22) Can we use Java for Arduino?
We able to use Java SE Embedded or Java ME on a Raspberry Pi, on the
other hand, the Arduino is a slightly too forced to execute Java directly.
Though, with the support of serial port communication IDE, we able to
communicate with java also control an Arduino from Java running on a
different PC.
23) What is Arduino in IOT?
At the present time a buzzword field and fastest growing area is Internet of
Things (IoT), IoT project is nothing but, all the physical things such as home
appliance, sensors, and gadgets are linked together with an internet structure.
IoT utilized in Plethora of Application such as Home Automation, Smart
Agriculture system, and Smart-Health monitoring system.
24) What is the smallest Arduino?
Arduino Beetle is the smallest Arduino microcontroller available in the
market. It has AtMega32u4 8bit AVR Microchip, It has 10 digital pins, 5
analog pins and 4 Pulse with Modulation pins, Beetle board functioning with
16MHz clock time.
25) What can the Arduino beetle do?
Beetle intended to make a Cost-efficient microcontroller, it should be simple
and straightforward to use, and to afford a cost-efficient solution for reusable
projects, Like DIY STEAM projects, electronic workspaces, E-Textiles, gift
projects, and Practical Education. Aimed for students, research scholar and
creators those who can’t afford too much on controller module purchasing,
Beetle should be a wonderful solution for them.
26) What is the difference between Arduino Uno and Leonardo?
The Primary modification between Uno and Leonardo is which Leonardo has
an ATmega32u4 Microchip that contain inbuilt micro-USB port, but the
Arduino UNO has ATmega328 Microchip which doesn't have the inbuilt
micro-USB onboard. However, the UNO needs an added microcontroller to
provide the USB capability. Cost wise Leonardo is 20%. Cheaper than UNO.
27) Which is better Arduino Uno or Nano?
As its name, Arduino Nano is a small in size and breadboard-friendly
microcontroller board based on ATmega328 processor, as a replacement for
the standard USB to connect to the PC, Instead Arduino Nano utilized the
Micro USB but without the power cable for external power source which
built on Arduino UNO.
28) What can the Arduino Nano do?
Arduino Nano is a more or less similar board to Arduino UNO in terms of
functionality, but its small size makes it stand out from other boards. A
breadboard-friendly, smaller-sized ATmega328 module built on the
ATmega328, the Arduino Nano is small in size, wide-ranging, and
breadboard-friendly.
29) Does Arduino have EEPROM?
In the Arduino Microcontroller boards, the EEPROM area is emulated and is
1024 bytes in size. Microcontrollers on Arduino boards are AVR-based and
include EEPROM memory, allowing them to retain their values after being
turned off (such a small hard drive). These EEPROM bytes can be read and
written with this Arduino library.
30) What is the use of EEPROM in Arduino?
This memory type is referred to as electrically erasable programmable read-
only memory. On the majority of Arduino boards, the microcontroller is built
with EEPROM capacity of each 512 bytes, 1024 bytes, or 4096 bytes.
Memory storage on this board is non-volatile, which means once the board
goes down or loses power, the information does not disappear.
31) Can Arduino save data?
Provided Arduino is interfacing to the PC, the information can be stored by
reading the serial output and saving that in a file. Provided a Micro SD card
insert to the Arduino, the files or information can be stored straightly to the
SD card.
32) What are the Different Types of Arduino Boards?
Arduino Uno (R3)
Arduino Mega (R3), Arduino Beetle
Arduino Nano, Mini
LilyPad Arduino, RedBoard Arduino
Arduino Leonardo
Arduino Shields and more...
Summary
This chapter introduces Arduino and shows you how you can get started with
the microcontroller and addresses frequently asked questions. In the next
chapter we will explore the basic components of electronics and different
types of Arduino-compatible sensors and their functions.
CHAPTER 2:
BASIC ELECTRONIC COMPONENTS
In Arduino projects, major components typically included resistors,
capacitors, transistors, integrated circuits (ICs), switches, relays, motors, etc.
Usually, these components are used to build Arduino projects, so before we
dive into Arduino sensors and projects, we need to learn about basic
electronic components.
Resistors
A resistor impedes the movement of electricity over a circuit, resistors have a
conventional value.
Since voltage, current and resistance are associated over Ohm’s law, resistors
are a simple technique to control voltage and current in your circuit.
Resistor color codes
Color Code Number: (BBROYGBVGW)
Unit
To Identifying your units is significant
Kilo & Mega are basic in resistors
Milli, micro, nano & Pico can be utilized in additional components
Capacitors
A capacitor is used to stores electrical energy. Here pool of electrons is
obtainable for electronic components to usage.
Capacitance is measured in the unit of Farads. The mini capacitors typically
used in electronics are often determined in micro-farads and Nano-farads.
Some capacitors are polarized. Have to know the different length of terminals
on one of the capacitors.
Polarity of capacitors
The smaller terminal goes on the -ive side.
Applications of capacitors
Capacitors can pass a pool of electrons for instant use.
If a component wants an instantaneous supply of electrons, the
capacitor can pass those electrons.
Capacitors can smooth out a
signal - remove the waves or spikes in DC voltage. The capacitor can attract
the peaks and fill in the vales of a waved signal.
Inductors
An inductor is a passive electronic component which is stores energy as a
magnetic field. In its minimum tough form, an inductor includes of a wire
loop or coil. The inductance is straight proportional to the amount of turns in
the coil. Inductance similarly relies upon the distance of the coil and on the
kind of material about which the coil is wound.
3. Base
Bipolar Junction Transistor (BJT): There are two different types of
transistors available in the market: NPN and PNP, presented in plastic cases
or metal cans. Plastic casings have a flat front side and pins arranged in a
serial manner on one side of the transistor. You can identify the pins by
counting them as one, two, etc. by keeping the front flat side facing you.
There will typically be three transistors in an NPN transistor: 1 (Collector), 2
(Base), and 3 (Emitter). Thus, the CBE. But in the case of PNP transistors,
the condition is reversed. In other words, that's EBC.
Field Effect Transistor (FET): A Field Effect Transistor can be identified
by starting counter-clockwise, keeping the curved portion facing you. The
first one is the source, the next the gate, and the last is the drain.
MOSFET: Metal Oxide Semiconductor Field Effect Transistor: It is not
uncommon for the pins of a MOSFET to be labeled as G, S, and D, which
indicate the gate, source, and drain, respectively. The datasheet for the
MOSFET may need to be consulted in some cases. As you make your way
from left to right, normally you want to make sure the flat side of the pin is
facing you.
IGBT- Insulated Gate Bipolar Transistor: With some practical IGBTs,
like the GN2470, the raised surface faces the person holding it so that the
short surface in the center acts as the cathode. Those on the left are Gates,
and those on the right are Emitters.
Phototransistor: In a practical phototransistor like the L14G2, the collector
is on the curved surface facing the person and the emitter is on the other side.
The base is on the side opposite the emitter.
Schematic symbols
Current microprocessor ICs can have billions of transistors each square inch,
The majority of electronic devices contain some form of integrated circuit. A
timer is an electronic device that functions as an amplifier, a logic unit, a
counter, a calculator, a temperature sensor, and a radio receiver. Electronics
have been revolutionized since integrated circuits are present in almost all
modern equipment.
ICs are physically much smaller than discrete circuits. Contrary to discrete
circuits, an integrated circuit is very light in weight. Compared to other
systems, it's more reliable. It has a lower power consumption due to its
smaller size. Failures can easily be replaced, but the failure can almost never
be repaired
What an IC can do for us?
Billions of electronically measured on/off switches (transistors) is
how the microprocessor in a digital computer ‘thinks’ and purposes.
A computer has a wide variety of tasks to perform.
But
other ICs can fully simpler, separate jobs. For i.e., an IC can take a
voltage input and output instructions to a motor.
IC Terminology: Op-amp
An
operational amplifier (op-amp) is a group of transistors inside the IC
(Integrated Circuit). They frequently are the components doing the
mathematical procedures.
An operational amplifier amplifies weak electric signals by using an
integrated circuit. Two inputs and one output are present in an operational
amplifier. The input voltage difference between the two input pins is
amplified and output by this driver.
The most common type of voltage amplifier is the Op-amp, which can be
broadly categorized into non-inverting and inverting amplifiers.
H-bridge
An electronic circuit which allows voltage to be applied across a load in any
direction.
The LCD contains of 16 pins which are utilized for power, control, in
addition data. It should follow a manufacturing standard Hitachi regulator
therefore the basic functions of LCD are almost similar across the various
kind of traders that sell them. They both have a 4-bit and an 8-bit parallel
interface. We have been utilizing 4-bit parallel interface instead of 8-bit.
Which means we will be transmit the upper nibble (1 nibble is equal to 4 bits)
first, next to the lower nibble to transmit the byte of information essential for
each command or character. LCD 16×2 or a 20×4 is most generally used in
many projects that means which it can be show 16 characters on both 2 lines
and 20 characters on both 4 lines, correspondingly.
LCD Pinout with an Arduino interface circuit shown below.
Why start with LCD?
The LCDs support a parallel interface, significance which the Arduino has to
handle numerous interface pins simultaneously to control the display. The
parallel edition capable 4 digital pins for display, Learners definitely express
vast degree of happiness from sending word to the LCD screen
DC Motor
Many of the electronic servo motors operates from 4.8V to 6.5V, if we give
high voltage, simultaneously we able to get high torque, However, usually an
electronics Servo motors are functioned at +5V. More or less all hobby servo
motors must be rotate just from 0° to 180° because of its gear placements
therefore validate your mini project be able to work with help of the half
circle if no, you be able to choose for a 0° to 360° motor or adjustment the
motor to modify a full circle. In motors the gears are simply subjected to
wear with tear, therefore if your project needs robust and long durable
running motors, you can choose metal gears or else just go with typical
plastic gear.
After picking the desired Servo motor for our project, the queries will come,
how to use it. As we know already servo motor having three wires, there is
power, ground, and a third wire to bring the signal. For rotating the servo
motor, we want to connect the battery to at +5V with the Red and Brown
wire as well as Transmit Pulse Width Modulation (PWM) signals to the
orange wire. Therefore, we must rather that may produce Pulse Width
Modulation signals to make the servo motor rotate well. We can able to
utilize this hobby servo motor with any electronic development board such as
555 Timer or further more microcontroller environments such as Arduino,
ARM, PIC, or even though a credit card sized computer or microprocessor
such as Raspberry Pie.
Applications
Hobby Servo motor utilized as actuators in various kind of robotic
projects such as Robotic arm, Biped Robot, and Hexapod, and
more….
Frequently using in RC toys as steering control system,
In Robots, doesn’t required feedback for position control,
Because of weightless, and little in size, as a result the servo motors
utilized in multi-purposes DOF (Degree of Freedom) robotic
application such as human-like robots.
Stepper Motor
IR Infrared sensor that will emits infrared radiation which bounced back by
the obstacle or objects in proximity sensor. After sensed by a digital output is
shown. Level of Sensitivity is might be adjusted by on-board variable resister
or potentiometers. It will very effective for sensing a robot is around to
interface with walls or other obstacles.
While the Sensor is in Wet: the resistance will Surges, and the output
voltage will decline.
While the Sensor is in Dry: the resistance is declines, and the output voltage
is Surges.
Microphone Sensor or Sound Sensor
Arduino Sound Sensor contains a sensitive capacitance mic for sensing sound
and comes with built-in amplifier circuit, the digital output reacts as a key,
and it will trigger, once the audio intensity has achieved a specific threshold
level. The sensitivity threshold can be increase or decrease through variable
resister on the module.
The analog output voltage is fluctuating by the intensity of sound acquired by
the microphone module, we may connect this sensor output to Arduino
analog pins and then we can able to process the output voltage, each
microphone has digital and analog outputs.
AO: Analog Output, to output voltage signals from microphone in a real-time
manner
DO: Once the audio intensity archives a specific threshold level, the
microphone outputs will be high or low level.
There are two types of microphone sensor available in the market:
‘Sensitivity Level’ is the one and only dissimilarity for both microphones
Digital Barometric Pressure Sensor
The Barometric Pressure Sensor (BMP180) is one of the fascinating sensor
modules available in the market, important role of this module is measuring
the pressure and altitude, which can be used to forecast the climate
conditions, sense altitude, and estimate perpendicular velocity, it’s a
tremendously sensitive sensor on top. By means of you can realize in a
second, it can be sensing the fluctuation in altitude of just a few inches.
This Barometric Pressure Sensor can be used in various kind of projects and
innovation such as flying robots, weather stations, for enhancing day to day
routine, autonomous vehicles, self-driving cars and much more…
Barometric Pressure
Barometric pressure is the pressure happened by load/weight of air pushing
down to the ground, moreover it’s called as atmospheric pressure, lets
visualize a cluster of air rising from the ground’s surface to the top of the sky.
The air in the sky has huge mass, therefore gravity causes the weight of
which cluster of air to exert pressure on the surface.
At the dark night time, LDR resistance is extremely high, the LDR is made-
up of cadmium sulphide tape, a semiconductor. Once the photons passing
through tapes, electrons can travel via the semiconductor. The significant role
of Photoresistor is estimate the intensity of lights (most commonly used in
street lights, night camera, detection systems, and automatic security lights).
The following are some of the advantages or benefits of photoresistor
devices:
In addition to being a replacement for variable resistance, it is also a
light-dependent device.
When light falls on it, its resistance drops, whereas in the dark, its
resistance increases.
There are many different types and sizes of photo resistors available at a
low cost.
They are very energy efficient and need very little voltage and power to
operate.
Simpler circuits can be created with it. Due to its bidirectional nature, all
directions can be connected with it.
Applications of LDR
Low-cost and simple, light-dependent resistors can be readily used in a
variety of applications. Devices such as these are used wherever it is
necessary to know when light is present or absent. Light-responsive resistors
are often used in lighting and light intensity meters, as well as burglar alarm
circuits, as they act as light sensors. To provide more insight into this
concept, here is an explanation of a live lighting project that uses LDR to
conserve energy
Digital Thermal Sensor - Humidity Sensor
There are several types of temperature sensors compatible with Arduino, as
you can see in the following image.
The MQ-2 Gas sensor module can be detecting fire, smoke or gasses such as
LPG, Hydrogen, Propane, Alcohol, Methane and also CO. The module series
of this Gas sensor including with Digital Pin that makes possible this sensor
to work even with no microcontroller support and that portable to use while
we need to senses one specific gas.
At what time it comes to detecting the gas in ppm the analog pin must be
used, the analog pin also TTL logic driven and operating at 5V and therefore
it can be utilized with most reputed development board.
Accordingly in case you may searching for a sensor module to sensitive for
fire or plethora of gasses then this sensor could be more suitable for you.
Application of MQ-2 LPG Smoke Gas Sensor
Ø MQ2 sensor module is used as a gas leakage alarm in Hospitals,
Industries, and Home), and also used in air quality monitoring projects.
It is right choice for sensing such as LPG, H2, Propane, Alcohol, and also
CH4. Because of its great sensitivity and quick reaction, this sensitivity
might be taken as early as possible. This sensor also used to identify the
presence of gases in the atmospheric air.
Ø To detect toxic or explosive gasses and measure gas concentration, these
devices are commonly used. Manufacturing facilities use gas sensors for
detecting gas leaks as well as detecting smoke and carbon monoxide in
homes. Various types of gas sensors have different sizes (portable or
fixed), ranges, and sensing abilities.
SW-420 Motion Sensor or Vibration Sensor
The vibration sensor based on the SW-420 Motion Sensor and LM393
Comparator that is utilized to sense the motion activity and vibrations, the
sensitivity of vibration can be modify with a built-in variable-resister. If the
time of without vibration or motion, the sensor will send command to the
logic as LOW and once the motion or vibration is detected, the sensor will
trigger to the logic as HIGH.
Vibration sensor has 3 pins there are VCC, Digital Output, and GND, The
Digital Output pin is associated to the output pin of LM393 comparator IC. It
extremely simple to interface Vibration sensor module with the any
development microcontroller board like Arduino, Raspberry Pi and ESP8266.
The wiring connection of an Arduino with this SW-420 module is very
straightforward, connect the DO pin of the sensor to any digital pin of
Arduino and connect VCC and GND pins to 5V and GND pins of an Arduino
board.
Applications of Vibration Sensor Module
Shocks triggering
Earthquake alarm
Theft alarm
Smart car
Motorcycle alarm
Passive Buzzer Module
A buzzer is an electronic device which can be produce unique tones, most
commonly utilized to provide loud response for the people. Buzzers are
utilized in various kind of application such as emergency alarm clocks,
calculator, keypads, hobby toys and several household appliances.
The Passive Buzzer Sensor contains a passive piezoelectric element. Which
can be produce sounds from 1.5 to 2.5 kHz with changing it ON and OFF at a
several frequencies whichever using PWM or Delays. On the other hand, an
active buzzer sensor which have an on-board oscillating crystal, therefore that
will make a unique sound once power-on. Nevertheless, a passive buzzer
doesn’t have this function, subsequently there is no beep-sound once given
DC signal; as an alternative you should be apply square-waves which
frequency is among 2K and 5K to operate it. The active buzzer sensor is
slightly more expensive than the passive buzzer sensor, for the reason that,
because it has numerous on-board oscillating circuits.
The buzzer module is extremely easy to wire up to the Arduino. Connect the
left pin of the module to the pin that will drive it and the right pin of the
module to Arduino GND. The module is driven by pin 8 in the circuit below.
Several pins of the module are not connected, including the middle one.
Application
Passive Buzzer Sensor is used in various kind of application such as
Detecting obstacles and gives warning, Burglar Alarm, Blind stick and also
used as a Door knock alerts system.
Speed Sensor Module LM393
A speed sensor is similar to the Tachometer which is utilized to find out the
speed of a spinning object such as fan, motor and a propeller, here is there are
several kinds of Speed Sensor available in the market such as Hall-effect,
Eddy Current, and Magneto-resistive Speed Sensor, etc.
Speed sensor is also known as Hall Effect Sensor, so that for estimate the
speed of any spinning devices with Arduino, we may use LM393 Speed
sensor. Speed Sensor Module consist of an IR Light Sensor combined with
LM393 Voltage Comparator IC.
Applications
LM393 Speed sensor most frequently used in Robotics.
Motor Drivers
Printers, Scanners, Copiers
Contactless Switching,
Measuring Speed, and used to find out an RPM.
This Infrared Hall Effect sensor with the Voltage comparator LM393, we be
able to measuring the speed of spinning or rotation of the wheels in most of
the robotic car projects. Provided we place a circle gear which rotates linked
to our wheel. This will likewise be utilized as an optical switch.
The simple working of this module is as follows; when anything is crossed
between the sensor slots, that generates a digital pulse on the D0 pin. This
pulse drives from 0V to 5V and is a digital TTL (Transistor-transistor logic)
signal, finally, we be able to read this pulse with an Arduino.
Relay Module
Before enter into the topics, you ever wondered how your mobile phone
knows up from down! that is one of the interesting features of today’s
smartphone gadgets, now a days majority of smart devices includes a
microchip called Accelerometer, which is built-in to the motherboard that
make senses once you tilt it from right to left and up and down. That’s how
your smart gadgets immediately realizes while to change the screen position
from landscape to portrait.
What is Acceleration?
The revolutionary scientist Isaac Newton well-defined in his 2nd law of
motion or law of force, acceleration by connecting it to mass and force.
The acceleration is nothing but, the rate of change of velocity with respect to
time, It have both magnitude and direction accordingly acceleration is comes
under vector quantity. Which is the 2nd derivative of spot with respect to
time or it is the 1st derivative of velocity with respect to time.
Here is the Examples of some real-time day to day life application of an
acceleration:
1. While the vehicle is speeding up, and while the vehicle is slows
down
2. When the vehicle turning at the bend is for e.g. of an acceleration for
the reason that the direction is fluctuating. When the vehicle turning
will be fast, the acceleration will be greater.
3. When you free fall form the bridge.
Force = Mass x Acceleration or (F = ma.)
Acceleration of an object is related on the mass of the object and the how
much of force applied.
Acceleration = Force / Mass
This means that, acceleration is the amount of force we want to change each
unit of mass.
Accelerometer is an electromechanical module that involved the
processes both electrical and mechanical that identify the force of
acceleration by reason of gravity in g unit.
The Accelerometer determining the acceleration laterally X, Y and Z axes
and gives output of an analog voltage relational to the acceleration
laterally these 3 axes.
ADXL335 Module is most commonly used in the applications of tilt
sensing.
Many developments board like Arduino be able to process these voltages
by transforming them to digital signals via ADC.
Accelerometer sensor module are broadly utilized in low power, cost
sensitive, tilt sensing and motion detection projects such as Smartphone’s
gadgets, Gaming control systems Joysticks, Image, Video stabilization on
gimbals cameras, Sports Fitness Gadgets & healthcare devices and Disk
drive protection.
At the heart of the ADXL335 sensors is tiny in size, less power three axis
MEMS (Micro Electro Mechanical System) accelerometer beginning Analog
Devices through tremendously less noise. The module has overall detection
range of ±3 g, which can be identifying the static acceleration caused by
gravity in tilt-sensing projects, along with dynamic acceleration resulting
from motion, shock or vibration.
This module functioning on voltage among 1.8V to 3.6V DC (3.3V ideal),
and usually its takes just 350µA of current. Nevertheless, a built-in 3.3V
regulator perform it a special choice for handling on 5V developments board
like Arduino and Raspberry Pi.
The breadboard friendly ADXL335 sensor module breaks out every single
pin of the accelerometer to a 6-pin, 0.1″ pitch header. This contains three
analog outputs for X, Y and Z axis estimation, there are two self-test pin and
a supply pin that make you to clarify works of the sensor in the finishing
projects.
Arduino Joystick Module
The joystick is more or less same function with two variable-resister
(potentiometer) connected together, one for the horizontal movement (X-
axis), and another one is vertical movement (Y-axis) variable-resistances are
nothing but potentiometers and, in a technique, they react as a sensors
module they deliver us with varying voltage relating on their spinning.
Mostly commonly the joysticks are utilized for gaming industries, aviation
sectors and military applications.
Have you interested to make some tones with Arduino? Possibly a basic
sound for an alarm, perhaps a beep to aware you after a particular input
threshold level is achieved, or it could be to run and play the Super Mario
Bro music to perform your young mind.
If any kind of sounds required for your projects, you may discover
the simplest, fastest and probably the cost efficient way to generate your
desired sounds with the tone() function and piezoelectric buzzer with your
Arduino microcontroller.
Here is the two kind of piezo buzzers which are usually existing in the
market. The one is present like a basic buzzer, once we give power source,
that will produce a Nonstop Beeeeeeppp.... tones, another type known as a
portable buzzer that appearance slightly bigger than traditional one and it will
make a sound like “Beep. Beep. Beep.” Why sound happening… Because of
the internal oscillating circuit can perform there within. However, the first
one is much often broadly utilized for the reason that, that can be
personalized with help of customized circuits to easily compatible in our
projects.
The buzzer is generally related with a switching circuit to turn ON or turn
OFF, most of the buzzers required time and interval. We can just operate the
buzzer with help of DC voltage ranging from 3V to 12V, and A basic 9V
battery may be used, but then that is optional to usage a regulated +5V or else
+6V DC power source.
Applications of Buzzer
Most of the buzzers are audio signaling device which is utilized in
various kind of application such as timer circuits, alarms and tone
generating devices,
Somewhere the people have to be alarmed about their project, and
utilized in application like automobile electronics, communication
devices, portable devices, because of its compact in size
Water Flow Sensor
Arduino Compatible TCS3200/230 color sensor module can detect color and
intensity of the light using photodiodes. This color sensor module converts
data from the photo-detector into a square wave by through the light to
frequency converter.
The frequency of the square waves is directly related to the intensity of light.
At that moment the Arduino will process the square waves then show us the
RGB color’s values as an output. Accordingly, we can see the working
diagram on interfacing controller with RGB Color Sensor TCS230 shown
upcoming section.
Here we can utilize widespread of projects with color sensors module such as
organize or separate a product by its color, Enhancing printer color, quality
control systems and etc. Theoretically speaking, figments of our imagination
is colors. When we see a green apple, which means that, it can reflect that
specific wavelength (~550 nm for Green) of the EM Spectrum (EM -
Electromagnetic).
This Electromagnetic wave is absorbed by the human eye and proportional on
some biochemical reaction, consequently our brain says that specific
wavelength is green color.
Optical Fingerprint Sensor
There are different kind of fingerprint sensors available in the market, from
capacitive fingerprint technology utilized in recent smartphones, to optical
fingerprint sensors frequently utilized in access control projects like smart
attendance. In this lesson, we will learn about optical fingerprint sensor.
Fig. R305 Optical Fingerprint Sensor-Scanner
The Optical fingerprint sensor module is an extremely portable device. It
come from embedded with an advanced DSP unit which stands for Digital
Signal Processing unit, that is utilized to processing the input images of
fingers captured and find out a match detect or not.
Once the fingerprint module acquired a fresh image, that is extracted and the
characteristic features are separated. The memory board of the module is
looking for a fingerprint with corresponding patterns and the consequence of
that period is sent to the Arduino board through serial communication. This
all process is finished within a second. The sensor module has the storage
ability up-to thousand fingerprints model with its memory and its training
accuracy rate is more than 99.8% which makes it more protected!
The Fingerprint reader is one of the safe and greatest technique to detect and
identify the original person, as we know already which every fingerprint is
unique even similar twins do not have unique fingerprints patterns. For
utilizing this we can develop and fulfil most safety needs. To add multiple
fingerprint authentication in Arduino like development board projects
application, also we can able to develop this multipurpose optical fingerprint
scanner-sensor (R305), which is make possible fingerprint sensing and
authentication is super simple.
By utilizing this fingerprint sensor module, we be able to develop project like
Biometric verification and Access control or smart attendance related security
application easily. This optical fingerprint sensor module includes high
powered AS601 Digital Signal Processing chip form Synochip which
perform the task such as feature extraction, image rendering, processing, and
searching. This also consist of TTL serial out consequently, we can link to
any Arduino and Raspberry pi board or system. The DSP processor has built-
in FLASH memory that can able to collect up to 120 fingerprints.
Heart Rate or Pulse Sensor
The Heart Rate Sensor is a plug-and-play pulse sensor for Arduino. Heart rate
sensor is used to measure the electrical activity of heart such as
electrical pulse. That can be utilized as a portable device and smart fitness
gadgets by athletes, students, performers, working people, and game and
mobile developers those who need to simply integrate a real time pulse-rate
information into their healthcare projects and many applications. Principle
which is an incorporated optical amplifying unit and noise removing unit in
the circuit module. Fastener the Heart Sensor to your tin ear or fingertip and
connect it into your Microcontroller like a Arduino and Raspberry Pi.
This Pulse rate sensor is pretty straightforward to use and activate it. Place or
hold your finger on top of the sensor and that can sense the electrical pulse of
heart is nothing but heartbeat by calculating the change in light from the
development of capillary blood vessels.
Capacitive Touch Sensor
Note: We don’t need touch our fingertip to touch pad. Capacitor can be
produced by attractive our finger closed the touch plate. Subsequently the
distance wanted to form capacitor is in Nano meters so typically we touch our
finger to the touch plate.
Arduino Bluetooth Module HC-05 or HC-06
You ever assumed monitoring any of your electronic devices and smart
gadgets with your smartphone? How about an autonomous robot or many
other electronic appliances? Wouldn't it be simple to control it with your
smartphone? Never mind, here is a cool sensor module for communicating an
Android smartphone with Arduino through Bluetooth HC-05!
How Does It Work?
There are 3 Essential parts to this project. First one is Bluetooth supported
smartphone, an Arduino and a HC05 Bluetooth Module.
NEO-6M GPS chip is the heart of the GPS module is from u-blox. That be
able to track more than 22 satellites on up to 50 channels and it can attains
the industry’s peak level of sensitivity, Such as For -161 dB level of tracking,
it will consuming simply 45mA source current. The u-blox 6 locating
machine correspondingly claims a Time-To-First-Fix (TTFF) of less than 1
second. Power Save Mode (PSM) is one of the greatest features that the chip
provides. PSM is permits a decrease in device power consumption through
selectively switching portions of the receiver ON and OFF. This will
intensely cut the energy consumption of the device to just at 11mA building it
appropriate for energy sensitive use cases, such as Fitness gadgets comes
with built-in GPS. The essential data pins of NEO-6M GPS chip are
fragmented out to a "0.1″ field headers. This comprises the pins mandatory
for transmission through a Arduino microcontroller over UART.
Note: - The GPS module and NEO-6M GPS chip can accept the baud rate
from 4800bps to 230400bps with default baud of 9600.
RFID
What is an RFID reader?
RFID is stands for Radio Frequency Identification, which utilizes mini-
RFID module for recognition and tracking purposes. An RFID tagging
device contains the label itself, a read/write technique, and a host system
use cases for data gathering, data processing, and data transmission.
Force sensing resistors are used in various fields such as foot pronation
systems, automotive sensors, electronic keyboards and controls, biomedical
devices, as well as musical instruments, as well as mobile electronics and
wireless communications.
Flex Sensor
A flex sensor is a different type of unique sensor that determines the amount
of deformation or bending. Materials like carbon or plastic can be utilized in
designing the sensor. The carbon surface is attached to a plastic strip. If you
turn this strip away, the sensor’s resistance will change. Therefore, it is also
termed a bend sensor. Since its varying resistance directly correlates to the
magnitude of the rotation, the bend sensor can also be employed as a
goniometer.
Most of the time, this sensor is mounted to the exterior, and you can adjust
the resistance by adjusting the exterior. It is used by Nintendo in its power
gloves, door sensors, robot whisker sensors, this also the key component in
making alert stuffed animals.
Analog resistors are what are called Flex sensors. Variable analog voltage
dividers are made with these resistors. There are carbon resistive elements
inside the flex sensor, surrounded by a thin flexible substrate. Increased
carbon content means a reduction in resistance. With a substrate bent, the
sensor makes resistance which is relational to the radius of the bend. Flexible
sensors are thin and flexible, which allows them to achieve high form factors.
A sensor, as shown in Figure, produces a resistance output inversely
proportional to the bend radius of the substrate, Consequently More
resistance will be given by a smaller radius.
Flex-sensors are used for the following applications.
v Physical Therapy
v Healthcare Instruments
v Robotics motion
v Virtual Motion (Video Games)
v A computer's peripheral devices
v Musical Instruments
Summary
We have discussed the basics of electronic components in this chapter, the
components you need to start with Arduino, and different types of Arduino
Sensors and Modules. In the next chapter, we will explore the basics of
Arduino programming and how to get started with Arduino programming
CHAPTER 3
ARDUINO PROGRAMMING
Introduction
A convenient, easy way to learn and use Arduino programming reference for
understanding the basic Arduino commands and syntax can be found in this
Chapter. Take it easy and keep things simple, some things have been left out
that makes it a secondary reference. This is best used alongside other books,
classes, websites, or workshops. Since then, the Arduino maker community
has refocused attention on standalone use and, for example, excludes the use
of arrays or more complex forms of serial communication. Starting with a
description of Arduino's C derived programming language, the language's
syntax and usage will be illustrated throughout this chapter with code
fragments and some examples. An appendix includes many functions of the
core library and sample schematics and starter programs. Where possible, this
format complements O'Sullivan and Lgoe’s Physical Computing.
Arduino code is written in C++ and adds some special methods and
functions, which will be discussed later. Human-readable programming
languages include C++. The Arduino code file is compiled into machine
language after being processed into a sketch (as it is called in Arduino
parlance), which is a very simple hardware programming language. A sketch
should be uploaded on an Arduino board after it has been written in the
Arduino IDE.
Downloading and installing the Arduino IDE is the first step in programming
the Arduino board. Linux, Mac OS X, and Windows are all supported by the
open-source Arduino IDE. From the Arduino website, download the software
(depending on your operating system) and follow the installation instructions.
Arduino programs follow a pretty straightforward structure. There are at least
two blocks in an Arduino program, The preparation process and the
execution of the plan The following statements are enclosed in curly braces in
each block:
Structure of an Arduino Code:
Bare minimum code
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
setup: The Arduino uses it only when powered on or when it's reset. It works
in the same way as initializing variables and pin modes.
loop: Until the device is powered off, loop functions will run continuously.
In this section, the logic of the program is defined. Microcontroller
programming follows a similar pattern to while (1).
Arduino Data Types
Arduino C, a variable of data type int uses 2 bytes of information. When a
sketch uses int, it tends to use it almost everywhere, unless it is very memory
hungry. For tiny integer values or for Boolean values, even a single byte
value could be used.
Table 1-1 Includes a complete list of available data types.
ADC in Arduino
} There are 6 ADC pins on the Arduino Uno board.
} Digital to analog converter with 10-bit resolution
} That means input voltages between 0 and 5 volts will be converted
into integer values between 0 and 1024.
Reading/Writing Analog Values
} analogRead(A0); // The pin A0 is used to read the analog value.
} analogWrite(2,128);
Reading/writing digital values
} digitalWrite(13, LOW); // this will select the output voltage on pin
13 , 0V
} digitalWrite(13, HIGH); // It will select the output voltage on pin 13
, 5V
} int buttonState = digitalRead(2); // Reads pin 2 values from the
buttonState
PinMode
} The pinMode function on the Arduino lets you choose an input and
output pin.
} pinMode(13, OUTPUT); // pin 13 becomes an output pin.
} pinMode(13, INPUT); // pin 13 becomes an input pin.
ARDUINO PROGRAMMING BASICS
Structure
Arduino's basic structure isn't too complicated and works in two parts. Blocks
of statements are enclosed between these two required parts, or functions.
void setup()
{
statements;
}
void loop()
{
statements;
}
Where setup() is the preparation, loop() is the execution. Both functions are
required for the program to work.
At the very entry level of the program, the setup function has to follow the
statement of any variables. A function that appears in the entire program runs
only one time, and is utilized to initialize serial communication or set the
pinMode.
Next comes a loop function, which contains the program to be run
instantaneously, it reads Inputs, triggered outputs and much more. In most
Arduino programs, this function is at the heart of the program.
setup()
When your program starts, setup() is called once. The pin mode is used to
start a serial connection or initialize pin modes. This type of statement must
be included, even if they will not be executed.
void setup()
{
pinMode(pin, OUTPUT); // sets the 'pin' as output
}
loop()
When naming the setup() function, the loop() function does specifically what
its name recommends, and loops sequentially, enabling the code to modify,
respond, and control the Arduino microcontroller.
void loop()
{
digitalWrite(pin, HIGH); // turns ‘pin’ on
delay(1000) ; // pauses for one second
digitalWrite(pin, LOW); // turns 'pin' off
delay(1000) ; // pauses for one second
}
functions
A Function is a block of code, wherever a function is called, a number of
statements are executed. In an earlier lecture, we talked about the functions
void set-up() and void loop() and others built-in will be explained later.
It is possible to write custom functions to simplify repetitive tasks and
minimize clutter in code. The first step in declaring functions is specifying
the type of function.
For example, ‘int’ represents an integer type function. A function's return
type would be void, if it returns no value. Name the function after type and
include any parameters that will be passed to it in parenthesis.
type functionName( parameters)
{
statements;
}
You can read the delay value from the potentiometer by using the function
delayVal(). A local variable v is declared, then one of the potentiometer
values is presented, The range for this number is 0-1023. Finally, it returns
this value back to the main program by dividing by 4 for an additional value
between 0 and 255.
int delayVal()
{
int v; // create temporary variable '‘v'
v= analogRead(pot) ; // read potentiometer value
v /= 4; // converts Q-1023 to 9-255
return v; // return final value
}
{} Curly braces
It is distinguished from "curly brackets" by its curly appearance, the void
loop() function and for and if statements, and may contain blocks which are
used to declare the beginning and end of function blocks and statement
blocks.
type function()
{
statements;
}
\*Do not forget to add the closing comment to the enclosed block comment –
it has to be balanced!*/
The program ignores comments, so they do not take up any memory, It's okay
to use them to “comment out” portions of code or to use them to fix bugs.
Note: A single-line comment may be enclosed in a block comment, but two
block comments are not allowed.
// line comments
Each line of code in a comment starts with // followed by the subsequent line
of code. They don't take up any memory, just like block comments.
// Such comments can be put in a single line.
In many cases, a single-line comment will be placed after a valid statement to
provide more info about what the statement accomplishes or to remind the
reader.
Variables
Variables are used by the program to name and store a mathematical value.
As their name implies, variables are numbers that can be changed
continuously as opposed to constants whose value stays the same. It is
necessary to declare a variable and optionally assign a value to it with the
goal of storing the value. An analog input pin is connected to a variable
named as input Variable, and its value is assigned to that variable:
int inputVariable = 0;
There are numerous places in which variables can be declared across the
program, and which part of the program uses the variable depends on where
the variable definition is located.
Variable scope
In a program, variables can be declared before void setup(), locally in
functions, and occasionally in for loops within statement blocks. It is
determined where the variable is declared, which calculates its scope, which
determines the program's ability to utilize the variable.
Any function in a program can see and use a global variable. An initialization
variable is declared before the setup() function.
byte
Bytes represent 8-bit numerical values without decimal points. They can
range from 0 to 255.
byte someVariable = 180; // declares 'someVariable'
// as a byte type
int
The integer data type is utilized to store numbers without decimal places and
stores 16-bit data with a range of 32,767 to -32,768.
Note: As long as a variable isn't forced past its maximum or minimum value
due to an assignment or comparison it will roll over. As an example, if x =
32767 and later x is added to by the addition of 1, then x will equal -32,768.
long
Integers stored in 32-bit format, without decimal points, are of extended size
datatype, with a range between 2,147,483,647 to -2,147,483,648.
float
Similarly, arrays can be declared by declaring the array type and size, and
later assigning values to an index position:
Arrays are retrieved by assigning an index position and the array's variable.
For loops also make use of array values in two-dimensional arrays, where the
index position and increment counter for each array value are the same.
Below is an example of flickering LEDs using an array, Within a for loop,
the counter reads the value contained at index spot 0 in the array flicker[], the
PWM pin 10 is set to 180, pauses for 200ms and the index position is moved
to the next position.
byte flicker[] = {180, 30, 255, 200, 10, 90, 150, 60};
// above array of 8
Arithmetic
These mathematical operations include addition, subtraction, multiplication,
and division. Two operands are returned as a product, difference,
sum(respectively) or quotient(respectively).
y = y + 3;
x = x - 7;
i = j * 6;
r = r / 5;
The operands of the operation are based on their data types. Therefore, the
result of 9 / 4 is 2 instead of 2.25 since 9 and 4 are not decimal numbers and
cannot be expressed as fractions. Additionally, if the result of the operation
exceeds the capacity of the data type, the result will overflow.
The larger type is used for the calculation if the operands are of different
types. The calculation will use floating point math if one of the numbers is of
the type float and the other of the type integer.
The variables selected for your calculations should have a large enough size
to hold the largest result. Understand when and how your variable will roll
over, in addition to knowing what happens in the opposite direction e.g. (0 -
1) OR (0 to - 32768). For fractions to be used in math, float variables are
preferable, but they are large and take a long time to compute.
Note: Convert a variable's type on the fly by using the cast operator,
(int)myFloat is an example. For example, 1 = (int) 3.6 will set i equal to 3
Compound Assignments
Examples include x *= 3 which would triple the value of x, which would lead
to a new value of x.
Comparison Operators
Logical operators
True/false
Logic levels are defined by Boolean constants. Typically, TRUE is defined as
one while FALSE is easy to decipher as zero (zero) but can also be anything
other than zero. Therefore, in the Boolean sense, -1, 2, and -200 all have the
same definition of TRUE.
if (b = = TRUE);
{
doSomething;
}
High/low
When reading or writing to digital pins, these constants are utilized to define
pin levels as HIGH or LOW. HIGH is defined as logic level 1, ON, or 5 volts
while LOW is logic level 0, OFF, or 0 volts.
digitalWrite(13, HIGH);
Input/output
The constants utilised to define a pin's mode will be either INPUT or
OUTPUT with the pinMode() function.
pinMode(13, OUTPUT);
if
if (someVariable ?? value)
{
doSomething;
}
Here, the variable someVariable is compared with another value, which may
be a variable or a constant. The statements inside brackets are run if the
condition inside the parentheses is true, A program taking care of the brackets
skips them if they are not present.
Note: Make sure you never accidentally use ‘=’. If (x=10), for example. x is
defined to the value 10 and thus is always true, even though technically it is
valid. It is better to instead use ‘==’, as in if (x==10), which simply checks
that the value x is the same as 10, Think of ‘=’ as “equals” opposed to ‘==’
being ‘is equal to”.
if... else
When used with if...else, a decision can be made either one way or the other.
In other words, if you needed to test digital inputs and perform one thing if
they were HIGH and another if they were LOW, you would write this way:
if (inputPin == HIGH)
{
doThingA;
}
else
{
doThingB;
}
if else tests can also be run before another if test, so that a number of tests
relating to the same thing can be run simultaneously. Moreover, one can have
a limitless number of these other branches. Although there are several
statements, only one set will be run according to the conditions:
for
Note: Some other computer languages include BASIC, but they offer
significantly less flexibility than for loops in C. Although semicolons are
required, any or all of the headers may be omitted. In addition, the statements
for the statement initialization, the condition, or the expression can have any
valid C statement that contains variables unrelated to each other. There may
be some solutions to rare programming problems with these unusual
statements.
while
While loops will continue to loop indefinitely until the argument within the
parenthesis turns false. Unless something changes the variable being tested,
the loop will never terminate. In your code, this can be internal, like an
incremented variable, or outside the code, like testing a sensor.
do... while
do loops work similarly to while loops as they are bottom-driven, except that
at the finish of the loop the condition is tested; therefore, the do loop will
always perform at least once.
do
{
doSomething;
} while (someVariable ?? value);
do
{
x = readSensors(); // assigns the value of
// readSensors() to x
delay(50); // pauses 50 milliseconds
} while (x < 100); // loops if x is less than 100
pinMode(pin, mode)
Following is an example where readSensors() is assigned to the variable ‘x’,
followed by a 50 millisecond delay, and then loops indefinitely until the
value of ‘x’ stops being less than 100:
pinMode(pin, OUTPUT); // sets ‘pin’ to output
Inputs are default for Arduino digital pins, so pinMode() is not required to
declare them as inputs explicitly. Impedance state is said to exist on pins
designated as INPUTS.
The Atmega chip comes with 20KQ pull-up resistors which are easily
accessible from software. There is one way to gain access to these pull-up
resistors:
digitalWrite(pin, value)
Outputs the specified digital pin as either HIGH or LOW. Either a constant or
a variable can be used to define this pin.
analogRead(pin)
This function interprets the value from a 10-bit analog pin. These functions
only work on pins 0-5 in the analog input. There are a total of 1023 possible
integer values.
analogWrite(pin, value)
At 255, a steady 5-volt signal is produced at the specified pin while a value of
0 generates a constant 0-volt output. For values in When the value is 0 to 255,
the pin alternates quickly between 0 and 5 volts. The greater the value, the
fewer times the pin is HIGH (5 volts). The value 64, for example, will be 0
volts three quarters of the time, and 5 volts one quarter of the time; 128 volts
equals 0 volts half the time and 255 volts the other half; and 192 volts equals
0 volts one quarter of the time and 5 volts two-thirds of the time.
As the pin is considered to be hardware, it will continue to generate a wave in
the background until another analogWrite call (or another call to digitalRead
or digitalWrite on similar pin) is received.
Note: Unlike digital pins, analog pins do not need to be stated as INPUT or
OUTPUT beforehand.
This example outputs a PWM signal to a PWM pin when we read an analog
value from an analog input pin, convert the value by dividing it by 4, and
convert it back into an analog value.
int led = 10; // LED with 220 resistor on pin 10
int pin = 0; // potentiometer on analog pin 0
int value; // value for reading
void setup(){} // no setup needed
void loop()
{
value = analogRead(pin); // sets ‘value’ equal to ‘pin'
value /= 4; // converts 90-1023 to 0-255
analogWrite(led, value); // outputs PWM signal to led
}
delay(ms)
A time period of 1000 milliseconds will pause your program.
delay(1000) ; // waits for one second
millis()
The time within milliseconds since the current program began running on the
Arduino board as an unsigned long quantity.
Note: Within approximately 9 hours, this number will overflow and reset to
zero.
min(x, y)
This function finds the smaller number between two numbers of any
information kind and returns it.
max(x, y)
A function that returns the largest number from a set of data types.
randomSeed(seed)
The random() function starts with the value, or seed, specified by random().
The Arduino does not produce a truly random number, so randomSeed lets
you place variables, constants, and functions into the random function, in
order to increase the number of random numbers. Several different functions,
or seeds such as millis() or even analogRead() can be utilized in this function
to read an analog pin's electrical noise.
random(max)
random(min, max)
Note: You need to utilize this after you have utilized the randomSeed()
function.
Below is an example that creates a stochastic value between 0-255 and
outputs on a PWM pin a PVVM signal similar to that quantity.
void loop()
{
randomSeed(millis()); // sets millis() as seed
randNumber = random( 255); // random number from 0-255
analogWrite(led, randNumber); // outputs PWM signal
delay (500); // pauses for half a second
}
Serial.begin(rate)
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.
void setup()
{
Serial.begin(9600); // opens serial port
} // sets data rate to 9600 bps
Note: You cannot use two digital pins at the same time when using serial
communication.
Serial.printin(data)
The printing commands include a carriage return and a line feed, followed by
printing data on the serial port. Printing data on the Serial Monitor is easier
with this command than the Serial.print() command.
Note: Please refer to the Arduino website to learn more about the
serial.printin() and serial.print() functions and their various permutations.
Below is a straightforward example transmitting information every 1 second
from analog pinO to the computer.
void setup()
{
Serial. begin(9600) ; // sets serial to 9600bps
}
void loop()
{
Serial.println(analogRead(0)); // sends analog value
delay(1000) ; // pauses for 1 second
}
Digital output
It simply turns something on or off using a simple ‘hello world’ program. In
this instance, an LED becomes visible by connecting pin13 to GND, which
blinks every second. Due to the Arduino's built-in resistor, it is possible to
omit the resistor on this pin.
Digital input
There are two possible states for this type of input: on or off. We're reading
from pin2 a simple switch or pushbutton. Input pin HIGH turns an LED on
when the switch is closed.
High current output
Controlling more than 40ma can sometimes be necessary with the Arduino.
Switching higher currents could be achieved by utilizing MOSFETs or
transistors. Using an instance, we can rapidly turn the MOSFET on and off
five times a second.
Note: On the schematic the diode is shown only as a protection to the motor.
But other eddy current devices would also be able to be utilized without the
diode.
PWM output
You can read values from 0-1024 using an analog potentiometer and an
analog-to-digital converter (ADC) pin on an Arduino. An LED’s blinking
rate can be controlled by adjusting the potentiometer in the following
example.
Pin definition
LED UNO R3
Long pin -> +5V
Short pin -> GND
Note: Digital signal port 13(D13) is connected to the longest LED on the pin.
Step 2: Make an LED Blink Program using Arduino IDE.
Step 3: Compile the sketch and upload to the Arduino UNO board. A Big
Kudos. As a result, you can see the LED blinking.
Uploading the Program
Ø Please connect your Arduino to your PC with the USB cable before
uploading code.
Ø Select Tools→Board→ Identify your board in the Arduino menu by
looking for Arduino Uno. You can also find the Arduino Mega,
Arduino's smaller cousin, through this menu.
Please make sure that you are connecting to the correct serial port on your
board, The list of accessible serial ports can be found by selecting,
Tools→Serial Port→ comX, as soon as your Arduino is linked to a
Windows laptop, it will take the largest number port, such as COM 3 or
COM 15.
} Click Verify the LED Blink Sketch will be checked
} Click Upload Consequently, the program is sent to the Arduino
microcontroller board
Project 2: Traffic Light 3 Way Controller
Overview:
The previous lesson covered how to get LEDs to light up when you program
the Arduino. Here, we use the Arduino to control various LEDs, and the
LEDs will be colored differently to make the lights shown in the traffic signal
system
Components:
1 x Arduino UNO
1 x USB Cable
3 x 200Ω Resistor
3 x 5mm RED LED
3 x 5mm YELLOW LED
3 x 5mm GREEN LED
1 x Breadboard
Several jumpers wire
Principle:
The experiment used in this lecture is very similar to the lesson in the
previous lesson. Traffic light controller based on an Arduino is an easy
project which is useful to know how traffic lights function in our everyday
lives. The traffic light circuit has been shown in this post. In this circuit, three
sides or ways have been demonstrated. Let's move on to the project.
One of the easiest Arduino projects to understand or code is the Traffic Light
Controller. Traffic Lights are demonstrated on the three-way road using the
LEDs on all three sides in the same method they would really work. This
results in either one of the two sides having two red traffic light signals and
one green light for their neighbour’s side. In between changes from Red to
Green, yellow light remains on, also for 1 second, but at progressively shorter
intervals; in other words, the first 5 seconds are on Red, followed by 1 on
Yellow, before the final second is on Green. The use of traffic control signals
ensures the flow of traffic in an orderly manner. In addition, they are helpful
in reducing the frequency of right-angle accidents. To allow other traffic to
safely cross an intersection, they intercept heavy traffic.
Procedure:
Step 1: Build the circuit
Step 3: The program was compiled and uploaded to the Arduino UNO
board.
As a result, it is possible to keep the traffic flowing at a constant speed on a
given route or route. In certain types of accidents or crashes, including right-
angle crashes, it helps reduce their severity and frequency IIHS concluded
that red-light cameras in all 79 large U.S. cities included in the study saved
nearly 1,300 lives since they were implemented through 2014.
As well as ensuring a smooth flow of traffic, traffic signals provide an
opportunity for pedestrians and vehicles to cross an intersection and reduce
conflicts between vehicles entering intersections from different directions.
The use of traffic control signals ensures the flow of traffic in an orderly
manner. As a result, there will be a decrease in the frequency of an accident
of a special nature, such as an accident at right angles. As a result, heavy
traffic can safely cross the road intersection while heavy traffic is stopped.
Project 3: Push button - LED Blinking
Overview:
We will learn in this lesson how to detect a button's state and toggle the
LED's state based on the button's state.
Components:
1 x Arduino UNO
1 x USB Cable
1 x 220Ω Resistor
1 x 10KΩ Resistor
1 x LED
1 x Push Button
1 x Breadboard
Several jumpers wire
Principle
Button
It is a common component of electronic devices to use buttons to control
them. Connecting and disconnecting circuits is often one of their main
functions. Despite the wide range of button shapes and sizes, we will use a
single 12mm button in this experiment.
A normally open button is what we used. A button has two open contacts
under normal circumstances; only when pressed are they closed. In an open
state (unpressed), no electrical connection exists between the two legs of the
pushbutton. Thus, we read a HIGH reading because the pin is set to 5 volts
(through the pull-up resistor). The button closes (reaches a connection) when
it is pressed, so when it hits a pin, it makes a connection to ground, so we
read LOW. (The pin will still be connected to 5 volts, but the resistor in-
between it will cause it to be closer to ground.)
It seems that the button jitters in the process of use. The jitter waveform can
be seen here:
The Arduino will consider a press of the button as having been made many
times since it will jitter. The jitteriness of the buttons should be dealt with
prior to use. By using software programming, jitter can be eliminated. You
can also solve the issue by using a capacitor. Here's an example of a software
method. The first step is to determine whether the interface consists of low
level or top buttons. If the level of the event is low, a delay of 510ms is
needed. Then determine if you have a low or high level of button interface.
With a low signal volume, you can surmise that the button has been pushed
once. The jitter from buttons can also be avoided by using a 0.1uF capacitor.
Interrupt
A hardware interrupt was implemented to minimize the amount of time spent
waiting for external events in polling loops. Their implementation may take
the form of a distinct system with control lines, or they may appear within the
memory subsystem.
Key functions:
attachInterrupt(interrupt, ISR, mode) Names one or more Interrupt Service
Routines (ISRs) to be named when an interrupt happens.
Procedure:
Step 1: Build the circuit
Schematic:
Step 2: Program: Open /Copy the code from the “CODE” Folder
/*********************************************************
Push button - LED Blinking
**********************************************************/
int ledpin=13;// definition digital interface
int inpin=5;//Define the number 5 Interface
int val;//Define the variable val
void setup() {
pinMode(ledpin,OUTPUT);//Define led as Output
pinMode(inpin,INPUT);//Button interface is defined as input
}
void loop() {
val=digitalRead(inpin);//Read digitalpin 5 level value assigned to val
if(val==HIGH)//Test button is pressed
{
digitalWrite(ledpin,LOW);
}
else {
digitalWrite(ledpin,HIGH);
}
}
Step 3: Now that the code has been compiled and uploaded to the Arduino
UNO board, press the button, and you'll see that the LED will turn ON or
OFF.
Push-buttons turn things on when pressed, completing a circuit. Release of
the button will result in the circuit breaking and turn it off as soon as the
connection is broken. As well as push-button switches, momentary and
normally-open switches are found in computer keyboards, for instance. The
push-button has four pins, but you generally only connect two at a time,
unlike a toggle switch, which stays in one position until you toggle it to the
other. Despite the two unused pins at the bottom of the board being able to do
the same thing, you will be using the top connections on this project.
Project 4: RGB Blinking LED (Common Anode)
Overview:
Schematic:
Common Anode
Procedure:
Step 1: Build the circuit
A matrix keypad will be the most appropriate type of keypad for this
project. There are far fewer output pins on this keypad than there are
keys, allowing it to have much less encoding. There are 16 keys on
the matrix keyboard we are utilizing, but only 8 output pins on the
circuit. If you were to build a linear keyboard, you would have to
put 17 output pins on the board (one for each key and a ground pin).
Matrix encoding saves a lot of connections for the keyboard since
smaller pins need to be utilized to have the keypad work. Because
they require less wiring, they are less inefficient than linear keypads.
Schematic:
The Arduino UNO board uses the digital output pins, D9-D2, when the pins
are connected to the pins. The first pin of the keypad is connected to D9, next
to D8, then to D7, fourth pin to D6, then to D5, next to D4, next to D2, and
the eighth pin to D2. These are the connections in a table.
There is also a code and wiring diagram for a 3X4 matrix keypad. For the
purpose of this article, I'll be utilizing a matrix membrane keypad. It's easy to
stick membrane style keypads to flat surfaces because they have an adhesive
backing. For people who like the telephone style keypad style, there are
thicker buttons as well. Using an Arduino, even an old telephone keypad can
be converted to work with the device.
Procedure:
Step 1: Build the circuit
Step 2: Program
/*****************************************************
Project 05 - Interfacing with Keypad Module
*****************************************************/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the Rows of the keypad pin
8, 7, 6, 5 respectively
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the Columns of the keypad
pin 4, 3, 2, 1 respectively
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins,
colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey); // Send the pressed key value to the arduino serial
monitor
}
}
Step 1:
Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/*********************************************************
File Name: Multiple Tones with One Piezo Buzzer
**********************************************************/
const int buzzer= 8;
void setup() {
pinMode (buzzer,OUTPUT);
}
void loop() {
tone(buzzer,1000);
delay(1000);
noTone(buzzer);
delay(1000);
}
When using pins 3 or 11, you can't simultaneously use tone() and
analogWrite(). Trying to use either of these in the same way results in wacky
results. Since the tone() function for pins 3 and 11 uses the same timer that
analogWrite() does, it's because it uses the same built-in timer. Just for the
sake of hearing the weird noises, it's well worth the effort.
In order to make this circuit work, we installed a photo resistor in analog pin
0 (any analog pin would work) and an auxiliary 5V supply on the right side
of the breadboard. An unsealed 1K ohm resistor is used as a grounding
element. An LED (of any color) was attached to pin 13 of the breadboard (a
digital pin would also work) and it was powered by a 220-ohm resistor (one
hundred ohms would also work). Next, there is a wired LED of a different
color connected to a different digital pin, just as the first LED was.
Procedure:
Step 1: Build the circuit
Step 2: Program
/****************************************************
Project 8 Seeing the light using photo resistor with an Arduino
*****************************************************/
const int sensorPin = 0;
const int ledPin = 9;
int lightCal;
int lightVal;
void setup() {
pinMode(ledPin, OUTPUT);
lightCal = analogRead(sensorPin);
}
void loop() {
lightVal = analogRead(sensorPin);
if (lightVal < lightCal - 50) {
digitalWrite(9, HIGH);
} else {
digitalWrite(9, LOW);
}
}
Step 3: Compile the program and upload to Arduino UNO board.
Project 9: Arduino Flame Sensor
Overview:
We will be studying a flame sensor built with an Arduino board in this
project.
Components:
1 x Arduino UNO
1 x USB Cable
1 x Flame Sensor
1 x Breadboard
Jumper wire
Principle:
The flame detector module on the KY-026 is interacting with a lighter or a
candle through its digital and analog interfaces. When the fire sensor detects
fire, a HIGH signal is sent to the Arduino (pin A0), lighting up the LED. The
detection threshold may be increased by turning the potentiometer
clockwise, or decreased by turning it counterclockwise .
Industrial buildings and commercial buildings are very commonly equipped
with fire alarm systems. Sensors are usually contained in these devices, and
they continuously monitor for flames, gas, and fires in the building and
trigger an alarm if they are detected. IR flame sensors contain an IR
photodiode which is sensitive to IR light and is therefore one of the simplest
ways of detecting fire. In a fire, fire does not only produce heat and light, but
also emits infrared rays, yes, every burning flame emits some degree of
infrared light. Flame sensors detect this light, which cannot be seen by human
eyes, and inform microcontrollers such as Arduino that a fire has been
detected.
A photodiode detects light, and an op-amp determines the sensitivity of the
flame sensor. It detects fire and sends a HIGH signal as soon as it is detected.
The Arduino reacts to the signals and activates the LED and buzzer to
provide alert.
Schematic:
Procedure:
Step 1: Build the circuit
Step 2: Program
/*********************************************************
Project 9 Arduino Flame Sensor.ino Description:
Let, fire is detected by the sensor turning on the LED
**********************************************************/
const int sensorMin = 0; // sensor minimum
const int sensorMax = 1024; // sensor maximum
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorReading = analogRead(A0);
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
switch (range) {
case 0: // A fire closer than 1.5 feet away.
Serial.println("** Close Fire **");
break;
case 1: // A fire between 1-3 feet away.
Serial.println("** Distant Fire **");
break;
case 2: // No fire detected.
Serial.println("No Fire");
break;
}
delay(1); // delay between reads
}
Step 3: Compile the program and upload to Arduino UNO board.
Applications of flame sensors
Detecting fire in Hydrogen stations
Monitors for burner combustion
Petroleum and natural gas pipelines
Production facilities for the automotive industry
Facilities related to nuclear energy
Keeping aircraft in hangars
Enclosures for turbines
Project 10: LED Matrix display 8 x 8 dots (MAX7219)
Overview:
Here we will learn about Arduino Microcontroller connections with 8x8 LED
matrix displays (MAX7219).
Components:
1 x Arduino UNO
1 x USB Cable
1 x Dot Matrix (MAX7219)
1 x Breadboard
Jumper wires
Principle:
Essentially a programmable LED display at a lower cost than conventional
LCD displays, these MAX7219/MAX7221 displays can be driven by either a
microcontroller or a microprocessor. The MAX7219 microprocessor is
equipped with a code-B decoder included in the circuit, MPC scan circuitry,
88-bit static RAM, a segment and digit driver, and a segment decoder (used
for identifying letters and numbers). All segment currents of LEDs can be set
with only one external resistor. A number of interfaces are supported,
including SPI, QSPI, and MICROWIRE, and the MAX7221 has slew-rate-
limited section drivers to minimize EMI. It is possible to address and update
specific numbers in the connected LED display without addressing and
altering the whole display. Attempting to encode each digit in the
MAX7219/MAX7221 can be achieved through code-B decoding the digits or
by leaving they unencoded.
Applications:
MAX7219 utilized in Bar-Graph Displays, 7-Segment Displays, Industrial
Controllers, Electronic Panel Meters, LED Matrix Displays, PIXEL gaming,
Character design, measuring instruments, Hobby projects, Display of
symbols, simple graphics and texts.
Features:
A Breadboard can be easily installed
The LED lights are bright
Designed compactly.
The LED is 3mm in diameter
Schematic:
Two methods can be used to control the LED matrix. It is possible to send
parallel (parallel data for each row or column) or serial (serial data is sent in
serial format and a conversion IC is used to turn it into parallel data). MAX
7219 Driver supports serial and parallel outputs on common cathode displays.
Microprocessors and microcontrollers can be interfaced with 64 LEDs (8 x 8
LED matrix has 64 LEDs, for example), seven segment displays up to 8
digits, or bar graph displays.
Procedure:
Step 1: Build the circuit
Step 2: Program
/**********************************************************
File Name: 10- LED Matrix display 8 x 8 dots (MAX7219).ino Description:
Let, LED Matrix Displays 8×8 dots (MAX7219) Interface with Arduino.
***************************************************/
#include <LedControl.h>
int DIN = 12;
int CS = 11;
int CLK = 10;
byte e[8]= {0x7C,0x7C,0x60,0x7C,0x7C,0x60,0x7C,0x7C};
byte d[8]= {0x78,0x7C,0x66,0x66,0x66,0x66,0x7C,0x78};
byte u[8]= {0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x7E};
byte c[8]= {0x7E,0x7E,0x60,0x60,0x60,0x60,0x7E,0x7E};
byte eight[8]= {0x7E,0x7E,0x66,0x7E,0x7E,0x66,0x7E,0x7E};
byte s[8]= {0x7E,0x7C,0x60,0x7C,0x3E,0x06,0x3E,0x7E};
byte dot[8]= {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18};
byte o[8]= {0x7E,0x7E,0x66,0x66,0x66,0x66,0x7E,0x7E};
byte m[8]= {0xE7,0xFF,0xFF,0xDB,0xDB,0xDB,0xC3,0xC3};
LedControl lc=LedControl(DIN,CLK,CS,0);
void setup() {
lc.shutdown(0,false); //The MAX72XX is in power-saving mode on startup
lc.setIntensity(0,15); // Set the brightness to maximum value
lc.clearDisplay(0); // and clear the display
}
void loop() {
byte smile[8]= {0x3C,0x42,0xA5,0x81,0xA5,0x99,0x42,0x3C};
byte neutral[8]= {0x3C,0x42,0xA5,0x81,0xBD,0x81,0x42,0x3C};
byte frown[8]= {0x3C,0x42,0xA5,0x81,0x99,0xA5,0x42,0x3C};
printByte(smile);
delay(1000);
printByte(neutral);
delay(1000);
printByte(frown);
delay(1000);
printEduc8s();
lc.clearDisplay(0);
delay(1000);
}
void printEduc8s() {
printByte(e);
delay(1000);
printByte(d);
delay(1000);
printByte(u);
delay(1000);
printByte(c);
delay(1000);
printByte(eight);
delay(1000);
printByte(s);
delay(1000);
printByte(dot);
delay(1000);
printByte(c);
delay(1000);
printByte(o);
delay(1000);
printByte(m);
delay(1000);
}
void printByte(byte character []) {
int i = 0;
for(i=0;i<8;i++)
{
lc.setRow(0,i,character[i]);
}
}
Step 3: Compile the program and upload to Arduino UNO board.
Internal structure of an 8*8 LED matrix
First, you must understand a simple LED to understand the LED matrix.
LEDs are powered by DC power with two pins that give out a light. There are
8 numbers of rows and 8 numbers of columns in the matrix. Since LED
positive pins share common ground with those of adjacent LEDs in rows, and
LED negative pins share common ground with those of adjacent LEDs in
columns. One LED will be turned on when the power is turned on and single
rows and columns are selected. A row 3 or column 3 led will come on if
current is applied to those two rows or columns.
The 8x8 LED matrix has the following features
LED matrix can be operated from any device with LOW voltage.
Drawing text or images on the matrix is possible.
Only 1.5-2V are required to drive the matrix in the forward bias.
There is no special requirement for the LED matrix since it can be
designed with simple LEDs.
It may be difficult for some developers to understand the
programming. So, there is a driver that helps simplify the
programming process as well.
It is possible to perform various patterns on the matrix, such as
scrolling and blinking.
Applications for LED matrix
Text signs are the most common application for LED matrix.
It is used most often by developers to create snake games.
In addition to the matrix clock, there are companies that use it
A matrix can also be found on most watches to make it look even
more attractive and unique.
Project 11: Interfacing with LCD 1602 Display
Overview:
This lesson shows you how to use an LCD1602 character display system on
the Arduino environment. Let's display "Hello World!" on the LCD1602 first.
Components
1 x Arduino UNO
1 x USB Cable
1 x potentiometer
1 x LCD (16 x 2) Display
1 x Breadboard
Jumper Wires
Principle
Displays like LCD1602 show characters. Microcontrollers have a parallel
interface, which means that they have to manipulate several interface pins
simultaneously to control the display. Three pins are present on the interface:
pins:
There is a register select RS pin on the LCD that governs where in the ram
you need to write data. The LCD's controller may look for instructions in
either the data register or an instruction register - what goes on the screen has
to be in the data register.
Read/Write pins are used to switch between reading mode and writing mode.
Write access to the register is enabled by an Enable pin. This card contains 8
data pins (D0-D7). When the pins are high or low, the data that is being
written to a register (or read), is represented by bits.
Additionally, there are three display pins (Vo, Bklt+ and Bklt-) as well as
power supply and LED backlight pins to power the LCD and control the
display contrast, respectively.
Display control involves putting data read from the data registers into the
display's instruction register, and then writing commands into the information
registers.
So that you don't have to know these low-level instructions, the Liquid
Crystal Library simplifies these tasks for you. Two modes of control are
available for the Hitachi LCDs: 4-bit and 8-bit. For text displays on the
screen, you can do most anything in 4-bit mode. The 8-bit mode requires 11
I/O pins. Potentiometers have two contacts and at least three terminals each,
making it possible to adjust the voltage divider. If only one terminal and the
wiper are used, the resistor behaves like a variable resistor.
Schematic:
Schematic:
The HC-SR04 can be interfaced in a 3-wire mode
Three-wire mode requires only one connection to a single digital I/O pin on
the Arduino instead of two. The exceptional parallax ping))) sensor is one of
the many ultrasonic sensors that only work in 3-Wire Mode.
One I/O pin is used in both input and output modes in 3-Wire mode. Due to
the fact that inputs and outputs are never used simultaneously, this is
possible. Then we can use the Arduino connection for something else by
eliminating one of the I/O pin requirements. This feature is also useful when
dealing with chips such as the ATtiny85 which have limited I/O pins.
This is how you can connect the HC-SR04 sensor to the Arduino using 3-
Wire mode.
Clearly, you simply need to connect pin 9 of the Arduino to both the trigger
and echo. There is only one difference you need to make in the sketch: you
must define both the Trigger and Echo pin values on pin 9. Everything else in
the sketch is the same.
Procedure:
Step 1: Build the circuit
Step 2: Program
/**********************************************************
File name: 12 – HC-SR04 Project .ino Description:
Let, Distance measure with ultrasonic sensor.************************/
#include <HCSR04.h>
const int TriggerPin = 8; //Trig pin
const int EchoPin = 9; //Echo pin
long Duration = 0;
void setup() {
pinMode(TriggerPin,OUTPUT); // Trigger is an output pin
pinMode(EchoPin,INPUT); // Echo is an input pin
Serial.begin(9600); // Serial Output
}
void loop() {
digitalWrite(TriggerPin, LOW);
delayMicroseconds(2);
digitalWrite(TriggerPin, HIGH); // Trigger pin to HIGH
delayMicroseconds(10); // 10us high
digitalWrite(TriggerPin, LOW); // Trigger pin to HIGH
Duration = pulseIn(EchoPin,HIGH); // Waits for the echo pin to get high
long Distance_mm = Distance(Duration); // Use function to calculate the
distance
Serial.print("Distance = "); // Output to serial
Serial.print(Distance_mm);
Serial.println(" mm");
delay(1000); // Wait to do next measurement
}
long Distance(long time)
{
long DistanceCalc; // Calculation variable
DistanceCalc = ((time /2.9) / 2); // Actual calculation in mm
//DistanceCalc = time / 74 / 2; // Actual calculation in inches
return DistanceCalc; // return calculated value
}
COMPONENTS:
1 x Arduino UNO
1 x USB Cable
1 x Servo Motor
1 x Breadboard
2 x Jumper Wires
Schematic
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/*******************************************************
File name: 15 Control Servo Motor .ino Description:
Let, servo motor rotate
**********************************************************/
# include <Servo.h>
Servo myservo;
int pos = 0;
void setup() {
myservo.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 5) {
myservo.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 5) {
myservo.write(pos);
delay(15);
}
}
Step 3: Compile the program and upload to Arduino UNO board.
Project 16: Stepper Motor Control with Arduino
Overview:
In this lesson we will learn how to control a stepper motor, a stepper motor is
controlled by a stepper motor’s rotational speed through an analog input,
analog input 0. Various control pins are available for unipolar or bipolar
motors including pins 2, 3, 4, and 5.
Components:
1 x Arduino UNO
1 x USB Cable
1 x Stepper Motor
1 x Motor Driver Module
1 x Battery
Jumper wires
Principle
Motors that are operated by a stepper controller require the use of a driver
module. In our case, the motor will not be able to run since the controller
module (Arduino) is not capable of providing enough current through its I/O
pins. A module such as ULN2003 will be utilized.
There are many different types of driver modules that are used as stepper
motors. The rating of each driver module depends on the type of motor used.
Here is a circuit diagram showing how an Arduino stepper motor controller is
implemented. In our setup, we used a Stepper motor 28BYJ-48 as well as the
ULN2003 Driver module. A digital pin 8,9,10 and 11 is used to engage the
four coils on the stepper motor. Powered by the Arduino's 5V pin, the driver
module powers the Arduino Board.
When you connect the steppe motor to a load with an external power supply,
the driver should be powered. The +5V rail of the Arduino Board was used
because it is just being used as a demonstration. Keep in mind that you
should always link the ground of the Arduino to the ground of the Diver
module.
Pin definition
Connecting 28BYJ-48 Stepper Motor and ULN2003 Driver to Arduino
Ø The motor is now ready to be hooked up to our Arduino! We can
begin connecting it to our Arduino now!
Ø The ULN2003 driver needs to be connected to the power supply.
Ø A stepper motor can be powered directly from the Arduino. As the
motor might induce electrical noise onto the Arduino's power supply
lines, this is not recommended since it could cause damage to the
board.
Ø You should therefore use a separate 5V power source for your
stepper motor.
Ø Lastly, connect the ground of the power supply to the ground of the
Arduino. It is very important to establish a voltage reference that is
the same between the two.
Ø Assemble the driver board by connecting pins IN1, IN2, IN3, and
IN4 to the Arduino digital pins 8, 9, and 10.
Ø The motor cable from the stepper motor should then be connected to
the driver board.
Ø Upon completion, the illustration below should look like what you
have done.
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/*********************************************************
File name: 16 stepper Motor Control .ino Description:
Let, Control stepper motor.
*********************************************************/
#include <Stepper.h>
#define STEPS 64
Stepper stepper(STEPS, 8, 9, 10, 11);
int previous = 0;
void setup() {
stepper.setSpeed(30);
}
void loop() {
int val = analogRead(0);
stepper.step(val - previous);
previous = val;
}
Step 3: The motor will rotate clockwise once the program is uploaded to the
Arduino UNO board. Motor speed is increased by increasing the
potentiometer value. You may notice the motor, which is subject to a time
delay, is insensitive to changes in the sensor value when it is running at low
speeds since setSpeed() extends the length of the delay between steps.
The applications of stepper motors
Used in 3D printing equipment, Textile machines.
Various printing presses are used, utilized in the gaming machines.
Machines used in medical imaging, and a small robotics system.
Machines for CNC milling, Typically, welding equipment is used.
There are some benefits associated with stepper motors.
A motion sensor is not required for stepper motors because of their
internal structure. A motor's position can be determined by simply
counting the steps it takes to move.
As well, stepper motors are pretty easy to control. Although the
motor requires a driver, it does not require complex calculations or
tuning. Most motors require less control effort than others. It is
possible to achieve high position precision with micro stepping, up to
approximately 0.007 degrees.
A stepping motor offers good torque, holds positions well, and has a
long lifespan.
Project 17: Interfacing Soil Moisture Sensor with an Arduino
Overview:
We will be studying soil moisture sensors in this project which have been
specially developed to identify how much moisture or water a soil includes.
Components:
1 x Arduino UNO
1 x USB Cable
1 x Soil Moisture Sensor
Jumper Wires
Principle
Soil Moisture sensors are utilized to precisely measure how much moisture
the soil includes. Dielectric constants are measured using capacitance in soil.
As the soil transmits electricity, the dielectric constant can be thought of as
the ability to conduct electricity.
Increased water content of the soil increases the soil's water content. Because
of its higher dielectric constant than any other portion of soil, water is used to
measure moisture in soil sensors. The sensor detects the moisture content in
the soil by generating a voltage proportional to its dielectric permittivity,
which consequently determines how much water is available.
The most important thing for us to take care of plants and turf is to take care
of them regularly when we have a home garden or a backyard with turf.
Watering your lawn and plants with sprinklers is one of the more popular
options, but for the best results, go for manual watering.
You must consider the amount of soil moisture when designing an Automatic
Plant Watering System, in which the water supply is either sprinklers or drip
irrigations.
A Microcontroller and a Water Pump can be used to precisely control the
amount of water supplied to the garden by measuring the soil moisture. By
integrating Soil Moisture with Arduino, I will demonstrate how to monitor
the soil moisture of a small pot.
Schematic:
Procedure:
Step 1: Build the circuit
Circuit
Diagram
Hardware Required
Material diagram Material name Number
LCD1602 1
Water Lever 1
Sensor
220/330Ω resistor 1
10KΩ 1
Potentiometer
USB Cable 1
UNO R3 1
Breadboard 1
Jumper wires Several
PIN Configuration
UNO R3 Water sensor
GND -> -
5V -> +
A0 -> S
UNO R3 LCD1602_IIC
Program
// include the library code:
#include <LiquidCrystal.h>
//initialise the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
void loop() {
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/****************************************************
File name: 19 – Infrared sensor Receiver module KY-022
Let, Only Receiver modules.
****************************************************/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
Overview
Pin definition
The infrared remote can be used to control the Arduino easily. This particular
remote control is available from many sources and is surprisingly affordable.
There are many similarities between them, including how they look and
operate.
A single Arduino is required for this project. The Arduino UNO that I used
should work just about with any Arduino. Connect your infrared receiver to
the kit's power supply. The wiring consists of three wires, PWR, GND, and
SIG. Port 11 was used for SIG. Important! It has been reported that some
readers have different wiring on their sensors. You should check it twice.
Hardware required
Material Material Name Number
diagram
IR Remote 1
IR Receiver 1
USB Cable 1
UNO R3 1
Breadboard 1
Circuit diagram
UNO IR Receiver
R3
D2 -> OUT
GND -> GND
+5V -> VCC
Program
To find the key codes for your remote control, upload this code to your
Arduino and open the serial monitor:
#include <IRremote.h>
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}
void loop(){
if (irrecv.decode(&results)){
Serial.println(results.value, HEX);
irrecv.resume();
}
}
Your computer must be connected to the USB port of the Arduino in order to
upload the sketch. Open up the Serial Monitor, grab the remote, and start
pressing the buttons. On the Serial Monitor, there should be some hex codes.
You can find the remote-control codes here. The FFFFFF command repeats,
so if you keep pressing a button, a stream of them will appear. Now press
each key on your remote and record the hexadecimal code printed for each
key press.
From the remote that came with my HX1838 IR receiver and remote set,
using the program above I derived a table of keys and their corresponding
codes. A 0XFFFFFFFF code will be displayed if you keep pressing the key
continuously.
Hexadecimal code
Key Code
CH- 0xFFA25D
CH 0xFF629D
CH+ 0xFFE21D
<< 0xFF22DD
>> 0xFF02FD
>|| 0xFFC23D
– 0xFFE01F
+ 0xFFA857
EQ 0xFF906F
100+ 0xFF9867
200+ 0xFFB04F
0 0XFF6897
1 0xFF30CF
2 0xFF18E7
3 0xFF7A85
4 0xFF10EF
5 0xFF38C7
6 0xFF5AA5
7 0xFF42BD
8 0xFF4AB5
9 0xFF52AD
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/*****************************************************
File name: 20 –Sound sensor module
*****************************************************/
const int ledPin = 13; //pin 13 built-in led
const int soundPin = 2; //sound sensor attach to A0
int threshold = 600; //Set minimum threshold for LED lit
void setup() {
pinMode(ledPin,OUTPUT);//set pin13 as OUTPUT
Serial.begin(9600); //initialize serial
}
void loop() {
int value = digitalRead(soundPin);//read the value of A0
Serial.println(value);//print the value
if(value > threshold) //if the value is greater than 600
{
digitalWrite(ledPin,HIGH);//turn on the led
delay(200);//delay 200ms
}
else
{
digitalWrite(ledPin,LOW);//turn off the led
}
delay(1000);
}
Step 3: Compile the program and upload to Arduino UNO board.
Project 23: Analog Joystick Module with Arduino
Overview:
This tutorial will demonstrate how to use an analog joystick module. Adding
some control to your projects is straightforward with analog joysticks.
Components:
1 x Arduino Uno
1 x USB cable
1 x Joystick Module
1 x Breadboard
Jumper wires
Principle
Joystick
This module has 5 prongs: Vcc, Ground, X, Y, Key. Its labels may differ
from yours. The module will depend on where you receive it from. With the
thumb stick, you can pull the left side of the control stick to push down, and
the right side of the control stick to push down. Furthermore, you can activate
a „press to select" button by pressing the joystick down (which is quite hard
on mine).
The data from the X/Y pins will be read using the Analog Arduino pins, and
the button will be read with a digital pin. If the joystick is pushed, it connects
to the ground, but it floats otherwise. Key and Select pins must be connected
via a pull-up resistor to Vcc in order to yield stable readings. Digital pins on
Arduino are equipped with built in resistors. The following schematic will
guide you through activating pull-up resistors on Arduino pins that are
designed as inputs.
In terms of analog joysticks, they are similar to two potentiometers connected
together, one for the vertical movement (Y-axis), and another for the
horizontal movement (X-axis). In addition to the joystick, it also has a Select
button. A controller like this can be very handy for retro gaming, robotic
control, and RC cars.
Schematic
Procedure:
Step 1:
Build the circuit
Step 2: Program
/****************************************************
File name: 21 - Analog Joystick Module. No
Description: Let, Analog Joystick Module
***********************************************/
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = A0; // analog pin connected to X output
const int Y_pin = A1; // analog pin connected to Y output
void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);
}
void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
delay(500);
}
Step 3: Compile the program and upload to Arduino UNO board.
Application
A camera's pan/tilt can be controlled
Controls and input for the game, Robotics control
Input of Analog Parameters, and Often used in DIY projects
Game controllers come to mind when we hear the word "Joystick". There are
many applications of the joystick in electronics. They are commonly used in
DIY robotics projects and Arduino-based projects. Having an analog output,
we can use this module to feed in an analog input based on movement or
direction. Alternatively, it can be controlled with a movable camera.
Project 24: Interfacing DHT11 Sensor with Arduino
Overview:
This project will answer all your questions on how to receive humidity and
temperature data using the DHT11 sensor and then send it to Arduino Ultra.
Components
1 x Arduino UNO
1 x USB Cable
1 x DTH11 Temperature Sensor
1 x BreadBoard
Jumper Wires
Schematic:
Procedure:
Step 1: Build the circuit
This is the time when the Arduino IDE software should be running. Next, you
have to install the DHT Sensor library. This can be done via the Arduino
Library Manager:
Look for the "DHT sensor library by Adafruit" within the "dht" search
field. Click "Install" or "Update" if you have an older version installed.
Step 2: Program: Open /Copy the code from the “CODE” Folder
/**********************************************************
File name: 22 Interfacing DHT11 Sensor with Arduino .ino Description: Let,
Showing the temperature using DHT.
**********************************************************/
#include <SimpleDHT.h>
int pinDHT11 = 7;
SimpleDHT11 dht11;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("=================================");
Serial.println("Sample DHT11...");
byte temperature = 0;
byte humidity = 0;
byte data[40] = {0};
if (dht11.read(pinDHT11, &temperature, &humidity, data)) {
Serial.print("Read DHT11 failed");
return;
}
Serial.print("Sample RAW Bits: ");
for (int i = 0; i < 40; i++) {
Serial.print((int)data[i]);
if (i > 0 && ((i + 1) % 4) == 0) {
Serial.print(' ');
}
}
Serial.println("");
Serial.print ("Sample OK: ");
Serial.print((int)temperature); Serial.print(" *C, ");
Serial.print((int)humidity); Serial.println(" %");
delay(1000);
}
Step 3: Compile the program and upload to Arduino UNO board.
Applications
The sensor is used for a wide range of applications, including the
measurement of humidity and temperature in HVAC systems. They can also
be used to predict weather conditions in weather stations. In homes where
humidity affects people, the humidity sensor provides a preventive measure.
The sensor is used for measuring humidity values in offices, cars, museums,
greenhouses, and industries as a safety measure.
This sensor gained popularity among hobbyists because of its small size and
high sampling rate. Besides the DHT11 sensor, there are some other sensors
that can be used instead, such as DHT22, AM2302, SHT71.
Project 25: Temperature and Humidity Monitoring Experiment
Overview
DHT11 1
USB Cable 1
UNO R3 1
Breadboard 1
Jumper wires Several
Connection
diagram
PIN Configure
Program
#include <LiquidCrystal.h>
LiquidCrystal lcd(4, 5, 0, 1, 2, 3);
byte degree_symbol[8] =
{
0b00111,
0b00101,
0b00111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
int gate=11;
volatile unsigned long duration=0;
unsigned char i[5];
unsigned int j[40];
unsigned char value=0;
unsigned answer=0;
int z=0;
int b=1;
void setup()
{
lcd.begin(16, 2);
lcd.print("Temp = ");
lcd.setCursor(0,1);
lcd.print("Humidity = ");
lcd.createChar(1, degree_symbol);
lcd.setCursor(9,0);
lcd.write(1);
lcd.print("C");
lcd.setCursor(13,1);
lcd.print("%");
}
void loop()
{
delay(1000);
while(1)
{
delay(1000);
pinMode(gate,OUTPUT);
digitalWrite(gate,LOW);
delay(20);
digitalWrite(gate,HIGH);
pinMode(gate,INPUT_PULLUP);//by default it will become high due to
internal pull up
// delayMicroseconds(40);
duration=pulseIn(gate, LOW);
if(duration <= 84 && duration >= 72)
{
while(1)
{
duration=pulseIn(gate, HIGH);
else if(z==40){
break;}
i[z/8]|=value<<(7- (z%8));
j[z]=value;
z++;
}
}
answer=i[0]+i[1]+i[2]+i[3];
z=0;
i[0]=i[1]=i[2]=i[3]=i[4]=0;
}
}
As a first step, the Arduino transmits a high to low start signal to DHT11
after a 18s delay to ensure that this device is detected. Once the data line is up
and running, Arduino waits for the data from DHT to come in for a period of
20-40 seconds. With a time, delay of about 80s, DHT sends low voltage level
response signals to Arduino once it detects the start signal. A DHT controller
pulls up the data line and holds it for 80s for the purpose of arranging the data
transmission.
A low voltage level on the data bus indicates that the DHT11 is transmitting a
response. After this is complete, DHT performs data line pull-up for 80s
again to prepare data transmission.
Every bit of data is sent by DHT by 50s of low voltage level and length of
high voltage level signal determining if it is "0" or "1".
Overview
In this project, the control of the LEDs is the same as the LED experiment,
however, the experiment can record time.
Pin definition
Embedded systems and industrial applications using one-digit seven segment
displays commonly known beforehand the range of outputs that will be
displayed. 0-9 numbers, and a few characters, can be displayed on this 7-
segment display. The types of 7 segment displays differ, for example the
number of characters and digits they can display varies. Basic 7 segment
displays can display only one character or one digit, and they are essentially
single units. In multiplexed 7 segment displays, 2 digits, 3 digits, or 4 digits
are shown through the multiplexing of single unit displays. You can connect
your Arduino to a 7-segment display very easily! We'll begin the tutorial
now.
In regards to the number of characters the 7-segment display can display, it
has many limitations. On the market are displays that are much more
advanced than seven segment displays; they are capable of displaying nearly
every alphabetical character. Suppose, for example, that you have a 16*2
LCD – which can display almost any ASCII character. It makes you wonder
why there are still 7 segment displays available on the market today. There is
no doubt that 7 segment displays represent the most affordable option among
display devices available. A 7 segment display capable of displaying one
digit or one character is available for one tenth the price of a LCD module.
The rectangular plastic package contains one of the LEDs' connection pins
which led out from its positional segment. The LED pins are labelled "a"
through "g", with each LED representing one of the individual LEDs. Each
LED pin is connected to another LED pin, forming a common pin. When
Forward Biased in a specific order, some LED segments will brighten but
others will remain dim, thus showing the corresponding character on the
display.
Displays are generally classified according to their common pins. Pin
connections consist of two types: one pin with cathodes connected and
another with anodes connected, indicating Common Cathode (CC) and
Common Anode (CA). CA displays have all the anodes connected to the
cathodes, while CC displays have all the cathodes connected to the anodes.
Hardware required
Material Material Number
Diagram
1 digit LED 1
Segment
Displays
220/330Ω 1
resistor
USB Cable 1
UNO R3 1
Breadboard 1
Jumper wires few
Connection diagram
Note: Pay attention to the direction of digital tube Connection:
UNO SEG
R3
D3 -> C
D4 -> D
D5 -> E
D6 -> G
D7 -> F
D8 -> A
D9 -> B
GND -> COM
Program
// declaring an array of integers
int numbers[] = { 90, 150, 30 };
int a, b;
void setup() {
a = numbers[0] + numbers[1]; // Sets variable a to 240
b = numbers[1] + numbers[2]; // Sets variable b to 180
}
// different ways of declaring arrays of chars
char string1[15];
char string2[7] = {'h', 'e', 'l', 'l', 'o', '!'};
char string3[7] = {'h', 'e', 'l', 'l', 'o', '!', ''};
char string4[] = "hello there!";
int a = 10;
Schematic
Procedure:
Step 1: Build the circuit
Overview
Here you will learn about using an 8x8 dot matrix to make an animated
beating heart.
Pin definition
In this project, we will demonstrate the use of a MAX7219 8x8 LED matrix
with Arduino. We will do this by connecting an 8*8 LED matrix module to
an Arduino Uno board with a MAX7129 LED driver. 64 LEDs (Light
Emitting Diodes) make up an 8*8 LED matrix, which has eight rows and
eight columns. It is therefore known as a LED matrix.
Utilizing different Arduino codes, we will design and generate different LED
patterns; the patterns will be displayed on an LED matrix.
int i = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (i < COUNT) {
Serial.print("i = ");
Serial.println(i);
}
i = i+1;
// i will overflow to -32768 eventually
// printing again
}
// replaces MYLED with number 8
void setup()
{
pinMode(MYLED, OUTPUT);
}
void loop()
{
digitalWrite(MYLED, HIGH);
delay(100);
digitalWrite(MYLED, LOW);
delay(100);
}
Schematic:
Procedure:
Step 1: Build the circuit
Step 2: Program
/*************************************************
File name: 25- Interfacing RC522 RFID Module with Arduino.ino
Description:
Let, RFID module. **********************************/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos
based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println(F("Warning: this example overwrites the UID of your UID
changeable card, use with care!"));
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
}
void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent() || !
mfrc522.PICC_ReadCardSerial() ) {
delay(50);
return;
}
Serial.print(F("Card UID:"));
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print (mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();
byte newUid[] = NEW_UID;
if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
Serial.println (F ("Wrote new UID to card."));
}
mfrc522.PICC_HaltA();
if ( ! mfrc522.PICC_IsNewCardPresent() || !
mfrc522.PICC_ReadCardSerial() ) {
return;
}
Serial.println(F("New UID and contents:"));
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
delay(2000);
}
Step 3: Compile the program and upload to Arduino UNO board.
In this 13.56MHz RFID Card Reader Module based on MFRC522, there is a
low-cost RFID Reader Module that can be used for a wide range of
applications at a low price. An integrated reader/writer IC with a frequency of
13.56 MHz, the MFRC522 is suitable for contactless communication.
In the development of portable hand-held devices and smart meters, the NXP
RC522, a highly integrated RFID card reader working on non-contact
13.56mhz communication, is the best choice since it is low power, low cost
and compact in size.
Project 31: Interfacing Bluetooth module HC-05 with Arduino
Overview:
This project will help you understand the Arduino using the HC-05 Bluetooth
module.
Components:
1 x Arduino Uno
1 x USB Cable
1 x Bluetooth Module HC-05
1 x Breadboard
Jumper wires
Principle:
Bluetooth modules such as HC-05 (master/slave) allow Arduino to
communicate with other devices. Using it, the Arduino can connect to
smartphones, computers or other microcontrollers and exchange information
with them. With Bluetooth communication, you can control robots remotely,
view and store data remotely on your PC or smartphone inside your home,
for example.
PIN Configuration:
Key – Arduino Pin 9
Vcc – Arduino 5v
GND – Arduino GND
TXD – Arduino Pin 10
RXD – Arduino Pin 11
A Brief Introduction to Bluetooth Protocols and Communication
There are several wireless communication methods, such as NRF, ZigBee,
Wi-Fi, and Bluetooth. PAN communication with Bluetooth protocol; a
wireless communication method with a maximum data rate of 1 Mb/S,
working on 2.4 G frequency, at a distance of up to 100 meters is a prevalent
method of wireless communication.
The HC05 Bluetooth module, usually used in electronics projects, is a serial
communications Bluetooth module. The following are important
specifications for the Bluetooth module HC05: An internal antenna is
included with the device. Automatic connection to the last device is available.
Bluetooth data transmission to Arduino
You can connect the HC05 module to a 5V voltage because it has an internal
3.3v regulator. The serial communication pins of the HC05 module operate at
3.3V, so we strongly recommend 3.3V voltage from the power supply.
Modules that receive 5V voltage may be damaged. A resistance division
circuit (5v to 3.3v) should be used between the Arduino TX and module RX
pins to prevent damage to the module. A blue and red LED on each board
blinks every 2 seconds when the master and slave are connected. When they
are not connected, only the blue light blinks every 2 seconds.
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/**********************************************************
File name: 26 – Interfacing Bluetooth module HC-05 with Arduino Let,
Bluetooth module HC 05.
**********************************************************/
// This program shown how to control arduino from PC Via Bluetooth
// Connect ... // arduino>>bluetooth
// D11 >>> Rx // D10 >>> Tx
//Written By Mohannad Rawashdeh
//for http://www.genotronex.com/
// you will need arduino 1.0.1 or higher to run this sketch
void setup()
{
// put your setup code here, to run once:
Genotronex.begin(9600);
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Genotronex.available()) {
BluetoothData=Genotronex.read();
if(BluetoothData=='1') { // if number 1 pressed ....
digitalWrite(ledpin,1);
Genotronex.println("LED On D13 ON ! ");
}
if (BluetoothData=='0')
{ // if number 0 pressed ....
digitalWrite(ledpin,0);
Genotronex.println("LED On D13 Off ! ");
}}
delay(100); // prepare for next data ...
}
Step 3: Compile the program and upload to Arduino UNO board.
AT Commands
In general, typing the command AT+<command>? will prompt the saved
parameter (ex: AT+PSWD? will display the module PIN code). If you enter
AT+<command>=<Param>, you can set the parameter value(ex:
AT+PWSD=0000 to modify the PIN code to 0000).
Following is a list of AT commands:
If everything is setup correctly, enter AT in the serial monitor on the
Arduino IDE. If the communication was successful, it should show OK.
To change the component name, enter AT+NAME=<Param>. The
component should answer OK (Defaut HC-05, Ex: To modification the
name to BTM1 enter AT+NAME=BTM1).
To modify the PIN code, enter AT+PSWD=<Param> . The module
should answer OK(Default 1234 Ex: To change the PIN to 0000 enter
AT+PSWD=0000).
AT+ROLE=<Param> to midy the role of the module as slave or master
(Default 0, Ex: to change the role as master enter AT+ROLE=1, as slave
enter AT+ROLE=0).
To modify the baudrate, enter AT+UART=<Param1>,<Param2>,
<Param3> with Param1, 2 and 3 serial communication parameters:
baudrate, stop bit and parity bit respectively (By default,set to 9600,0,0.
Ex: to modify the baudrate to 115200 enter AT+UART=115200, 0, 0).
There are multiple AT commands available for the HC-05 Bluetooth
module on the Internet.
https://cdn.instructables.com/ORIG/FOR/4FP2/HKZAVRT6/FOR4FP2HKZAVRT6.pdf
Slave Configuration
To set the module as a slave, you can change the name as
AT+NAME=HC05-Slave and choose the communication parameters and the
PIN code that you want. You’ll need to make sure that master and slave as
the same communication parameters.
AT returns OK
AT+NAME=HC05-Slave
AT+UART=9600,0,0
AT+ROLE=0
Enter AT+ADDR to obtain the module address (ex:
+ADDR:98d3:32:21450e)
Master Configuration
The slave module needs to be made master by changing the module's role and
setting the same communication parameters as the master module.
AT returns OK
AT+NAME=HC05-Master
AT+UART=9600,0,0
AT+ROLE=1
The slave module address must be entered in the master module to allows it
to appair: AT+BIND=98d3,32,21450e (replace dots “:” by coma “,”)
How do these AT commands work?
Hayes developed a simple command language from 1981 until 1984 to
control his smart modem, eventually combining a series of short text strings
into instructions for tasks strings which can be combined to produce
commands for operations such as dialing, hanging up, and changing the
parameters of the connection. It is from this point that the idea of enhancing
the Hayes set or the AT commands set and interacting with more devices
with a prefix character is born.
You can interface the Bluetooth modules with AT commands in order to set
their parameters like the other devices. For this reason, before we can use AT
commands on a Bluetooth module, it must first be switched to AT mode. This
tutorial will use the HC-05 and HC-06 Bluetooth modules, which are the
most common Bluetooth modules. If you use a breakout board, you can tell
the difference between these two Bluetooth from the pins
Project 32: Interfacing Thermistor Module with Arduino - To measure
Temperature
Overview:
In this project, we will look at an implementation of the Thermistor Sensor
Module that takes temperature information and converts it into output signals.
Components:
1 x Arduino Uno
1 x USB Cable
1 x Thermal sensor
1 x Breadboard
Jumper wires
Principle:
Temperature is sensed using Thermistor Sensor Module that gives off output
signals. There are two different pins associated with it, each labelled as AO
or DO on the board. Semiconductor materials are used in Thermistor Sensor
Module. NTC thermistors generally have a negative resistance when
subjected to a temperature increase, i.e., they will have negative electrical
resistance if their body temperature increases. An adjustment potentiometer
has been involved in this module to modify the thermistor's sensitivity
towards temperature.
Configure:
Thermistor Arduino
A0 A5
D0 -
G GND
+ 5v
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/**********************************************************
File name: 27 – Interfacing Thermistor Module with Arduino:
To measure Temperature Let, Thermistor sensor module
**********************************************************/
void setup(){
Serial.begin(9600);
}
void loop() {
unsigned int AnalogValue;
AnalogValue = analogRead(A5);
Serial.println(AnalogValue);
delay(1000);
}
Step 3: Compile the program and upload to Arduino UNO board.
Project: 33: DC Motor Direction Control
Overview:
With these projects we have examined how DC Motors can be controlled to
drive forward or to reverse through the use of RGB LEDs.
Components
1 x Arduino UNO
1 X USB Cable
1 x Breadboard
1 x RGB LED
1 x Push Button
1 x Dc Motor
1 x 10kΩ Resistor
Jumper wires
Principle:
Make the RGB LED into the motion indicator and control the rotation of the
DC Motor either clockwise or counter clockwise. There are DC Motors in
everything, from electronic equipment to toys, fans, tools, discs, and pumps.
A DC motor is an actuator that converts DC energy into rotational motion. It
is possible to get a DC motor in different designs: Brushed DC motor,
Brushless DC motor, Geared DC motor, Servo motor, Stepper motor and DC
Linear Actuator.
In different applications such as robotics, precision positioning, and industrial
automation, different types of motors are used.
Motor Driver ICs are used to supply the necessary current to run any DC
motor in a microcontroller-based system. The IC is what drives the DC
motor. They can also control the speed of the motor. Using Arduino as the
motor driver IC, the project aims to control the speed and direction of a DC
motor without the use of an IC.
It is not possible to connect a DC Motor to a Microcontroller since the output
current of the Microcontroller is very small and can't drive the motor.
Applications
A single DC motor can be driven with this circuit without Motor
Driver IC.
It is possible to implement dual H-bridges and connect two motors in
the circuit.
Control of speed and direction of single motors can be achieved by
using this device in simple robotics applications.
Schematic:
The main processing unit of the project is the Arduino. A0 is the Analog Pin
of the Arduino connected to the wiper terminal of the POT. The other
terminals of the POT are connected to Vcc and GND. On the circuit diagram
you can see four transistors connected together.
They connect together as an H - bridge when the load, i.e., DC motor, is in
the middle. In a backward direction, transistor Q1 is the dominant
component, while transistor Q3 is dominant.
Inputs to the transistors are provided by the Arduino. The Arduino pins 3 and
2 are connected to Q4's base and Q1/Q4's base, respectively. A pin 5 is
connected to the base of Q2, and a pin 4 is connected to the base of Q3. A
total of four 1K resistors are used to connect each pin.
We can generate back EMF from DC motors when we change their direction,
as they are inductive loads. The two collectors and emitters of each transistor
are connected together through four diodes in order to eliminate any back
EMF.
Procedure:
Step
1: Build the circuit
Step 2: Write a Program
/**********************************************************
File name: 28 DC Motor Direction Control.ino Description:
Let, DC motor control by RGB LED.
*********************************************************/
const int inputPin=1;
const int blue=3;
const int red=4;
const int motorPin1=5, motorPin2=6;
int dir = LOW;
int prevState=0, currentState=0;
void setup() {
pinMode(inputPin, INPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(red, OUTPUT);
}
void loop () {
currentState=digitalRead(inputPin);
if (currentState!= prevState)
{
if (currentState == HIGH)
{
}
}
prevState = currentState;
if (dir==HIGH)
{
digitalWrite(motorPin1,HIGH);
digitalWrite(motorPin2,LOW);
digitalWrite(blue,HIGH);
digitalWrite(red,LOW);
}
else {
digitalWrite(motorPin1,LOW);
digitalWrite(motorPin2,HIGH);
digitalWrite(blue,LOW);
digitalWrite(red,HIGH);
}
}
Step 3: Compile the program and upload to Arduino UNO board.
Summary
The following chapter should be quite interesting to you, and we presume
that you have practiced more than 30 Arduino Project Ideas as they will be
useful to you in building your dream project. In upcoming sessions, we will
cover How to Troubleshoot and Fix Arduino Issues as well as how to
repurpose your old Arduino.
CHAPTER 5
How to Troubleshoot and Fix Arduino Issues
There are times when your Arduino program and your hardware won't
function as expected. There are a number of causes to this problem, including
software or hardware incompatibility. Using this section, you can
troubleshoot Arduino or ESP8266 and solve hardware and software related
problems.
Can’t Load Programs on Arduino
The right board should make it easy for you to load programs once the
computer program is configured correctly. There are several reasons for why
codes cannot be loaded into the system.
An unknown problem may result from using the incorrect port, using the
wrong drivers, or missing the right drivers. Physical connection problems or
issues with the device's firmware can give rise to hardware problems.
Solution: Verify that the board model is compatible with the configured
model
As a first solution, you should confirm that you have configured the Arduino
model on the program properly. The program's users often select the incorrect
board type. If you haven't already done so, verify the model used within the
Arduino software by going to Tools > Board. You can then reload the code
to see if it was loaded when you selected the right board type.
Also, make sure the board has the right type of microcontroller. Many
Arduino boards, particularly the older ones, feature the ATmega160
microcontroller. In the newer models, an ATmega328 is used. Look at the
board's microcontroller and choose it on the device if you aren't sure which
one to select.
There are also many reasons why the code can't be loaded, such as driver
issues. Make sure the serial port driver is installed by going to Tools > Serial
Port. Make sure to verify this information with a computer connected to the
board.
Your computer's device manager is another place to look. Identify any items
in the device that are marked yellow or unidentified. It might be the Arduino-
specific driver that is causing the problem if you are unaware of the drivers
that are causing the problem. If you need to install a new driver, you can
access its properties and install it by accessing its driver installation tab.
Review the previous chapter for more information about installing drivers.
Solution: Ensure a Functioning Arduino
When the device isn't powered, it may not be detected by your computer. By
viewing its LED, you can determine whether the board itself is receiving
power. There must be some sort of problem with the electric system if it isn't
working. Check the power supply source to see if it's functioning.
Those boards with dual power options need to be set to receive power from
the appropriate source. In the case of USB power, look for a jumper direction
that points towards the side of the USB connector, which means the system
should be powered by this connector. To fix it, re-plug it after disconnecting
it, setting the jumper to ground, and resetting it to power. The LED indicator
should turn on to let you know if it is functioning.
Solution: Reset the Device
Arduino boards come with a reset button, which can be useful if you run into
problems loading codes. By pressing the reset button, the board can be reset.
Hold the button down for several seconds and then reset it. If it doesn't work
after waiting for a few minutes, reload the program.
Solution: Diagnose USB Connection Problem
In most cases, the inconsistency is caused by the hardware itself. If the data
pathway itself is down, the code transfer will not be completed. Change your
USB cable to solve this problem. Diagnosis of the cable problem can be done
in a variety of ways. The board may not be detected if it is plugged into your
computer with the wrong cable. Verify through the Arduino program whether
or not your board has the serial port that should be assigned.
Arduino Software is Not Working
If the previous solution does not work, you can download the
Arduino program. Upon installing the program, make sure it is
loaded
Arduino Software is Freezing and Crashing
It is caused by a program inconsistency that causes Arduino software to
freeze. Programs installed with peripherals, drivers, or other files can conflict
with conflicting programs. By using MS-Config, identify likely conflicting
programs. Disable Start-up programs and services by loading this utility.
Load Arduino software and restart your computer. You might have an issue
with one of your starts up programs, even if the Arduino program loaded
flawlessly. Identify the cause of the problem by testing each program and
service. The result will be necessary to prevent lagging before you can load
Arduino software.
Although the program does not freeze or crash, sometimes it runs slowly.
Additionally, a device on your computer may be causing this issue. It is most
commonly caused by installation of the COM port interfering with loading.
To troubleshoot and disable program causes, use MS-Config again. Connect
all of your computers' other devices to your computer before turning it off.
Connect the device to the computer once it has been turned on. Try opening
the program and taking a look at how it responds.
Don’t Throw Damaged Arduino
Beginners have a high risk of damaging an Arduino PCB q43. This is part of
the learning process, so don't worry about it.
Never discard a board after it has been damaged. It still has value as a way
for you to become familiar with its components. In order to understand how
its parts are assembled, it's recommended that you take it apart. When you are
ready to build a custom board, this information will come in handy.
Essential Resources