KITPARLAND
KS10
Project Guide
ELECTRONIC
EMAIL
2
index
1) Preface..............................................................................3
2) Arduino..............................................................................4
3) Advanced Kit Parland KS10 ................................................5
4) Components in Detail .................................................6
5) Project 1–4x4 Matrix Keyboard......................................10
6) Project 2–RTC Module DS1302 .......................................17
7) Project 3 - DHT11 Sensor with 16x2 LCD Display .............22
8) Project 4–MQ-2 Gas Detector Module.........................27
9) Project 5 - Parking Sensor..............................32
10) Project 6 – Light Sensor with LDR Module ..................39
11) Project 7 – Infrared Control of Servo Motor and
Relay Module .....................................................................43
12) Final Information.......................................................49
13) Notes ....................................................................50
3
Preface
The Advanced Parland KS10 Arduino Kit was developed
especially for those who already have experience with the platform
Arduino, in order to conduct medium complexity experiments
encompassing more components of the KIT.
Considered a complete and low-cost set, it has all
the components necessary to continue knowledge
and even to take the first steps both in terms of programming
how much installation next to the microcontroller platform.
Developed in a didactic and illustrative way, the guide that
accompanies presents the details of each item, in such a way as to
provide greater knowledge and mastery to the user, in addition to
teach the step-by-step of how to execute the proposed projects.
Initially, we will work with the basic considerations about
Arduino, demonstrating a little about 'what it is', 'what it is for' and
what are your connections, which will be demonstrated in a way
self-illustrative throughout this guide.
Next, we will work with the characteristics of each item
which is part of the Advanced Arduino Kit Parland KS10, specifying
each of them, in order to increase and contribute to the
development of the reader's learning and knowledge.
To start the practical work with Arduino, we will learn to
develop and reproduce 7 projects that encompass all the
components of the KIT, where the hobbyist will be able to learn how to join
various components to Arduino.
There is no need to worry, all the projects will be
specified with demonstrative images of the process of
assembly, in addition to detailed example codes with explanations and
comments.
Note: The codes provided for projects 1 to 6 are
available at our GitHub repository through the following
Link: [Link]
Usina-Info. O project 7 is available in
[Link]
UsinaInfo.
4
Arduino
The Arduino Uno is the current 'standard' Arduino board.
market, and probably the best choice for beginners who are
starting to work with the controlling platform. It has
an even greater range of compatibility with accessories and
programs when compared to the other models in the line
Arduino. Furthermore, the ATmega328 microcontroller can be
removed from its socket and replaced, in case you damage it from
some way.
It is an open-source platform for physical computing, based on
in a programming language that allows for the
development of both home automation projects and
robotic.
With Arduino, it is possible to develop interactive objects and
autonomous environments, just connect it to a computer to
that, using the platform available for free download through
do link: [Link] o usuário possa
control actions and interactions of the object or environment from a
remote device.
Known for being a low-cost microcontroller board, the
UNO allows you to do really amazing things when connected to
various types of accessories, such as, for example, sensors, lights,
motors, among others. With it, it is possible to build projects of
interactive display, like robots and then share your
inventions with the world.
5
ComponentsinDetail
The accessories that come with the Advanced Arduino Parland KIT
KS10 are as follows:
1 Organizer Box; 12. 20 Male-Female Fios;
2. 1 Ultrasonic Sensor; 13. 1 Male pin bar;
3. 1 Active Buzzer Module; 14. 1 LCD Display 16x4 Background
4. 1 breadboard with 400 points; Green
5. 1 4x4 Matrix Keyboard; 15. 1 Relay Module;
6. 1 Temperature Sensor 16. 1 LDR Module;
DHT11; 17. 1 RTC Clock Module;
7. 1 MQ-2 Gas Detector; 1 CR2032 3V battery
8. 20 Jumpers Macho-Macho; Lithium.
9. 1 IR control and receiver;
10. 1 Servo Motor SG90;
11. 1 RGB LED KY-016;
6
ComponentsinDetail
Organizer Box
You who work with small products or
tiny components need to have a
organized bench, with a designated place
for each utensil, part, tool. The best
way to keep your workplace
organized and functional is storing the
products, tools, and components in boxes
organizers like this.
RTC Module - DS1302
The Real Time Clock Module RTC - DS1302 is
able to provide the information on hours,
minutes, seconds, day of the week, date, month and
Yes. It automatically adjusts the data.
referring to the months with fewer than 31 days and
also leap years.
Breadboard
Also known as a breadboard or
contact matrix, it is a board with holes and
conductive connections for circuit assembly
experimental electric. The big advantage of the
breadboard for circuit assembly
electronics is the ease of insertion of
components, since it does not require
soldering on the contacts. The protoboard plates
vary from 170 holes to 6000 holes, having
vertical and horizontal connections, following
the kit, one of 400 points.
7
ComponentsinDetail
RGB Module KY-016
The KY-016 RGB Led Module is a board that has
with the aim of facilitating the implementation of
small projects with RGB LED. The RGB LED
has the ability to display a large
number of colors that are originated from
of three primary colors–red, green, and blue.
4x4 Membrane Matrix Keyboard for Arduino -
16 keys
The Arduino 16-digit Matrix Keypad was
developed for application in conjunction with the
microcontroller systems Arduino, AVR, PIC,
ARM, complementing the functions of the boards
microcontrollers. Ideal for sets
electronics that require coding or for
placement of passwords in the systems. It counts
still with numbers from 0 to 9 and letters from "A" to
"D", in addition to having the asterisk (*) key and
hash (#)
Ultrasonic Sensor HC-SR04
The HC-SR04 Ultrasonic Sensor is a sensor that
it can measure distances. It emits an ultrasonic sound at
40,000 Hz (40kHz) that travels through the air and, if there is
an object or obstacle in your way, it
returns to the module. Considering the time of
travel and the speed of sound, is it possible
calculate the distance.
8
ComponentsinDetail
DHT11 Sensor
The DHT11 is a basic digital sensor of
low-cost temperature and humidity. It uses
a capacitive moisture sensor and a thermistor
to measure the surrounding air and emit a signal
digital in the data pin (not necessary)
analog input pins). It is quite simple
to use, but requires a precise calculation
to obtain the data.
Active Buzzer Module
The active buzzer has an oscillating source.
internal, and it will sound as soon as powered on. This
this type of component is widely used in
computers printers copiers,
alarms, electronic toys, electronics
automotive, phones, timers, and others
electronic products for sound devices.
IR Remote Control and Receiver KY-022
An IR remote control (the transmitter) sends
infrared light pulses that represent
specific binary codes. These codes
binaries correspond to commands, like turn on /
turn off and increase the volume. As for the module
receptor KY-022 consists of an IR receiver
1838, a 1kΩ resistor and an LED. It works.
together with the IR transmitter module KY-005.
Compatible with electronic platforms
popular ones like Arduino, Raspberry Pi, and ESP8266
9
ComponentsinDetail
16x2 LCD display with green background
The 16x2 LCD display is commonly used in
various devices and circuits. A 16x2 LCD
it means you can display 16 characters per line
and there are 2 of these lines. In this LCD, each
Character is displayed in a 5x7 pixel matrix.
9g Servo Motor
The servo motor is a small device that
it has an output shaft. This shaft can be
positioned in specific angular positions,
sending a coded signal to the servant. While
the encoded signal exists on the input line, the
the servo will maintain the angular position of the axis. If the
encoded signal changes, the angular position of the axis
also changes.
Relay Module
Relays are electrical switches that use
electromagnetism to convert small ones
electrical stimuli in larger currents. These
conversions occur when electrical inputs
activate electromagnets to form or interrupt
existing circuits.
LDR Sensor Module
The LDR Module is used to detect the presence
of light and measure the intensity of light. The output of
module is high in the presence of light and low in
absence of light. The sensitivity of detection of
signal can be adjusted using the
potentiometer.
10
Project1–MatrixKeyboard
4x4membrane
As the first project, we will learn to use the membrane
matrix along with Arduino. In addition, you will learn
some different ways to program this component.
Matrix keyboards are the type of keyboard that you see in
cell phones, calculators, microwave ovens, locks
of doors, etc.
For DIY electronics, they are a great way to enable
that users interact with your project and are frequently
needed to navigate menus, type passwords, and control
robots.
Membrane keyboards are made of a membrane material.
thin and flexible. There are various models in different sizes: 4 × 3, 4
× 4, 4 × 1, etc, but, regardless of their size, all of them
function in the same way.
In the case of the Kit Parland KS10, we have the following keyboard in hand.
Matrix 4 x 4:
11
Project1-MatrixKeyboard
4x4Membrane
The image to the left represents the component that
we will use for this project while the previous illustration
right, represents all the keys of the component (a total of 16).
Note that below each key there is a special switch for
membrane where all these switches are connected to each other
others with conductive traces below the keys of the component
forming a 4 × 4 matrix.
Project assembly
The operating principle of this component is quite
simple. By pressing a button, one of the lines is activated like this
like a column and this allows the current to flow between them.
For example, see the image below that when the '4' key is
pressed, column 1 and row 2 are activated:
A microcontroller can scan these lines to a state
of the button pressed. To do this, the following procedure is
executed
The microcontroller defines all the column lines and rows.
as an appetizer;
Em seguida, ele escolhe uma linha e a define como HIGH;
After that, he checks the lines of the column one by one.
time
12
Project1–MatrixKeyboard
4x4membrane
If the column connection remains in LOW it means that the
the button on the line was not pressed;
Yes, if it is HIGH, the microcontroller will know which line it was.
defined as HIGH and which column was detected as HIGH
also;
Finally, he knows which button was pressed that
corresponds to the detected row and column.
Now that we know everything about the membrane keyboard, we can
connect it to the Arduino. The connections are quite straightforward. Start
connecting pin 1 of the keyboard to digital pin 9 on the Arduino, pin 2
to digital 8, and so on.
The necessary components for this project are:
1 x 4 x 4 Matrix Keyboard;
1 x Arduino;
Some wires/jumpers.
Observe:
13
Project1–MatrixKeyboard
4x4membrane
Code used
To determine which key was pressed, we need to check
continuously as lines e columns. Fortunately, a
[Link] was written to solve this logic and for what
we can issue simple commands to know which key was pressed
pressed.
To install the library, navigate to Sketch > Include Library >
Manage Libraries ... Please wait for the Library Manager to download
the index of libraries and update the list of installed libraries.
Filter your search by typing 'keypad' and click on the following
illustrated library in the image below:
14
Project1-MatrixKeyboard
4x4membrane
After this step, you are ready to run the following code on
your Arduino:
#include <Keypad.h>
const byte linhas = 4; // 4 Linhas
const byte columns = 4; // And 4 Columns
char membrane[rows][columns] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pinosLinha[lines] = {9, 8, 7, 6}; // Arduino pins that correspond
to the lines
byte columnPins[columns] = {5, 4, 3, 2}; // Arduino pins that correspond
in the columns
Creating an object for your keyboard
Keypad keypad = Keypad( makeKeymap(membrana), pinosLinha, pinosColuna, linhas
, columns );
void setup() {
[Link](9600);
}
void loop() {
15
Project1-MatrixKeyboard
4x4membrane
char button = [Link](); // Reading the buttons
Prints to the serial monitor when pressed
if (button){
The button
[Link](button);
[Link](" foi pressionado");
}
}
To download this code and paste it directly into your IDE, access the
repository da4x4 membraneno GitHub.
In addition, there are some useful functions you can use.
with the object Keyboard.
Some of them are listed below:
char waitForKey()
This function interrupts the execution of the code until someone
press a key. Warning - blocks all other codes until
that a key is pressed. This means no LED flashing,
no update of the LCD screen, nothing but routines of
interruption.
KeyState getState()
This other function returns the current state of any of the
keys. The four states are IDLE, PRESSED, RELEASED, and HOLD.
boolean keyStateChanged()
This one allows you to know when the key changed from a
state to another. For example, instead of just testing a key
valid, you can test when a key was pressed.
16
Project1–MatrixKeyboard
4x4membrane
setHoldTime(unsigned int time)
Define the amount of milliseconds that the user will have to
hold a button until the HOLD state is activated.
setDebounceTime(unsigned int time)
Define the amount of milliseconds that the keyboard will wait
until accepting a new keypress / keyEvent.
addEventListener(keypadEvent)
Triggers an event if the keyboard is used.
I already have some other project ideas using the matrix keypad.
4x4 can be:
Create a locking system with the matrix keyboard and
with Arduino;
Build a safe that uses a system similar to
keyless lock but using a system with the
matrix membrane, and;
Create a vending machine that uses
the keyboard to select the products or a system of
payment for the machine that uses the membrane matrix.
17
Project2-RTCModuleDS1302with
Arduino
In this other project, you will learn about the RTC model.
DS1302 e como exibir na tela do Arduino datas e horas.
It is known that Arduino can control time very
precision using the millis() function, but only from that moment
to which it was connected.
If the little plaque is turned off or a restart is made, the
The microcontroller timer starts at mark 0.
Because of this, the board becomes not very useful in this case.
the real-time being necessary in projects with Arduino.
thus, this problem is solved with the Real-Time Clock module
(RTC).
A RTC module keeps real-time control, using a
internal clock mechanism and a long-lasting battery.
The battery is made of 3V lithium ion and the module is composed of
a 32 kHz crystal and a DS1302 chip on a small board with
five pines.
The DS1302 chip is very energy efficient and can
operate with a 3 V lithium battery for up to 5 years.
See below an illustration of the RTC module with lithium battery
3V that came in your KIT:
Furthermore, the supply voltage of this module is 5V and the
the communication protocol used is I2C, which makes it much easier to
interface of this module with the microcontroller.
18
Project2-RTCModuleDS1302with
Arduino
Project assembly
The necessary components for this project are:
1 x RTC DS1302 Module;
1 x Arduino;
1 x Protoboard (optional);
Some wires/jumpers.
Only two pins (CLK and DAT) are needed to make the
interface with the Arduino, except VCC and GND.
The CLK and DAT pins are actually the SCL and SDA pins.
necessary for I2C communication while RST is the pin of
reinitialization (optional).
The Arduino has pins A4 and A5, specifically for communication.
I2C, but with the help of the code from this tutorial, any pin can
to be used to serve the purpose. This is called a bus
Software I2C.
However, to work with the code that comes next
you should connect the DAT, CLK, and RST pin of the RTC module with
the digital pins 6, 7, and 8 on the Arduino.
Look at this:
19
Project2-RTCModuleDS1302with
Arduino
Code used
Para nosso objetivo, iremos usar a biblioteca do componente e
to download it you must go to:
Tools -> Manage libraries and type "Rtc by
Makuna”na Arduino IDE.
After installation, the examples available with the library
can be used to learn more about the functions and methods of
initialization of the RTC module.
Install the respective library in your IDE
Now, we are ready to write the code to set the date.
and current time read from the RTC module and write to the serial monitor every
second.
Look at this:
#include <ThreeWire.h>
#include <RtcDS1302.h>
// Declares a set of 3 wires that will be used to initialize the object R
20
Project2-RTCModuleDS1302with
Arduino
TC
ThreeWire myWire(6,7,8); // DAT, CLK, RST
RtcDS1302<ThreeWire> Rtc(myWire);
void setup () {
[Link](57600);
Compiled:
[Link](__DATE__);
[Link](__TIME__);
[Link]();
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
PrintData(compiled);
[Link]();
if (![Link]()) {
Common causes: 1) the first time you ran it and the device is
it was not working yet
The device's battery is weak or even missing.
RTC lost confidence in DateTime!
// SetDateTime resets the date and time of the DS1302 chip
[Link](compiled);
}
if ([Link]()) {
RTC was protected against writing, allowing the gr
"evaluation now"
[Link](false);
}
if (![Link]()) {
The RTC was not actively working, starting ag
now
[Link](true);
}
RtcDateTime now = [Link]();
if (now < compilado) {
The RTC is older than the compilation time! (Update
using DateTime)
[Link](compiled);
}
else if (now > compiled)
RTC is more recent than the compilation time. (this is
expected)
else
RTC is the same as compile time! (not expected
Oh, but everything is fine)
}
void loop () {
RtcDateTime now = [Link]();
PrintData(now);
21
Project2-RTCModuleDS1302with
Arduino
if (![Link]()) {
Common causes: 1) the device's battery is weak or even
absent and the line
// the power supply was disconnected
RTC lost confidence in the DateTime!
}
delay(1000);
}
#define count(a) (sizeof(a) / sizeof(a[0]))
void PrintDate(const RtcDateTime& dt) {
char stringData[20];
snprintf_P(stringData,
count(stringData),
PSTR("%02u/%02u/%04u %02u:%02u:%02u")
[Link](), [Link](), [Link]()
[Link](), [Link](), [Link]() ;
[Link](stringData);
[Link]();
}
Don't forget to change the communication speed with the
Monitor Serial from 9600 to 57600, otherwise the date and time values
will not be displayed on your PC screen.
To download this code and paste it directly into your IDE, access the
repository ofoRTC DS1302 Moduleno GitHub.
Some other project ideas using the RTC module
DS1302 are:
Create a digital clock using an LCD display of
a way that it is placed in a strategic location in your home to
to see the hours;
Build an alarm using only a buzzer to
may you wake up at the right time to go to work
or to college/school, and;
Do something more complex than just an alarm with
a buzzer: insert a matrix keyboard to change the
hours, minutes and seconds and display them on an LCD screen
for you to wake up and do your activities.
22
Project3–DHT11Sensorwith
Arduinoand16X2LCDDisplay
The DHT11 is a humidity and temperature sensor that generates a
calibrated digital output. It can be connected to any
microcontroller like Arduino, Raspberry Pi, etc., and obtain results
instantaneous. It is a low-cost humidity and temperature sensor
that offers high reliability and long-term stability.
In this project, we will build a small circuit to make the
Arduino interface with temperature and humidity sensor
DHT11. One of the main applications of the DHT11 sensor connection.
with Arduino it is climate monitoring.
The DHT11 humidity and temperature sensor consists of 3
main components. A resistive type humidity sensor, a
NTC thermistor (negative temperature coefficient for measurement of
temperature) and an 8-bit microcontroller, which converts the signals
analog signals from both sensors and sends a single digital signal.
This digital signal can be read by any microcontroller or
microprocessor for later analysis.
23
Project3–DHT11Sensorwith
Arduinoand16X2LCDDisplay
Project Assembly
The necessary components for this project are:
1 x Sensor DHT11;
1 x 16x2 LCD Display;
1 x 10kΩ Resistor;
1 x Arduino;
1 x Breadboard;
Some wires/jumpers.
Below is a schematic assembly to assist in the assembly of
circuit of the proposed project:
Connect the LCD pins: RS, E, D4, D5, D6, D7 respectively
the digital pins of the Arduino: 12, 11, 5, 4, 3, 2.
You connect the data pin of the DHT11 sensor to the digital pin.
8 of Arduino.
24
Project3–DHT11Sensorwith
Arduinoand16X2LCDDisplay
Code used
After making the connections, we don't need to do anything else,
because the program will take care of everything. Although there is a library
special for the DHT11 module called "DHT", we did not use it in this
tutorial. If you want to use this library, you will need to download it
separately and add it to the existing Arduino libraries.
The written program is based on the data timing diagrams.
provided by the component's datasheet.
The algorithm will make the Arduino automatically read the
sensor data displaying as Humidity and Temperature at
Display LCD.
#include <LiquidCrystal.h>
Define the used ports of the LCD
// LiquidCrystal(RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte symbol_degrees[8] =
{
0b00111,
0b00101
0b00111
0b00000
0b00000
0b00000
0b00000
0b00000
};
int DHT11 = 8;
volatile unsigned long duration=0;
unsigned char i[5];
unsigned int j[40];
unsigned char value=0;
unsigned response=0;
int z=0;
int b=1;
void setup()
{
[Link](16, 2);
[Link]("Temp = ");
[Link](0,1);
[Link]("Humidity = ");
[Link](1, degree_symbol);
25
Project3-DHT11Sensorwith
Arduinoand16X2LCDDisplay
[Link](9,0);
[Link](1);
[Link]("C");
[Link](13,1);
%
}
void loop()
{
delay(1000);
while(1)
{
delay(1000);
pinMode(DHT11,OUTPUT);
digitalWrite(DHT11,LOW);
delay(20);
digitalWrite(DHT11,HIGH);
pinMode(DHT11,INPUT_PULLUP);//by default, it will be HIGH due to the internal pull
o
// delayMicroseconds(40);
duration=pulseIn(DHT11, LOW);
if(duration <= 84 && duration >= 72)
{
while(1)
{
duration=pulseIn(DHT11, HIGH);
if(duration <= 26 && duration >= 20) {
valor=0;}
else if(duracao <= 74 && duracao >= 65){
valor=1;}
else if(z==40){
break;
i[z/8] |= value << (7 - (z % 8));
j[z]=value;
z++;
}
}
response=i[0]+i[1]+i[2]+i[3];
if(response==i[4] && response!=0)
{
[Link](7,0);
[Link](i[2]);
[Link](11,1);
[Link](i[0]);
}
27
Project4-GasDetectorModule
MQ2
The MQ2 is one of the commonly used gas sensors in the series of
MQ sensors. It is a metal oxide semiconductor type gas sensor.
(MOS), also known as a chemical resistor, as the detection
is based on the change in resistance of the detection material
when the gas comes into contact with the MQ2 where a network is used
simple voltage divider that detects different concentrations of
gas.
The MQ2 gas sensor operates at 5V DC and it can detect
concentrations of LPG, smoke, alcohol, propane, hydrogen, methane and
carbon monoxide anywhere from 200 to 10000 ppm (parts
per million.
The output analog voltage provided by the sensor changes in
proportion to the concentration of smoke/gas. The greater the
the higher the gas concentration, the higher the output tension; while,
lower gas concentration results in low output voltage.
To calibrate the gas sensor, you can hold it close to
smoke / gas that you want to detect and turn its potentiometer on the part
the back of the component until the red LED starts to shine.
Turn the screw clockwise to increase sensitivity
or counterclockwise to decrease sensitivity.
Observe:
28
Project4–GasDetectorModule
MQ2
Project Assembly
The necessary components for this project are:
1 x MQ2 gas sensor module;
1 x Arduino;
1 x Breadboard;
Some wires/jumpers.
Now that we have a complete understanding of how the sensor of
MQ2 gas works, we can connect it to our Arduino!
This task is very simple to do. Start by inserting the
connect the sensor pins on your breadboard. Connect the VCC pin to the 5V pin on
Connect the GND pin to the ground pin on the Arduino.
Connect the output pin D0 of the module to digital pin 8 and the pin
from output A0 in the module to analog pin 0.
When you finish, you will have something similar to the following
illustration:
29
Project4-GasDetectorModule
MQ2
Now that we have connected our gas sensor, it's time to write the
code to test the component is right below.
30
Project4–GasDetectorModule
MQ2
Code used
The code plays the role of continuously reading the voltage.
analog on pin A0. It also prints a message on the
monitor serial when smoke is detected.
Look at this:
#define MQ2pin (0)
float sensorValue; // Variable that stores the sensor value
void setup()
{
[Link](9600); // Sets the serial port at 9600 bps
Starting MQ2 Gas sensor!
delay(20000); // Allows for the initialization of the Detector
}
void loop()
{
valorSensor = analogRead(MQ2pin); // Lendo a entrada analógico do pino 0
Sensor Value:
[Link](sensorValue);
if(sensorValue > 300)
{
[Link](" | Gas detected!");
}
[Link]("");
delay(2000); // Wait for 2 seconds for the next measurement
}
To download this code and paste it directly into your IDE, go to the
repository ofDetector MQ2no GitHub.
When the gas concentration is high enough, the sensor
usually produces a value greater than 300.
We can monitor this value using the if statement and when the
value of the sensor exceeds 300, display the message 'Detection'
of smoke!
Instead of just displaying the message on the serial monitor,
we can put the following ideas into practice:
31
Project4-GasDetectorModule
MQ2
Create an air quality monitoring system
inside your residence or another location like yours
work environment;
Build a circuit for early fire detection in
your kitchen or another place that can easily catch fire
and create an emergency call system for the
police or to your own phone;
Outline an action to take when detecting gas to turn on or
turn off a relay that is connected to an actuator or something
similar to eliminate the propagation of the gas.
32
Project5-ParkingSensor
In this project, we will use 3 types of components and we will
build something similar to parking sensors used in
cars.
For this, we have several different ways to calculate
distances with the Arduino. One of them is through the sensor
infrared, which uses the properties of light to calculate the
distance.
The second way, which we will apply in this project, is
use the ultrasonic sensor, which uses the propagation properties
do some, more specifically ultrasound, to measure distances.
Note: These types of sound waves are above the spectrum
audible to humans.
The operation is very simple. The sensor sends a wave.
ultrasonic through the trigger, ricochets off the object and the receiver or
echo detects the wave. Knowing how long this wave took to
travel, we can know the distance.
33
Project5-ParkingSensor
Finally, we incorporated the visual alert system into the project with the
use of an RGB Module that will allow us to see if we are
far, near, or in a danger zone of an obstacle, colors
green, blue, and red respectively:
And to complement the project, we will use the module of
active buzzer for an audible alert that increases in frequency
as the object approaches the sensor.
The buzzer works based on the reverse piezoelectric effect.
Connecting the component to a digital port, just send it.
a signal at a high logic level to make the component beep.
It has 3 terminals, one is positive, the other is negative and
end the signal.
34
Project5–ParkingSensor
Project assembly
This is a circuit that requires a little more caution.
mounting compared to the previous ones.
In order to build this circuit, we will need the following:
1 x Ultrasonic Sensor;
1 x LED RGB KY-016;
1 x Active buzzer module;
1 x Arduino Uno;
Some wires/jumpers.
No diagrama a seguir as conexões com os componentes pode ser
better observed where, on one hand, all the acoustic alerts and
visuals and, on the other hand, the ultrasonic sensor:
35
Project5–ParkingSensor
Pay attention to the components and their connections:
The respective red pin of the RGB LED will
connected to pin 4 of the Arduino, the blue to pin 3 and the green
no pin 2;
The ultrasonic sensor connects to two digital pins of the
Arduino: one for the trigger (pin 5) and another for the echo
(pine 6), and;
The Arduino buzzer connects to the PWM output of pin 9.
Code used
After learning more about how the sensor works
ultrasonic and the rest of the components of the project, it is important
denote that now you will write a program that will read
constantly the information from the proximity sensor and, of
according to the distance measured by the sensor, the color red, blue or
the green LED RGB will light up and the Buzzer will beep.
For this to happen you will use the following conditions:
if the distance is between 30 cm and 20 cm, the color green will
turn on and the Buzzer will beep at a frequency of 2000 Hz;
If the distance is between 20 cm and 10 cm, the color blue will
turn on and the Buzzer will beep at a frequency of 2500 Hz;
3. if the distance is below 10 cm, the color red will
turn on and the Buzzer will beep at a frequency of 3000 Hz;
Look here:
Used pins
#define LEDverde 2
#define blueLED 3
#define redLED 4
#define TRIGGER 5
36
Project5–ParkingSensor
#define ECHO 6
#define BUZZER 9
// Constants used
const float sound = 34300.0; // Velocidade do som em cm/s
const float limit1 = 30.0; // Distance limits in cm
const float limit2 = 20.0;
const float limit3 = 10.0;
void setup() {
Start the assembly circuit
[Link](9600);
Pin input/output mode
set mode of green LED to output
set the pin mode of LEDazul to OUTPUT;
Set the mode of LEDvermelho to OUTPUT;
set pin mode of ECHO to INPUT
pinMode(TRIGGER, OUTPUT);
pinMode(BUZZER, OUTPUT);
Function that turns off the LEDs
turnOffLEDs();
void loop() {
Prepare the ultrasonic sensor
initializeTrigger();
Get the distance
float distance = calculateDistance ();
Turn off the LEDs
turnOffLEDs();
Alert if within the danger zone
if (distance < limit1)
{
Trigger the alerts
alerts(distance);
}
// Function to turn off the LEDs
void turnOffLEDs()
{
digitalWrite(greenLED, LOW);
digitalWrite(blueLED, LOW);
digitalWrite(redLED, LOW);
37
Project5-ParkingSensor
Check if any visual or audible alert is needed
void alerts (float distance) {
If the distance is between limit1 and limit2
if (distance < limit1 && distance >= limit2){
Turn on the Green LED
digitalWrite(greenLED, HIGH);
tone(BUZZER, 2000, 200);
}
If the distance is between limit2 and limit3
else if (distance < limit2 && distance >= limit3) {
Turn on the blue LED
digitalWrite(blueLED, HIGH);
tone(BUZZER, 2500, 200);
}
If the distance is less than limit3
else if (distance < limit3) {
Turn on the red LED
digitalWrite(redLED, HIGH);
tone(BUZZER, 3000, 200);
}
}
Function used to calculate the distance between the sound and the object
float calculateDistance() {
unsigned long time = pulseIn(ECHO, HIGH);
float distance = time * 0.000001 * sound / 2.0;
[Link](distance);
[Link]("cm");
[Link]();
delay(500);
return distance;
}
// Function used to initialize the Trigger
void initializeTrigger() {
digitalWrite(TRIGGER, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER, LOW);
}
38
Project5-ParkingSensor
To download this code and paste it directly into your IDE, access the
repository ofParking Sensorno GitHub.
If you want to improve the proposed project you can
incorporate more LEDs and add longer distances. In addition,
change the frequencies of your Buzzer to higher numbers or
minors.
If you want to go further, you can put the following ideas into practice:
Create a digital ruler using the LCD, RGB display or
more LEDs and the Ultrasonic sensor;
Integrar o sensor de luminosidade LDR, que veio no seu
KIT, along with the Ultrasonic sensor to create a
type of home automation. The system will, with the
relay assistance (which also came in your KIT), detect if
whether there is light or not and if there is movement in the environment
and will turn on or off the lights in your house.
39
Project6-LightSensorwithLDR
In this penultimate project, we will use the LDR module and you will
learn to configure it to detect changes in light
easily.
This component is based on a light-dependent resistor
(LDR), an operational amplifier LM393 and a potentiometer
for intensity adjustment.
Normally, the resistance of the LDR will decrease when the
ambient light intensity increases. This means that the signal of
the output of this module will be high in bright light and low in the dark. The output
analog is identified in the component as AO.
See an illustration of this module:
Another important factor, as already mentioned, is the
utility of the module in adjusting light sensitivity. This is possible
adjusting the value of the potentiometer.
Observe:
40
Project6–LightSensorwithLDR
Project assembly
The circuit we need to build is quite simple and you
It shouldn't have too many problems configuring it.
The necessary components are:
1 x RGB LED Module KY-016;
1 x Photoresistor;
1 x Arduino;
Some jumpers/wires.
With everything in hand, pay attention to the following assembly:
41
Project6–LightSensorwithLDR
When it is dark, the resistor will have a very high resistance.
from up to 10 MegaOhms. When it is clear, it will have only a few
hundreds of ohms of resistance.
In this way, you can approximately discover the
resistance looking at the technical sheet of the device. It is likely that it
refer to 'lux' the unit of illuminance and provide information about it
approximate resistance at a certain lux value.
The RGB LED in our circuit will represent the current amount of
resistance in the photoresistor.
It will be green when it is in low resistance (lots of light);
Blue will remain when there is medium resistance in the LDR.
(shaded)
Finally, the red will light up when it is high
resistance (very dark).
Code used
When the connections are ready, we can upload.
Arduino code:
Define all the variables used and their respective pins
int greenLED = 2;
int yellowLED = 3;
int LEDvermelho = 4;
int sensorLDR = A0;
int valorA0 = 0;
void setup() {
// Define the LEDs as outputs
pinMode(greenLED, OUTPUT);
setPinMode(LEDyellow, OUTPUT);
pinMode(redLED, OUTPUT);
// Initialize the serial monitor at a rate of 9600 bps
[Link](9600);
}
void loop() {
The variable receives the analog value read from the sensor
42
Project6–LightSensorwithLDR
valorA0 = analogRead(sensorLDR);
// Print to the Serial monitor
Read value:
[Link](valorA0);
if(valorA0 < 50){ // If it is dark
digitalWrite(redLED, HIGH);
}
else if(valorA0 >= 50 && valorA0 <= 150){ // Neither too dark nor too light
digitalWrite(yellowLED, HIGH);
}
else{
digitalWrite(LEDgreen, HIGH); // Very bright
}
Delay of 2ms for the reading to be processed
delay(200);
All LEDs are turned off
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(LEDred, LOW);
}
To download this code and paste it directly into your IDE, visit the
repository ofLDRno GitHub.
Some extra implementations:
You can use the photoresistor in a light-sensitive alarm of
how you know when an environment changes its state
natural lighting;
As an alternative, you can use the same configuration in
an alarm clock to wake you up as it goes
dawning of the day;
Furthermore, you can use an LDR to activate lights when
it starts to get dark. For example, this would work well if
you have outdoor lights that illuminate some external part of
your house or something similar, but just want them to be
they occur when reaching a certain level of darkness.
43
Project7-InfraredControlof
ServoMotorandRelayModule
For this last project, we will use a system of
infrared communication and through this, control the position of
servo motor and the operation of a relay module.
The infrared signal can come from any remote control that uses
this technology, however for this project we will use the control
infrared forwarded along with the kit.
In this way, the control will send the signal to a receiver.
infrared and the same will communicate with the Arduino,
informing the button that was pressed through the respective code
received.
The SG90 Micro Servo Motor integrated into the project is a motor that
enables precise control through angles, allowing for variation in
your position from 0 to 180º using the keyboard.
Due to its small size and easy adaptability, the Micro
SG90 Servo Motor is widely used to control the position of
objects, such as robot legs, arms or hands, moving sensors
with high precision and mobility, such as the Robotic Arm
in MDF.
44
Project7-InfraredControlof
ServoMotorandRelayModule
Most servos come with the brown color sequence,
red and yellow, but can also be found in black
red and white in which we can classify each color as follows
way
Brown or black: GND;
Red: 5VCC;
Yellow or white: Digital Signal (PWM).
To further enhance our project and to conclude,
we added a relay module to the connection diagram, device
widely known to those who work in electronics and that
has the ability to control the flow of the electric grid.
Through the Relay Module we can control the on and off of
equipment such as lamps, fans and equipment
various electronics. Its application is widely developed and
for this reason, it easily adapts to various projects.
Project Assembly
The connection of this project is not complicated, however there is a fact
very important in it regarding the feeding of the Module
Infrared, as we can see in the connection diagram, it is
being powered separately next to pin 3.3V.
45
Project7–InfraredControlof
ServoMotorandRelayModule
This separate feeding must be done due to the excessive
current consumption of the servo, which sometimes ends up interfering with the
functioning of infrared communication.
The necessary components for the project are:
1 x IR Control and Receiver;
1 x Relay Module;
1 x Servo Motor SG90;
1 x Arduino;
1 x Protoboard;
Some wires/jumpers.
In the connection scheme below, we can observe all the
project connections, however remember that if you choose to
use of other pins, not those indicated in the diagram, these
they must also be changed in the code used.
The IR Receiver Signal pin must be connected to pin 4 of
Arduino, the signal pin of the relay module on pin 5 and finally, the pin of
The servo motor signal must be connected to pin 9 of the Arduino UNO.
46
Project7-InfraredControlof
ServoMotorandRelayModule
Used Code
For our project, we will use two libraries, one of them
What is the Servo.h library that is available when we install it?
our Arduino IDE on the computer, but the library IRremote.h
It needs to be installed so we can use the controller and the receiver.
IR.
To install the library, follow the steps outlined below.
at the beginning of this manual through the following steps (p.3):
Tools -> Manager libraries -> Type "IRremote"
Install the following item listed in the image below:
After installation, all the examples and functions of this same
will be available and operational whenever called through the
function "#include".
Having all the items mentioned above in accordance with
specifications, it's time to upload our code and
to get our project up and running.
Look at this:
47
Project7-InfraredControlof
ServoMotorandRelayModule
#include <IRremote.h>
#include <Servo.h>
Servo servo;
int pinoreceptor = 4;
int rele = 5;
int servomotor = 9;
int angle = 0;
float command;
IRrecv receptor(pin receptor);
decode_results result;
void setup() {
[Link](9600);
[Link]();
setPinMode(rele, OUTPUT);
[Link](servomotor);
void loop() {
if ([Link](&result)) {
[Link]("0x");
[Link]([Link], HEX);
command = ([Link]);
if (command == 0xFF6897) { // Button '*'
digitalWrite(relay, HIGH);
}
if (command == 0xFFB04F) { // Button "#"
digitalWrite(rele, LOW);
}
if (command == 0xFF18E7) { // Up Button
[Link](0);
}
if (command == 0xFF4AB5) { // Down Button
[Link](180);
}
[Link]();
}
delay(10);
}
48
Project7–InfraredControlof
ServoMotorandRelayModule
The code is preconfigured to work with the
buttons listed in the same, however it is worth noting that these can
They should be exchanged whenever necessary, according to the needs.
individuals.
Every button pressed generates a specific code that
can be viewed through the serial monitor, to change or include
any element to the code just copy this code and use it
wherever you wish.
if (command == 0xFFB04F) { // Button "#"
digitalWrite(rele, LOW);
}
In the above code, '0x' represents the beginning of the IR code and 'FFB04F'
it's the code we took from the serial monitor.
Other uses for the project:
The project can be modified to accommodate a password system.
for triggering the relay module through the infrared remote control,
for example, and even be used with the most diverse
available infrared control models.
49
FinalInformation
After completing the 7 projects developed in this guide, we you
we invite you to adapt the codes and apply them in robotic projects
simplified or home automation, since there are no limits to the
designers and hobbyists who work with programming of
Arduino microcontroller platform.
In addition, we recommend you access the Automation site and
IOT of our partnerFlávio Babosfor more definitive projects and
complete articles on electronics, Arduino, IoT, and systems
embarked.
Moreover, when you feel ready, we invite you to get to know
our category ofRoboticswith amazing components waiting
for you to bring projects to life with various functionalities and take
your ideas off the paper by taking your knowledge to the next one
level.
Continue improving your projects more and more in a
professional and of quality with exclusive products that you
find only on the UsinaInfo online store website
([Link] which still has the largest
diversity of sensors and modules for Arduino available at
Brazil.
We thank you for your preference and invite you to visit the Blog of
UsinaInfo([Link] which weekly
There is content waiting for you.
50
Notes
51
Notes
INDUSTRIAL PLANT, TRADE AND IMPORT
INFORMATICS PRODUCTS LTD
CNPJ: 07.182.837/0001-48
R. Marechal Floriano, 2183
CEP: 98802-275
Saint Angel/RS
Tel.: (55) 3313-2778
E-mail: contato@[Link]
[Link]