Keyestudio KS4028 User manual

1
www.keyestudio.com
Smart Home Kit for Micro:bit
Contents
Smart Home Kit for Micro:bit..................................................................................... 1
1.Introduction:.............................................................................................................. 3
2.Description:................................................................................................................4
3.Kit List:......................................................................................................................... 5
4. Preparations:............................................................................................................. 10
4.1 Background Information about Micro:bit..............................................10
( 1 )What is Micro:bit?.................................................................................10
( 2 )Layout...................................................................................................... 11
( 3 ) Pinout......................................................................................................13
( 4 )Notes for the application of Micro:bit main board....................14
4.2.Install Micro:bit driver..................................................................................16
5.Getting Started with Micro:bit.............................................................................. 16
5.1 Write code and program............................................................................ 17
5.2.Makecode:.................................................................................................... 28
5.3 Quick Download............................................................................................29
5.4.Makecode extension library:......................................................................37
5.4.Resources and test code............................................................................. 46
5.5.Input test code...............................................................................................47

2
www.keyestudio.com
5.6. Install CoolTerm:........................................................................................52
6.Install the Smart Home........................................................................................... 55
7. Project:...................................................................................................................109
Project 1: Heartbeat..........................................................................................109
Project 2: Light A Single LED..........................................................................112
Project 3: LED Dot Matrix................................................................................ 117
Project 4: Programmable Buttons................................................................ 121
Project 5: Temperature Detection.................................................................128
Project 6: Geomagnetic Sensor..................................................................... 142
Project 7: Accelerometer................................................................................. 156
Project 8: Light Brightness Detection.......................................................... 167
Project 9: Speaker..............................................................................................176
Project 10: Touch-sensitive Logo.................................................................. 189
Project 11: Microphone................................................................................... 193
Project 12: Play Music...................................................................................... 201
Project 13: Dodge Bullets................................................................................205
8.Expansion Projects:............................................................................................. 240
Project 1:LED Blinks........................................................................................241
Project 2:Breathing LED................................................................................ 246
Project 3:6812 2x2 Full Color RGB.............................................................254
Project 4:PIR Motion Sensor....................................................................... 270
Project 5:Induction Lamp............................................................................. 278

3
www.keyestudio.com
Project 6: Adjust angles of servo.................................................................. 282
Project 7: 130 Motor.........................................................................................288
Project 8:Lithium Battery Power Module................................................ 298
Project 9:1602 LCD.........................................................................................302
Project 10:Steam Sensor...............................................................................310
Project 11:Rains Alarm.................................................................................. 317
Project 12:Analog Gas(MQ-2)Sensor.................................................. 322
Project 13:Gas Leakage Detector...............................................................331
Project 14:DHT11 Temperature and Humidity Sensor........................336
Project 15:Temperature and Humidity Display..................................... 347
Project 16:Multiple Functions..................................................................... 351
Project 17:BT-controlled LED...................................................................... 354
Project 18:Smart Home.................................................................................358
9.Resources:.................................................................................................................361
1.Introduction:
Fueled by the rapid development of technology, smart homes
automatically controlled remotely by smart phones and other devices have
become more common. For the same reason, they have increasingly

4
www.keyestudio.com
gained closer attention and caught people’s fancy.
Bearing the aim to make improvements in household living conditions, the
smart home system has been integrated with technologies including
computer science, telecommunication, automatic control and others and
emerged as a comprehensive and smart system featuring safety,
convenience, coziness, services , utility and environmental consciousness.
2.Description:
Launched by Keyestudio, this smart home kit is based on the open-source
hardware of Micro:bit and designed for those who dream of living a more
comfortable life with the help of technologies.
This smart home system, with Micro:bit as its control board, is equipped
with a 1602 LCD, a DHT11 temperature and humidity sensor, an analog gas
sensor(MQ_2), a PIR motion sensor , a 6812 RGB module, a servo, a steam
sensor, a Micro:bit BT and other sensors.
With the help of these sensors, this kit can be applied to detect
temperature, humidity and the concentration of flammable gases in your
home and open and close doors. Furthermore, all the information detected
can display on 1602 LCD in real time available for you to check and monitor

