KS0085 Keyestudio Smart Home Kit For Arduino
KS0085 Keyestudio Smart Home Kit For Arduino
com
1
www.keyestudio.com
Content
1. Overview:....................................................................................................................... 3
2. Kit.................................................................................................................................... 4
5. Projects.........................................................................................................................32
2
www.keyestudio.com
1. Overview:
This Smart Home Learning Kit based on the Arduino platform is newly rolled out
It simulates the real smart home and demonstrates the cozy and comfortable life
for people.
3
www.keyestudio.com
home: it turns on the air conditioner, boots up the water heater, secures your
home with an electronic lock, and sets your LED lights and smart curtains to turn
on automatically when you get home. Meanwhile, the intelligent lighting system
As Bill Gates puts it, "In the near future, a house without a smart home system
So, go ahead and get started; let's build this amazing analog smart home.
2. Kit
After getting this smart home kit, we need to make sure that there are not
missing components.
4
www.keyestudio.com
UNO )
6 Button Sensor 2
5
www.keyestudio.com
7 Photocell Sensor 1
10 Relay Module 1
13 Fan module 1
6
www.keyestudio.com
14 Steam Sensor 1
15 Servo Motor 2
18 USB Cable 1
24 M3*10MM Dual-pass 4
7
www.keyestudio.com
Copper Bush
Black-yellow
Screwdriver
8
www.keyestudio.com
When we get control board, we need to download Arduino IDE and driver in the
first place.
below:
You can select the latest version-----1.8.13. Alternatively, the previous release is
9
www.keyestudio.com
for non admin install,a zip file of Arduino 1.8.12 version, can be directly
10
www.keyestudio.com
Now, let’s get to know Keyestudio PLUS development board. It is the core of the
11
www.keyestudio.com
whole kit.
Keyestudio PLUS Control Board is fully compatible with Arduino UNO R3 board. Its
made highly strengthen its function. Alternatively, it is the best choice to learn
SPI communication interface: D10 is SS, D11 is MOSI, D12 is MISO, D13 is SCK
12
www.keyestudio.com
Let’s install the driver of Keyestudio PLUS Control Board. The USB-TTL chip on
PLUS board adopts CP2102 serial chip. The driver program of this chip is included
When you attach USB port to computer, the driver of CP2102 can be installed.
Device Manager.
13
www.keyestudio.com
There is a yellow exclamation mark on the page, which implies the failure
Operate as follows;
14
www.keyestudio.com
Click “OK” to enter the following page and click “browse my computer for
15
www.keyestudio.com
Click “Browse”, then search the driver of CP2102 and click “Next”,
chips.
16
www.keyestudio.com
When opening the device manager, we will find the yellow exclamation mark
17
www.keyestudio.com
18
www.keyestudio.com
19
www.keyestudio.com
When downloading the sketch to the board, you must select the correct
20
www.keyestudio.com
Then select the correct COM port (you can see the corresponding COM port after
21
www.keyestudio.com
22
www.keyestudio.com
23
www.keyestudio.com
F- Used to send the serial data received from board to the serial monitor.
Open the file to select Example, and click BASIC>BLINK, as shown below:
24
www.keyestudio.com
Set board and COM port, the corresponding board and COM port are
25
www.keyestudio.com
26
www.keyestudio.com
etc.
download.
27
www.keyestudio.com
Step 1:After downloading the Arduino IDE, you can right-click the icon of
Arduino IDE.
28
www.keyestudio.com
Step 3 : Next, search the “ libraries ” of smart home kit(seen in the link:
29
www.keyestudio.com
30
www.keyestudio.com
below:
31
www.keyestudio.com
5. Projects
Alright, let’s get straight to our projects. In this kit, there are 14 sensors and
modules. We will make you know the smart home deeply from the simple sensor.
However, if you are professional with Arduino. You can skip theses steps and
assemble the smart home kit directly(there is assembly video in the folder)
Note: In this course, the interface of each sensor / module marked with
sensor shield or control board; “V” is positive pole and linked with V,
VCC or 5V.
32
www.keyestudio.com
1. Description
Let’s connect GND and VCC to power. The LED will be on when signal end S is
high level, on the contrary, LED will turn off when signal end S is low level.
delayed time.
2. Specifications
33
www.keyestudio.com
4. Sensor Shield
We usually combine Arduino control board with a large number of sensors and
modules. However, the pins and ports are limited on control board.
This V5 shield can be directly attached to sensors with 3 pin connectors, and be
34
www.keyestudio.com
Pins Description
5. Wiring Diagram
35
www.keyestudio.com
Note: pin G, V and S of white LED module are linked with G, V and 13 of V5 board.
6. Test Code
/*
Project 1
Blink
http://www.keyestudio.com
*/
void setup() {
pinMode(13, OUTPUT);
36
www.keyestudio.com
void loop() {
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
}//**************************************************************
*************
7. Test Result:
After the code is uploaded, the white LED flashes for 1000ms, alternately.
8. Code Explanation
The code looks long and clutter, but most of which are comments. The grammar
of Arduino is based on C.
The code contains many vital information, such as the author, the issued
agreement, etc.
37
www.keyestudio.com
The comments, major part of the whole code, are inclusive of significant
// the setup function runs once when you press reset or power the board
void setup() {
pinMode(13, OUTPUT);
According to comments, we will find that author define the D13 pin mode as
Setup() is the basic function of Arduino and executes once when running
program.
void loop() {
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
38
www.keyestudio.com
Loop() is the necessary function of Arduino, it can run and loop all the time after
digitalWrite(): set the output voltage of pin to high or low level. We make D13
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
Similarly, we make D13 output low level, LED will turn off.
Delay for 1s, light on LED--keep on 1s--light off LED--stay on 1s, iterate the
What if you want to make LED flash rapidly? You only need to modify the value of
delay block. Reducing the delay value implies that the time you wait is shorter,
that is, flashing rapidly. Conversely, you could make LED flash slowly.
39
www.keyestudio.com
1. Description
40
www.keyestudio.com
In the previous lesson, we control LED on and off and make it blink.
In this project, we will control LED brightness through PWM to simulate breathing
effect. Similarly, you can change the step length and delay time in the code so as
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 five hundred 0 or 1 signals within 1 second.
41
www.keyestudio.com
If output five hundred 1, that is 5V; if all of which is 1, that is 0V. If output
010101010101 in this way then the output port is 2.5V, which is like showing
movie. The movie we watch are not completely continuous. It actually outputs 25
pictures per second. In this case, the human can’t tell it, neither does PWM. If
want different voltage, need to control the ratio of 0 and 1. The more 0,1 signals
3. Wiring Diagram
42
www.keyestudio.com
Note: on sensor shield, the G, V and S pins of yellow LED module are linked with
G, V and 5.
4. Test Code
/*
Project 2
PWM
http://www.keyestudio.com
*/
void setup () {
void loop () {
}}
//**********************************************************
LED smoothly changes its brightness from dark to bright and back to dark,
44
www.keyestudio.com
Code Analysis
Round 1:1 → 2 → 3 → 4
Round 2:2 → 3 → 4
45
www.keyestudio.com
...
...
The two “for”statement make value increase from 0 to 255, then reduce from 255
We know that digital port only has two state of 0 and 1. So how to send an analog
value to a digital value? Here, we need this function, observe the Arduino board
and you will find 6 pins with “~”. They are different from other pins and can
analogWrite(pin,value)
analogWrite() is used to write an analog value from 0~255 for PWM port, so the
46
www.keyestudio.com
value is in the range of 0~255, attention that you only write the digital pins with
control forms a square wave, and the square wave signal only has two states of
switching (that is, high or low levels of our digital pins). By controlling the ratio of
the duration of on and off, a voltage varying from 0 to 5V can be simulated. The
Through the following five square waves, let’s know more about PWM
In the above figure, the green line represents a period, and value of analogWrite()
corresponds to a percentage which is called Duty Cycle as well. Duty cycle implies
bottom, the duty cycle of first square wave is 0% and its corresponding value is 0.
The LED brightness is lowest, that is, turn off. The more time high level lasts, the
brighter the LED. Therefore, the last duty cycle is 100%, which correspond to 255,
PWM mostly is used for adjusting the LED brightness or rotation speed of motor.
1. Description
The most common one is sound and light display. We always use LED to make
experiments. For this lesson, we design circuit to emit sound. The universal sound
components are buzzer and horns. Buzzer is easier to use. And buzzer includes
about active buzzer and passive buzzer. In this experiment, we adopt passive
buzzer.
While using passive buzzer, we can control different sound by inputting square
waves with distinct frequency. During the experiment, we control code to make
buzzer sound, begin with “tick, tick” sound, then make passive buzzer emit “do re
48
www.keyestudio.com
3. Wiring Diagram
4. Test Code
49
www.keyestudio.com
/*
Project 3.1
Buzzer
http://www.keyestudio.com
*/
void setup ()
void loop ()
unsigned char i, j;
while (1)
50
www.keyestudio.com
}}}
//***************************************************************
***************************
From the above code, number 80 and 100 decide frequency in “for” statement.
We will play fabulous music if control ling frequency and beats well, so let’s figure
Bass:
Tone Note 1# 2# 3# 4# 5# 6# 7#
Alto:
52
www.keyestudio.com
Tone Note 1 2 3 4 5 6 7
Treble:
53
www.keyestudio.com
Tone Note 1# 2# 3# 4# 5# 6# 7#
Next, we need to control the time the note plays. The music will be produced
when every note plays a certain amount of time. The note rhythm is divided into
The time for a note is stipulated as half beat( 0.5), 1/4 beat(0.250, 1/8
54
www.keyestudio.com
1. Normal note, like the first note 3, correspond to 350(frequency), occupy 1 beat
3. The note with dot( )means that 0.5 beat is added, that is 1+0.5 beat
4. The note with”—” represents that 1 beat is added, that is 1+1 beat.
55
www.keyestudio.com
5. The two successive notes with arc imply legato, you could slightly modify the
frequency of the note behind legato(need to debug it yourself), such like reducing
/*
Project 3.2
Buzzer music
http://www.keyestudio.com
*/
#define NTD0 -1
56
www.keyestudio.com
#define WHOLE 1
57
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,
58
www.keyestudio.com
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;
void setup ()
void loop ()
59
www.keyestudio.com
delay (350* durt [x]); // This is used to adjust the delay according to the beat,
noTone (tonepin);
//***************************************************************
****************************
60
www.keyestudio.com
1. Description
In this lesson, we will use the input function of I/O port, that is, reading the
output value of external device. Also, we will do an experiment with a button and
The button switch is ordinary in our life. It belongs to switch quantity( digital
When the normally open contact bears pressure, the circuit will be on state ;
however, when this pressure disappears, the normally open contact will go back
61
www.keyestudio.com
Module*1 Cable*2
3. Wiring 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
5. Test Code
Then, we will design the program to make LED on by button. Comparing with
62
www.keyestudio.com
the condition judgement statement of C is suitable for Arduino, like while, swich,
etc.
If button is pressed, digital 4 is low level, then we make digital 5 output high
level , then LED will be on; conversely, if the button is released, digital 4 is high
level, we make digital 5 output low level, then LED will go off.
/*
Project 4
Button
http://www.keyestudio.com
*/
void setup ()
63
www.keyestudio.com
void loop ()
val = digitalRead (inpin); // Read the digital 4 level value and assign it to val
if (val == LOW) // Whether the key is pressed, the light will be on when pressed
else
//***************************************************************
This experiment is pretty simple, and widely applied to various of circuits and
electrical appliances.
64
www.keyestudio.com
1. Description:
expansion board. It has a control system (also called an input loop) and a
switch" that controls a larger current and a lower voltage with a smaller current
conversion in the circuit. It allows Arduino to drive loads below 3A, such as LED
65
www.keyestudio.com
The main internal components of the relay module are electromagnet A, armature
B, spring C, moving contact D, static contact (normally open contact) E, and static
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
pulls in and releases, thus achieving the purpose of turning on and off in the
circuit. The "normally open and closed" contacts of the relay can be distinguished
in this way: the static contacts on disconnected state when the relay coil is
powered off are called "normally open contacts"; the static contacts on connected
66
www.keyestudio.com
state are called "normally closed contact". The module comes with 2 positioning
2. Specifications:
67
www.keyestudio.com
4. Wiring Diagram:
Note: On the shield, the G, V, and S pins of 1-channel relay module are connected
module.
68
www.keyestudio.com
5. Test Code:
/*
Project 5
Relay
http://www.keyestudio.com
*/
void setup ()
void loop ()
delay (2000);
delay (2000);
69
www.keyestudio.com
//************************************************
6. Test Result:
When the relay is connected(“NO” is on , NC is off) for 0.5s, the white LED will be
1. Description:
70
www.keyestudio.com
Its signal end is connected to the analog port of the microcontroller. When the
light intensity increases, the resistance will decrease, but the analog value of the
microcontroller won’t. On the contrary, when the light intensity decreases, the
Therefore, we can use the photoresistor sensor module to read the corresponding
circuit as well.
1 Cables*2
71
www.keyestudio.com
3. Wiring Diagram:
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 yellow LED
4. Test Code:
/*
Project 6
photocell
http://www.keyestudio.com
*/
void setup () {
void loop () {
if (val <900)
else
***************************************************************
LED will be on after uploading test code. If you use a flashlight to point at the
photocell, LED will be automatically off. However, if you turn off flashlight, LED
73
www.keyestudio.com
will be on again.
5. Review
For this code string, it is simple. We read value through analog port and attention
that analog quantity doesn’t need input and output mode. You can read the
The analog value will gradually decrease if there is light. When the value is up to
900, this value can be set up according to the brightness you choose
74
www.keyestudio.com
1. Description:
Servo can control doors and windows. In this course, we’ll introduce its principle
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
When the motor speed is constant, the potentiometer is driven to rotate through
the cascade reduction gear, which leads 0 voltage difference, and the motor stops
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
180°. But note that for different brand motor, the same signal may have different
75
www.keyestudio.com
rotation angle.
One way is using a common digital sensor port of Arduino to produce square
wave with different duty cycle and to simulate PWM signal and use that signal to
Another one is using the Servo function of the Arduino to control the motor. In
this way, the program will be easier to design, but it can only control two-channel
motor because the servo function only uses digital pin 9 and 10.
The Arduino drive capacity is limited. So if you need to control more than one
Note that don’t supply power through USB cable, there is possibility to damage
the USB cable if the current demand is greater than 500MA. We recommend the
external power.
2. Specifications:
76
www.keyestudio.com
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)
PLUS Control
Sensor Shield*1 Servo*1 USB Cable*1
Board*1
4. Wiring Diagram:
77
www.keyestudio.com
Note: The servo is connected to G (GND), V (VCC), 9. The brown wire of the servo
is connected to Gnd (G), the red wire is linked with 5v (V), and the orange wire is
5. Test Code:
/*
Project 7
Sevro
http://www.keyestudio.com
*/
78
www.keyestudio.com
Servo myservo;
void setup ()
void loop ()
for(pos = 0; pos < 180; pos += 1)// angle from 0 to 180 degrees
//***************************************************************
**********************************
79
www.keyestudio.com
6. Test Result:
1. Description
80
www.keyestudio.com
The L9110 fan module adopts L9110 motor control chip, and controls the rotation
direction and speed of the motor. Moreover, this module is efficient, with high
quality fan, which can put out the flame within 20cm distance. Similarly, it is an
2. Specifications:
Working voltage: 5V
4. Wiring Diagram:
81
www.keyestudio.com
Note: On the shield, the GND, VCC, INA, and INB pins of the fan module are
respectively connected to G, V, 7, 6.
5. Test Code:
/*
Project 8
Fan
http://www.keyestudio.com
*/
void setup () {
82
www.keyestudio.com
void loop () {
//***************************************************************
**********************************
6. Test Result:
Upload test code, hook up the components according to connection diagram, and
dial the DIP switch to right side and power on. The fan rotates counterclockwise
for 3000ms, stops for 1000ms, then rotates clockwise for 3000ms.
83
www.keyestudio.com
1. 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
content is, the more wires will be connected. As the conductive contact coverage
84
www.keyestudio.com
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.
Arduino series microcontrollers. When using it, we provide the guide to operate
First, connect the sensor to the analog port of the microcontroller, and display the
Note: the connection part is not waterproof, therefore, don’t immerse it in the
water please.
2. Specifications:
85
www.keyestudio.com
5. Wiring Diagram:
Note: On the sensor shield, the pins G,V and S of steam sensor are connected to
G, V and A3
6. Test Code:
86
www.keyestudio.com
/*
Project 9
Steam
http://www.keyestudio.com
*/
void setup()
void loop()
int val;
Serial.print("Moisture is ");
//***************************************************************
**********************************
7. Test Result:
87
www.keyestudio.com
When detecting different humidity, the sensor will get the feedback of different
When the sensor detects the steam of boiled water, the moisture value is
88
www.keyestudio.com
1. Description:
The Pyroelectric infrared motion sensor can detect infrared signals from moving
Conventional pyroelectric infrared sensors are much more bigger, with complex
circuit and lower reliability. Yet, this new pyroelectric infrared motion sensor, is
pins. It features higher sensibility and reliability, lower power consumption, light
89
www.keyestudio.com
weight, small size, lower voltage working mode and simpler peripheral circuit.
2. Specifications:
Note:
2. In the test, open the white lens to check rectangular sensing part. When
the long line of the sensing part is parallel to the ground, the distance is the
best.
3. In the test, covering the sensor with white lens can sense the distance
precisely.
4. The distance is best at 25℃, and the detection distance value will reduce
90
www.keyestudio.com
5. After powering up and uploading the code, you can start testing after
4. Wiring Diagram:
91
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 linked with
G,V,7,6. The pin G, V and S of LED module are linked with G, V and 13.
5. Test Code:
/*
Project 10
PIR
http://www.keyestudio.com
*/
void setup () {
92
www.keyestudio.com
Serial.begin (9600); // open serial port, and set baud rate at 9600bps
Serial.begin (9600);
void loop () {
93
www.keyestudio.com
}}
//***************************************************************
**********************************
6. Test Result:
Upload the above test code, open serial monitor, and set baud rate to 9600. If PIR
motion sensor detects someone nearby, the serial monitor will display “1” , and
LED and D13 will be turned on as well, and fan will rotate. If nobody is around,
the serial monitor will show “0”, indicators will be off and fan will stop rotating.
94
www.keyestudio.com
1. Description:
This gas sensor is used for household gas leak alarms, industrial combustible gas
alarms and portable gas detection instruments. Also, it is suitable for the
95
www.keyestudio.com
The MQ-2 smoke sensor can be accurately a multi-gas detector, with the
advantages of high sensitivity, fast response, good stability, long life, and simple
drive circuit.
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 internal signal line to blow.
temperature, tin dioxide adsorbs oxygen in the air and forms negative ion
When in contact with flammable gas in the air and smog, and the potential barrier
at the grain boundary is adjusted by the smog, it will cause the surface
flammable gas in the air, the greater the conductivity, and the lower the output
resistance, the larger the analog signal output. In addition, the sensitivity can be
96
www.keyestudio.com
2. Specifications:
Weight: 7.5g
Cable*3
4. Wiring Diagram:
97
www.keyestudio.com
Note: On the shield, the pin GND, VCC, D0 and A0 of gas sensor are linked with
pin G, V and A0. The pin G,V and S of passive buzzer are connected to G,V and 3.
5. Test Code:
/*
Project 11
Gas
http://www.keyestudio.com
*/
98
www.keyestudio.com
void setup ()
pinMode (buzzer, OUTPUT); // Set the digital IO pin mode for output
void loop ()
val = analogRead (MQ2); // Read the voltage value of A0 port and assign it to val
if (val> 450)
delay(300);
else
noTone (buzzer);
//***************************************************
99
www.keyestudio.com
6. Test Result:
power on. When the detected value of flammable gas is greater than 70, the
passive buzzer will emit sound, however, when there is no flammable gas, the
100
www.keyestudio.com
1. Description:
This is a display module, with I2C communication module, can show 2 lines with
It shows blue background and white word and is attached to I2C interface of MCU.
On the back of LCD display is a blue potentiometer for adjusting the backlight.
The original 1602 LCD can run with 7 IO ports, but ours is built with
with 4 positioning holes with a diameter of 3mm, which is convenient for you to
Notice that when the screen gets brighter or darker, the characters will become
2. Specifications:
101
www.keyestudio.com
Adjustable contrast
4. Wiring Diagram:
102
www.keyestudio.com
Note: there are pin GND, VCC, SDA and SCL on 1602LCD module. GND is linked
SCL to SCL.
5. Test Code:
/*
Project 12
1602 LCD
http://www.keyestudio.com
*/
#include <Wire.h>
103
www.keyestudio.com
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27,16,2); // set the LCD address to 0x27 for a16 chars
void setup ()
lcd.backlight ();
lcd.setCursor (3,0);
lcd.setCursor (2,1);
void loop ()
//***************************************************************
**********
6. Test Result
After hooking up components and uploading sample code, the 1602 LCD will print
"Hello, world!, keyestudio!", and you can adjust LCD backlight with
104
www.keyestudio.com
a potentiometer
*****************************************************************
Note: When the display doesn’t show characters, you can adjust the
potentiometer behind the 1602LCD and backlight to make the 1602LCD display
105
www.keyestudio.com
1. Description
If the soil is lack of water, the analog value output by the sensor will decrease;
otherwise, the value will increase. It can be applied to prevent your household
The soil humidity sensor module is not as complicated as you think. It has two
probes. When inserted into the soil,it will get resistance value by reading the
current changes between the two probes and converting resistance value into
moisture content. The higher the moisture (less resistance), the higher the
conductivity.
106
www.keyestudio.com
2. 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
107
www.keyestudio.com
4. Wiring Diagram:
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
5. Test Code:
/*
Project 13
Soil Humidity
108
www.keyestudio.com
http://www.keyestudio.com
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C mylcd (0x27,16,2); // set the LCD address to 0x27 for a16 chars
void setup () {
value = 0;
mylcd.init ();
void loop () {
Serial.print ("");
Serial.println (value);
109
www.keyestudio.com
mylcd.print ("value:"); //
mylcd.print (value);
else if ((value>=300) && (value <= 700)) // If the value is greater than 300
mylcd.print ("value:");
mylcd.print (value);
110
www.keyestudio.com
mylcd.print ("value:");
mylcd.print (value);
}}
//***************************************************************
**********************************
6. Test Result:
Upload code, open the serial monitor and insert the soil humidity sensor into the
soil.
The greater the humidity is, the larger the value(0-1023). Also, the 1602LCD will
111
www.keyestudio.com
112
www.keyestudio.com
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 used as the Host, it can send commands to the slave actively;
when used 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
In the experiment, we take the HM-10 Bluetooth module as a Slave and the
cellphone as a Host. We install the Bluetooth APP on the mobile phone, connect
the Bluetooth module; and use the Bluetooth APP to control the smart home kit.
We also provide you with APP for Android and iOS system.
1. Pins Description
Pins Description
113
www.keyestudio.com
As the input pin, short press control, or input single pulse of 100ms
connected state
2. Parameters:
114
www.keyestudio.com
command.
during transmission.
Power supply: 5V DC
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
115
www.keyestudio.com
There are twelve control buttons and four sliders on App. When we press control
button on APP, the Bluetooth of cellphone will send a control character, and
according to the corresponding key control character. Next, let’s test 16 buttons
on app.
be connected.
116
www.keyestudio.com
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
Start Bluetooth of your cellphone and open App to click “SCANNING” to pair.
117
www.keyestudio.com
As shown below;
3. iOS System:
118
www.keyestudio.com
119
www.keyestudio.com
follows:
(4) After uploading the test code successfully, insert the Bluetooth module and
power on.
First start the Bluetooth on cellphone, then click “connect” on app to search
Bluetooth and pair. After paring successfully, the LED of Bluetooth module will be
always on.
Note: Remove the Bluetooth module please when uploading the test code.
Remember to pair Bluetooth and Bluetooth module after uploading the test code.
120
www.keyestudio.com
4. Wiring Diagram:
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 connecting.
5. Test Code:
/*
Project 14
Bluetooth
http://www.keyestudio.com
*/
char val;
121
www.keyestudio.com
void setup()
void loop()
while (Serial.available()>0)
//***************************************************************
**********
122
www.keyestudio.com
123
www.keyestudio.com
124
www.keyestudio.com
6. Assembly Guide
A board*1
button sensor*2
125
www.keyestudio.com
white LED*1
LCD1602 display*1
126
www.keyestudio.com
a. Fix the white LED, 2 button sensors and the PIR motion sensor on the
corresponding areas of the A board with 4pcs M3*10MM round head screws and
4pcs M3 nuts.
b. Then install the LCD1602 display on A board with 4pcs M2.5*10MM round
M2.5*10MM
Round head
screw*4
127
www.keyestudio.com
128
www.keyestudio.com
M3 Nickel
plated nut *4
M3*10MM Round
head screw *4
B board,
129
www.keyestudio.com
A relay module
Assemble the relay module on B board with 2 pcs M3*10MM screws and 2pcs M3
nickel plated nuts, and attach a 3pin F-F dupont cable to the relay module
130
www.keyestudio.com
131
www.keyestudio.com
132
www.keyestudio.com
C board*1
A battery holder
133
www.keyestudio.com
A. Fix the battery holder on C board with 2pcs M3*10MM flat head screws and 2
B. Then install the MQ-2 gas sensor on the corresponding area of C board with a
134
www.keyestudio.com
A servo
D board
A gear
Board1
135
www.keyestudio.com
We need to set the servo to 90° before installing. Just follow the steps below
Connect servo to Keyestudio PLUS Control Board and upload test code to make
Servo Motor
Red wire 5V
136
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);}
After the test code is uploaded successfully, the servo will rotate to 90°
137
www.keyestudio.com
A. Fix the servo on the corresponding area of D board with 2pcs M2*12MM round
B. Then install the square board 1 on the D board with 4pcs M3*12MM round
138
www.keyestudio.com
M3*12MM
Install 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.
139
www.keyestudio.com
140
www.keyestudio.com
A E board
141
www.keyestudio.com
Mount the yellow LED on the corresponding area of E board with 1 M3*10MM
round head screw and 1 M3 nickel plated nut,then connect a 3pin dupont line to
it.
142
www.keyestudio.com
A servo
A passive buzzer
143
www.keyestudio.com
A sensor shield
H board E
2 gears
Board 2*2
144
www.keyestudio.com
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 M3 nut.
145
www.keyestudio.com
Set the servo to 90° before installing, and the method is same as the step 6.
Fix the 4pcs M3*10MM copper pillars on the Keyestudio PLUS control board with 4
M3*6MM round head screws, then mount the servo on the corresponding area of
146
www.keyestudio.com
M3*6MM
Round head
screw *4
Mount 2pcs board 2 together, then fix white cross mount on the gear with 4pcs
147
www.keyestudio.com
Fix the gear with white cross mount on the black servo with 1 M2*5MM
another servo on the corresponding area of H board, finally stack the sensor
148
www.keyestudio.com
M2*5MM
Round head
screw*1
(Note: the port of PLUS Control Board is aligned with the hole ⑧ on board B, and
150
www.keyestudio.com
A steam sensor,
A photocell sensor
Board F
151
www.keyestudio.com
Separately fix the steam sensor, the photocell sensor and the fan module on the F
board with 3pcs M3*10MM round head screws and 3pcs M3 nuts, then attach
152
www.keyestudio.com
M3*10MM
M3 Nickel plated nut*3
Round head
screw*3
Connect one end of a 3pin dupont line to soil humidity sensor, then link all sensors
with the sensor shield. (make dupont wires of the servo go through the holes of
board)
153
www.keyestudio.com
installed area
on the board
Sensor
door
windows
154
www.keyestudio.com
sensor
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 and mount G board with
2 “T” bolts.
155
www.keyestudio.com
VCC 5V
GND GND
TXD RXD
RXD TXD
156
www.keyestudio.com
M3 Nickel
plated nut*2
M3*10MM
Round head
screw *2
157
www.keyestudio.com
158
www.keyestudio.com
1. Description
In the previous projects, we’ve introduced how to use sensors, modules and
HM-10 Bluetooth module. For this lesson, we will present all functions of this
smart home.
LED is off.
160
www.keyestudio.com
When button1 is pressed, you can input password(set password in the test code),
and the 1602LCD will show “*”, then press button2 to “confirm”. If the password
is correct, the 1602LCD will show “open” and the door will be open. However, if
the password is wrong, the “error” pops up; after 2s, “error” will turn into
button1, long press button1, long press button1, short press button1, long
(3) The door will be closed when PIR motion sensor doesn’t detect people around.
What’s more, if you press and hold button2, the buzzer will emits a sound, and
( If the password is right, the servo will rotate to 180°, otherwise, it doesn’t
rotate)
when the soil is too dry, the buzzer will alarm and
161
www.keyestudio.com
(5) When the gas sensor detects the gas with high
sound.
Yellow LED module * 1, relay Module * 1, passive buzzer module * 1, fan module
humidity sensor * 1 MQ-2 gas sensor* 1, 3pinF-F dupont cable * 10, 4pin F-F
162
www.keyestudio.com
3. Wiring diagram:
163
www.keyestudio.com
Sensor
Module
INA/INB
Servo 1 Brown/Red/
door
Servo 2 Brown/Red/
the window
D0/A0
164
www.keyestudio.com
Sensor
4. Test Code:
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
165
www.keyestudio.com
Servo servo_10;
Servo servo_9;
166
www.keyestudio.com
int length;
#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
167
www.keyestudio.com
#define M5 783
#define M6 879
#define M7 987
#define H1 1045
#define H2 1171
#define H3 1316
#define H4 1393
#define H5 1563
#define H6 1755
#define H7 1971
#define WHOLE 1
int tune[] =
168
www.keyestudio.com
M2, M1, M1
};
float durt[] =
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
169
www.keyestudio.com
1 + 0.5, 0.5, 1 + 1,
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,
};
void setup() {
mylcd.init();
mylcd.backlight();//initialize LCD
170
www.keyestudio.com
mylcd.setCursor(1 - 1, 1 - 1);
mylcd.print("password:");
delay(300);
171
www.keyestudio.com
void loop() {
auto_sensor();
pwm_control();
switch (val) {
up
break;//exit loop
172
www.keyestudio.com
break;//exit loop
connected to COM
break;//exit loop
disconnected to COM
break;//exit loop
break;//exit loop
break;//exit loop
break;//exit loop
173
www.keyestudio.com
delay(100);
break;//exit loop
delay(100);
break;//exit loop
delay(100);
break;//exit loop
delay(100);
break;//exit loop
delay(500);
break;//exit loop
delay(500);
break;//exit loop
174
www.keyestudio.com
delay(500);
break;//exit loop
delay(500);
break;//exit loop
break;//exit loop
break;//exit loop
digitalWrite(7, LOW);
break;//exit loop
digitalWrite(7, LOW);
break;//exit loop
175
www.keyestudio.com
void birthday()
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);
176
www.keyestudio.com
tone(3, 587);
delay(250);
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);
177
www.keyestudio.com
tone(3, 587);
delay(250);
tone(3, 532);
delay(500);
//detect gas
void auto_sensor() {
while (flag == 1)
tone(3, 440);
delay(125);
delay(100);
noTone(3);
178
www.keyestudio.com
delay(100);
tone(3, 440);
delay(125);
delay(100);
noTone(3);
delay(300);
} else
//otherwise
179
www.keyestudio.com
if (infrar == 1)
// if variable infra is 1
} else//Otherwise
while (flag2 == 1)
180
www.keyestudio.com
delay(300);//delay in 300ms
delay(100);
water
break;//exit loop
} else//Otherwise
delay(10);
181
www.keyestudio.com
while (flag3 == 1)
tone(3, 440);
delay(125);
delay(100);
noTone(3);
delay(100);
tone(3, 440);
delay(125);
delay(100);
delay(300);
soil
182
www.keyestudio.com
break;//exit loop
} else//Otherwise
door();//run subroutine
void door() {
delay(10);//delay in 10ms
183
www.keyestudio.com
Serial.print(".");
Serial.print("");
mylcd.setCursor(1 - 1, 2 - 1);
mylcd.print(pass);
if (btn1_num >= 5)
//if variablebtn1_num ≥5
Serial.print("-");
184
www.keyestudio.com
mylcd.setCursor(1 - 1, 2 - 1);
mylcd.print(pass);
delay(10);
mylcd.setCursor(1 - 1, 2 - 1);
mylcd.print("open!");
delay(300);
delay(5000);
passwd = "";
pass = "";
185
www.keyestudio.com
mylcd.setCursor(1 - 1, 1 - 1);
mylcd.print("password:");
} else //Otherwise
mylcd.setCursor(1 - 1, 1 - 1);
mylcd.print("error!");
passwd = "";
pass = "";
delay(2000);
mylcd.setCursor(1 - 1, 1 - 1);
mylcd.print("again");
186
www.keyestudio.com
delay(50);
delay(10);
delay(100);
tone(3, 532);
delay(125);
mylcd.setCursor(1 - 1, 1 - 1);
mylcd.print("password:");
187
www.keyestudio.com
mylcd.setCursor(1 - 1, 1 - 1);
mylcd.print("wait");
} else//Otherwise
// Birthday song
void music1() {
birthday();
//Ode to joy
void music2() {
Ode_to_Joy();
188
www.keyestudio.com
tone(tonepin, tune[x]);
delay(300 * durt[x]);
//PWM control
void pwm_control() {
switch (val)
servo1 = Serial.readStringUntil('#');
servo1_angle = String(servo1).toInt();
digital 9 to servo1_angle
delay(300);
break;//exit loop
servo2 = Serial.readStringUntil('#');
servo2_angle = String(servo2).toInt();
189
www.keyestudio.com
digital 10 to servo2_angle
delay(300);
break;//exit loop
led2 = Serial.readStringUntil('#');
value_led2 = String(led2).toInt();
break;//exit loop
fans_char = Serial.readStringUntil('#');
fans_val = String(fans_char).toInt();
digitalWrite(7, LOW);
break;//exit loop
*****************************************************************
********************************
190
www.keyestudio.com
Note: Remove the Bluetooth module please when uploading the test code.
Remember to pair Bluetooth and Bluetooth module after uploading the test code.
5. 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. Related Resources
https://fs.keyestudio.com/KS0085
191