Kit Smart Home For Arduino KS0085
Kit Smart Home For Arduino KS0085
com
1. Overview:
The smart home kit based on Arduino is newly issued by Keyestudieo company.
You could remotely control your assorted smart systems through your phone or
computer when you’re out, like turning on air conditioner and water heater on the
way home; the electronic door lock and led light will automatically run when you
get home.
1
www.keyestudio.com
Additionally, the intelligent lighting system can be used to select preset lighting
your brain completely relaxed. You just need a remote control to finish all the
process. What surprises you is that the smart system can save electricity as well.
As Bill Gates puts it, in the future, homes without smart home systems will be as
Contents
1. Overview........................................................................................................................ 1
2. Kit List............................................................................................................................. 4
5. Projects.........................................................................................................................32
2
www.keyestudio.com
7.Resources.................................................................................................................... 174
3
www.keyestudio.com
2. Kit List
UNO )
4
www.keyestudio.com
6 Button Sensor 2
7 Photocell Sensor 1
10 Relay Module 1
13 Fan module 1
5
www.keyestudio.com
14 Steam Sensor 1
15 Servo Motor 2
18 USB Cable 1
6
www.keyestudio.com
Pillar
7
www.keyestudio.com
Description
Keyestudio PLUS control board is fully compatible with Arduino IDE development
environment. It contains all the functions of the Arduino UNO board. Moreover,
some improvements we made highly strengthen its function. It is the best choice
to learn how to build circuit and write code as well. Let’s get started!
8
www.keyestudio.com
SPI communication interface: D10 is SS, D11 is MOSI, D12 is MISO, D13 is SCK
Introduction:
When we get control board, we need to download Arduino IDE and driver firstly.
https://www.arduino.cc/en/Main/OldSoftwareReleases#1.5.x.
9
www.keyestudio.com
There are various versions of the IDE in the official link, here we download a
10
www.keyestudio.com
Click “Browse” and select another folder. Click “Install” to start the installation.
11
www.keyestudio.com
12
www.keyestudio.com
Finish the download, now, let’s install the driver of keyestudio PLUS control board.
included in it.
13
www.keyestudio.com
14
www.keyestudio.com
15
www.keyestudio.com
16
www.keyestudio.com
should see the corresponding COM port as the figure shown below.
17
www.keyestudio.com
There are driver files for each Windows system in the link:
https://www.silabs.com/products/development-tools/software/usb-to-uart-bridg
e-vcp-drivers
computer)
18
www.keyestudio.com
Please refer to the following link for installing driver on MAC system
https://v.qq.com/x/page/s0367yegedj.html
Next to show how to install the driver on Windows system, open driver file, as
shown below.
19
www.keyestudio.com
below.
20
www.keyestudio.com
21
www.keyestudio.com
should see the corresponding COM port as the figure shown below.
22
www.keyestudio.com
To avoid the errors when uploading the program to the board, you need to select
the correct Arduino board that matches the board connected to your computer.
Then come back to the Arduino software, you should click Tools→Board, select
23
www.keyestudio.com
Then select the correct COM port (you can see the corresponding COM port after
24
www.keyestudio.com
25
www.keyestudio.com
Before uploading the program to the board, let’s demonstrate the function of
26
www.keyestudio.com
F- Used to send the serial data received from board to the serial monitor.
27
www.keyestudio.com
Description
In the experiments, you might often use ARDUINO control board and several
sensor modules. If the interfaces of power output is not enough, you may need to
But now, with this keyestudio sensor shield, you can easily solve that problem.
This shield is fully compatible with keyestudio PLUS Control Board, so you can
This keyestudio sensor shield has extended the digital and analog ports out as
3PIN interface (G,V, S), which can directly connect 3PIN sensor modules.
28
www.keyestudio.com
It also breaks out some communication pins of 2.54mm pitch, like serial, IIC, and
SPI communication.
The shield comes with a reset button and 2 signal indicators as well.
Additionally, you can supply the voltage needed to the sensor modules through
blue terminal blocks on the shield. Because some sensor modules is not used with
Parameter:
Breakout all the digital and analog ports of keyestudio PLUS Control Board as
3PIN headers
You can supply the voltage needed for sensor modules via terminal blocks.
Pins Description:
29
www.keyestudio.com
When SE is connected with jumper cap, and input DC 7V to VCC /GND terminal
When SE is connected with jumper cap, and VCC /GND terminal block without
voltage input, shield is powered via PLUS control board, so the voltage of V, V1
30
www.keyestudio.com
When SE is disconnected, and VCC /GND terminal block without voltage input,
shield is powered via PLUS control board, so the voltage of V pin is 0V, the voltage
Example Use
Stack the Keyestudio Sensor Shield V5 on the Keyestudio PLUS Control Board, and
31
www.keyestudio.com
5. Projects
When you get this kit, there are 14 sensors/modules inside like keyestudio
We firstly stack Keyestudio Sensor Shield V5.2 on the keyestudio PLUS control
board and connect 14 sensors to sensor shield via dupont lines, upload the test
Note: In this course, the interface of each sensor / module marked with
(G,-, GND) indicates the negative pole, and G and GND are connected to
Arduino board or the sensor shield; V, +, and VCC stands for positive
pole, they are linked with V, VCC and 5V of Arduino board or sensor
shield.
Description:
In this kit, there are white and yellow LED modules. Their operating method is
same. In this lesson, we directly connect the white LED module to the sensor
32
www.keyestudio.com
shield with three female-to-female DuPont cables. After wiring, we can upload
code on the keyestudio PLUS control board to control white LED to display
different colors.
After GND and VCC are powered on, the LED lights up when the signal terminal S
is HIGH, and the LED turns off when signal end S is LOW.
Specifications:
Size: 30 * 20mm
Weight: 3g
Equipment:
Sensor shield * 1
USB cable * 1
33
www.keyestudio.com
Connection Diagram:
Note: The G, V, and S ports of the white LED module are separately
Test Code:
*************************************************************
************************************
void setup()
34
www.keyestudio.com
void loop()
*****************************************************************
********************************
Test Result:
Upload the test code successfully. After power on, the white LED starts blinking,
35
www.keyestudio.com
Description
In this project, we will control the red LED brightness via PWM.
In the previous course, we introduced how to control the yellow LED on and off by
code. Similarly, you can change the step length and delay in the code to set the
PWM is a means of controlling the analog output via digital means. Digital control
is used to generate square waves with different duty cycles (a signal that
constantly switches between high and low levels) to control the analog output.In
general, the input voltage of port are 0V and 5V. What if the 3V is required? Or
what if switch among 1V,3V and 3.5V? We can’t change resistor constantly. For
For the Arduino digital port voltage output, there are only LOW and HIGH, which
correspond to the voltage output of 0V and 5V. You can define LOW as 0 and
HIGH as 1, and let the Arduino output 500 0 or 1 signals within 1 second.
The output port is 2.5V, which is like showing movie. The movie we watch are not
the human can’t tell it. So does PWM. If want different voltage, need to control
the ratio of 0 and 1. The more 0,1 signals output per unit time, the more accurate
the control.
36
www.keyestudio.com
In the following figure, the green line represents a period, and its value is the
reciprocal of the PWM frequency. In other words, if the frequency of the Arduino
PWM is 500 Hz, then the period between the two green lines is 2 ms. The range
(255) means 100% duty cycle (normally open), and analogWrite (127) duty cycle
Specifications:
Size: 30 * 20mm
Weight: 3g
Equipment:
Sensor shield * 1
USB cable * 1
Connection Diagram:
Note: The G, V, and S ports of the yellow LED module are separately
38
www.keyestudio.com
On the sensor expansion board, the G, V, and S pins of the yellow LED module are
Test Code:
*****************************************************************
********************************
void setup(){
void loop(){
delay(500);//delay in 500ms
39
www.keyestudio.com
delay(500);//delay in 500ms
}}
*******************************************************
******************************************
Test Result:
Upload test code successfully and power on, yellow LED gradually become
1. Description
There are many interactive works that can be completed with Arduino. The most
common element is buzzer and speaker. Buzzer is easy to use. And buzzer
40
www.keyestudio.com
concludes in active buzzer and passive buzzer. In this experiment, we make the
Specifications:
Equipment
Sensor shield * 1
USB cable * 1
Connection Diagram:
41
www.keyestudio.com
Note: The G, V, and S port of the passive buzzer module are separately connected
Test Code:
*****************************************************************
********************************
void setup(){
42
www.keyestudio.com
void loop(){
delay(250);//delay in 250ms
delay(250);//delay in 250ms
tone(3,330);
delay(250);
tone(3,349);
delay(250);
tone(3,392);
delay(250);
tone(3,440);
delay(250);
tone(3,494);
delay(250);
tone(3,532);
delay(250);
delay(1000);
*****************************************************************
********************************
43
www.keyestudio.com
Test Result:
Upload test code on keyestudio PLUS Control Board, wire according to connection
Description:
In this project, we will control LED to light on and off via button module.
When the button is pressed, the signal end outputs low level (0); when
Specifications:
Size: 34 * 22 * 15mm
Weight: 3.8g
Equipment
44
www.keyestudio.com
Sensor shield * 1
Button module * 1
USB cable * 1
Connection Diagram:
Note: The G, V, and S pins of button sensor module are separately connected to G,
V, and 4 on the shield, and the G, V, and S pins of the yellow LED module are
45
www.keyestudio.com
Test Code:
*****************************************************************
********************************
void setup(){
void loop(){
delay(500);//delay in 500ms
if (digitalRead(4) == 0)
else
46
www.keyestudio.com
}}
*****************************************************************
********************************
Test Result:
Upload test code, wire according to connection diagram, when the button is
pressed, serial monitor displays 0 (low level ), yellow LED is on; when
Description
This module is an arduino dedicated module, and compatible with arduino sensor
expansion board. It has a control system (also called an input loop) and a
47
www.keyestudio.com
control circuits, it is an "automatic switch" for high voltage which control a larger
current and a lower voltage with a smaller current and a lower voltage.
conversion circuit in the circuit. It allows Arduino to drive loads below 3A, such as
LED light strips, DC motors, miniature water pumps, solenoid valve pluggable
interface.
and static contact (normally closed contact) F, (as shown in the figure ).
As long as a certain voltage is applied to both ends of the coil, a certain current
will flow through the coil to generate electromagnetic effects, and the armature
will attract the iron core against the pulling force of the return spring under the
action of electromagnetic force attraction, thereby driving the moving contact and
the static contact (normally open contact) to attract. When the coil is
disconnected, the electromagnetic suction will also disappear, and the armature
will return to the original position under the reaction force of the spring, releasing
the moving contact and the original static contact (normally closed contact). This
48
www.keyestudio.com
pulls in and releases, thus achieving the purpose of turning on and off in the
circuit. The "normally open, normally closed" contacts of the relay can be
distinguished in this way: the static contacts on off state when the relay coil is not
energized are called "normally open contacts"; the static contacts on state are
called "normally closed contact". The module comes with 2 positioning holes for
Specifications:
Interface: G, V, S interface
Contacts: static contacts (normally open contacts, normally closed contacts) and
moving contacts
Weight: 15g
49
www.keyestudio.com
Equipment:
White LED * 1
USB cable * 1
Connection Diagram:
50
www.keyestudio.com
Note: On the shield, the G, V, and S pins of 1-channel relay module are connected
Test Code:
*****************************************************************
********************************
void setup(){
void loop(){
51
www.keyestudio.com
connected,LED is on
delay(500);//delay in 500ms
disconnected,LED is off
delay(500);//delay in 500ms
Test Result:
Wire, power up and upload the code. The relay is connected(“NO” is on , NC is off)
for 0.5s, then disconnected for 0.5s (NC is on, NO is off), and alternately. When
the relay is connected, the white LED is on, otherwise, the white LED is off.
52
www.keyestudio.com
Description
module. The signal end of the module is connected to the analog port of the
microcontroller. When the light intensity increases, the resistance decreases, and
the voltage of the analog port rises, that is, the analog value of the
microcontroller also goes up. Otherwise, when the light intensity decreases, the
resistance increases, and the voltage of the analog port declines. That is, the
analog value of the microcontroller becomes smaller. Therefore, we can use the
photoresistor sensor module to read the corresponding analog value and sense
circuit as well.
Specifications:
Weight: 2.3g
53
www.keyestudio.com
Equipment:
USB cable * 1
Connection Diagram:
54
www.keyestudio.com
Note: On the expansion board, the G, V, and S pins of the photocell sensor
module are connected to G, V, and A1; the G, V, and S pins of the passive buzzer
module are linked with G, V, and 3 respectively; the G, V, and S pins of the yellow
55
www.keyestudio.com
Test Code:
*****************************************************************
********************************
void setup(){
void loop(){
delay(500);//delay in 500ms
delay(250);//delay in 250ms
delay(500);//delay in 500ms
56
www.keyestudio.com
delay(250);//delay in 250ms
delay(500);//delay in 500ms
tone(3,330);
delay(250);
digitalWrite(5,HIGH);
delay(500);
tone(3,349);
delay(250);
digitalWrite(5,LOW);
delay(500);
tone(3,392);
delay(250);
digitalWrite(5,HIGH);
delay(500);
tone(3,440);
delay(250);
digitalWrite(5,LOW);
delay(500);
57
www.keyestudio.com
else
}}
*****************************************************************
********************************
Test Result:
Wire according to connection diagram, burn the code, and set the baud rate to
9600 after powering on with USB cable. When the value displayed on serial
monitor is less than or equal to 600, the yellow LED flashes and the passive
buzzer sensor plays music; otherwise, the yellow LED is off, and the passive
58
www.keyestudio.com
59
www.keyestudio.com
Description
When we make this kit, we often control doors and windows with servos. In this
course, we’ll introduce its principle and how to use servo motors.
circuit board, core-less motor, gear and position sensor. Its working principle is
that the servo receives the signal sent by MCU or receiver and produces a
reference signal with a period of 20ms and width of 1.5ms, then compares
Servo motor comes with many specifications. But all of them have three
connection wires, distinguished by brown, red, orange colors (different brand may
Brown one is for GND, red one for power positive, orange one for signal line.
The rotation angle of servo motor is controlled by regulating the duty cycle of
PWM (Pulse-Width Modulation) signal. The standard cycle of PWM signal is 20ms
(50Hz). Theoretically, the width is distributed between 1ms-2ms, but in fact, it's
between 0.5ms-2.5ms. The width corresponds the rotation angle from 0° to 180°.
But note that for different brand motor, the same signal may have different
rotation angle.
60
www.keyestudio.com
One is to use a common digital sensor port of Arduino to produce square wave
with different duty cycle to simulate PWM signal and use that signal to control the
Another way is to directly use the Servo function of the Arduino to control the
motor. In this way, the program will be easier but it can only control two-contact
motor because for the servo function, only digital pin 9 and 10 can be used.
The Arduino drive capacity is limited. So if you need to control more than one
Specifications:
No-load speed: 0.12 ± 0.01 sec / 60 (DC 4.8V) 0.1 ± 0.01 sec / 60 (DC 6V)
No-load current: 200 ± 20mA (DC 4.8V) 220 ± 20mA (DC 6V)
Stopping torque: 1.3 ± 0.01kg · cm (DC 4.8V) 1.5 ± 0.1kg · cm (DC 6V)
Connection Diagram:
Note: The servo is connected to G (GND), V (VCC), 9. The brown wire of the servo
62
www.keyestudio.com
is connected to Gnd (G), the red wire is connected to 5v (V), and the orange wire
Test Code:
*****************************************************************
********************************
pinMode(servopin, OUTPUT);
digitalWrite(servopin,HIGH);
pulsewidth
pinMode(servopin, OUTPUT);
digitalWrite(servopin,LOW);
63
www.keyestudio.com
void setup(){
void loop(){
to 90°
*****************************************************************
********************************
Test Result:
Upload code, wire according to connection diagram, and power on. The DIP
64
www.keyestudio.com
Description
The L9110 motor control chip is applied on Keyestudio L9110 motor control
module. It can control the rotation direction and speed of the motor so as to
The module is compatible with servo motor control. This module is efficient with
Specifications:
Working voltage: 5V
Equipment:
Sensor shield* 1
65
www.keyestudio.com
USB cable * 1
Connection Diagram:
Note: On the shield, the GND, VCC, INA, and INB pins of the fan module are
respectively connected to G, V, 7, 6.
Test Code:
*****************************************************************
********************************
66
www.keyestudio.com
void setup(){
void loop(){
digitalWrite(7,LOW);
digitalWrite(6,HIGH);
delay(3000);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
delay(1000);
digitalWrite(7,HIGH);
digitalWrite(6,LOW);
delay(3000);
*****************************************************************
********************************
67
www.keyestudio.com
Test Result:
Upload test code, wire according to connection diagram, the DIP switch is dialed
to right side and power on. The fan rotates counterclockwise for 3000ms, stops
Description
This is a commonly used steam sensor. Its principle is to detect the amount of
water by bare printed parallel lines on the circuit board. The more the water is,
the more wires will be connected. As the conductive contact area increases, the
output voltage will gradually rise. It can detect water vapor in the air as well. The
steam sensor can be used as a rain water detector and level switch. When the
humidity on the sensor surface surges, the output voltage will increase.
68
www.keyestudio.com
Arduino series microcontrollers. When using it, we provide the guide to operate
steam sensor and Arduino control board. Connect the signal end of the sensor to
the analog port of the microcontroller, sense the change of the analog value, and
It comes with the 3pin with 2.54mm pitch. Connect it to control board with
dupont lines. We particularly design the shield compatible with this sensor and
keyestudio PLUS control board. You just need to stack shield to keyestudio PLUS
control board and connect them together with 3pin dupont lines.
Note: the connect part is not waterproof, don’t immerse it in the water please.
Specifications:
Size: 35 * 20 * 8mm
Weight: 2.2g
S: signal output
69
www.keyestudio.com
Equipment:
Sensor shield * 1
Servo * 1
Yellow LED * 1
USB cable * 1
Connection Diagram:
70
www.keyestudio.com
Note: On the sensor shield, the pins G,V and S of steam sensor are connected to
G, V and A3; the pins G, V and S of photocell sensor are connected to G, V and A1;
the pins G, V and S of yellow LED are linked with G, V and 5; the brown line is
71
www.keyestudio.com
Test Code:
*****************************************************************
********************************
Servo servo_9;
void setup(){
void loop(){
Serial.print("illumination");
Serial.print(" ");
Serial.print("humidity");
72
www.keyestudio.com
A3
delay(500);//delay in 500ms
//if the analog value of A3≥500 and the analog value of ≤ 450
delay(200);//delay in 200ms
else
//otherwise
//if the analog value of A3 is less than 500 and the analog value of A3 is greater
than 450
delay(200);//delay in 200ms
}}}
*****************************************************************
********************************
73
www.keyestudio.com
Test Result:
Upload test code successfully, wire according to connection diagram. When put a
drop of water on steam sensor and cover the photocell sensor, the analog value of
steam sensor will increase on serial monitor, the analog value of photocell sensor
will gradually go down, the yellow LED will light on, servo will rotate to 0°.
However, when wipe off the water drop and the photocell sensor is under strong
light, the analog value on the serial monitor will gradually decline, the analog
value of photocell sensor will gradually increase, yellow LED will be off, and servo
Description
The Pyroelectric infrared motion sensor can detect infrared signals from a moving
74
www.keyestudio.com
pyroelectric infrared sensors are much more bigger, with complex circuit and
lower reliability. Now we launch this new pyroelectric infrared motion sensor,
pyroelectric infrared sensor, and the connection pins. It features higher reliability,
Specifications:
Special note:
2. When testing, first open the white lens, you can see the rectangular sensing
part. When the long line of the rectangular sensing part is parallel to the ground,
75
www.keyestudio.com
3. When testing, the sensor needs to be covered with white lens, otherwise it will
4. The distance is best at 25℃, and the detection distance is shortened when it
exceeds 30℃.
5. Done powering up and uploading the code, you need to wait 5-10 seconds then
Equipment:
USB cable * 1
Connection Diagram:
76
www.keyestudio.com
Note: On the shield, the G, V and S of PIR motion sensor are connected to G, V
and 2; the GND, VCC, INA and INB of fan module are separately connected to
G,V,7,6. The pin G, V and S of LED module are linked with G, V and 13.
77
www.keyestudio.com
Test Code:
*****************************************************************
********************************
void setup(){
void loop(){
delay(500);//delay in 500ms
if (digitalRead(2) == 1)
78
www.keyestudio.com
} else
digitalWrite(7,LOW);
analogWrite(6,0);
}}
*****************************************************************
********************************
Test Result:
Upload test code, open serial monitor, and set baud rate to 9600. If PIR motion
sensor detects the people around, the serial monitor displays “1”, the D13 and
white LED light on at same time, fan rotates. If there is no person around, the
serial monitor shows “0”, the D13 indicator and white LED stops rotating.
79
www.keyestudio.com
Description
This gas sensor is used for household gas leak alarms, industrial combustible gas
alarms and portable gas detection instruments. And it is suitable for the detection
of liquefied gas, benzene, alkane, alcohol, hydrogen, etc., and widely used in
various fire alarm systems. The MQ-2 smoke sensor can be accurately a multi-gas
detector, and has the advantages of high sensitivity, fast response, good stability,
80
www.keyestudio.com
It can detect the concentration of flammable gas and smoke in the range of
It must be heated for a period of time before using the smoke sensor, otherwise
the output resistance and voltage are not accurate. However, the heating voltage
should not be too high, otherwise it will cause my internal signal line to blow.
dioxide adsorbs oxygen in the air and forms negative ion adsorption of oxygen,
resistance value. When in contact with flammable gas in the air and smog, if the
potential barrier at the grain boundary is adjusted by the smog, it will cause the
smoke or flammable gas can be obtained. The greater the concentration of smoke
or flammable gas in the air, the greater the conductivity, and the lower the output
resistance, the larger the analog signal output. The sensor comes with a
positioning hole, which is convenient for you to fix the sensor to other devices. In
81
www.keyestudio.com
Specifications:
Weight: 7.5g
Equipment:
Sensor shield* 1
Passive sensor*1
fan module * 1
USB cable * 1
Connection Diagram:
82
www.keyestudio.com
Note: On the shield, the pin GND, VCC, D0 and A0 of gas sensor are linked with
pin GND, VCC, D0 and A0. Pin GND, VCC, INA and INB of fan module are
connected to G,V, 7 and 6. The pin G,V and S of passive buzzer are connected to
G,V and 3; the pin G, V and S of yellow LED are connected to G,V and 5.
Test Code:
*****************************************************************
********************************
83
www.keyestudio.com
void setup(){
void loop(){
digital11
delay(500);//delay in 500ms
//if the analog value of A0 is greater than 45 and the digital value of digital11 is 0
delay(125);//delay in 125ms
digitalWrite(7,LOW);
84
www.keyestudio.com
analogWrite(6,200);//set the PWM value of digital6 to 200, the bigger the the
delay(200);//delay in 200ms
delay(200);//delay in 200ms
} else
//otherwise
digitalWrite(7,LOW);
analogWrite(6,0);
}}
Test Result:
Upload test code, wire according to connection diagram and power on. When
gas sensor detects the flammable gas, passive buzzer will sound, fan will rotate
and yellow LED will be on; when there is no flammable gas, the passive buzzer
won’t sound, the fan won’t rotate and yellow LED will be off.
85
www.keyestudio.com
Description
keyestudio 1602 I2C module is a 16 character by 2 line LCD display with Blue
The original 1602 LCD needs 7 IO ports to be up and running, but ours is built
This LCD is ready-to-use because it is compatible with the Arduino Liquid Crystal
Library. LCDs are great for printing data and showing values. Adding an LCD to
your project will make it super portable and allow you to integrate up to 32
On the back of LCD display there is a blue potentiometer. You can turn the
Notice that the screen will get brighter or darker and that the characters become
86
www.keyestudio.com
Specifications:
Adjustable contrast
Equipment:
USB cable * 1
Connection Diagram:
87
www.keyestudio.com
Note: there are pin GND, VCC, SDA and SCL on 1602LCD module. GND is linked
SCL to SCL.
Test Code:
*****************************************************************
********************************
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C mylcd(0x27,16,2);
//set the communication address of I2C to 0x27 , set to 1602 for display ( 16
88
www.keyestudio.com
void setup(){
mylcd.init();
mylcd.backlight();
void loop(){
mylcd.setCursor(0, 0);
mylcd.print("Hello World!");
mylcd.setCursor(0, 1);
mylcd.print("");
delay(300);//delay in 300ms
*****************************************************************
********************************
89
www.keyestudio.com
Test Result:
Upload the test code, wire according to connection diagram and power on. 1602
LCD shows “Hello World!” at first line and rolls to the left.
Note: Wire according to connection diagram, upload the code, and after power-on,
when the display doesn’t show characters, you can adjust the potentiometer
behind the 1602LCD and backlight to make the 1602LCD display the
Description
This is a simple soil humidity sensor aims to detect the soil humidity.
If the soil is in lack of water, the analog value output by the sensor will decrease;
otherwise, it will increase. If you use this sensor to make an automatic watering
device, it can detect whether your botany is thirsty to prevent it from withering
Using the sensor with Arduino controller makes your plant more comfortable and
your garden smarter. The soil humidity sensor module is not as complicated as
90
www.keyestudio.com
you might think, and if you need to detect the soil in your project, it will be your
best choice. The sensor is set with two probes inserted into the soil, then with the
current go through the soil, the sensor will get resistance value by reading the
current changes between the two probes and convert such resistance value into
moisture content. The higher moisture (less resistance), the higher conductivity
the soil has. Insert it into the soil and then use the AD converter to read it. With
the help of this sensor, the plant can remind of you: I need water.
Specification
Output Voltage: 0-2.3V (When the sensor is totally immersed in water, the voltage
will be 2.3V) the higher humidity, the higher the output voltage
Size: 63 * 20 * 8mm
Weight: 2.5g
91
www.keyestudio.com
Equipment
1602 LCD * 1
USB cable * 1
Connection Diagram
92
www.keyestudio.com
Note: On the shield, the pin G, V and S of soil humidity sensor are connected to G,
V and A2; GND of 1602LCD is linked with GND of ICC communication, VCC is
Test Code:
*****************************************************************
********************************
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C mylcd(0x27,16,2);
//Set the I2C communication address to 0x27 and the display to 1602 (16
void setup(){
mylcd.init();
mylcd.backlight();
93
www.keyestudio.com
void loop(){
Serial.print(" ");
delay(500);//delay in 500ms
// Display the "value" character from the first character in the first line
mylcd.setCursor(1-1, 1-1);
mylcd.print("value:");
//Display the value of variable value from the seventh character at the first line
mylcd.setCursor(7-1, 1-1);
mylcd.print(value);
//Display the "dry soil" character from the first character in the second line
mylcd.setCursor(1-1, 2-1);
mylcd.print("dry soil");
delay(300);//delay in 300ms
94
www.keyestudio.com
//else if the variable value is greater than or equal to 300 and less than or equal
to 700
//Display the "value" character from the first character in the first line
mylcd.setCursor(1-1, 1-1);
mylcd.print("value:");
//Display the value of variable value from the seventh character of the first line
mylcd.setCursor(7-1, 1-1);
mylcd.print(value);
//Display the "humid soil" character from the first character on the second line
mylcd.setCursor(1-1, 2-1);
mylcd.print("humid soil");
delay(300);//delay in 300ms
//Display the "value" character from the first character in the first line
mylcd.setCursor(1-1, 1-1);
95
www.keyestudio.com
mylcd.print("value:");
//Display the value of variable value from the seventh character of the first line
mylcd.setCursor(7-1, 1-1);
mylcd.print(value);
//Display the "in water" character from the first character in the second line
mylcd.setCursor(1-1, 2-1);
mylcd.print("in water");
delay(300);//delay in 300ms
*****************************************************************
********************************
Test Result:
Connect according to wiring diagram, and burn the program. After powering on,
open the serial monitor and insert the soil sensor into the soil. The greater the
humidity is, the bigger the number, in the range of 0-1023. The soil sensor is
inserted into the soil and water with different humidity, and the 1602LCD displays
96
www.keyestudio.com
In 21th century, technology has changed our life. People can work at home
with wireless device like mouse, earphone, printer and speaker, which highly
Bluetooth can make work at home easily, as well as the entertainment. Users
can control wirelessly the audio file from PC or Apple iPod within 30 inches.
Bluetooth technology can also be used in adapters, allowing people to share their
building personal area networks (using UHF radio waves in the ISM band of 2.4 to
2.485 GHz).
This kit is equipped with the HM-10 Bluetooth module, which is a master-slave
machine. When use as the Host, it can send commands to the slave actively;
when use as the Slave, it can only receive commands from the host.
The HM-10 Bluetooth module supports the Bluetooth 4.0 protocol, which not only
97
www.keyestudio.com
In the experiment, we default use the HM-10 Bluetooth module as a Slave and
the cellphone as a Host. We install the Bluetooth APP on the mobile phone,
connecting the Bluetooth module; finally use the Bluetooth APP to control the
We also provide you with 2 types of mobile APP, for Android and iOS system.
Pins Description
As input pin, short press control, or input single pulse of 100ms low
98
www.keyestudio.com
connected state
Parameters:
command.
99
www.keyestudio.com
during transmission.
Power supply: 5V DC
Description:
In the previous lesson, we’ve introduced the basic parameter principle of HM-10
Bluetooth module. In this project, let's show you how to use the HM-10 Bluetooth
100
www.keyestudio.com
There are 16 control buttons in the app. When we connect the HM-10 Bluetooth
module and app, only press control button of APP, and the Bluetooth of cellphone
sensor or module according to the corresponding key control character. Next, let’s
Enter google play,search “keyes IoT”,if you can’t search it on app store, please
https://play.google.com/store/apps/details?id=com.keyestudio.iot_keyes
Download Link:https://pan.baidu.com/s/1xE1kGjG3CroPNH3-HgF6pQ
After installing and open the app ,the interface pops up as below:
101
www.keyestudio.com
Upload code and power on, Led of Bluetooth module blinks. Start Bluetooth and
102
www.keyestudio.com
103
www.keyestudio.com
below:
104
www.keyestudio.com
(4) Upload the test code successfully, insert the Bluetooth module and power on.
“connect” on the left to search Bluetooth and pair. After paring successfully, the
Note: Remove the Bluetooth module please, when uploading the test code.
Otherwise, the program will fail to upload. Connect the Bluetooth and Bluetooth
4. Connection Diagram
105
www.keyestudio.com
Note: On the sensor expansion board, the RXD, TXD, GND, and VCC of the
Bluetooth module are respectively connected to TXD, RXD, GND, and 5V, and the
STATE and BRK pins of the Bluetooth module do not need to be connected.
Test Code:
*****************************************************************
********************************
void setup(){
106
www.keyestudio.com
void loop(){
}}
*****************************************************************
********************************
module
Function:disconnect Bluetooth
107
www.keyestudio.com
intensity detected by
“S” value;
sensor
108
www.keyestudio.com
sensor
capacity detected by
Press to send “k”;
steam sensor,”water”
Press again to send
changes into data
“S”
value;
counterclockwise
109
www.keyestudio.com
window is closed
is 0, fan stops
110
www.keyestudio.com
6. Assembled Guide
1*A board
4*M3 nuts
111
www.keyestudio.com
4*M2.5 nuts
2* Button sensor
1*LCD1602 display
a. Fix white LED, 2 button sensors and PIR motion sensor on the corresponding
area of the A board with 4pcs M3*10MM round head screws and 4pcs M3 nuts.
112
www.keyestudio.com
b. Then install LCD1602 display on A board with 4pcs M2.5*10MM round head
M2.5*10MM
round head
screw*4
M3*10MM
round
head screw
*4
M2.5 nut *4
M3 nut
*4
B board*1
M3 nut*4
Relay module*1
Assemble the relay module on B board with 2 pcs M3*10MM screws and 2pcs M3
M3 nut *2
114
www.keyestudio.com
115
www.keyestudio.com
116
www.keyestudio.com
C board*1
Battery holder
M3 nut*3
A. Fix the battery holder on C board with 2pcs M3*10MM flat head screws and 2
pcs M2 nuts
B. Then install the MQ-2 gas sensor on the corresponding area of C board with a
117
www.keyestudio.com
M3*10MM flat
screw *2
M3 nut* 3
Black servo*1
M2 nut*2
M3 self-locking nut*4
D board*1
Gear*1
118
www.keyestudio.com
Board 1*1
Rotate servo to 90° before installing, connect servo to keyestudio PLUS control
board; upload test code on control board and make servo rotate to 90°
Servo Motor
Brown GND
wire
Red 5V
wire
Orange S(10)
wire
119
www.keyestudio.com
Test Code:
#include <Servo.h>
Servo servo_10;
void setup(){
servo_10.attach(10);
void loop(){
servo_10.write(90);
delay(500);}
A. Fix servo on the corresponding area on D board with 2pcs M2*12MM round
120
www.keyestudio.com
B. Then install the square board 1 on the D board with 4pcs M3*12MM round
M2 nut *2
M2*12MM round
head screw*2
M3*12MM round
M3 nut *4
head screw*4
121
www.keyestudio.com
Fix the white cross mount on the gear with 4pcs M1.2*5MM self-tapping screws,
and mount the gear on the servo motor with 1 M2*5MM round head screw.
M1.2*5MM
self-tapping screw*4
122
www.keyestudio.com
Yellow LED*1
E board*1
123
www.keyestudio.com
M3 nut*1
Assemble the yellow LED on the corresponding area of E board with 1 M3*10MM
round head screw and 1 M3 nut,then connect them with a 3pin female to female
dupont line.
124
www.keyestudio.com
M3*10MM round
M3 nut*1
head screw *1
Black servo*1
Passive buzzer*1
M2 nut*2
M3 nut*1
Board E
Gear *2
Board 2*2
A. Mount 4pcs dual-pass copper pillars on the H board with 4pcs M3*6MM screws
B. Then fix the passive buzzer on H board with 1 M3*10MM round head screw
and 1 MS nut.
126
www.keyestudio.com
M3 nut*1
M3*10MM
Rotate the servo to 90° before installing, the method is same as the step 6.
Assemble the 4pcs M3*10MM copper pillars on the keyestudio PLUS control board
with 4 M3*6MM round head screws, then fix the servo on the corresponding area
127
www.keyestudio.com
M3*6MM round
head screw *4
M2*12MM
Assemble 2pcs board 2 together, then fix white cross mount on the gear with
128
www.keyestudio.com
M1.2*5MM
self-tapping screw*4
Fix the gear with white cross mount on the black servo by 1 M2*5MM
another servo on the corresponding area of H board, finally stack the sensor
129
www.keyestudio.com
M2*5MM
round head
screw*1
130
www.keyestudio.com
Step 9: Assemble A, B, C, D, E and H board together, then fix them with 2 “T” type
bolts. (Note: the power interface of PLUS control board is aligned with the hole
⑧ on board B, and the interface of USB cable is aligned with the hole ⑦ on
board B)
131
www.keyestudio.com
132
www.keyestudio.com
133
www.keyestudio.com
Steam sensor*1
Photocell sensor*1
Fan module*1
F board*1
M3 nut*3
Separately fix steam sensor, photocell sensor and fan module on the F board with
3pcs M3*10MM round head screws and 3pcs M3 nuts, then connect them with
134
www.keyestudio.com
M3*10MM M3 nut*3
round head
screw*3
Connect one end of 3pin dupont line to the pin of soil humidity sensor, then link all
sensors to sensor shield. (fix 2 servo and make dupont wire go through the holes
of board)
135
www.keyestudio.com
installed area
on the board
Sensor
door
windows
136
www.keyestudio.com
sensor
137
www.keyestudio.com
Insert the Bluetooth module into sensor shield, then fix the F board with 2
M3*10MM round head screws, 2 M3 nuts and 2 pcs parts with holes in the middle,
Sensor
Bluetooth
Expansion
Module
Board
VCC 5V
GND GND
TXD RXD
RXD TXD
138
www.keyestudio.com
139
www.keyestudio.com
M3 nut*2
M3*10MM
round head
screw *2
140
www.keyestudio.com
141
www.keyestudio.com
142
www.keyestudio.com
Description
In the previous projects, we introduce all buttons on app. In this lesson, we will
(1)When at night, someone is passing, the LED lights on, otherwise, the LED
lights off.
143
www.keyestudio.com
(2)There are 1602LCD display, 2 buttons, 1 servo on the board. Press button1
to enter the password(you can set password in the test code), the 1602LCD will
show “*”, then press button2 to “ensure”. Then 1602LCD will show “open”, the
door will be open. If the password is wrong, the “error” pops up , after 2s, “error”
The door will be closed when PIR motion sensor doesn’t detect people around.
What’s more, press and hold button2, buzzer will sound, LCD displays “wait”.
(If the password is right, the servo will rotate to 180°, otherwise,the servo don’t
rotate)
(3)Insert soil humidity into plant pot, when the soil is too dry, buzzer will alarm
(4)When the gas sensor detects the gas with high concentration, the buzzer
(5)When steam sensor detects rains, the servo 2 will be activated, the window
Equipment:
Bluetooth module * 1
144
www.keyestudio.com
Photocell sensor * 1
Button module * 2
Relay module * 1
Steam sensor * 1
Servo module * 2
USB cable * 1
Connection Diagram:
145
www.keyestudio.com
installed area
on the board
146
www.keyestudio.com
Sensor
Module
door
window
147
www.keyestudio.com
Sensor
Test Code:
*****************************************************************
********************************
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
148
www.keyestudio.com
149
www.keyestudio.com
delay(250);//delay in 250ms
tone(3,440);
delay(250);
tone(3,392);
delay(250);
tone(3,532);
delay(250);
tone(3,494);
delay(500);
tone(3,392);
delay(250);
tone(3,440);
delay(250);
tone(3,392);
delay(250);
tone(3,587);
delay(250);
150
www.keyestudio.com
tone(3,532);
delay(500);
tone(3,392);
delay(250);
tone(3,784);
delay(250);
tone(3,659);
delay(250);
tone(3,532);
delay(250);
tone(3,494);
delay(250);
tone(3,440);
delay(250);
tone(3,698);
delay(375);
tone(3,659);
delay(250);
tone(3,532);
delay(250);
tone(3,587);
delay(250);
151
www.keyestudio.com
tone(3,532);
delay(500);
#define D0 -1
#define D1 262
#define D2 293
#define D3 329
#define D4 349
#define D5 392
#define D6 440
#define D7 494
#define M1 523
#define M2 586
#define M3 658
#define M4 697
#define M5 783
#define M6 879
#define M7 987
#define H1 1045
#define H2 1171
152
www.keyestudio.com
#define H3 1316
#define H4 1393
#define H5 1563
#define H6 1755
#define H7 1971
#define WHOLE 1
Servo servo_10;
Servo servo_9;
int tune[]=
M3,M3,M4,M5,
M5,M4,M3,M2,
M1,M1,M2,M3,
M3,M2,M2,
M3,M3,M4,M5,
153
www.keyestudio.com
M5,M4,M3,M2,
M1,M1,M2,M3,
M2,M1,M1,
M2,M2,M3,M1,
M2,M3,M4,M3,M1,
M2,M3,M4,M3,M2,
M1,M2,D5,D0,
M3,M3,M4,M5,
M5,M4,M3,M4,M2,
M1,M1,M2,M3,
M2,M1,M1
};
//Set I2C communication address of LED to 0x27, display 16 characters each line,
2 lines in total
LiquidCrystal_I2C mylcd(0x27,16,2);
//set beats
float durt[]=
1,1,1,1,
1,1,1,1,
1,1,1,1,
1+0.5,0.5,1+1,
154
www.keyestudio.com
1,1,1,1,
1,1,1,1,
1,1,1,1,
1+0.5,0.5,1+1,
1,1,1,1,
1,0.5,0.5,1,1,
1,0.5,0.5,1,1,
1,1,1,1,
1,1,1,1,
1,1,1,0.5,0.5,
1,1,1,1,
1+0.5,0.5,1+1,
};
int length;
for(int x=0;x<length;x++)
tone(tonepin,tune[x]);
155
www.keyestudio.com
delay(300*durt[x]);
// gas detection
void auto_sensor() {
while (flag == 1)
tone(3,440);
delay(125);
delay(100);
noTone(3);
delay(100);
tone(3,440);
delay(125);
delay(100);
noTone(3);
156
www.keyestudio.com
delay(300);
} else
//otherwise
if (infrar == 1)
//if infra is 1
157
www.keyestudio.com
} else//otherwise
while (flag2 == 1)
delay(300);//delay in 300ms
delay(100);
158
www.keyestudio.com
} else//otherwise
delay(10);
while (flag3 == 1)
159
www.keyestudio.com
tone(3,440);
delay(125);
delay(100);
noTone(3);
delay(100);
tone(3,440);
delay(125);
delay(100);
delay(300);
} else//otherwise
160
www.keyestudio.com
door();//Run subroutine
void door() {
delay(10);//delay in 10ms
delay(100);//delay in 100ms
if (btn1_num >= 1 && btn1_num < 5) //if variable btn1_num is greater than or
161
www.keyestudio.com
Serial.print(".");
Serial.print("");
mylcd.setCursor(1-1, 2-1);
mylcd.print(pass);
if (btn1_num >= 5)
Serial.print("-");
mylcd.setCursor(1-1, 2-1);
mylcd.print(pass);
162
www.keyestudio.com
delay(10);
//LCD displays the "open!" character from the first character in the second line
mylcd.setCursor(1-1, 2-1);
mylcd.print("open!");
delay(300);
delay(5000);
passwd = "";
pass = "";
//LCD displays the "password:" character from first character on the first
line
mylcd.setCursor(1-1, 1-1);
mylcd.print("password:");
} else //otherwise
163
www.keyestudio.com
//LCD displays the "error!" from the first character in the first line
mylcd.setCursor(1-1, 1-1);
mylcd.print("error!");
passwd = "";
pass = "";
delay(2000);
//LCD displays the "again" from the first character in the first line
mylcd.setCursor(1-1, 1-1);
mylcd.print("again");
delay(50);
164
www.keyestudio.com
delay(10);
delay(100);
tone(3,532);
delay(125);
//LCD displays the "password:" from the first character in the first line
mylcd.setCursor(1-1, 1-1);
mylcd.print("password:");
//LCD displays the "wait" from the first character in the first line
mylcd.setCursor(1-1, 1-1);
mylcd.print("wait");
} else//otherwise
165
www.keyestudio.com
void music1() {
birthday();
//Ode_to_Joy Song
void music2() {
Ode_to_Joy();
//PWM control
void pwm_control() {
switch (val)
servo1 = Serial.readStringUntil('#');
servo1_angle = String(servo1).toInt();
166
www.keyestudio.com
servo1_angle
delay(300);
servo2 = Serial.readStringUntil('#');
servo2_angle = String(servo2).toInt();
to servo2_angle
delay(300);
led2 = Serial.readStringUntil('#');
value_led2 = String(led2).toInt();
fans_char = Serial.readStringUntil('#');
fans_val = String(fans_char).toInt();
digitalWrite(7,LOW);
167
www.keyestudio.com
void setup(){
mylcd.init();
delay(300);
delay(300);
//LCD displays the "password:" from the first character in the first line
mylcd.setCursor(1-1, 1-1);
mylcd.print("passcord:");
168
www.keyestudio.com
passwd = "";
pass = "";
169
www.keyestudio.com
servo1 = "";
servo2 = "";
led2 = "";
fans_char = "";
void loop(){
auto_sensor();
pwm_control();
170
www.keyestudio.com
switch (val) {
171
www.keyestudio.com
delay(100);
delay(100);
delay(100);
delay(100);
delay(500);
172
www.keyestudio.com
delay(500);
delay(500);
delay(500);
digitalWrite(7,LOW);
173
www.keyestudio.com
digitalWrite(7,LOW);
}}
*****************************************************************
********************************
Note: Remove the Bluetooth module please, when uploading the test code.
Otherwise, the program will fail to upload. Connect the Bluetooth and Bluetooth
Test Result
Upload the test code, stack expansion board on PLUS control board, and power
on. After pairing and connecting Bluetooth successfully, we can control the smart
7.Resources
174
www.keyestudio.com
175