Professional Documents
Culture Documents
KS0190 keyestudio Environment Monitoring Kit
KS0190 keyestudio Environment Monitoring Kit
www.keyestudio.com
keyestudio
simplified into blocks. Compiling is as easy as block building.
exciting works.
starters. As long as you love it, everyone can play with Arduino
Content
1. Kit List..................................................................................5
www.keyestudio.com
keyestudio
Project 6: Button-controlled LED..........................................28
Project 7: Responder..........................................................33
3. Projects of Modules.............................................................96
www.keyestudio.com
keyestudio
Project 11 I2C1602 Liquid Crystal Display Module..............136
.......................................................................................139
4. Integrated Project..............................................................150
www.keyestudio.com
keyestudio
1. Kit List
KEYESTUDIO
1 REV4 Control 1
Board
2 V5 Shield 1
Piranha LED
3 3
Module
Active Buzzer
4 1
Module
Ambient Light
5 1
Sensor
www.keyestudio.com
keyestudio
PIR Motion
6 1
Sensor
7 Vapor Sensor 1
Ultraviolet
8 1
Sensor
DHT11Temperat
9 ure and 1
Humidity Sensor
10 1602 I2C 1
11 Soil Sensor 1
Analog Gas
12 1
Sensor
13 Breadboard 1
www.keyestudio.com
keyestudio
14 Platform 1
1-digit Segment
16 1
Displays
4-digit Segment
17 1
Displays
18 Button 4
19 Blue LED 5
20 Red LED 5
21 Yellow LED 5
www.keyestudio.com
keyestudio
22 Passive Buzzer 1
23 Active Buzzer 1
24 1K 5
25 10K 5
26 220R 8
27 Full-color RGB 1
28 Screw 4
www.keyestudio.com
keyestudio
Adjustable
29 1
Resistor
30 IC 595 1
31 Button Cap 4
32 Jumper Wire 1
33 USB Cable 1
Female to
34 Female Dupont 60
Line
35 Dust Sensor 1
www.keyestudio.com
keyestudio
36 Resistor Chip 1
Or you can browse the ARDUINO website to download the latest version from
this link, https://www.arduino.cc, pop up the following interface.
Then click the SOFTWARE on the browse bar, you will have two options
www.keyestudio.com
keyestudio
ONLINE TOOLS and DOWNLOADS.
Click DOWNLOADS, it will appear the latest software version of ARDUINO 1.8.5
shown as below.
In this software page, on the right side you can see the version of development
software for different operating systems. ARDUINO has a powerful compatibility.
You should download the software that is compatible with the operating system
of your computer.
www.keyestudio.com
keyestudio
We will take WINDOWS system as an example here. There are also two
options under Windows system, one is installed version, the other is non-
installed version.
For simple installed version, first click Windows Installer, you will get the
following page.
www.keyestudio.com
keyestudio
This way you just need to click JUST DOWNLOAD, then click the downloaded file
to install it.
For non-installed version, first click Windows ZIP file, you will also get the pop-up
interface as the above figure.
Click JUST DOWNLOAD, and when the ZIP file is downloaded well to your
computer, you can directly unzip the file and click the icon of ARDUINO software
to start it.
www.keyestudio.com
keyestudio
www.keyestudio.com
keyestudio
You can press Browse… to choose an installation path or directly type in the
directory you want. Then click “Install” to initiate installation.
Wait for the installing process, if appear the interface of Window Security, just
continue to click Install to finish the installation.
www.keyestudio.com
keyestudio
www.keyestudio.com
keyestudio
Installing Driver:
Next, we will introduce the driver installation of Keyestudio REV4 (Black) Main
Control Board. The driver installation may have slight differences in different
computer systems. So in the following let’s move on to the driver installation in
the WIN 7 system.
The Arduino folder contains both the Arduino program itself and the drivers that
allow the Arduino to be connected to your computer by a USB cable. Before we
launch the Arduino software, you are going to install the USB drivers.
Plug one end of your USB cable into the Arduino and the other into a USB socket
on your computer.
When you connect Keyestudio REV4 (Black) Main Control Board to your computer
at the first time, right click the icon of your “Computer” —>for “Properties”—>
click the “Device manager”, under “Other Devices”, you should see an icon for
“Unknown device” with a little yellow warning triangle next to it. This is your
Arduino.
www.keyestudio.com
keyestudio
Then right-click on the device and select the top menu option (Update Driver
Software...) shown as the figure below.
www.keyestudio.com
keyestudio
www.keyestudio.com
keyestudio
After that, select the option to browse and navigate to the “drivers” folder of
Arduino installation.
www.keyestudio.com
keyestudio
Click “Next” and you may get a security warning, if so, allow the software to be
installed. Shown as below.
www.keyestudio.com
keyestudio
Installation completed, click “Close”.
Up to now, the driver is installed well. Then you can right click “Computer” —
>“Properties”—>“Device manager”, you should see the device shown below.
www.keyestudio.com
keyestudio
www.keyestudio.com
keyestudio
www.keyestudio.com 1
keyestudio
2 www.keyestudio.com
keyestudio
Check the code for errors
Verify/Compile
Upload the current Sketch to the
Arduino
Upload
Hardware Required
Arduino Board *1
USB Cable *1
www.keyestudio.com 3
keyestudio
Sample Code
After installing driver for Arduino, let's open Arduino software and
connected to pin 13, we can instruct the LED to blink first when
//////////////////////////////////////////////////////////
void setup()
needed.
4 www.keyestudio.com
keyestudio
void loop()
“R”.
{ // if it’s “R”,
delay(500);
delay(500);
////////////////////////////////////////////////////////////////
Result
www.keyestudio.com 5
keyestudio
6 www.keyestudio.com
keyestudio
you!
******************************************************
*************************
www.keyestudio.com 7
keyestudio
Project 2: LED Blinking
Introduction
connect an LED to one of the digital pins rather than using LED13,
Hardware Required
Arduino Board *1
Red M5 LED*1
220Ω Resistor*1
8 www.keyestudio.com
keyestudio
Breadboard*1
USB Cable *1
Circuit Connection
Here we use digital pin 10. We connect LED to a 220 ohm resistor
www.keyestudio.com 9
keyestudio
Sample Code
//////////////////////////////////////////////////////////
void setup()
{
10 www.keyestudio.com
keyestudio
pinMode(ledPin, OUTPUT);// define pin with LED connected as
output.
void loop()
//////////////////////////////////////////////////////////
Result
******************************************************
*************************
www.keyestudio.com 11
keyestudio
Introduction
analog signal level by modulating the duty cycle of PMW. The PWM
current is fed to the analog load (the device that uses the
12 www.keyestudio.com
keyestudio
power) by repeated pulse sequence being ON or OFF. Being on,
the current is fed to the load; being off, it's not. With
PWM. The output voltage value is calculated via the on and off
voltage value.
Width
Level
Cycle
www.keyestudio.com 13
keyestudio
controlled LED", using digital signal to control digital pin, also one
Hardware Required
Arduino Board *1
Potentiometer*1
Red M5 LED*1
220Ω Resistor*1
Breadboard*1
USB Cable *1
Circuit Connection
14 www.keyestudio.com
keyestudio
The input of potentiometer is analog, so we connect it to analog
port, and LED to PWM port. Different PWM signal can regulate the
Sample Code
read the analog value of the potentiometer and assign the value to
www.keyestudio.com 15
keyestudio
PWM port, so there will be corresponding change to the brightness
of the LED. One final part will be displaying the analog value on
the screen. You can consider this as the "analog value reading"
//////////////////////////////////////////////////////////
void setup()
“input”
void loop()
//////////////////////////////////////////////////////////
Result
www.keyestudio.com 17
keyestudio
After downloading the program, when we rotate the potentiometer
knob, you can see changes of the displaying value, also obvious
******************************************************
*************************
Introduction
experiment with one LED. Now, it’s time to up the stakes and do a
18 www.keyestudio.com
keyestudio
bit more complicated experiment-traffic lights. Actually, these two
Hardware required
Arduino Board *1
USB Cable *1
Red M5 LED*1
Yellow M5 LED*1
Blue M5 LED*1
220Ω Resistor *3
Breadboard*1
Circuit Connection
www.keyestudio.com 19
keyestudio
Sample Code
LED should be the same with those in traffic lights system. In this
20 www.keyestudio.com
keyestudio
/////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////
void setup()
“output”
“output”
void loop()
www.keyestudio.com 21
keyestudio
digitalWrite(blueled, HIGH);// turn on blue LED
/////////////////////////////////////////////////////////////////////////////
////////////
Result
Note: this circuit design is very similar with the one in LED chase
effect.
22 www.keyestudio.com
keyestudio
The blue light will be on for 5 seconds, and then off., followed by
the yellow light blinking for 3 times, and then the red light on for 5
******************************************************
*************************
Introduction
www.keyestudio.com 23
keyestudio
We often see billboards composed of colorful LEDs. They are
Hardware Required
Arduino Board *1
USB Cable *1
Red M5 LED*2
Yellow M5 LED*2
Blue M5 LED*2
220Ω Resistor *6
Breadboard*1
Circuit Connection
24 www.keyestudio.com
keyestudio
Sample Code
//////////////////////////////////////////////////////////
void setup()
www.keyestudio.com 25
keyestudio
for (int i = BASE; i < BASE + NUM; i ++)
void loop()
one by one.
delay(200); // delay
one by one
delay(200); // delay
//////////////////////////////////////////////////////////
26 www.keyestudio.com
keyestudio
Result
******************************************************
*************************
Introduction
I/O port means interface for INPUT and OUTPUT. Up until now,
will try to use the input function, which is to read the output value
www.keyestudio.com 27
keyestudio
Hardware Required
Arduino Board *1
USB Cable *1
Button Switch*1
Red M5 LED*1
220Ω Resistor*1
10KΩ Resistor*1
Breadboard*1
Circuit Connection
28 www.keyestudio.com
keyestudio
Sample Code
Now, let's begin the compiling. When the button is pressed, the
LED will be on. After the previous study, the coding should be easy
we use an if () statement.
www.keyestudio.com 29
keyestudio
Arduino IDE is based on C language, so statements of C language
program.
When we press the button, pin 7 will output high level. We can
program pin 11 to output high level and turn on the LED. When
pin 7 outputs low level, pin 11 also outputs low level and the LED
remains off.
//////////////////////////////////////////////////////////
void setup()
void loop()
to val
{ digitalWrite(ledpin,LOW);}
else
{ digitalWrite(ledpin,HIGH);}
//////////////////////////////////////////////////////////
Result
off. After the above process, the button controlled LED experiment
come across it in your every day life. One typical example is when
you press a certain key of your phone, the backlight will be on.
******************************************************
*************************
www.keyestudio.com 31
keyestudio
Project 7: Responder
Introduction
find this one easy. In this program, we have 3 buttons and a reset
pins.
Hardware Required
Arduino Board *1
USB Cable *1
Button Switch*4
Red M5 LED*1
Yellow M5 LED*1
Blue M5 LED*1
220Ω Resistor*3
10KΩ Resistor*4
Breadboard*1
32 www.keyestudio.com
keyestudio
Circuit Connection
Sample Code
www.keyestudio.com 33
keyestudio
//////////////////////////////////////////////////////////
int red;
int yellow;
int blue;
void setup()
pinMode(redled,OUTPUT);
pinMode(yellowled,OUTPUT);
pinMode(blueled,OUTPUT);
pinMode(redpin,INPUT);
pinMode(yellowpin,INPUT);
pinMode(bluepin,INPUT);
34 www.keyestudio.com
keyestudio
{
red=digitalRead(redpin);
yellow=digitalRead(yellowpin);
blue=digitalRead(bluepin);
if(red==LOW)RED_YES();
if(yellow==LOW)YELLOW_YES();
if(blue==LOW)BLUE_YES();
void RED_YES()// execute the code until red light is on; end cycle
while(digitalRead(restpin)==1)
digitalWrite(redled,HIGH);
digitalWrite(blueled,LOW);
digitalWrite(yellowled,LOW);
clear_led();
www.keyestudio.com 35
keyestudio
{
while(digitalRead(restpin)==1)
digitalWrite(redled,LOW);
digitalWrite(blueled,LOW);
digitalWrite(yellowled,HIGH);
clear_led();
void BLUE_YES()// execute the code until blue light is on; end
while(digitalRead(restpin)==1)
digitalWrite(redled,LOW);
digitalWrite(blueled,HIGH);
digitalWrite(yellowled,LOW);
clear_led();
36 www.keyestudio.com
keyestudio
{
digitalWrite(redled,LOW);
digitalWrite(blueled,LOW);
digitalWrite(yellowled,LOW);
//////////////////////////////////////////////////////////
Introduction
www.keyestudio.com 37
keyestudio
Hardware Required
Arduino Board *1
USB Cable *1
Active Buzzer*1
Breadboard*1
Circuit Connection
38 www.keyestudio.com
keyestudio
When connecting the circuit, pay attention to the positive & the
negative poles of the buzzer. In the photo, you can see there are
red and black lines. When the circuit is finished, you can begin
programming.
Sample Code
www.keyestudio.com 39
keyestudio
level.
//////////////////////////////////////////////////////////
void setup()
void loop()
//////////////////////////////////////////////////////////
Result
40 www.keyestudio.com
keyestudio
Project 9: Passive Buzzer
Introduction
and simple.
www.keyestudio.com 41
keyestudio
Hardware Required
Arduino Board *1
USB Cable *1
Passive Buzzer*1
Breadboard*1
Circuit Connection
42 www.keyestudio.com
keyestudio
Sample Code
//////////////////////////////////////////////////////////
void setup()
www.keyestudio.com 43
keyestudio
pinMode(buzzer,OUTPUT);// set digital IO pin pattern, OUTPUT to
be output
void loop()
while(1)
{ digitalWrite(buzzer,HIGH);// sound
delay(1);//delay1ms
digitalWrite(buzzer,LOW);//not sound
delay(1);//ms delay
{ digitalWrite(buzzer,HIGH);// sound
digitalWrite(buzzer,LOW);//not sound
delay(2);//2ms delay
//////////////////////////////////////////////////////////
*************************
Introduction
www.keyestudio.com 45
keyestudio
Hardware Required
Arduino Board *1
USB Cable *1
RGB LED * 1
220Ω Resistor*3
Breadboard*1
Circuit Connection
46 www.keyestudio.com
keyestudio
Sample Code
//////////////////////////////////////////////////////////
int redpin = 11; //select the pin for the red LED
int bluepin =10; // select the pin for the blue LED
int greenpin =9;// select the pin for the green LED
int val;
www.keyestudio.com 47
keyestudio
void setup() {
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
Serial.begin(9600);
void loop()
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(1);
analogWrite(11, val);
analogWrite(10, 255-val);
48 www.keyestudio.com
keyestudio
analogWrite(9, 128-val);
delay(1);
Serial.println(val, DEC);
//////////////////////////////////////////////////////////
Result
Directly copy the above code into arduino IDE, and click upload
******************************************************
*************************
Introduction
www.keyestudio.com 49
keyestudio
project. Potentiometer used here is a typical output component of
Hardware Required
Arduino Board *1
USB Cable *1
Potentiometer *1
Breadboard*1
Circuit Connection
experiments.
50 www.keyestudio.com
keyestudio
Note:
www.keyestudio.com 51
keyestudio
Sample Code
read the value of the interface. The A/D acquisition of Arduino 328
Arduino and PC, so the baud rate of the Arduino should match the
the one in the PC's software set up. Otherwise, the display will be
set up. The set up here needs to match the one in the program.
//////////////////////////////////////////////////////////
52 www.keyestudio.com
keyestudio
int val=0;// define val, assign initial value 0
void setup()
void loop()
//////////////////////////////////////////////////////////
Result
The sample program uses the built-in LED connected to pin 13.
www.keyestudio.com 53
keyestudio
Below is the analog value it reads.
When you rotate the potentiometer knob, you can see the
******************************************************
*************************
54 www.keyestudio.com
keyestudio
Introduction
use a 74HC595 to control LED? Well, think about how many I/O it
control 8 LEDs!
www.keyestudio.com 55
keyestudio
Hardware Required
Arduino Board *1
USB Cable *1
74HC595 Chip*1
Red M5 LED*4
blue M5 LED*4
220Ω Resistor*8
Breadboard*1
GND
Circuit Connection
56 www.keyestudio.com
keyestudio
The circuit may seem complicated, but once you give it a good
www.keyestudio.com 57
keyestudio
Sample Code
//////////////////////////////////////////////////////////
int ledState = 0;
void setup()
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
void loop()
updateLEDs(i);
delay(500);
digitalWrite(latch, LOW);//
//////////////////////////////////////////////////////////
Result
******************************************************
*************************
www.keyestudio.com 59
keyestudio
Project 13: 1-digit LED Segment Display
Introduction
has one more LED unit ( for decimal point display) than 7-segment
60 www.keyestudio.com
keyestudio
the wiring method of LED units, LED segment displays can be
divided into display with common anode and display with common
cathode. Common anode display refers to the one that combine all
www.keyestudio.com 61
keyestudio
Each segment of the display consists of an LED. So when you use
Hardware Required
Arduino Board *1
USB Cable *1
220Ω Resistor*8
Breadboard*1
Circuit Connection
62 www.keyestudio.com
keyestudio
Sample Code
www.keyestudio.com 63
keyestudio
displaying number 1, b and c segments will be turned on. We
the delay time, the longer the delay time, the longer the displaying
time.
//////////////////////////////////////////////////////////
unsigned char j;
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
64 www.keyestudio.com
keyestudio
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
digitalWrite(dp,LOW);
unsigned char j;
segment c
digitalWrite(j,LOW);
unsigned char j;
digitalWrite(b,HIGH);
www.keyestudio.com 65
keyestudio
digitalWrite(a,HIGH);
for(j=9;j<=11;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
digitalWrite(c,LOW);
digitalWrite(f,LOW);
{digitalWrite(g,HIGH);
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(dp,LOW);
digitalWrite(f,LOW);
digitalWrite(e,LOW);
{digitalWrite(c,HIGH);
digitalWrite(b,HIGH);
digitalWrite(f,HIGH);
66 www.keyestudio.com
keyestudio
digitalWrite(g,HIGH);
digitalWrite(dp,LOW);
digitalWrite(a,LOW);
digitalWrite(e,LOW);
digitalWrite(d,LOW);
unsigned char j;
digitalWrite(a,HIGH);
digitalWrite(b, LOW);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e, LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dp,LOW);
unsigned char j;
www.keyestudio.com 67
keyestudio
for(j=7;j<=11;j++)
digitalWrite(j,HIGH);
digitalWrite(c,HIGH);
digitalWrite(dp,LOW);
digitalWrite(b,LOW);
unsigned char j;
for(j=5;j<=7;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
for(j=8;j<=11;j++)
digitalWrite(j,LOW);
unsigned char j;
for(j=5;j<=11;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
68 www.keyestudio.com
keyestudio
}
unsigned char j;
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e, LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dp,LOW);
void setup()
for(i=4;i<=11;i++)
void loop()
www.keyestudio.com 69
keyestudio
while(1)
70 www.keyestudio.com
keyestudio
delay(1000); // wait for 1s
//////////////////////////////////////////////////////////
Result
Introduction
www.keyestudio.com 71
keyestudio
because no 100Ω resistor available. If you use 100Ω, the
Hardware Required
Arduino Board *1
USB Cable *1
220Ω Resistor*8
Breadboard*1
Circuit Connection
72 www.keyestudio.com
keyestudio
For 4-digit displays, there are 12 pins in total. When you place the
decimal point downward , the pin on the lower left part is refer to
www.keyestudio.com 73
keyestudio
74 www.keyestudio.com
keyestudio
Sample Code
//////////////////////////////////////////////////////////
// display 1234
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 6;
www.keyestudio.com 75
keyestudio
int g = 7;
int dp = 8;
int d4 = 9;
int d3 = 10;
int d2 = 11;
int d1 = 12;
// set variable
long n = 1230;
int x = 100;
void setup()
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
76 www.keyestudio.com
keyestudio
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(dp, OUTPUT);
/////////////////////////////////////////////////////////////
void loop()
Display(1, 1);
Display(2, 2);
Display(3, 3);
Display(4, 4);
///////////////////////////////////////////////////////////////
switch(n)
case 1:
digitalWrite(d1,LOW);
digitalWrite(d2, HIGH);
www.keyestudio.com 77
keyestudio
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
case 2:
digitalWrite(d1, HIGH);
digitalWrite(d2, LOW);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
case 3:
digitalWrite(d1,HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, LOW);
digitalWrite(d4, HIGH);
break;
case 4:
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, LOW);
break;
78 www.keyestudio.com
keyestudio
default :
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
void Num_0()
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
digitalWrite(dp,LOW);
void Num_1()
www.keyestudio.com 79
keyestudio
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp,LOW);
void Num_2()
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
void Num_3()
80 www.keyestudio.com
keyestudio
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
void Num_4()
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
www.keyestudio.com 81
keyestudio
void Num_5()
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
void Num_6()
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
82 www.keyestudio.com
keyestudio
}
void Num_7()
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp,LOW);
void Num_8()
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
www.keyestudio.com 83
keyestudio
digitalWrite(dp,LOW);
void Num_9()
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
84 www.keyestudio.com
keyestudio
digitalWrite(g, LOW);
digitalWrite(dp,LOW);
switch(n)
case 0:Num_0();
break;
case 1:Num_1();
break;
case 2:Num_2();
break;
case 3:Num_3();
break;
case 4:Num_4();
break;
case 5:Num_5();
break;
case 6:Num_6();
break;
www.keyestudio.com 85
keyestudio
case 7:Num_7();
break;
case 8:Num_8();
break;
case 9:Num_9();
break;
default:Clear();
break;
WeiXuan(x);
pickNumber(Number);
delay(1);
//////////////////////////////////////////////////////////
Result
86 www.keyestudio.com
keyestudio
Download the above code to the controller board and see the
result.
Thank you.
******************************************************
*************************
Introduction
www.keyestudio.com 87
keyestudio
With low-voltage scanning, LED dot-matrix displays have
advantages such as power saving, long service life, low cost, high
Hardware Required
Arduino Board *1
USB Cable *1
220ΩResistor*8
Breadboard*1
Circuit Connection
88 www.keyestudio.com
keyestudio
dot, you should set pin 9 to high level and pin 13 to low level. If
you want to light LEDs on the first row, you should set pin 9 to
high level and pins 13, 3, 4, 10, 6, 11, 15 and 16 to low level. If
you want to light the LEDs on the first column, set pin 13 to low
www.keyestudio.com 89
keyestudio
is used to control the rows of the dot-matrix while the other chip is
90 www.keyestudio.com
keyestudio
//////////////////////////////////////////////////////////
unsigned char
Text[]={0x00,0x1c,0x22,0x22,0x22,0x22,0x22,0x1c};
function
www.keyestudio.com 91
keyestudio
{ clear_();
digitalWrite(x+2, HIGH);
digitalWrite(y+10, LOW);
delay(1);
function
for(i=0;i<8;i++)
data=Text[i];
for(j=0;j<8;j++)
data>>=1;
void setup(){
int i = 0 ;
92 www.keyestudio.com
keyestudio
for(i=2;i<18;i++)
pinMode(i, OUTPUT);
clear_();
void loop()
{ show_num();
{for(int i=2;i<10;i++)
digitalWrite(i, LOW);
for(int i=0;i<8;i++)
digitalWrite(i+10, HIGH);
//////////////////////////////////////////////////////////
Result
Burn the program into REV4 board The dot-matrix will display 0.
******************************************************
www.keyestudio.com 93
keyestudio
*************************
4. Projects of Modules
94 www.keyestudio.com
keyestudio
Introduction
This project is easier and you can make LED blink simply by
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
Dupont Line*3
www.keyestudio.com 95
keyestudio
Circuit Connection
Sample Code
//////////////////////////////////////////////////////////
void setup() {
pinMode(led, OUTPUT);
}
96 www.keyestudio.com
keyestudio
void loop() {
voltage level)
voltage LOW
//////////////////////////////////////////////////////////
Result
Upload the codes to REV4 board and then you can see piranha
LED and L light on the board are blinking together with an interval
of one second.
www.keyestudio.com 97
keyestudio
Project 2 Active Buzzer Module
Introduction
This project uses the same codes as Project 1’s, and then the
buzzer will ring for one second and stop for one second.
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
98 www.keyestudio.com
keyestudio
Dupont Line*3
Circuit Connection
Sample Code
//////////////////////////////////////////////////////////
www.keyestudio.com 99
keyestudio
void setup() {
pinMode(led, OUTPUT);
void loop() {
voltage level)
voltage LOW
//////////////////////////////////////////////////////////
Result
After uploading the codes to REV4 board, you can hear the buzzer
ringing and see the L light blinking at the same time with an
100 www.keyestudio.com
keyestudio
Project 3 Soil Module
Introduction
www.keyestudio.com 101
keyestudio
conductivity of soil is bad (increasing resistance).
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
Dupont Line*3
Circuit Connection
102 www.keyestudio.com
keyestudio
Sample Code
//////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
void loop() {
www.keyestudio.com 103
keyestudio
Serial.println(sensorValue, DEC);
//////////////////////////////////////////////////////////
Result
After uploading the codes to REV4 board, insert the sensor into
soil of different humidity, and you can see different analog value
104 www.keyestudio.com
keyestudio
Introduction
sensor, MCU will get a feedback of analog signal from S signal pin
of the sensor. You can read out the value from MCU to deduce
whether it rains.
Hardware Required
Arduino board *1
V5 Shield*1
USB Cable*1
Vapor Sensor*1
Dupont Line*3
Circuit Connection
www.keyestudio.com 105
keyestudio
Sample Code
//////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
void loop() {
Serial.println(sensorValue);
//////////////////////////////////////////////////////////
Result
After uploading the codes to REV4 board, open serial monitor, and
you can see current value. Add drop on the sensing point and the
www.keyestudio.com 107
keyestudio
Introduction
signal.
smoke and other harmful gas. It can detect various harmful gases,
108 www.keyestudio.com
keyestudio
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
Dupont Line*4
Circuit Connection
www.keyestudio.com 109
keyestudio
Sample Code
///////////////////////////////////////////////////
///////////////////////////////////////////////////
//////////
110 www.keyestudio.com
keyestudio
int buttonState = 0; // variable for reading the pushbutton
status
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
void loop(){
int val;
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
www.keyestudio.com 111
keyestudio
// turn LED on:
digitalWrite(ledPin, LOW);
else {
digitalWrite(ledPin, HIGH);
delay(100);
///////////////////////////////////////////////////
///////////////////////////////////////////////////
//////////
Result
sensor, and you can see the analog value increases, LED on the
112 www.keyestudio.com
keyestudio
Project 6 PIR Motion Sensor
Introduction
and est.
the object will produce current or its electric charge will pile up.
First the lens receives IR from testing object; next the sensor
converts IR into electrical signal ; finally, the circuit will process the
www.keyestudio.com 113
keyestudio
signal.
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
Dupont Line*3
Circuit Connection
114 www.keyestudio.com
keyestudio
Sample Code
///////////////////////////////////////////////////
///////////////////////////////////////////////////
//////////
void setup()
pinMode(IRswitch,INPUT);
www.keyestudio.com 115
keyestudio
pinMode(led,OUTPUT); //defining ports;
void loop()
if(val)
else
http://keyes-arduino.taobao.com
///////////////////////////////////////////////////
///////////////////////////////////////////////////
//////////
Result
116 www.keyestudio.com
keyestudio
none, L light is on for some time and then off.
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
Ultraviolet Sensor*1
Dupont Line*3
www.keyestudio.com 117
keyestudio
Circuit Connection
Sample Code
///////////////////////////////////////////////////
////////////////////////////////////////
void setup() {
Serial.begin(9600);
118 www.keyestudio.com
keyestudio
// the loop routine runs over and over again forever:
void loop() {
Serial.println(sensorValue);
///////////////////////////////////////////////////
////////////////////////////////////////
Result
After uploading the codes, open serial monitor, and you can see
the monitor.
www.keyestudio.com 119
keyestudio
120 www.keyestudio.com
keyestudio
Introduction
value.
www.keyestudio.com 121
keyestudio
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
Dupont Line*3
Circuit Connection
122 www.keyestudio.com
keyestudio
Sample Code
///////////////////////////////////////////////////
////////////////////////////////////////////
void setup() {
Serial.begin(9600);
void loop() {
Serial.println(sensorValue);
///////////////////////////////////////////////////
////////////////////////////////////////////
Result
www.keyestudio.com 123
keyestudio
After uploading the codes, open serial monitor, and you can see
increases.
Introduction
124 www.keyestudio.com
keyestudio
term stability. It has excellent quality, fast response, anti-
and easy.
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
Dupont Line*3
Circuit Connection
www.keyestudio.com 125
keyestudio
Sample Code
///////////////////////////////////////////////////
///////////////////////
int DHpin = 8;
byte dat[5];
byte read_data()
byte data;
126 www.keyestudio.com
keyestudio
{
if(digitalRead(DHpin) == LOW)
level to decide 0 or 1;
if(digitalRead(DHpin) == HIGH)
backward
return data;
void start_test()
signal;
www.keyestudio.com 127
keyestudio
digitalWrite(DHpin,HIGH);
pinMode(DHpin,INPUT);
while(digitalRead(DHpin) == HIGH);
if(digitalRead(DHpin) == LOW);
dat[i] = read_data();
pinMode(DHpin,OUTPUT);
void setup()
Serial.begin(9600);
pinMode(DHpin,OUTPUT);
128 www.keyestudio.com
keyestudio
void loop()
start_test();
humidity;
Serial.print('.');
humidity;
Serial.println('%');
temperature;
Serial.print('.');
temperature;
Serial.println('C');
delay(700);
///////////////////////////////////////////////////
///////////////////////
www.keyestudio.com 129
keyestudio
Result
After uploading the codes, you can see current temperature and
130 www.keyestudio.com
keyestudio
Project 10 GP2Y10 Dust Sensor
Introduction
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
Dupont Line*4
www.keyestudio.com 131
keyestudio
Circuit Connection
Sample Code
int dustPin=A0;
float dustVal=0;
int ledPower=2;
int delayTime=280;
int delayTime2=40;
float offTime=9680;
void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT);
pinMode(dustPin, INPUT);
132 www.keyestudio.com
keyestudio
}
void loop(){
on the sensor
digitalWrite(ledPower,LOW);
delayMicroseconds(delayTime);
dustVal=analogRead(dustPin);
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH);
delayMicroseconds(offTime);
delay(1000);
if (dustVal>36.455)
Serial.println((float(dustVal/1024)-0.0356)*120000*0.035);
Result
After uploading the codes, you can see the following value on
serial monitor:
www.keyestudio.com 133
keyestudio
1050-3000 = bad
300-1050 = normal
150-300 = good
0-75 = tiptop
134 www.keyestudio.com
keyestudio
Project 11 I2C1602 Liquid Crystal Display Module
Introduction
I/O port of MCU. You can adjust contrast ratio of screen through
Hardware Required
Arduino Board *1
V5 Shield*1
www.keyestudio.com 135
keyestudio
USB Cable*1
Dupont Line*4
Circuit Connection
Sample Code
///////////////////////////////////////////////////
///
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
void setup()
136 www.keyestudio.com
keyestudio
{
lcd.backlight();
lcd.print("Hello Arduino");
void loop()
///////////////////////////////////////////////////
///
Result
After uploading the codes, you can see there is displaying “Hello
www.keyestudio.com 137
keyestudio
LED
Introduction
brightness of LED.
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
Shield V5*1
Dupont Line*Several
138 www.keyestudio.com
keyestudio
Circuit Connection
Plug Shield V5 into REV4 board and don’t misplace pins to avoid
Sample Code
//////////////////////////////////////////////////
www.keyestudio.com 139
keyestudio
///////////////////////////////////////////////////
//
void setup()
void loop()
5V corresponding to 0-1204)
//////////////////////////////////////////////////
///////////////////////////////////////////////////
Result
140 www.keyestudio.com
keyestudio
Introduction
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
Shield V5*1
Buzzer Module*1
Ultraviolet Sensor*1
Dupont Line*Several
Circuit Connection
www.keyestudio.com 141
keyestudio
Sample Code
////////////////////////////////////////////////
///////////////////////////////////////
int ON = 11;
void setup() {
pinMode(ON, OUTPUT);
Serial.begin(9600);
142 www.keyestudio.com
keyestudio
void loop() {
int n;
if(sensorValue>=20)
for(n=0;n<8;n++)
digitalWrite(ON, HIGH);
delay(1000);
digitalWrite(ON, LOW);
delay(500);
else
digitalWrite(ON, LOW);
www.keyestudio.com 143
keyestudio
Serial.println(sensorValue);
/////////////////////////////////////////////////
//////////////////////////////////////
Result
After uploading the codes, you can see when the value is equal to
or more than 20, the buzzer rings for 1 second and stop for 0.5
Introduction
LCD1602.
144 www.keyestudio.com
keyestudio
Hardware Required
Arduino Board *1
V5 Shield*1
USB Cable*1
LCD1602*1
Dupont Line*Several
Circuit Connection
Sample Code
/////////////////////////////////////////////////
//////////////////////////////////////
www.keyestudio.com 145
keyestudio
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
LiquidCrystal_I2C lcd(0x27,20,4);
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
lcd.init();
146 www.keyestudio.com
keyestudio
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("DHT-11 test!");
void loop() {
milliseconds!
float h = dht.readHumidity();
float t = dht.readTemperature();
lcd.clear();
if (isnan(t) || isnan(h)) {
lcd.setCursor(0,0);
lcd.print("Failed DHT");
} else {
Serial.print("Humidity: ");
www.keyestudio.com 147
keyestudio
lcd.setCursor(0,0);
lcd.print("H:");
Serial.print(h);
lcd.setCursor(3,0);
lcd.print(h);
Serial.print(" %\t");
lcd.setCursor(9,0);
lcd.print("%");
Serial.print("Temperature: ");
lcd.setCursor(0,1);
lcd.print("T:");
Serial.print(t);
lcd.setCursor(3,1);
lcd.print(t);
Serial.println(" *C");
lcd.setCursor(8,1);
lcd.print(" *C");
delay(200);
////////////////////////////////////////////////
148 www.keyestudio.com
keyestudio
///////////////////////////////////////
Result
After adding the libraries and uploading the codes, you can see
4. Integrated Project
Introduction
Hardware Required
Arduino Board *1
Shield V5*1
LCD1602*1
Piranha LED*3
www.keyestudio.com 149
keyestudio
MQ 135 Gas Sensor*1
Buzzer Module*1
USB Cable*1
Dupont Line*Several
Circuit Connection
150 www.keyestudio.com
keyestudio
Humid Sensor
ity
Sensor
2 D0
3 S
4 S
5 S
7 LED
9 S
10 S
www.keyestudio.com 151
keyestudio
11 S
12
13
A0 S
A1 S
A2 A0
A3 OUT
A4/ SDA
SDA
A5/ SCL
SCL
152 www.keyestudio.com
keyestudio
Sample Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
LiquidCrystal_I2C lcd(0x27,20,4);
www.keyestudio.com 153
keyestudio
#define GAS A2 //defining analog ports of Gas Sensor
Sensor
float dustVal=0;
int delayTime=280;
int delayTime2=40;
float offTime=9680;
Sensor
154 www.keyestudio.com
keyestudio
int TEMT_val; //reading signal in real time of
int S12SD_val;
void setup() {
Serial.begin(9600);
dht.begin();
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(5,0);
lcd.print("HELLO");
delay(1000);
pinMode(GP2Y_LED,OUTPUT);
pinMode(LED1,OUTPUT);pinMode(LED2,OUTPUT);pinMode(LED3,
OUTPUT);
pinMode(BUZZ,OUTPUT);pinMode(PIR,INPUT);pinMode(DHTPIN,
www.keyestudio.com 155
keyestudio
OUTPUT);pinMode(GAS_D,INPUT);
pinMode(GP2Y_OUT, INPUT);pinMode(GAS,
digitalWrite(LED1, LOW);
void loop()
DHT11_FUNC();
GP2Y_FUNC();
PIR_FUNC();
TEMT_FUNC();
S12SD_FUNC();
void S12SD_FUNC()
S12SD_val = analogRead(S12SD);
Serial.println(S12SD_val);
lcd.setCursor(10,1);
lcd.print("R:");
156 www.keyestudio.com
keyestudio
lcd.setCursor(12,1);
lcd.print(S12SD_val*10);
digitalWrite(BUZZ,HIGH);
else
digitalWrite(BUZZ,LOW);
void TEMT_FUNC()
TEMT_val = analogRead(TEMT);
Serial.println(TEMT_val);
void GP2Y_FUNC()
digitalWrite(GAS_D, HIGH);
digitalWrite(GP2Y_LED,LOW);
delayMicroseconds(delayTime);
www.keyestudio.com 157
keyestudio
dustVal=analogRead(GP2Y_OUT);
delayMicroseconds(delayTime2);
digitalWrite(GP2Y_LED,HIGH);
delayMicroseconds(offTime);
if (dustVal>36.455)
Serial.println((float(dustVal/1024)-0.0356)*120000*0.035);
lcd.setCursor(0,1);
lcd.print("GP:");
lcd.setCursor(3,1);
lcd.print((float(dustVal/1024)-0.0356)*120000*0.035);
gasdigi = digitalRead(GAS_D);
if(gasdigi == 0) digitalWrite(LED3,HIGH);
else digitalWrite(LED3,LOW);
void DHT11_FUNC()
milliseconds!
158 www.keyestudio.com
keyestudio
// Sensor readings may also be up to 2 seconds 'old' (its a very
slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
lcd.clear();
// check if returns are valid, if they are NaN (not a number) then
if (isnan(t) || isnan(h))
lcd.setCursor(0,0);
lcd.print("Failed DHT");
else
lcd.setCursor(0,0);
lcd.print(h);
lcd.setCursor(6,0);
lcd.print("%");
lcd.setCursor(8,0);
www.keyestudio.com 159
keyestudio
lcd.print(t);
lcd.setCursor(14,0);
lcd.print("*C");
void PIR_FUNC()
if(IR_val)
LED on;
else
//http://keyes-arduino.taobao.com
Result
160 www.keyestudio.com
keyestudio
After uploading the codes, first you can see the data displayed on
detecting range.
www.keyestudio.com 161