5
www.keyestudio.com
via smart phones or iPad. By the way, it supports powering by solar energy
or via USB cable.
This tutorial will guide you to make and control the smart home kit by the
code written in the online graphical programming platform Makecode. In
this process, not only can you enhance your ability to make stuffs but also
learn the skills of programming.
MakeCode for micro:bit is the most widely used graphical programming
environment on the micro:bit official website. It is based on the graphical
programming environment developed by Microsoft's open source project
MakeCode. This graphical programming can also be converted to textual
version, namely Python or JavaScript. The combination of code and
graphics makes it very convenient and easy to learn. At the same time, it
can be simulated or programmed for electronic components.
3.Kit List:
When you get this delicate kit, please confirm whether all components
listed below have been delivered.
#
Parts
Quantity
Picture

6
www.keyestudio.com
1
Micro:bit Main Board
1
2
Keyestudio Micro:bit
Expansion Board with
IO Port
1
3
Wooden Board
7
4
Acrylic Board
3
5
6812 RGB Module
1
6
Analog Gas Sensor
1
7
130 Motor Module
1
8
Steam Sensor
1

7
www.keyestudio.com
9
DHT11 Temperature
and Humidity Sensor
1
10
PIR Motion Sensor
1
11
Yellow LED Module
1
12
Rechargeable Lithium
Battery Power
Module with Solar
and USB Ports
1
13
Battery Holder
1
14
Micro:bit Solar Energy
Panel
1
15
Servo
2
16
I2C 1602 LCD Module
1
17
Rocker Switch
1

8
www.keyestudio.com
18
15cm 3Pin F-F
DuPont Wire
4
19
20cm 3Pin F-F
DuPont Wire
2
20
20cm F-F DuPont
Wire
4
21
20cm 4Pin F-F
DuPont Wire
1
22
200mm 2Pin DuPont
Wire
2
23
M2*8MM
Round-head Screw
3
24
M1.4*6MM
Round-head
Self-tapping Screw
10
25
M3 Nickel-plated
Self-locking Nut
5
26
M4*8MM
Round-head Screw
18
27
M3*6MM
Round-head Screw
9
28
M3*10MM
9

9
www.keyestudio.com
Round-head Screw
29
M2*12MM
Round-head Screw
5
30
M4 Nickel-plated Nut
18
31
M3 Nickel-plated Nut
6
32
M2 Nickel-plated Nut
7
33
M3*8MM
Round-head Screw
2
34
Wrench
1
35
3.0*40MM
Screwdriver
Red-Black
1
36
2.0*40MM
Screwdriver
Purple-Black
1
37
M3*45MM Dual-pass
Copper Pillar
4
38
USB Cable
AM/MK5P(micro)
Black OD:3.5 L=1M
PVC
1

10
www.keyestudio.com
39
F5 Blue to Blue LED
2
40
18650 Battery(Not
Included)
1
4. Preparations:
4.1 Background Information about Micro:bit
( 1 )What is Micro:bit?
Micro:bit is an open source hardware platform based on the ARM
architecture launched by British Broadcasting Corporation (BBC) together
with ARM, Barclays, element14, Microsoft and other institutions. The core
device is a 32-bit Arm Cortex-M4 with FPU micro-processing.
Though it is just the size of a credit card, the Micro:bit main board is
equipped with loads of components,including a 5*5 LED dot matrix, 2
programmable buttons, an accelerometer, a compass, a thermometer, a
touch-sensitive logo and a MEMS microphone, a Bluetooth module of low
energy, and a buzzer and others. Thus, it also boasts multiple functions.
The buzzer built in the other side of the board makes playing all kinds of
sound possible without any external equipment. The golden fingers and

11
www.keyestudio.com
gears added provide a better fixing of crocodile clips. Moreover, this board
has a sleeping mode to lower power consumption of batteries and it can
be entered if users long press the Reset & Power button on the back of it. It
is capable of reading the data of sensors, controlling servos and RGB lights
and attaching with a shield so as to connect with various sensors. It also
supports a variety of codes and graphical programming platforms, and is
compatible with almost all PCs and mobile devices. It has no need to install
drivers. It is of high integration of electronic modules, and has a serial port
monitoring function for easy debugging.
The board has found wild applications. It can be applied in programming
video games, making interactions between light and sound, controlling a
robot, conducting scientific experiments, developing wearable devices and
make some cool inventions like robots and musical instruments, basically
everything imaginable.
( 2 )Layout

12
www.keyestudio.com
For the Micro: Bit main board, pressing the Reset & Power button, it will
reset the board and rerun the program.If you hold it tight, the red LED will
slowly get darker.When the power indicator flickers into darkness, releasing
the button and your Micro: Bit board will enter sleep mode for power
saving .This will make the battery more durable. And you could press this
button again to‘wake up’your Micro:bit.
For more information,please resort to following links:

14
www.keyestudio.com
The functions of pins:
GPIO
P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,
P13,P14,P15,P16,P19,P20
ADC/DAC
P0,P1,P2,P3,P4,P10
IIC
P19(SCL),P20(SDA)
SPI
P13(SCK),P14(MISO),P15(MOSI)
PWM(used
frequently)
P0,P1,P2,P3,P4,P10
PWM(not
frequently
used)
P5、P6、P7、P8、P9、P11、P12、P13、P14、P15、P16、P19、
P20
Occupied
P3(LED Col3),P4(LED Col1),P5(Button A),P6(LED Col4),
P7(LED Col2),P10(LED Col5),P11(Button B)
Browse the official website for more details:
https://tech.microbit.org/hardware/edgeconnector/
https://microbit.org/guide/hardware/pins/
( 4 )Notes for the application of Micro:bit main board
a. It is recommended to cover it with a silicone protector to prevent short
circuit for it has a lot of sophisticated electronic components.

15
www.keyestudio.com
b. Its IO port is very weak in driving since it can merely handle current less
than 300mA. Therefore, do not connect it with devices operating in large
current, such as servo MG995 and DC motor or it will get burnt.
Furthermore, you must figure out the current requirements of the devices
before you use them and it is generally recommended to use the board
together with a Micro:bit shield.
c. It is recommended to power the main board via the USB interface or via
the battery of 3V. The IO port of this board is 3V, so it does not support
sensors of 5V. If you need to connect sensors of 5 V, a Micro: Bit expansion
board is required.
d. When using pins(P3, P4, P6, P7 and P10)shared with the LED dot matrix,
blocking them from the matrix or the LEDs may display randomly and the
data about sensors connected maybe wrong.
e. Pin 19 and 20 can not be used as IO ports though the Makecode shows
they can. They can only be used as I2C communication.
f. The battery port of 3V cannot be connected with battery more than 3.3V
or the main board will be damaged.

16
www.keyestudio.com
g. Forbid to operate it on metal products to avoid short circuit.
To put it simple, Micro:bit V2 main board is like a microcomputer which has
made programming at our fingertips and enhanced digital innovation. And
as for programming environment, BBC provides a website:
https://microbit.org/code/, which has a graphical MakeCode program easy
for use.
4.2.Install Micro:bit driver
Micro:bit is free of driver installation. However, in case your computer fail
to recognize the main board, you can install the diver too.
Just enter the link https://fs.keyestudio.com/KS4027-4028
to download the driver file of micro:bit in
file folder .
5.Getting Started with Micro:bit
The following instructions are applied for Windows system but can also
serve as a reference if you are using a different system.

17
www.keyestudio.com
5.1 Write code and program
This chapter describes how to write program and load the program to the
Micro: Bit main board V2.
You are recommended to browse the official website of Micro:bit for more
details, and the link is attached below:
https://microbit.org/guide/quick/
Step 1: connect the Micro: Bit main board with your computer
Firstly, link the Micro: Bit main board with your computer via the USB cable.
Macs, PCs, Chromebooks and Linux(including Raspberry Pi)systems are all
compatible with the Micro: Bit main board.
Note that if you are about to pair the board with your phone or tablet,
please refer to this link:
https:/microbit.org/get-started/user-guide/mobile/

18
www.keyestudio.com
Secondly, if the red LED on the back of the board is on, that means the
board is powered. When your computer communicates with the main
board via the USB cable, the yellow LED on it will flashes. For example, it
will flicker when you burn a “hex”file.
Then Micro: bit main board will appear on your computer as a driver
named “MICROBIT(E:)”. Please note that it is not an ordinary USB disk as
shown below.

19
www.keyestudio.com
Step 2: write programs
View the link https://makecode.microbit.org/ in your browser;
Click ‘New Project’;
The dialog box‘Create a Project’ appears, fill it with‘heartbeat’and click
‘Create √’to edit.
(If you are running Windows 10 system, it is also viable to edit on the APP
MakeCode for micro:bit , which is exactly like editing in the website. And
the link to the APP is
https://www.microsoft.com/zh-cn/p/makecode-for-micro-bit/9pjc7sv48lcx?
ocid=badgep&rtc=1&activetab=pivot:overviewtab )
Take Google Chrome as an example as shown below and it is almost the
same for other browsers.

20
www.keyestudio.com
Table of contents