0% found this document useful (0 votes)
15 views

Adeep-Arduino Project Book

Uploaded by

kamakshi.etprime
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Adeep-Arduino Project Book

Uploaded by

kamakshi.etprime
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 628

1

Contents
Arduino................................................................................................................................................3
Building the Arduino development environment..............................................................................12
Arduino graphical programming.......................................................................................................28
Lesson 1 How to Light the Blinking LED........................................................................................ 50
Lesson 2 The Application of the Active Buzzer............................................................................... 75
Lesson 3 Controlling LED with Button............................................................................................ 96
Lesson 4 Controlling LED with Relay Module.............................................................................. 116
Lesson 5 Controlling LED with Potentiometer.............................................................................. 133
Lesson 6 Making a Flowing LED with LED..................................................................................149
Lesson 7 Controlling LED Bar with Potentiometer....................................................................... 164
Lesson 8 Making Breathing LED with LED.................................................................................. 180
Lesson 9 The Application of the RGB LED................................................................................... 199
Lesson 10 The Application of the Passive Buzzer..........................................................................216
Lesson 11 The Application of the LCD1602 and the IIC Interface................................................233
Lesson 12 Making Voltmeter.......................................................................................................... 250
Lesson 13 The Application of the 7-segment Display....................................................................265
Lesson 14 Making A Simple Counter............................................................................................. 282
Lesson 15 Controlling the Servo Motor..........................................................................................299
Lesson 16 Making a Digital Thermometer..................................................................................... 316
Lesson 17 The Application of IR Remoter Controller....................................................................334
Lesson 18 The Application of DHT-11(Digital Temperature & Humidity Sensor)....................... 350
Lesson 19 The Application of the Ultrasonic Distance Sensor...................................................... 369
Lesson 20 Application of MPU6050...............................................................................................385
Lesson 21 The Application of the 4*4 Matrix Keyboard............................................................... 410
Lesson 22 Controlling the DC Motor............................................................................................. 427
Lesson 23 The Application of the PS2 Joystick Module................................................................441
Lesson 24 Controlling LED with Tilt Switch................................................................................. 457
Lesson 25 The Application of the 8*8 Dot-matrix Module............................................................471
Lesson 26 Controlling the Stepper Motor.......................................................................................487
Lesson 27 Using Photoresistor to Measuring Light intensity.........................................................501
Lesson 28 Making Light Tracking System..................................................................................... 517
Lesson 29 Making Frequency Meter.............................................................................................. 532
Lesson 30 The Application of the PIR Movement Sensor............................................................. 549
Lesson 31 Using IR Remoter Controller to control Relay............................................................. 565
Lesson 32 Controlling RGB LED with IR Remoter Controller..................................................... 579
Lesson 33 Controlling Stepper Motor with IR Remoter Controller...............................................595
Lesson 34 Controlling the Size of a Circle by Potentiometer........................................................ 610
Lesson 35 Controlling the 3D Model by PS2 Joystick...................................................................619
Lesson 36 Snake Game................................................................................................................... 622
Lesson 37 Star Wars........................................................................................................................ 625

2
Arduino

1. Arduino

Arduino is an easy-to-use open source electronic prototype platform. The name


Arduino is derived from the inherent, originally intended as "strong friends". It was
born in 2005 in Italy Interaction Design Institute (Interaction Design Institute
Ivrea).One of the main founders of the project is called Massimo Banzi.
The original intention of the Arduino project was to lower the threshold for
students in the Interactive Design Institute to create interactive works. In addition to
reducing the cost of students, it also takes into account the difficulty of learning. That
is to say, it only takes a little money and requires a very small amount of
programming knowledge to create different works according to the unexpected
creativity.
In the spirit of open source: for the benefit of more enthusiasts, from the
beginning of the creation of the Arduino project, it has complied with the agreement
of open source hardware. Anyone not only is allowed to get the design drawings of
the Arduino hardware circuit board for free, but also do mass produce according to
their own design process.
In recent years, with the rise of smart hardware, a wave called Maker has
emerged all over the world. They use Arduino and various hardware modules around
it to quickly build a variety of fun products.Such as personalized air quality detectors,
fire alarms.People who love cats make smart cat feeders. Some people make all kinds
of weird small robots. Flying enthusiasts design various aircrafts to complete a variety
of thrilling aerial photography.
Next let us learn about Arduino!

3
2.Features of Arduino

At present, there are many other single-chip and single-chip platforms on the
market, such as 51 single-chip and STM32 single-chip. However, they have relatively
high thresholds for ordinary developers. They not only ask for certain basic
knowledge of programming and hardware,but also the internal registers of them are
more complicated.
Arduino not only simplifies the process of working with a microcontroller, but
also provides teachers, students and hobbyists with some advantages and features that
other systems do not have:
Openness: Arduino is an early open source hardware project. Its various open
source projects have been widely recognized and widely used. Its hardware circuit
and software development environment are completely open, and anyone can use,
modify, and share it without engaging in commercial use. This not only allows users
to better understand the circuit principle of Arduino, but also can modify according to
their needs. For example, due to space constraints, we need to design a special-shaped
circuit board, or design our own expansion circuit and main control circuit to connect
together.
Ease of use: for those who are interested, regardless of the basics knowledge,
however within one hour they can get to run the first simple program on Arduino. The
connection between Arduino and PC uses the most popular USB connection. You can
connect the Arduino directly to the computer just like using a smart phone without
installing any additional drivers. And the development environment software of
Arduino is also very simple. The clear menu only provides the necessary toolbar,
eliminating all the elements that may dazzle beginners. You can even compile and
download routines without reading the tutorial.
Communication: For beginners, communication and display are very effective
ways to stimulate learning enthusiasm. But sometimes, for beginners who do not have
a particularly deep understanding of single chip microcomputer, I am afraid it will be

4
difficult to communicate between them. But Arduino has defined a relatively unified
framework, and some of the underlying initialization has adopted a unified
method,and the ports used for digital and analog signals are also calibrated, which is
helpful for beginners to communicate.
Rich third-party resources: Arduino hardware and software are all open source,
you can have a deep understanding of all the underlying mechanisms, and it also
reserves a very friendly third-party library development interface. Adhering to the
openness and sharing of the open source community, many enthusiasts will bring their
own hardware and software to share with you after successfully implementing their
own designs. For latecomers, you can easily find some basic function modules you
want to use in the Arduino community, such as servo control, PID speed regulation,
A/D conversion, etc. Some function module suppliers are also paying more and more
attention to the Arduino community.They provide libraries and related tutorials for
their products under Arduino. These are extremely convenient for Arduino developers.
You can focus on the functional design that you want to do without having to stick to
the writing of basic functions.

3. Introduction of Arduino Development Board

Since the development of Arduino, various models and many derivative


controllers have been introduced, including Arduino Uno, Arduino Nano, Arduino
Yún, etc. Our course uses the Arduino Uno R3 development board. As shown below:

5
The following is a detailed introduction to the development board of Arduino
Uno R3 model:

(1) Power port:

Arduino UNO has three power supply methods:


1. Power supply via USB interface.The voltage is 5 V;
2. Power is supplied with the DC power input interface, and the voltage requires 7 to
12 V;
3. Power is supplied with the 5 V or VIN port at the power supply interface. The
power supply at the 5 V port must be 5 V, and the power supply at the VIN port is 7 to
12 V.
4. IOREF: Provide working reference voltage for the expansion board.
5. RESET: reset pin. Restart the Arduino and start the program from the beginning.
6. GND: Ground terminal.
7. Vin: provides external power supply voltage, which can be directly connected to
external power supply by this port.

6
(2) Analog port (A0~A5):

Arduino Uno has 6 analog pins. Pins A0-A5 can read analog voltages. They are
used as ADCs (analog-to-digital converters). ADCs convert the voltages into bits that
the microprocessor can understand. These pins are used as analog inputs, but they can
also be used as digital inputs or digital outputs. They are often used to read sensor
data.

(3) Digital port (0~13):

Pins 0 to 13 of Arduino Uno are used as digital input/output pins. Among them,
pin 13 is connected to the on-board LED indicator (D13 indicator); digital pins can be
turned on or off. When they are on, they are at a high level of 5V.When they are off,
they are at a low level of 0V status. On the Arduino, when the digital pins are
configured as outputs, they are set to 0 or 5V. When the digital pin is configured as an
input, the voltage is provided by an external device. This voltage can be varied
between 0-5V and converted to a digital 0 or 1 to indicate low or high level. To
determine this, there are 2 thresholds:
1. If it is lower than 0.8v, it is regarded as 0.
2. If it is higher than 2.0v, it is regarded as 1.
When connecting components to digital pins, make sure that the logic levels
match. If the voltage is between the thresholds, the return value will be undefined.
Pins 3, 5, 6, 9, 10, 11 have PWM function.
Pins 10, 11, 12, and 13 can be used for SPI communication.
0 and 1 are Rx and Tx pins. These two pins are generally used as serial ports.
Non-serial devices should not occupy this pin as much as possible. (Rx send, Tx
receive).
Pin 2 and 3 can input an external interrupt signal.
A4 (SDA), A5 (SCL) and TWI interface can be used for TWI communication,
being compatible with I²C communication. You can use the official Wire library to
7
operate.
The AERF pin can be used for analog input reference voltage.
【Attention】:
1. Each pin can provide/receive up to 40mA of current. But the recommended
current is 20mA.
2. The absolute maximum current provided by all pins is 200mA.

(4) ICSP port:

The ICSP (In-Circuit Serial Programming) port is an online program


programming port, which is a 2*3 pin header on the Arduino development board, and
its 6 pins are connected to the microcontroller on the Arduino development board ,
corresponding to 5V, MISO, MOSI, SCK, GND and RESET respectively. These pins
enable users to program the firmware on the Arduino development board. Generally,
when programming a program, the ICSP port close to the microcontroller is used.

(5) Indicator light:

Arduino Uno has 4 LED indicators.The functions are as follows:


1. ON: power indicator. When the Arduino is powered on, the ON light will be on.
2. TX: serial port sending indicator. When the USB is connected to the computer and
the Arduino transmits data to the computer, the TX light will be on.
3. RX: serial port receiving indicator. When using USB to connect to the computer
and the Arduino receives the data from the computer, the RX light will be lit up.
4. L: D13 pin indicator light, also known as programmable control indicator light. The
LED is connected to pin 13 of the Arduino by a special circuit. When the pin 13 is
high or high impedance, the LED will be lit; when it is low, it will not be lit. The LED
can be controlled to be on or off by a program or an external input signal.

(6) DC external plug:

8
Using an external power supply of 7-12V to power the Arduino.

(7) USB interface:

It is used to connect the USB interface of the computer to achieve serial


communication, uploading programs, and serial port monitoring between the Arduino
and the computer.

(8) Reset button:

Restart the Arduino and start the program from the beginning.

(9) Microcontroller:

The "brain" of Arduino is based on the smallest system of ATmega328P


microcontroller.

4. the use of Breadboard (breadboard) in the circuit

Breadboard is a commonly used plug-in board with porous sockets in circuit


experiments. When conducting circuit experiments, you can insert the pins and wires
of electronic components into the corresponding holes according to the circuit
connection requirements to make them contact with the elastic contact spring in the
hole, thereby connecting into the required experimental circuit.

9
The internal circuit connectivity of the breadboard:
(1) In area 1 of the figure, only five holes from left to right are connected, and the
red line is drawn as shown in the figure. The upper and lower holes are not connected.
(2) In area 2 in the figure, only five holes from top to bottom are connected, and
the red line is drawn as shown in the figure. Left and right are not connected.
(3) In area 3, only five holes from top to bottom are connected, and the red line is
drawn as shown. Left and right are not connected.
(4) In area 4 in the figure, only the five holes from left to right are connected, and

10
the red line is drawn as shown in the figure. The upper and lower holes are not
connected.
【Attention】
Zone 1, zone 2, zone 3 and zone 4 are not connected to each other.

11
Building the Arduino development environment

1. Arduino development language

Arduino uses C/C++ to write programs, so before learning Arduino, you need to
master the C/C++ language. Although C++ is compatible with the C language, these
are two different languages. C is a process-oriented programming language, and C++
is an object-oriented programming language. The early Arduino core library was
written in C language. Later, object-oriented ideas were introduced. At present, the
latest Arduino core library is written in C and C++.
Generally speaking, the Arduino language refers to a collection of various
Application Programming Interfaces (APIs) provided by the Arduino core library files.
These APIs are formed by secondary packaging of the lower-level microcontroller
support library. For example, the core library of Arduino using AVR microcontroller is
the secondary packaging of AVR-Libc (GCC-based AVR support library).
In the traditional development method, multiple registers need to be configured to
achieve the corresponding functions. In Arduino, the complicated registers are
encapsulated into simple APIs, which can be intuitively controlled, enhancing the
readability of the program and improving the development efficiency.

2.Arduino program structure

The Arduino program structure is different from the traditional C/C++ program
structure-there is no main() function in the Arduino program. In fact, it is not that
there is no main() function in the Arduino program, but that the definition of the main()
function is hidden in the core library file of the Arduino. In the development of
Arduino, the main function is not directly operated, but the two functions of setup()
and loop() are used instead.

12
3. The construction of the Arduino development
environment

The IDE of the Arduino development environment can be downloaded from the
official website. The download address of the Arduino IDE is:
https://store.arduino.cc/usa/

(1) Install Arduino IDE under Windows


We will teach you how to download and install:
1.Open Google Chrome and enter the URL in the address bar:
https://store.arduino.cc/usa/
After successfully opening the interface as shown below, we click
DOWNLOADS under SOFTWARE.

2. After jumping to the following interface, slide the mouse to the middle to find
the part marked in the red circle.You can find that the official website provides us
with installation files for Windows, Mac OS X, and Linux systems.

13
3. We click the installation package of Windows ZIP file for non admin
install.After the interface jumps, we select JUST DOWNLOAD.And then start the
download. The download status will be displayed in the lower left of Google
Chrome.Then we wait for the download to complete.

14
4.After the download is complete, open the folder.There are downloaded
compressed installation files:
arduino-1.8.12-windows.zip

5. Double-click to open the file and unzip it.

6. The file arduino-1.8.12 appears after decompression.As shown follows;

7. Open the arduino-1.8.12 folder and double-click arduino.exe to open the

15
software.

8. The interface will show as follows after the Arduino software is opened,
indicating that our software has been downloaded and installed successfully.

4. Introduction of Arduino software interface

The following figure is the interface introduction of Arduino software

16
(1)Menu bar

Menu bar contains File, Edit, Sketch, Tools and Help.


(1) "File" can operate new file, open file, save file, close file, save, etc. For the
Examples, you can check the official sample program.

(2) "Edit" has the functions for the program code of editing, copying and pasting,
commenting, indenting,searching, etc.

17
(3) Sketch can perform Verify/Compile, Upload and other operations on the
written project.

The Include Library can load the library. After selecting the library file in the list,
the relevant header files are automatically added in the code editing area.

18
(4) Board and Port are often used in "Tools".

19
Board can choose different development boards. Our course uses Arduino Uno
development board, so we need to choose Arduino Uno. The list contains many
Arduino development board models.We choose the corresponding ones according to
the model.

Port can set the port used by Arduino IDE to download the program, that is, the

20
port number of the development board connected to the computer. The port display of
each computer is different. When we use the Arduino Uno to connect to the computer,
it displays the COM3 port number.

(2)Button bar

Button bar includes functions of Verifying,Uploading,Building New,Opening and


Saving.

(1)Verify :

Checking and compilation. This button is used to check the correctness of your
"syntax" or code. If your code has any syntax errors or undefined variables, an error
message will appear at the bottom of the IDE screen. At the same time, the line of
error code will be marked with a red background color for easy modification. But if it
is correct, you will see the message that the compilation is complete.

(2)Upload :

Download the program code to the Arduino development board. It is better to


click Verify first, and then click Upload.

(3)New :

Open a new program editing window to create a new project.

21
(4)Open :

This button can open an existing draft file. You will use it when you need to open
a file that you have downloaded or used before.

(5)Save :

Save the program file being edited.

(3)Code editing area

The code editing area is where to write program code and code comments.

(4)Console

The debug window will output information showing various compilation and
debugging results. For example, if your code is written incorrectly, you will be
prompted about what went wrong.

5.Connecting the Arduino development board and the


computer

(1)Connecting the Arduino development board and the

computer

You need to use USB Cable to connect the Arduino to the computer.As shown
below:

22
(2) Select the Arduino Uno development board in Tools

Open Arduino IDE under Tools—>Board.Select Arduino UNO in the list.

(3)Install CH341SER driver

1.Open Arduino IDE, you will see the serial port is not accessible, meaning that
you have not installed the serial port driver.

23
2. You need to find the user folder provided by Adeept:
Adeept_Ultimate_Kit_For_Arduino_V2_0, find the Adeept driver folder and open
it.If you are using a Windows system, you can double-click directly to open
CH341SER_Windows.EXE and install corresponding driver according to the
computer operating system.

3. Click INSTALL.Wait for the installation to succeed.And click OK.

24
4.Now you will find the Arduino serial port is accessible (different computer
configuration has different serial port).It means that the Arduino UNO development
board has been successfully connected to the computer. You will need to pay attention
to this connection step in the following course.

25
6.The solution for situation that Arduino IDE cannot
be opened

When opening the Arduino IDE, you will suddenly encounter a situation that it
cannot be opened.

【Solution】
You need to find the Arduino15 folder in the
\Users\ASUS\AppData\Local\Arduino15 directory of the C drive.As shown below:

26
You need to delete the package_index.json file, and then reopen the Arduino IDE.

27
Arduino graphical programming

We creatively provide users with Arduino graphical programming tools-GwBlock.


Using graphical program instruction blocks to achieve control of Arduino with the
Web page. Compared with the traditional pure character interface code programming
platform, graphical programming is more conducive to learners who have not
mastered C/C++. If you have studied Scratch, then you will be able to easily master
the graphical programming of Arduino. Next we will teach you how to build graphical
programming of Arduino.

1.Downloading and installing Python

(1) Log in to the official website by browser: https://www.python.org/downloads/

(2) Click the "Download Python 3.8.3" button to download and wait for the download
to complete:

28
(3) Open the downloaded file, double-click to open it to install:

(4) Select the "Add Python 3.8 to PATH" option:

(5) Then click "Install Now" to install.

29
(6) Wait for the Python installation to complete and click "Close" to close.

2.Installing pySerial and connecting GwBlock


graphical editor

pySerial encapsulates the serial communication module,supporting Linux,


Windows, BSD (may support all operating systems that support POSIX), Jython (Java)
30
and IconPython (.NET and Mono). The pyserial module encapsulates access to the
serial port.The port number starts from 0 by default.There is no need to know the port
name in the program. APIs like file reading and writing, read and write (readline, etc.
are also supported), support binary transmission, no null elimination, no cr-lf
conversion. All programs are completed by Python In addition to the standard library,
it does not depend on other packages, except pywin32 (windows), JavaComm
(Jython). POSIX (Linux, BSD) only depends on the Python standard library.APIs like
file read and write, read, write (readline, etc. are also supported), support binary
transmission, no null elimination, no cr-lf conversion, all programs are all done by
Python, and do not depend on other packages except the standard library, except
pywin32 (windows), JavaComm (Jython). POSIX (Linux, BSD) only depends on the
Python standard library.
Before downloading and installing, you need to connect the Arduino development
board to the computer.

(1) Press Win+R shortcut key to open CMD under Windows 10:

(2) Click "OK":

31
(3) Enter the command in the window:
pip install pyserial
Press the Enter and wait for the installation to complete.

(4) Open the folder "Adeept_Ultimate_Kit_For_Arduino_V2_0" provided by Adeept


to the user → "block_py" and find this file: "block_py.ino".

(5) Then right-click the file: "block_py.ino". Select "Open with" → "Choose another
app".

32
(6) Click "More apps", then click "OK".

(7) Slide the mouse down, click "Look for annother app on this PC", and then click
"OK".

33
(8) Find the Arduino software on Desktop or the place where you installed the
Arduino software, select it and click "Open".

(9) Then the Arduino software opens the file "block_py.ino".

34
(10) First select the Arduino development board as UNO version with Tools.

(11) Then continue to select the "Port" of the Arduino connected to the computer with
Tools.

35
(12) Click the Upload button to download the code program to the Arduino
development board.

(13) After downloading, an error warning will be displayed because the Arduino
software we downloaded and installed from the official website is missing some
related libraries.

36
(14) Solution: We first close the Arduino softwar.Open the folder we provide to users:
Adeept_Ultimate_Kit_For_Arduino_V2_0.Then open the "Arduino libraries" folder
inside.As shown below:

(15) We need to copy all the folders inside to the libraries folder under the folder
where we installed the Arduino software. As shown below after copying:

(16)We use the Arduino software to open the "block_py.ino" file again, and then click

37
the Upload button again to download the code program to the Arduino development
board. After the download is successful, the following figure is shown below:

(17) Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provided to


the user again, find the websocket folder and open it.

(18) Double-click to open this file: GUI info v1.0.py

(19) After opening the file, the following interface will appear. We need to record this
IP address, which will be used later: 192.168.3.69

38
(20) In the input box, enter the port we set in step (11).Everyone's port is different.The
port of my Arduino development board is: COM4. After entering, click the Connect
button.

(21) Enter the URL of the GwBlock graphical editor in the browser:
http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

(22) Click the "Connecting device" button in the upper right corner. In the pop-up box,
enter the IP address we recorded in step (19), as shown below, and then click the

39
Connecting button.

(23) After the connection is successful, a green "connected" will appear in the lower
left corner of the interface, indicating that the connection with the Arduino is
successful.

3.The method of reconnecting the GwBlock graphical


editor

In the following cases, you need to reconnect to the GwBlock graphical editor:
[1] When you close the GwBlock editor.

40
[2] When you close the Adeept Arduino Robot window.
[3] When you restart the computer.
[4] When you log in to the GwBlock website again.
[5] When you close the Arduino IDE.
(1) Before doing the experiment, you must first connect the Arduino development
board to the computer.
(2) First, open the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0, after opening, as shown below:

(3)Open this folder: block_py again, and find a block_py.ino file inside, as shown
below:

(4) Double-click to open this block_py.ino file (use Arduino to open!), as shown
below:

41
(5) First select COM4 as the Arduino port in Tools, click the icon in the upper
left corner to download the program to the Arduino development board, and the
following picture will be prompted after successful download:

42
(6)Next, open the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0.
Then find the websocket folder.As shown below:

(7) Open the websocket folder.There is a file inside: GUI info v1.0.py.

(8) Double-click to open the GUI info v1.0.py file, and the following picture will
appear after opening:

(9) After opening the file, the following interface will appear. We need to record this
IP address, which will be used later: 192.168.3.69

(10) Enter the Arduino software download program in the input box of Adeept
Arduino Robot.The connected port number: COM4. Click the Connect button.As

43
shown below:

(11)Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

(12)Click the "Connecting device" button in the upper right corner. It will show as
below:

44
(13) In the pop-up box, enter the IP address in step (9): 192.168.3.69. And then click
the Connecting button, as shown below:

(14) After a successful connection, as shown below, a green connected prompt will
appear in the lower left corner. It means that we have successfully connected to the
GwBlock graphical editor, with which we can realize the graphical programming of
Arduino. Later I will teach you how to use GwBlock graphical editor.

45
4.Get to know about Arduino's graphical editor
GwBlock

The functions of the buttons on the main interface of the GwBlock editor will be
described in detail below according to the function numbers in the picture. As shown
below:

【1】 Blocks: Click this button to switch to the programming mode of the graphical
code block.
【2】Python: Click this button to display the edited graphical code block in the form

46
of Python code.
【 3 】 Connecting device: Click this button to connect to the Arduino development
board, which requires you to enter the IP address.

【4】 :

(1) is the cancel button.Click it to return to the state of the previous operation
(cancel this operation).

(2) is the forward button.Click it to advance to the state of the next operation.

(3) is the button to run the program. Click it to run the correct program we
have compiled.
【5】 is a drop-down menu button:

Under the drop-down menu button, you can "Import project file" and "Save
project file". In addition,by the drop-down button on the right of UNO R3, you can
switch to the programming mode of different controllers.We are using Arduino UNO
R3 version of the development board in the current course, so we choose UNO R3
mode to programmatically control Arduino.

You can also switch the language display mode of the editor by the drop-down
button to the right of English. Currently, we only support English and Simplified
Chinese.

47
【 6 】 is the icon of the Arduino UNO development board, indicating that it is
currently in the Arduino programming mode.

【7】 is the camera button, which is gray in the initial off state: When you click it,

the camera will turn red: ,indicating that the camera is on. At this time, a screen

window will appear in the editing area on the right. Click to close the camera

screen,The screen can be dragged to any position by clicking the camera.As shown
below:

【8】is the code instruction module toolbar.You can select the code instruction block
you need here.

48
【9】is the editing area (code area or work area), where we edit the code instruction

block. Each code instruction block must be placed below .

【10】 is the connection status of the device.There are two states:


(1) The following is displayed when the device is not connected:

(2) After the device is successfully connected, the display is as follows:

【11】is a code trash, you can drag and drop the code instruction block to delete it.

49
Lesson 1 How to Light the Blinking LED

In this lesson, we will learn how to light the blinking LED.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 1

LED 1

2. The LED Light-Emitting Diode

(1)What is Diode?

1. Definition:
A diode is an electronic device made of semiconductor materials (silicon,
selenium, germanium, etc.). It has unidirectional conductivity. In the circuit, current
(voltage) is allowed to flow in a single direction, and it will prevent current and
voltage from passing in the opposite direction. Therefore, the diode has positive and
negative poles (anode and cathode). When a positive voltage is applied to the anode
and cathode of the diode, the diode conducts. When a reverse voltage is applied to the
anode and cathode, the diode is turned off. Therefore, the turning on and off of the
diode is equivalent to the turning on and off of the switch.

50
2. Structure of a diode:
A diode is made up of a PN junction plus corresponding electrode leads and
package.
PN junction: P-type semiconductor and N-type semiconductor are made on the
same semiconductor (usually silicon or germanium) substrate, and a space charge
region formed at their interface is called PN junction. The electrode drawn from the P
area is called the anode, and the electrode drawn from the N area is called the cathode.
Because of the unidirectional conductivity of the PN junction, the direction of the
current when the diode is turned on is from the anode to the cathode through the
inside of the tube. The following picture is a common diode:

(2)Anode (Positive Electrode) and Cathode (Negative Electrode)

of Common Diodes:

1. The positive and negative electrodes of ordinary diodes are shown in the
picture:

51
2. The positive and negative poles of the light-emitting diode are shown in the
picture: the long pin is the positive pole, and the short pin is the negative pole.

figure1-3

52
(3)What is Light-Emitting Diode?

1. Definition
Light-emitting diode is short as LED. The light-emitting diode is a type of diode,
composed of a PN junction. With the characteristics of a diode, it has unidirectional
conductivity like a diode. In the circuit, current can only flow in from the anode of the
diode and out of the cathode. The difference between a light emitting diode and a
diode is that it can emit light, red light, green light, blue light, yellow light, etc.
2. Why do LEDs emit light?
(1) The reason why the light-emitting diode emits light is that its core
light-emitting part is a chip. The chip in the light-emitting diode is a compound
gallium nitride, which has a property: it emits light when low current passes, mainly
to convert electrical energy into light energy.
(2) The principle of light emitting diode:
The principle of light emission is mainly a combination of N (-: negative)
semiconductors with many electrons (negatively charged) and P (+: positive)
semiconductors with many holes (positively charged). When the semiconductor is
applied with a forward voltage, electrons and holes will move and combine again at
the junction. It is during the junction that a lot of energy is generated, and this energy
is released in the form of light. As shown below:

53
Light-emitting diodes have a wide range of uses in modern society, such as
lighting, displays, medical devices, circuits and instruments as indicator lights.
(3) Classification of light-emitting diodes
Light-emitting diodes can also be divided into ordinary monochrome
light-emitting diodes, high-brightness light-emitting diodes, ultra-high-brightness
light-emitting diodes, color-changing light-emitting diodes, flashing light-emitting
diodes, voltage-controlled light-emitting diodes, infrared light-emitting diodes, and
negative resistance light-emitting diodes.

(4) How to wire (connect) the LED in the circuit

1. The LED has positive and negative poles. When connecting to the circuit, we
need to connect the positive pole of the LED to the positive pole of the power supply,
and the negative pole to the negative pole of the power supply. The light emitting
diode cannot be directly connected to the power supply, which can damage the
components. In the circuit using LED light-emitting diodes, a resistor with a certain
resistance value must be connected in series.
2. Calculation formula of LED current limiting resistor:

Limit Resistance (R) =

The limit current I of the LED light-emitting diode in our course is 5-20mA, and
the limit voltage U is 3.3V, so our limit resistance R is:

U 3 .3V
R= = = 165Ω ~ 660Ω
I (5 ~ 20 mA )

In the experiment, when we choose the connecting resistance, we can only choose
between 165Ω ~ 660Ω.
3. The circuit diagram of the LED light-emitting diode is as follows:

54
4.Two ways to connect LED and GPIO
The first method is as shown in the picture below: The positive pole of the
LED is connected to the positive pole of VCC (+ 3.3V), and the negative pole of
the LED is connected to the Raspberry Pi GPIO. When GPIO outputs a low level,
the LED lights up because of a potential difference between VCC and GPIO;
when GPIO outputs a high level, because the potential difference between VCC
and GPIO does not form, the LED turns off.

The second method is as follows: the positive pole of the LED is connected
to GPIO, and the negative pole of the LED is connected to GND (0V). When the
GPIO outputs a high level, the LED lights up because of the potential difference
between GPIO and GND; when the GPIO outputs a low level, because the
potential difference between the GPIO and GND does not form, the LED lights
are off.

55
(5) Main parameters and precautions of Light-emitting Diodes

(1) Allowable power consumption (Pm): Maximum value of the product of the
forward DC voltage applied to both ends of the LED and the current flowing through
it. If this value is exceeded, the LED will become hot or damaged.
(2) Maximum forward DC current (IFm): Maximum forward DC current allowed
to be added. Exceeding this value can damage the diode.
(3) Maximum reverse voltage (VRm): Maximum reverse voltage allowed to be
applied. Above this value, the light emitting diode may be damaged by breakdown.
(4) Working environment (topm): Ambient temperature range where the LED can
work normally. Below or above this temperature range, the LED will not work
properly and the efficiency will be greatly reduced.
【Remarks】
1. LED cannot be directly connected to the power supply, which can damage the
components. In the circuit using LED light-emitting diodes, a resistor with a certain
resistance value must be connected in series.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

56
4.How to light the blinking LED

We provide two different methods to light the blinking LED.One is to program


on the Arduino UNO with C language through the Arduino IDE. You need to master
the C language; the other is to program on the Arduino UNO with the graphical code
57
block through GwBlock IDE.This method is very suitable for beginners who have not
mastered the advanced programming languages C and C++. We will introduce these
methods respectively.

1.Using C language to program to light the blinking LED on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3. Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_01_blinkingLed directory.
Select_01_blinkingLed.ino. This file is the code program we need in this course. Then
click Open.

58
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

59
5. At this time, when we observe the LED, it will be on then off, and keep cycling,
indicating that our experimental test is successful. The physical connection diagram of
the experiment is as follows:

60
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to light the LED on Arduino UNO.We will introduce how
our core code can be achieved:
Define the pin of led as pin 8 by int ledPin=8; in the setup() method, set ledPin as
the output mode with pinMode(ledPin, OUTPUT); in the loop() method, set ledPin to
high level with digitalWrite(ledPin, HIGH) , and the LED will be on. Control the LED
to stay on for 1s with delay (1000); set ledPin to low level with digitalWrite (ledPin,
LOW), then the LED is off. Control the LED to be off continuously for 1s with delay
(1000) . When the code in loop() is executed cyclically, the LED will be on and off
repeatedly.

61
2.Using graphical code blocks to program to light the LED on

Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

62
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

63
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

64
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

65
(2)Using graphical programming to light up the LED
Next let's learn how to use the graphical code block to program the LED on the
Arduino UNO development board.
1. After successfully connecting to the GwBlock IDE, we find "Hardware" in the

toolbar of the code instruction module in the middle, where the UNO_R3 code
instruction module is a collection of graphical code blocks that control the Arduino
UNO.

2. The opened UNO_R3 code instruction module is as shown in the figure below, and
each graphical code block has different functions.

66
3. Click Create variable under Variables in the toolbar of the code instruction block to
create variables.

4. Create a variable a, after successful creation is as follows:

67
5. Drag to the right below .Find the instruction under the

instruction module .Change the number "0" to 8.As shown below:

6.Then we need to initialize the LED pin to the output

mode.Find under the code instruction

module .Drag it to the right below the . Change to


Output.As shown below:

68
7.The variable a represents the pin number of the LED. You need to change the 0

of to the variable a. Drag and drop it into under the toolbar of the

code instruction block , as shown below:

8. Find the loop judgment instruction under the Loops code instruction
module, as shown below:

9. Drag to the position as shown below:

69
10.We need to determine whether the condition is TRUE, find under the code

instruction module , and drag it to the following location:

11.When the condition is True, control the LED on and off by setting the high and low

levels of the LED pin. Find under the code instruction

module . This instruction block can set high and low level.Place it in the
position of the following figure:

12. First set the LED pin to high level, and the LED will light up. Change to

70
the variable a: .Change to .As shown below:

13. We need to use a delay command to control the LED to continue to light for a

period of time.Find under the code command module .And

then you can enter the number of time to delay in . We enter 2 to control the

LED to keep on for 2 seconds. As shown below:

14. When we set the LED pin to low level, the LED will be off. Use the mouse to

move to the location .Click the right button.Select "Duplicate".As shown below:

71
It will copy and generate an identical code instruction block, as shown below:

15. Place the copied code instruction block as shown below:

72
16. To control the LED to be off, we only need to change the to

. As shown below:

17.We need to use another delay command to control the LED to be off for a period of

time.Find under the code instruction module .And then you

can enter the number of the time to delay in .We enter 2 to control the LED to be

off for 2 seconds. As shown below:

18. The final program is as shown in the figure below.Click in the upper right
corner.Pay attention to observe the LED .It indicates successful if the LED is on then
off.

73
19. The physical connection of the experiment is as follows:

74
Lesson 2 The Application of the Active Buzzer

In this lesson, we will study the application of the Active Buzzer.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(1KΩ) 1

Active Buzzer 1

NPN Transistor(8050) 1

2. The introduction of the Buzzer

(1) The Buzzer

The Buzzer is an electronic sounder with an integrated structure. It is powered by


DC voltage and is widely used as a sounding device in electronic products such as
computers, printers, copiers, alarms, electronic toys, automotive electronic equipment,
telephones, timers, and other electronic products. . There are two types of buzzer:
active buzzer and passive buzzer. As shown in the figure below, the left is the active
buzzer (the two pins have different lengths), and the right is the passive buzzer (the
two pins have the same length).

75
(2) Working principle of the Buzzer

The sounding principle of buzzer is composed of vibration device and resonance


device, and buzzer is divided into passive buzzer and active buzzer. The working
sounding principle of passive buzzer is: square wave signal input resonant device is
converted into sound signal output; the working sounding principle of active buzzer is:
DC power input is generated by the amplification sampling circuit of the oscillation
system under the action of the resonance device Sound signal. Our course in this
section uses an active buzzer. As long as the power is on, the active buzzer will sound.
We can program the Arduino UNO output high and low alternately, so that the active
buzzer will sound.

(3) Two kinds of Transistors (S8050 and S8550)

To make the active buzzer sound, a large current is required. However, the output
current of Arduino UNO development board is very weak, so we need a transistor
S8050 or S8550 to drive the active buzzer. The main function of the transistor S8050
(S8550) is to amplify the voltage or current, and it can also be used to control the
conduction or cut-off time of the circuit.
There are two kinds of transistors, one is NPN, such as the transistor S8050 used
in our course; the other is a PNP transistor, such as the other S8550 we provide. The
pin structure of the two transistors we use is the same. Their pin structure is as shown

76
in the figure below. In the circuit, Emitter is abbreviated as e, Base is abbreviated as b,
and Collector is abbreviated as c.

The S8050 and S8550 transistors provided by our course are as shown below.
The letter H is S8050, and the letter H is S8550.

The transistors S8050 and S8550 and the buzzer are connected in the circuit as
shown below:

77
Figure1:
Set the Arduino UNO as a high level, the transistor S8050 will conduct, and then
the buzzer will sound; set the Arduino UNO as low level, the transistor S8050 will cut
off, then the buzzer will stop.
Figure2:
Set the Arduino UNO as low level, the transistor S8550 will conduct, and the buzzer
will sound; set the Arduino UNO as a high level, the transistor S8550 will cut off,
then the buzzer will stop.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connected them in the circuit as shown in the


following figure. When connecting the circuit, we should pay attention to the
difference between positive and negative electrodes, as shown in the following figure:

78
79
4. The application of the Active Buzzer

We provide two different methods to control the active buzzer. One is to program
the active buzzer on the Arduino UNO with C language through the Arduino IDE. You
need to master the C language; the other is to program the active buzzer on the
Arduino UNO with the graphical code block through GwBlock IDE.This method is
very suitable for beginners who have not mastered the advanced programming
languages C and C++. We will introduce these methods respectively.

1.Programming and controlling the Active Buzzer in C language

on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_02_activeBuzzer directory. Select _02_activeBuzzer.ino. This file is the code
program we need in this course. Then click Open.

80
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5.If the program upload is successful, the active buzzer will sound, indicating that the
experimental test was successful. The physical connection diagram of the experiment
is as below:

81
(1) The core code program
After the above hands-on operation, you must be very interested to know how we
make the Active Buzzer sounded with C language on Arduino UN. We will introduce
how our core code can be achieved:
1.Define the pin of the active buzzer by int buzzerPin=8. Then connect it to port 8
on the Arduino UNO. In the setup () method, set buzzerPin as the output mode
through pinMode (buzzerPin, OUTPUT).

2.In loop() method, set buzzerPin to HIGH state through digitalWrite(buzzerPin,


HIGH). At this time the active buzzer sounds. Then set the active buzzer to delay 2s to
sound through delay (2000). Set buzzerPin to LOW state through digitalWrite
(buzzerPin, LOW) after 2s. At this time the active buzzer is off. Then set the active
buzzer to delay 2s to be off through delay (2000).

82
2.Programming and controlling the Active Buzzer on Arduino

UNO with graphical code blocks

(2)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (opened with Arduino). Then click and upload the program to

the Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.
83
3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be
used later. It will show as below:

4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

84
6.Click the "Connecting device" button in the upper right corner. It will show as
below:

7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

85
8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

(2)Controlling the Active Buzzer


Now let us learn how to use the GwBlock graphical editor to program the active
buzzer on the Arduino UNO.
1.After successfully connecting to the GwBlock IDE, we find "Hardware" in the
toolbar of the code instruction module in the middle. The UNO_R3 code instruction
module is a collection of graphical code blocks that control the Arduino UNO.

86
2.The code instruction module after opening is as shown in the figure
below, and each graphical code block has different functions.

3.Click Create variable under Variables in the toolbar of the code instruction block to
create variables.

87
4.Create the variable buzzerPin. It will show as below:

5.The variable buzzerPin represents the pin number of the active buzzer. Drag

to the position as shown below. It will show as below:

6.By knowing that the pin of the active buzzer is connected to port 8 in "3. Wiring

Diagram", we need to change buzzerPin to 8. Find the instruction in the

instruction bar . The number "0" can be modified to 8. It will show as

below:

88
7.Find the instruction under the instruction

module , which can set the PIN to Input and Output modes respectively.

Drag this instruction to the editing area on the right. It will show as below:

8.In the command module , drag the variable to the right

editing area .You need to initialize buzzerPin to Output mode. Click

to modify it to Output mode.It will show as below:

9.Find the loop judgment instruction under the Loops code instruction
module.It will show as below::

89
10.Drag to the position as shown below:

11.We need to determine whether the condition is TRUE. Find under the code

instruction module , and drag it to the following location:

12.Set buzzerPin to a high level, then you can make the active buzzer sound. Find the

instruction under the code instruction

module . Place it in the position as shown below:

90
13.In the instruction module , drag variable into the editing

area on the right. Change to .It will show as below:

14.Use a delay command to control the active buzzer to continue to be on for a period

of time. Find under the code command module . And then

you can enter the number of the time you need in to control the delay. We enter

2 to control the active buzzer to continuously sound for 2 seconds. It will show as
below:

91
15. If the pin buzzerPin of the active buzzer is set to low level, the active buzzer is in

the off state. Move the mouse to the position . Click the right mouse button.
Select "Duplicate".It will show as below:

At this time, the same code instruction block will be copied and generated.It will
show as below:

92
16. Place the copied code instruction block as shown below:

17.If you want to turn off the active buzzer, you only need to change to

.It will show as below:

18.Use a delay command to control the active buzzer to continue to be off for a period

of time. Find under the code command module . And then

you can enter the number of the time you need in to control the delay. We enter

2 to control the active buzzer to be off for 2 seconds. It will show as below:

93
19.The final program is as shown in the figure below. Click the run program button

in the upper right corner and pay attention to observe the active buzzer. If the
active buzzer sounds and is off after a while and repeat this process, it indicates that
the experiment is successful. It will show as below:

20.The physical connection of the experiment is shown below

94
95
Lesson 3 Controlling LED with Button

In this lesson, we will learn how to control LED with Button.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 1

LED 1

Resistor(10KΩ) 1

Button(Large) 1

2. Experimental principle of Button controlling to


LED

(1) What is a Button

Button is one of the most common input devices. There are two non-touching
touch pieces inside a common Button. When the Button is pressed by external force,
the two touch pieces are connected together and the circuit is connected. After the
external force is released, it returns to the disconnected state, that is, the circuit is
disconnected. Many functions can be achieved when used in conjunction with other
96
components. Its operation is intuitive and effective, and many operations need to be
controlled by Button. Almost all electronic devices have the design of Button reserved.
Let's learn how to realize simple Button operation on raspberry pie.

The Button used in this lesson is as following figure:

(2) Experimental principles

We control the state of the LED by judging the state of the GPIO port connected
to the Button. Since the Arduino IO port can be used as output mode to light up the
light, it can also be used as input mode to detect the high and low level of the IO port.
Here, when we detect the Button pressed, we give the Arduino IO port a low level,
indicating that the Button has been pressed, then we will light the LED. When we
detect the release of the Button, we give the Arduino IO port a high level, which

97
means that the Button has been released, and then we will turn off the LED.

(3) Dealing with Button jitter

The button jitter must happen in the process of using. The jitter waveform is as the
flowing:

Each time you press the button, the Arduino will think you have pressed the
button many times due to the jitter of the button. We have to deal with the jitter of
buttons before we use the button. We can remove the jitter of buttons through the
software programming, besides, we can use a capacitance to remove the jitter of
buttons. Here we introduce the software method. First, we detect whether the level of
button interface is low level or high level. When the level we detected is low level,
5~10 MS delay is needed, and then detect whether the level of button interface is low
or high. If the signal is low, we can confirm that the button is pressed once. You can
also use a 0.1uF capacitance to clean up the jitter of buttons. The schematic diagram
is shown in below.

3.Wiring diagram (Circuit diagram)


98
Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes, as shown in the following figure:

4. Controlling the LED through Button

We provide two different methods to light up the LED. One is to program on the
Arduino UNO with C language through the Arduino IDE. You need to master the C
99
language; the other is to program on the Arduino UNO with the graphical code block
through GwBlock IDE.This method is very suitable for beginners who have not
mastered the advanced programming languages C and C++. We will introduce these
methods respectively.

1.Using C language to program Button to control LED on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_03_btnAndLed01 directory. Select _03_btnAndLed01.ino. This file is the code
program we need in this course. Then click Open.

100
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

101
5.If we press the Button, the LED will light up; if we press the Button again, the LED
will turn off, indicating that the experimental test was successful. The physical
connection diagram of the experiment is as below:

(2)The core code program


After the above hands-on operation, you must be very interested to know how we
use C language to program Button to control LED on Arduino UNO.We will
introduce how our core code can be achieved:
1.Define the pin that controls the LED as pin 11 through int ledPin=11. Define the
pin that controls the Button as pin 2 through int btnpin=2. In the setup() method, set
ledPin to output mode via pinMode(ledPin, OUTPUT) ledPin; set btnpin as the input
mode through pinMode(btnpin, INPUT).

102
2.In the loop() method, we check whether the Button is pressed with if. when
digitalRead(btnpin)==LOW, it means that the Button is pressed. The pin state of the
ledpin is set to 1 (high by digitalWrite(ledpin,1) Level),and the LED will be lit up.
When digitalRead(btnpin)!==LOW, it indicates that the Button is released. When the
digitalWrite(ledpin,0) sets the pin status of the ledpin to 0 (low level), the LED will be
off.

2. Programming Button to control LED on Arduino UNO with

graphical code blocks

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

103
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

104
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

105
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

106
(2)Controlling LED with Button
Now let us learn how to use the GwBlock graphical editor to program to control
LED with Button on the Arduino UNO.
1.After successfully connecting to the GwBlock IDE, we find "Hardware" in the
toolbar of the code instruction module in the middle. The UNO_R3 code instruction
module is a collection of graphical code blocks that control the Arduino UNO.

2.The code instruction module after opening is as shown in the figure


below, and each graphical code block has different functions.

107
3.Click Create variable under Variables in the toolbar of the code instruction block to
create variables.

4.Create the variable ledpin and btnpin. It will show as below:

108
5.The variable ledpin represents the pin number of the LED.The variable btnpin
represents the pin number of the Button. Drag them to the position as shown below. It
will show as below:

6.By knowing that the pin of the LED is connected to port 11 and the pin of the
Button is connected to port 2 in "3. Wiring Diagram", we need to change ledpin to 11

and the btnpin to 2. Find the instruction in the instruction bar . The

number "0" can be modified to 11 and 2 respectively. It will show as below:

109
7.Find the instruction under the instruction

module , which can set the PIN to Input and Output modes respectively.

Drag this instruction to the editing area on the right. It will show as below:

8.In the command module , drag the variable and to

the right editing area .You need to initialize ledpin to Output mode and btnpin

to iutput mode. Click to modify it to Output mode.It will show as below:

9.Find the loop judgment instruction under the Loops code instruction
module.It will show as below::

110
10.Drag to the position as shown below:

11.We need to determine whether the condition is TRUE. Find under the code

instruction module , and drag it to the following location:

12.Use the if command block to determine whether the Button is pressed. Determine
whether its high or low state is 0 or 1.Then set the LED to be on or off. Find the

instruction in the instruction module . It will show as below:

111
13. Drag the instruction to the instruction in the editing area on the

right.Find in the instruction module .It will show as below:

14.Determine whether the status of btnpin is low (0). Find the instruction

under the code instruction module .Find the instruction

under the instruction module .It will show as below after the modification:

15.When btnpin=0, it means that the Button is pressed and the LED is on. By setting

112
the state of the ledpin pin to high level through the

command , the LED will be lit (turned on).It will


show as below:

16.On the contrary, when btnpin is not equal to 0, it means that the Button is released.
At this time, the LED is off (turned off).We can know that the btnpin is not equal to 0

through the instruction .It will show as below:

17.If the state of the ledpin pin is set to the low state through the

command , the LED will be off.It will show as


below:

113
18.Then our program is done.It will show as below:

19.Click the run program button in the upper right corner to Upload the program
on the Arduino UNO. If the LED lights up when the Button is pressed, and the LED
goes out when the Button is released, indicating that the experimental test was
successful. It will show as below:

114
115
Lesson 4 Controlling LED with Relay Module

In this lesson, we will study how to control LED with Relay Module.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 1

LED 1

Relay Module 1

2. The introduction of the Relay Module

(1) The Relay Module

Relay module is an electrical control, which is an electrical appliance that causes


a predetermined step change in the controlled quantity in the electrical output circuit
when the input quantity (excitation quantity) changes to the specified requirements. It
has the interaction between control system (also known as the input loop) and the
controlled system (also known as the output loop). Usually used in automated control
circuits, it is actually a kind of “Automatic switch” with small current to control the
operation of large current. Therefore, it plays a role of automatic adjustment, safety

116
protection and conversion circuit in the circuit.
As a control element, in all, the relay has the following functions:
1) Expand the control range: for example, when the control signal of the
multi-contact relay module reaches a certain value, it can be changed, broken and
connected to the multi-circuit according to the different forms of the contact group at
the same time.
2) Amplification: for example, sensitive relay, Intermediate relay, etc., with a
very small amount of control, can control a large power circuit.
3) Integrated signals: for example, when multiple control signals are input into
multiple Coilrelays according to the prescribed form, the predetermined control effect
can be achieved through comparison and integration.
4) Automatic, remote control and monitoring: for example, the relay module on
the automatic device can be combined with other electrical appliances to form a
program control line, so as to realize automatic operation.

(2) Working principle of the Relay Module

The role of the relay module is to use one circuit (usually a small current) to

117
control the on and off of another circuit (usually a large current), and in this control
process, the two circuits are generally isolated. Its basic principle is to use the
electromagnetic effect is used to control the mechanical contacts to achieve the
purpose of making and breaking, and the coil with the iron core is energized-the coil
current generates a magnetic field-the magnetic field absorbs the armature action to
make and break the contact.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connected them in the circuit as shown in the


following figure. When connecting the circuit, we should pay attention to the
difference between positive and negative electrodes. Use 220Ω resistor. As shown in
the following figure:

118
【pay attention】
When the relay is connected, you need to use a screwdriver to open the position
of the two nuts, as shown below:

119
4. Controlling the Relay Module

We provide two different methods to control the active buzzer. One is to program
the active buzzer on the Arduino UNO with C language through the Arduino IDE. You
need to master the C language; the other is to program the active buzzer on the
Arduino UNO with the graphical code block through GwBlock IDE.This method is
very suitable for beginners who have not mastered the advanced programming
languages C and C++. We will introduce these methods respectively.

120
1.Using C language to program Relay Module to control LED on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_04_relay directory. Select _04_relay.ino. This file is the code program we need
in this course. Then click Open.

121
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. If Relay Moudle will make a sound during the experiment and the LED will be on
and off at the same time. This shows that our experimental test is successful. The
physical connection diagram of the experiment is as follows:

122
(2)The core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program Relay Module to control LED on Arduino UNO.We will
introduce how our core code can be achieved:
1.Set relayPin to Output mode through pinMode(relayPin, OUTPUT) in the setup()
method;
2.In the loop() method, set relayPin to HIGH through digitalWrite(relayPin, HIGH).
At this time, the Relay Module is closed and powered on, and the circuit is on, and
then the LED lights up. Set relayPin to LOW through digitalWrite(relayPin, LOW).At
this time, the Relay Module closes the circuit and the LED goes out.

123
2. Controlling LED with Relay Module by programming on

Arduino UNO with graphical code blocks

(2)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

124
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

125
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

126
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

127
(2)Core code program
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

128
3.The file will then be displayed. It will show as below:

4. Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_04_relay
folder.It will show as below:

5. Select the "04relay.gwblock" file. This file is the graphical code program for our
lesson. Click "Open" in the lower right corner.It will show as below:

129
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

8. Click the run program button in the upper right corner and observe the

130
experiment phenomenon. You will find that the relay module will make a sound, and
the LED will be on and off, indicating that the experiment test is successful. The
physical connection of the experiment is as follows:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
control LED with Relay Module by programming on Arduino UNO with graphical
code blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .

First initialize the relayPin pin number to 8 through the instruction

block , and the relayPin is set to the Output mode through the

instruction block ; in the while loop statement,

sets relayPin to Low-level state through the instruction block

.At this time, the Relay Module is closed


and connected, and the LED will light up, delaying 1s through the

instruction ; similarly, the relayPin is set to High-level state

131
through the instruction block .At this time,
the Relay Module is in the off state and the LED will be off, delaying 1s through the

instruction .

132
Lesson 5 Controlling LED with Potentiometer

In this lesson, we will learn how to control LED with Potentiometer.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 1

LED 1

Potentiometer(10KΩ) 1

2. Introduction of Potentiometer

(1) Potentiometer

The potentiometer is a resistance element with three terminals and the resistance
value can be adjusted according to a certain change law, which is equivalent to a
variable resistor. Because its role in the circuit is to obtain a certain relationship with
the input voltage (external voltage) to output Voltage, so called potentiometer.
Potentiometers can be divided into rotary potentiometers, push-pull potentiometers,
straight slide potentiometers, etc. according to the adjustment method. Our course
experiment uses a rotary potentiometer.Its three pins are showed as below:

133
(2)Working principle of potentiometer

The rotary potentiometer is an adjustable resistance element. It is composed of a


resistor and a rotating system. When a voltage is applied between the two fixed
contacts of the resistive body, the position of the contact on the resistive body is
changed by the rotating system, and a voltage that has a certain relationship with the
position of the moving contact can be achieved between the moving contact and the
fixed contact. Potentiometer can be used to adjust the voltage and current.
Our course uses a rotary potentiometer. Its structure is as shown in the figure
below. By rotating the knob, the position of pin 2 is changed, thereby changing the
resistance value from pin 2 to both ends. In the experiment. Connect pin 1 and pin 3
to the GND and 5V of the development board respectively. And then read the voltage
divided by the pin 2 of the potentiometer through the analog input pin A0. The range
is between 0V and 5V. The analog input function of Arduino has 10-bit precision, that
is, it can convert the voltage signal of 0 to 5V into an integer form of 0 to 1024.

134
3.Wiring diagram (Circuit diagram)

Before the experiment, we connected them in the circuit as shown in the


following figure. When connecting the circuit, we should pay attention to the
difference between positive and negative electrodes. Use 220Ω resistor. As shown in
the following figure:

135
4. Controlling LED with Potentiometer

We provide two different methods to control the active buzzer. One is to program
the active buzzer on the Arduino UNO with C language through the Arduino IDE. You
need to master the C language; the other is to program the active buzzer on the
Arduino UNO with the graphical code block through GwBlock IDE.This method is
very suitable for beginners who have not mastered the advanced programming
languages C and C++. We will introduce these methods respectively.

1.Using C language to program Potentiometer to control LED on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

136
2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_05_potentiometer directory. Select _05_potentiometer.ino. This file is the code
program we need in this course. Then click Open.

137
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After running the program, turn the potentiometer counterclockwise to light up the
LED; turn the potentiometer clockwise to turn off the LED. This shows that our
experimental test is successful. The physical connection diagram of the experiment is
as below:

138
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to control LED with Potentiometer on Arduino UNO.We
will introduce how our core code can be achieved:
1. Set the relayPin pin to Output mode through pinMode(relayPin, OUTPUT) in the
setup() method;
2. Use the analogRead() function in the loop() method to read the voltage value input
by the potentiometer.And then determine whether the read value is greater than 500
through the if judgment statement. When it is greater than 500, we set the relayPin pin
to HIGH through digitalWrite(relayPin, HIGH ), and the LED will be on; when it is
less than 500, set relayPin to LOW through digitalWrite(relayPin, LOW), and the
LED will be off.

139
2. Using graphical code blocks to program to control LED with

Potentiometer on Arduino UNO

(2)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

140
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

141
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

142
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

143
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

144
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_05_potentiometer
It will show as below:

5. Select the "05_potentiometer.gwblock" file. This file is the graphical code program
for our lesson. Click "Open" in the lower right corner.It will show as below:

145
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

146
8. After running the program, turn the potentiometer counterclockwise to light up the
LED; turn the potentiometer clockwise to turn off the LED. This shows that our
experimental test is successful. The physical connection diagram of the experiment is
as below:

(3) Core code program


After the above hands-on operation, you must be very interested to know how we

147
control LED with Potentiometer by programming on Arduino UNO with graphical
code blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .

First initialize the pin number of ledpin to 13 through the instruction

block , and the ledpin is set to the Output mode through the

instruction block ; In the while loop

statement, read the voltage value input by the potentiometer through the instruction

block ; use the if judgment statement to judge

whether the read value is greater than 500. If the obtained value is greater than 500,
then set the ledpin to High-level through the instruction

block , and the LED will be on. If the

obtained value is less than 500, then set the ledpin to Low-level through the

instruction block , and the LED will be off.

148
Lesson 6 Making a Flowing LED with LED

In this lesson, we will learn how to make Flowing LED with LED.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 8

LED 8

2. The introduction of the Flowing LED

(1)What is a Flowing LED

Flowing lights refer to lights that are on and off in sequence according to the set
order and time under the control of the microcomputer, visually feeling flowing of the
lights. It is widely used in the decoration of architecture, interior and advertising
signs.

(2)The principle of making the Flowing LED

We programmed pin number to 2,3,4,5,6,7,8,9 which are connected to the


Arduino UNO. Connect the pins to GND.During program design, by controlling their
lighting sequence and delay time, from left to right, and then from right to left,

149
making 8 LEDs flash out of the effect of Flowing Lights.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connected them in the circuit as shown in the


following figure. When connecting the circuit, we should pay attention to the
difference between positive and negative electrodes, as shown in the following figure:
Before the experiment, we connected them in the circuit as shown in the
following figure. When connecting the circuit, we should pay attention to the
difference between positive and negative electrodes. Use 220Ω resistor. As shown in
the following figure:

150
4. Making Flowing LED with LED

We provide two different methods to control the active buzzer. One is to program
the active buzzer on the Arduino UNO with C language through the Arduino IDE. You
need to master the C language; the other is to program the active buzzer on the
Arduino UNO with the graphical code block through GwBlock IDE.This method is
very suitable for beginners who have not mastered the advanced programming
languages C and C++. We will introduce these methods respectively.

1.Using C language to program to make Flowing LED on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

151
2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_06_flowingLed directory. Select _06_flowingLed.ino. This file is the code
program we need in this course. Then click Open.

152
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After running the program, it can be observed that the LED will be on and off from
right to left, then from left to right, indicating that our experimental test is successful.
The physical connection diagram of the experiment is as below:

153
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to make Flowing LED on Arduino UNO.We will introduce
how our core code can be achieved:
2. Set the ledpin to Output mode through pinMode(ledpin, OUTPUT) in the setup()
method;

2.In the loop() method, set the ledpin to HIGH through digitalWrite(ledpin, HIGH),
then light the LED in sequence according to the pin numbers from 2 to 9, and delay
300ms through delay(300); then set ledpin to LOW through digitalWrite(ledpin,
LOW ), and the LED will be off; similarly, turn on and turn off the LED in order
according to the pin number sequence of 9 to 2. In this way, the effect of Flowing
LED is realized.

154
2.Using graphical code blocks to program to make Flowing LED

on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

155
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

156
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

157
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

158
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

159
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_06_flowingLed
It will show as below:

5. Select the "06_flowingLed.gwblock" file. This file is the graphical code program
for our lesson. Click "Open" in the lower right corner.It will show as below:

160
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

161
8.After running the program, it can be observed that the LED will be on and off from
right to left, then from left to right, indicating that our experimental test is successful.
The physical connection diagram of the experiment is as below:

(4) Core code program

162
After the above hands-on operation, you must be very interested to know how we
program to make Flowing LED on Arduino UNO with graphical code blocks.We will
introduce how our core code can be achieved:
In the GwBlock graphical editor, all code programs are executed from

.First initialize the pin number of ledpin to 2,3,4,5,6,7,8,9 through the

instruction block , and the ledpin is set to the

Output mode through the instruction

block ;In the while loop statement, set the

ledpin to High-level in order of pin number sequence through the instruction

block ,and the LED will be on.Delay 300ms of

time through .Turn off the LED through the instruction

block ; set the ledpin to HIgh-level and

Low-level according to the pin number sequence of 9 to 2, and the LED will be on
and off in sequence.then turn on and off the LED in sequence.Delay 300ms of time

through .

163
Lesson 7 Controlling LED Bar with
Potentiometer

In this lesson, we will learn how to control LED bar with Potentiometer.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 10

Potentiometer(10KΩ) 1

LED Bar Graph 1

2. Introduction of LED Bar

(1)LED Bar

The bar LED module is composed of a 10-segment bar LED. Each LED has two
pins.One side is a positive pole and the other side is a negative pole. There is a total of
twenty pins.Ten LED can be controlled respectively. LED Bar displays are widely
used, such as audio equipment, dashboards and digital readout displays.

164
(2)Experimental principle of controlling LED Bar

A series of LED in a row. They can be applied to any series of digital outputs.

This tutorial borrows from the For Loop and Arrays tutorial as well as the Analog
Input tutorial.

The sketch works like this: first read the input. Map the input to the output range
which is 0-10 in this case since ten LED are used. Then you set up a for loop to iterate
over the outputs. If the number in the array of the output is lower than the mapped
input minimum, it is on. If not, it's off.

165
The internal schematic diagram for the LED bar graph is as shown below:

A potentiometer, informally a pot, is a three-terminal resistor with a sliding or


rotating contact that forms an adjustable voltage divider. If only two terminals are
used, one end and the wiper, it acts as a variable resistor or rheostat.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connected them in the circuit as shown in the


following figure. When connecting the circuit, we should pay attention to the
difference between positive and negative electrodes. Use 220Ω resistor. As shown in
the following figure:

166
4. Controlling LED Bar with Potentiometer

We provide two different methods to control the active buzzer. One is to program
the active buzzer on the Arduino UNO with C language through the Arduino IDE. You
167
need to master the C language; the other is to program the active buzzer on the
Arduino UNO with the graphical code block through GwBlock IDE.This method is
very suitable for beginners who have not mastered the advanced programming
languages C and C++. We will introduce these methods respectively.

1.Using C language to program Potentiometer to control LED

Bar on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_07_LEDBarGraph directory. Select _07_LEDBarGraph.ino. This file is the
code program we need in this course. Then click Open.

168
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After running the program, turn the potentiometer counterclockwise to light up each
LED of LED bar; turn the potentiometer clockwise to turn off each LED of LED bar.
This shows that our experimental test is successful. The physical connection diagram
of the experiment is as below:

169
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program Potentiometer to control LED Bar on Arduino UNO.We
will introduce how our core code can be achieved:
3. Set the pin number of pin1 to pin10 to Output mode through pinMode(pin,
OUTPUT) in the setup() method;

2.In the loop() method, read the voltage value input by the potentiometer by using the
analogRead() function.Then turn off each LED of LED bar in turn through
digitalWrite(i, LOW) in the for loop statement; digitalWrite(j, HIGH)is the LED in
the bar LED module.

170
2. Using graphical code blocks to program to control LED Bar

with Potentiometer on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

171
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

172
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

173
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

174
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

175
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_07_LEDBarGraph
It will show as below:

5. Select the "07_LEDBarGraph.gwblock" file. This file is the graphical code


program for our lesson. Click "Open" in the lower right corner.It will show as below:

176
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

177
8. After running the program, turn the potentiometer counterclockwise to light up the
LED; turn the potentiometer clockwise to turn off the LED. This shows that our
experimental test is successful. The physical connection diagram of the experiment is
as below:

(5) Core code program

178
After the above hands-on operation, you must be very interested to know how we
control LED bar with Potentiometer by programming on Arduino UNO with graphical
code blocks.We will introduce how our core code can be achieved:
In the GwBlock graphical editor, all code programs are executed from

.First initialize the pin number from 2 to 11 through the instruction

block , and the pin numbers are set to the Output mode

through the instruction block .In the while loop

statement, set the pin number from 2 to 11 to Low-level through the instruction

block , and the LED of LED bar will be off;set the

pin number from 2 to 11 to High-level through the instruction

block ,and the LED of LED bar will be on. Delay

0.05s of time through .

179
Lesson 8 Making Breathing LED with LED

In this lesson, we will learn how to make Breathing LED with LED.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 1

LED 1

2. The introduction of the Breathing LED

(1)Breathing LED

Breathing LED refers to the LED whose light gradually changes from bright to
dark on the Arduino. It feels like a person who is breathing. It is widely used on
mobile phones and serves as a reminder.

180
(2)The working principle of Breathing LED

(1)The working principle of the breathing light


How does our breathing light achieve a similar lighting effect? The breath light
controls the brightness of the LED by controlling the frequency (time) of the light
flashing, and this process is repeated over and over again to create the effect of
"breathing".
In this lesson, the Arduino analog output function is used to control the
brightness of the LED light through PWM pulse width modulation to present the
breathing light effect.
A r d u i n o generates a square wave with a certain duty cycle on the pin through PWM
technology. Changing the duty cycle is equivalent to changing the equivalent voltage
output by the pin, thereby causing the change of brightness of the LED.
In the circuit, the GND of the LED is connected to the GND on the Arduino
UNO development board through a 220Ω current limiting resistor, and the VCC is
connected to pin 11 of the GPIO on the Arduino UNO development board.The higher
the duty cycle of the PWM signal output by the GPIO, the lighter the LED; otherwise,
the lower the duty cycle, the darker the LED. We gradually increase the duty cycle of
the PWM signal through programming, and then the brightness of the LED will

181
gradually increase; otherwise, the brightness of the LED will gradually decrease. The
brightness of the LED gradually changes from dark to bright, and then changes from
bright to dark, and alternately produces a respiration-like effect.

How to control the frequency (time) of LED flashing? It is through PWM (pulse
width modulation) principle to achieve. We will introduce the principle of PWM as
follow.
(2) Pulse width modulation (PWM)
1. Definition of pulse width modulation:
Pulse width modulation is an analog control method, which modulates the bias of
the transistor base or MOS gate according to the change of the corresponding load to
realize the change of the transistor or MOS tube conduction time, so as to realize the
change of the output of the switching voltage stabilized power supply. This method
can make the output voltage of the power supply remain constant when the working
conditions change, and it is a very effective technique to control the analog circuit
with the digital signal of the microprocessor. Pulse width modulation is a very
effective technique for controlling analog circuits with the digital output of
microprocessors. It is widely used in many fields, from measurement and
communication to power control and transformation.
2. Principle of pulse width modulation
The control mode is to control the on-off of the inverter circuit switching device,
so that the output end can get a series of pulses with the same amplitude, and use
these pulses to replace the sine wave or the required waveform. In other words,
multiple pulses are generated in the half period of the output waveform, so that the
equivalent voltage of each pulse is a sinusoidal waveform, so that the output obtained
is smooth and has fewer low-order harmonics. The width of each pulse can be
modulated according to certain rules, which can not only change the output voltage of
the inverter circuit, but also change the output frequency.

182
The above method may not be easy for you to understand, but you can
understand it through the following sentence:
In the range of 0-1s: the lighting time of led lamp between 0-1ms is 0us; Light
1us in 1-2ms, light 2us in 2-3ms... Bright 999us in 999-1000ms.
3. Change duty cycle to realize breathing light:
The lighting and extinguishing of LED is the result of the level change, which
can be regarded as a cycle. Each cycle will be shown as LED flicker. When the cycle
is very short, that is, when the frequency is very high, this flicker will not be
recognized by the naked eye, which will make people have the sense of continuous
LED glow. In one cycle, the ratio between the duration of high level and the duration
of one cycle is called duty cycle ratio. The higher the duty cycle is, the larger the
current passing through the LED will be, and the brighter the visual perception will be.
Now, you should have the train of thought that makes breathing light, namely change
duty cycle! If the duty cycle is slightly stepped up, there will be a sense of brightening
of LED. Otherwise it will get dark.
(3)Experimental Principle

183
Digital signals are signals whose levels are discontinuously changed by 0 and 1,
while analog signals are used to represent information by continuously changing
physical quantities. The signal changes continuously with time. Most of the exposures
in our lives are analog signals, such as changes in sound, light, and temperature.
On our Arduino Uno R3 development board, pins 3, 5, 6, 9, 10, 11 have PWM
(Pulse Width Modulation) function.
By using the analogWrtie() function, a square wave with a fixed period is output
through the continuous conversion of high and low levels on the specified pin, and by
changing the proportion of high and low levels in each cycle (duty cycle).Then we get
different voltage output.
When the high level appears longer in a cycle, the output voltage will be higher
and the LED light will be brighter. When the high level time is shorter, the output
voltage will be lower and the LED brightness will be darker.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connected them in the circuit as shown in the


following figure. When connecting the circuit, we should pay attention to the
difference between positive and negative electrodes, as shown in the following figure:

184
4. Making Breathing LED with LED

We provide two different methods to control the active buzzer. One is to program
the active buzzer on the Arduino UNO with C language through the Arduino IDE. You

185
need to master the C language; the other is to program the active buzzer on the
Arduino UNO with the graphical code block through GwBlock IDE.This method is
very suitable for beginners who have not mastered the advanced programming
languages C and C++. We will introduce these methods respectively.

1.Using C language to program to make Breathing LED on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_08_breathingLed directory. Select_08_breathingLed.ino. This file is the code
program we need in this course. Then click Open.

186
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we will observe that the LED changes
slowly from the extinguished state to the increasingly brighter state, and then slowly
changes from the brightest state to the increasingly darker state, until it turns off.
Repeat this process non-stop to form the breathing light effect. This shows that our
experimental test is successful. The physical connection diagram of the experiment is
as below:

187
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to make Breathing LED on Arduino UNO.We will
introduce how our core code can be achieved:
1.Define pin 11 as the pin of the LED. Represent it to ledpin; in the setup() function,
use pinMode(ledpin, OUTPUT) to set the ledpin to OUTPUT mode.

2.In the loop() function, we use the principle of PWM to control the brightness of
LED to gradually increase. Then we use the principle of PWM to control the
brightness of LED to gradually decrease.We control the state of the LED through the
delay() function and repeat this process continuously to achieve the effect of breathing

188
to LED.

2.Using graphical code blocks to program to make Breathing

LED on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

189
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

190
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

191
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

192
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

193
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_08_breathingLed
It will show as below:

5. Select the "08_breathingLed.gwblock" file. This file is the graphical code program
for our lesson. Click "Open" in the lower right corner.It will show as below:

194
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

195
8.After successfully running the program, we will observe that the LED changes
slowly from the extinguished state to the increasingly brighter state, and then slowly
changes from the brightest state to the increasingly darker state, until it turns off.
Repeat this process non-stop to form the breathing light effect. This shows that our
experimental test is successful. The physical connection diagram of the experiment is
as below:

196
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
program to make Breathing LED on Arduino UNO with graphical code blocks.We
will introduce how our core code can be achieved:
In the GwBlock graphical editor, all code programs are executed

from .First initialize the pin number of ledpin to 11 through the instruction

block ,and the ledpin is set to the Output mode through the

instruction bloc k ; in the while loop

statement, increase the brightness of LED with PWM.Use the

command to keep the LED in the corresponding state for

0.015s. Decrease the brightness of LED with PWM through the instruction

block .Use the

command to keep the LED in the corresponding state for

0.015s again.Then we achieve the effect of breathing to LED.

197
198
Lesson 9 The Application of the RGB LED

In this lesson, we will learn how to control RGB LED.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 3

RGB LED 1

2. The introduction of the RGB LED

(1)The RGB LED

RGB LED modules are commonly known as three primary colors (red, green and
blue) light-emitting diodes. Commonly have four pins, a common terminal and three
colors (one red, one green, one blue) control terminal. Any combination of the three
colors can produce other colors. The longest pin is connected to the positive electrode.
A four-wire connection with a common lead (anode or cathode) is usually used. These
LED lights may have a common anode lead or a common cathode lead. In this lesson,
common anode RGB LED lights are used. The longest pin is the common anode of
the three LED lights. This pin is connected to the 5V port of the Arduino UNO, and
the remaining three pins are connected to the port9,10,11 of the Arduino UNO

199
through current limiting resistors.

(2)Working principle of the RGB LED

RGB LED light imaging principle: RGB lights are combined with three primary
colors to form an image, and there are also blue LED lights with yellow phosphors,
and ultraviolet LED lights with RGB phosphors. Overall, both types have their
imaging principles, but the attenuation problem and the impact of ultraviolet light on
the human body are both It is a problem that is difficult to solve in the short term, so
although it can meet the needs of white light, it has different results.
RGB LED color changing principle: When two LED lights are lit by three
primary color LED lights, it can emit yellow, purple, and cyan (such as red and blue
LED lights emit purple light when lit); if red, green, and blue When the LED lights up
at the same time, it produces white light. If there is a circuit that can make the red,
green, and blue LED lights light up two by two, individually, and the three primary
colors simultaneously, then he can emit seven different colors of light.
We used ordinary anode RGB LED lights in this experiment. The longest pin is
the common anode of the three LED lights. This pin is connected to the +3.3V pin of
the Raspberry Pi, and the remaining three pins are connected to the pin11, pin12, and
pin13 of the Raspberry Pi through current limiting resistors. In this way, we can
control the color of RGB LED through 3 PWM signals.

200
3.Wiring diagram (Circuit diagram)

Before the experiment, we connected them in the circuit as shown in the


following figure. When connecting the circuit, we should pay attention to the
difference between positive and negative electrodes. Use 220Ω resistor. As shown in
the following figure:

201
4. How to change the color of RGB LED

We provide two different methods to change the color of RGB LED. One is to
program the RGB LED on the Arduino UNO with C language through the Arduino
IDE. You need to master the C language; the other is to program the RGB LED on the
Arduino UNO with the graphical code block through GwBlock IDE.This method is
very suitable for beginners who have not mastered the advanced programming
languages C and C++. We will introduce these methods respectively.

1.Using C language to program to change the color of RGB LED

on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

202
2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_09_rgbLed directory. Select _09_rgbLed.ino. This file is the code program we
need in this course. Then click Open.

203
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we will observe that the RGB LED lights
up, and the colors of red, green, blue, yellow, white, and purple appear in turn,
indicating that our experimental test is successful. The physical connection diagram of
the experiment is as below:

(2)Core code program


After the above hands-on operation, you must be very interested to know how we
use C language to program to change color of RGB LED on Arduino UNO.We will
introduce how our core code can be achieved:
1.Define pins of R, G, and B to be connected to ports of 11, 10, and 9 respectively and
represent them with redPin, greenPin, and bluePin respectively; in the setup() function,

204
set the redPin, greenPin, and bluePin pins in turn through the pinMode() function to
OUTPUT mode.

2.In the loop() function, set the color of the RGB LED through the color(R,G,B)
function.The value represents the corresponding color. For example, color(255,0,0)
means red.Then the RGB LED will become red and light up.

2. Using graphical code blocks to program to change color of

RGB LED on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:

205
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

206
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

207
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

208
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

209
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_09_rgbLed
It will show as below:

5. Select the "09_rgbLed.gwblock" file. This file is the graphical code program for our
lesson. Click "Open" in the lower right corner.It will show as below:

210
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

211
8. After successfully running the program, we will observe that the RGB LED lights
up, and the colors of red, green, blue, yellow, white, and purple appear in turn,
indicating that our experimental test is successful. The physical connection diagram of
the experiment is as below:

212
(6) Core code program
After the above hands-on operation, you must be very interested to know how we
change the color of RGB LED by programming on Arduino UNO with graphical code
blocks.We will introduce how our core code can be achieved:
In the GwBlock graphical editor, all code programs are executed from

.First define the pins of the RGB LED to connect to the ports of 9, 10, 11 on

Arduino UNO through the instruction block .The pin a is set to the output

mode through the instruction block .


Similarly, the pins of b and c are also set to the output mode.

213
In the while loop statement, the values of R, G, and B are set by

instructions , and respectively to

control the RGB LED to display different colors.

The code to change the RGB LED color is shown below:

214
215
Lesson 10 The Application of the Passive Buzzer

In this lesson, we will learn how to control the Passive Buzzer.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 1

Passive Buzzer 1

PNP Transistor(8550) 1

2. The introduction of the Buzzer

(1) Buzzer

The Buzzer is an electronic sounder with an integrated structure. It is powered by


DC voltage and is widely used as a sounding device in electronic products such as
computers, printers, copiers, alarms, electronic toys, automotive electronic equipment,
telephones, timers, and other electronic products. . There are two types of buzzer:
active buzzer and passive buzzer. As shown in the figure below, the left is the active
buzzer (the two pins have different lengths), and the right is the passive buzzer (the
two pins have the same length).

216
(2)Working principle of the Buzzer

The sounding principle of buzzer is composed of vibration device and


resonance device, and buzzer is divided into passive buzzer and active buzzer. The
working sounding principle of passive buzzer is: square wave signal input resonant
device is converted into sound signal output; the working sounding principle of active
buzzer is: DC power input is generated by the amplification sampling circuit of the
oscillation system under the action of the resonance device Sound signal. Our course
in this section uses an active buzzer. We can program the Raspberry Pi output high
and low alternately, so that the active buzzer will sound.

(3) Two kinds of Transistors (S8050 and S8550)

To make the active buzzer sound, a large current is required. However, the output
current of Raspberry Pi GPIO is very weak, so we need a transistor S8050 or S8550 to
drive the active buzzer. The main function of the transistor S8050 (S8550) is to
amplify the voltage or current, and it can also be used to control the conduction or
cut-off time of the circuit.
There are two kinds of transistors, one is NPN, such as the transistor S8050 used
in our course; the other is a PNP transistor, such as the other S8550 we provide. The
pin structure of the two transistors we use is the same. Their pin structure is as shown
in the figure below. In the circuit, Emitter is abbreviated as e, Base is abbreviated as b,

217
and Collector is abbreviated as c.

The S8050 and S8550 transistors provided by our course are as shown below.
The one with letter H is S8050, and the other without H is S8550.

The two transistors S8050 and S8550 and the buzzer are connected in the circuit
as shown below:

218
Figure1:
Set the Raspberry Pi GPIO as a high level, the transistor S8050 will conduct, and
then the buzzer will sound; set the Raspberry Pi GPIO as low level, the transistor
S8050 will cut off, then the buzzer will stop.
Figure2:
Set the Raspberry Pi GPIO as low level, the transistor S8550 will conduct, and the
buzzer will sound; set the Raspberry Pi GPIO as a high level, the transistor S8550 will
cut off, then the buzzer will stop.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connected them in the circuit as shown in the


following figure. When connecting the circuit, we should pay attention to the
difference between positive and negative electrodes. Use 220Ω resistor. As shown in
the following figure:

219
4. The Application of the Passive Buzzer
We provide two different methods to control the Passive Buzzer. One is to
program on the Arduino UNO with C language through the Arduino IDE. You need to

220
master the C language; the other is to program on the Arduino UNO with the
graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

1.Using C language to program to control the Passive Buzzer on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_10_music directory. Select _10_music.ino. This file is the code program we
need in this course. Then click Open.

221
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, the passive buzzer will sound, indicating
that our experimental test is successful. The physical connection diagram of the
experiment is as below:

222
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
control the Passive Buzzer on Arduino UNO.We will introduce how our core code can
be achieved:
Define the pin number of passive buzzer as 8 and represent it with tonepin.
MUSIC represents sound frequency. In the setup() function, set the tonepin to
OUTPUT mode through the pinMode(tonepin, OUTPUT) function. Drive the buzzer
to sound at 500Hz through the tone(tonepin, MUSIC) function. Delay 1000ms of time
with delay (1000). Turn off the buzzer through noTone (tonepin) function.

2. Using graphical code blocks to control the Passive Buzzer on

223
Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

2. Due to the use of special components in this course: Passive Buzzer, we need to
modify the block_py.ino file to upload the program. First, we need to modify the code

file into .At the same time,we

need to modify into .It will show as below:

224
3.After the modification is completed.It will show as below:

4.After opening, click to upload the code program to the Arduino UNO.It will
show as below:

225
5.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

6.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

7.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

8.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

226
9.Click the "Connecting device" button in the upper right corner. It will show as
below:

10.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then
click the Connecting . It will show as below:

227
11.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

(2)Run the code program for this course


Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

228
2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_10_music
It will show as below:

5. Select the "10_music.gwblock" file. This file is the graphical code program for our

229
lesson. Click "Open" in the lower right corner.It will show as below:

6.Click OK.It will show as below:

7.It will show as below after successfully opening:

8. After successfully running the program, the passive buzzer will sound, indicating

230
that our experimental test is successful. The physical connection diagram of the
experiment is as below:

(3)Core code program


After the above hands-on operation, you must be very interested to know how to
control the Passive Buzzer by programming on Arduino UNO with graphical code
blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .First

set the pin number of tonepin of Buzzer to 8 with the instruction

block .Then set tonepin to Output mode with the instruction

block .Set the Buzzer to sound at 500 Hz

with the instruction block .The

instruction can delay the sound for 1s. Finally, close Buzzer

through command .

231
If you click "Python", you will find that the graphical code instruction block will be
converted into Python language. If you have studied Python, you will easily
understand it.

232
Lesson 11 The Application of the LCD1602 and the
IIC Interface

In this lesson, we will learn the application of the LCD1602 and the IIC
Interface.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

LCD1602 1

Adeept IIC Module 1

Male to Female Jumper Wires Several

2. The introduction of the LCD1602 and the IIC


Interface

(1)The LCD1602 and the IIC Interface

1. The LCD1602
LCD1602 liquid crystal display is a character liquid crystal display module
widely used. It is composed of a character liquid crystal display (LCD), a main
control circuit HD44780 and its extended drive circuit HD44100, and a small number

233
of resistors, capacitors, and structural parts, etc., which are assembled on a PCB.

2. The IIC Interface


IIC "Inter-Integrated Circuit" is a serial communication bus used for
communication between low-speed devices on board. The purpose of this
communication protocol developed by Philips is to simplify the system hardware
design and reduce the connections between devices. IIC can reduce the number of
pins occupied by LCD1602, and reduce the number of pins to two.

(2)Working principle of the LCD1602

The LCD1602 character liquid crystal display module is a dot-matrix LCD


specifically for displaying letters, numbers, and symbols. Commonly used modules
are 16×1, 16×2, 20×2, and 40×2. The internal controller of the general LCD1602
character liquid crystal display is mostly HD44780, which can display English letters,
Arabic numerals, Japanese Katakana and general symbols.

234
LCD1602 is a kind of character LCD display. The LCD has a parallel interface,
meaning that the microcontroller has to manipulate several interface pins at once to
control the display. The interface consists of the following pins:
● A register select (RS) pin that controls where in the LCD's memory you're
writing data to. You can select either the data register, which holds what goes on the
screen, or an instruction register, which is where the LCD's controller looks for
instructions on what to do next.
● A Read/Write (R/W) pin that selects reading mode or writing mode
● An Enable pin that enables writing to the registers
● 8 data pins (D0-D7). The state of these pins (high or low) is the bits that you're
writing to a register when you write, or the values when you read.
● There are also a display contrast pin (Vo), power supply pins (+5V and Gnd)
and LED Backlight (Bklt+ and BKlt-) pins that you can use to power the LCD,
control the display contrast, and turn on or off the LED backlight respectively.
The process of controlling the display involves putting the data that form the
image of what you want to display into the data registers, then putting instructions in
the instruction register. The LiquidCrystal Library simplifies this for you so you don't
need to know the low-level instructions.
The Hitachi-compatible LED can be controlled in two modes: 4-bit or 8-bit. The
4-bit mode requires seven I/O pins from the Arduino, while the 8-bit mode requires 11
pins. For displaying text on the screen, you can do most everything in 4-bit mode, so
example shows how to control a 2x16 LCD in 4-bit mode.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. Use 220 Ω resistor. As shown in the following
figure:

235
4.Application of the LCD1602

We provide two different methods to display characters on the LCD1602 screen.


One is to program on the Arduino UNO with C language through the Arduino IDE.
You need to master the C language; the other is to program on the Arduino UNO with
the graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

236
1.Using C language to program to display characters on

LCD1602 on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_11_LCD1602 directory. Select_11_LCD1602.ino. This file is the code program
we need in this course. Then click Open.

237
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After the program runs successfully, hello geeks will be displayed on the LCD1602
screen first, and then www.adeept.com is displayed, indicating that our experimental
test is successful. The physical connection diagram of the experiment is as below:

238
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
control the LCD1602 on Arduino UNO.We will introduce how our core code can be
achieved:
1.Define the text information to be displayed on the LCD1602 screen through the
array char array[]. In the setup() function, initialize the LCD through lcd.init(), and
use lcd.backlight() to open the backlight.

2.In the loop() function, print out the corresponding text information on the LCD1602

239
screen through lcd.print(array[]) in the for loop statement

2. Using graphical code blocks to program and display

characters on LCD1602 on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

240
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

241
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

242
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

243
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

244
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_11_LCD1602
It will show as below:

5. Select the "11_LCD1602.gwblock" file. This file is the graphical code program for
our lesson. Click "Open" in the lower right corner.It will show as below:

245
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

246
8. After the program runs successfully, hello geeks will be displayed on the LCD1602
screen first, and then www.adeept.com is displayed, indicating that our experimental
test is successful. The physical connection diagram of the experiment is as below:

247
(3)Core code program
After the above hands-on operation, you must be very interested to know how we
display characters on LCD1602 on Arduino UNO with graphical code blocks.We will
introduce how our core code can be achieved:
In the GwBlock graphical editor, all code programs are executed from

.First initialize LCD through the instruction block .In the while

loop statement,the position of the text information to be displayed on the LCD1602

screen can be set through the instruction block .

Using the instruction block , the text information "hello


geeks"can be displayed on the LCD1602 screen. The text information in this
instruction can be directly modified. You only need to enter the text information you

need to display. The instruction block can be used to control the

text information displayed on the LCD screen for 2s. Finally, the instruction block

needs to be used to clear the LCD1602, so that it can

248
display at last.

249
Lesson 12 Making Voltmeter

In this lesson, we will learn how to make voltmeter with LCD1602, I2C and
potentiometer.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

LCD1602 1

Adeept IIC Module 1

Male to Female Jumper Wires Several

Potentiometer 1

2. The introduction of Voltmeter

In this lesson, we will make a simple voltmeter (0~5V) with Arduino UNO and
LCD1602. Then, we will measure the voltage of the potentiometer(when adjusting the
knob) with the simple voltmeter and display the voltage detected on the LCD1602.

(1)LCD1602

Please refer to Lesson 11, for we have introduced the LCD1602 in detail in Lesson

250
11.

(2)Potentiometer

Please refer to Lesson 5, for we have introduced the potentiometer in detail in


Lesson 5.

(3)Experimental principle of making Voltmeter

The basic principle of this experiment: Convert the analog voltage collected from
Arduino to digital quantity by the ADC (analog-to-digital converter) through
programming, and then display the voltage on the LCD1602.
Connect the three wires from the potentiometer to your Arduino board. The first goes
to ground from one of the outer pins of the potentiometer. The second goes from
analog input 0 to the middle pin of the potentiometer. The third goes from 5V to the
other outer pin of the potentiometer.
By turning the shaft of the potentiometer, you change the resistance on either side
of the wiper which is connected to the center pin of the potentiometer. This changes
the voltage at the center pin. When the resistance between the middle and the side one
(connected to 5V) is close to zero (and the resistance on the other side is close to 10k
Ohm), the voltage at the middle pin is close to 5V. When the resistances are reversed,
the voltage at the center pin changes to about 0V, or ground. This voltage is the analog
voltage that you're reading as an input.
The Arduino UNO board has a circuit inside called an analog-to-digital converter
that reads this changing voltage and converts it to a number between 0 and 1023.
When the shaft is turned all the way in one direction, there are 0 volts going to the pin,
and the input value is 0. When the shaft is done in the opposite direction, it's 5 volts
going to the pin and the input value is 1023. In between, analogRead( ) returns a
number between 0 and 1023 that is proportional to the amount of voltage being
applied to the pin.

251
3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

252
4.How to make Voltmeter

We provide two different methods to make Voltmeter. One is to program on the


Arduino UNO with C language through the Arduino IDE. You need to master the C
language; the other is to program on the Arduino UNO with the graphical code block
through GwBlock IDE.This method is very suitable for beginners who have not
mastered the advanced programming languages C and C++. We will introduce these
methods respectively.

1.Using C language to program voltage measurement on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
253
Code\_12_voltage directory. Select_12_voltage.ino. This file is the code program we
need in this course. Then click Open.

4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After running the program, rotate the potentiometer clockwise to increase the
voltage to a maximum of about 5V; turn the potentiometer counterclockwise to
decrease the voltage. The value of Voltage will be displayed on the LCD1602 screen.
The physical connection diagram of the experiment is as below:

254
【Pay Attention】
If the voltage number displayed on LCD1602 keeps changing during the
experiment, it may be that the pin of the potentiometer connected to the breadboard is
loose, you can have a try to reconnect it at other locations.
(2)The core code program
After the above hands-on operation, you must be very interested to know how we
program to display the voltage value on LCD1602 on Arduino UNO.We will
introduce how our core code can be achieved:
1.In the setup() method, the text information in the corresponding array is displayed
on the LCD1602 screen through the lcd.print() function in the for loop statement.

2.In the loop() function, read the value of the potentiometer through the
analogRead(photoresistorPin) function. In the for loop statement, display the voltage
value on the LCD1602 screen through the lcd.print() function.

255
2. Using graphical code blocks to program voltage measurement

on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

256
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

257
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

258
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

259
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

260
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_12_voltage
It will show as below:

5. Select the "12_voltage.gwblock" file. This file is the graphical code program for
our lesson. Click "Open" in the lower right corner.It will show as below:

261
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

262
8. After running the program, rotate the potentiometer clockwise to increase the
voltage to a maximum of about 5V; turn the potentiometer counterclockwise to
decrease the voltage. The value of Voltage will be displayed on the LCD1602 screen.
The physical connection diagram of the experiment is as below:

【Pay Attention】
If the voltage number displayed on LCD1602 keeps changing during the

263
experiment, it may be that the pin of the potentiometer connected to the breadboard is
loose, you can have a try to reconnect it at other locations.
(3)Core code program
After the above hands-on operation, you must be very interested to know how we
program voltage measurement on Arduino UNO with graphical code blocks.We will
introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .

First initialize the pin number of photoresistorPin of potentiometer to 0 through the

instruction block .In the while loop statement, the

value of the potentiometer is read through the instruction

block .Convert the read value through

instruction block .Finally display the voltage value on the

LCD1602 screen through the instruction block .

264
Lesson 13 The Application of the 7-segment Display

In this lesson, we will learn the application of the 7-segment Display.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 1

7-segment Display 1

2. The introduction of the 7-segment Display

(1)The 7-segment Display

The 7-segment display is also called the 7-segment LED display. It is a type of
LED display, using 7 LED lights to form the font "8", and another dot LED to display
the decimal point, which means that there are 8 LED lights in total to form the font of
"8."
According to the connection form, it can be divided into common anode display
and common cathode display. By controlling the display mode of semiconductor light
emitting diodes, LED display panel (LED panel) is used to display information such
as text, graphics, images, animations, quotes, videos, video signals, etc. The
7-segment display module is used to display numbers from decimal 0 to 9 and

265
decimal point, and can also display English letters, including English A to F in
hexadecimal (b and d are lowercase, others are uppercase)

(2)Working principle of the 7-segment Display

The 7-segment display module is packaged by multiple LED light-emitting


diodes. Each LED is called a segment. In addition to the seven-segment strokes
necessary for displaying numbers, a decimal point is also provided in the display. It
has 8 pins with numbers from a to g. By forward installing the appropriate pins of the
LED segments in a specific order, some segments will be bright and others will be
dark, allowing the desired character pattern of the numbers generated on the display.
Then each of the ten decimal digits 0 to 9 can be displayed on the same 7-segment
display.
The seven-segment display is an 8-shaped LED display device composed of
eight LEDs (including a decimal point). The segments respectively named a, b, c, d, e,
f, g, and dp.
The segment display can be divided into common anode and common cathode
segment display by internal connections.
When using a common anode LED, the common anode should to be connected to
the power supply (VCC); when using a common cathode LED, the common cathode
should be connected to the ground (GND).
Each segment of a segment display is composed of LED, so a resistor is needed
for protecting the LED.

266
A 7-segment display has seven segments for displaying a figure andone more for
displaying a decimal point. For example, if you want to display a number '1', you
should only light the segment b and c, as shown below.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

267
4.The Application of the 7-segment Display

268
We provide two different methods to control the 7-segment Display. One is to
program on the Arduino UNO with C language through the Arduino IDE. You need to
master the C language; the other is to program on the Arduino UNO with the
graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

1.Using C language to program to control the 7-segment Display

on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_13_7segment directory. Select_13_7segment.ino. This file is the code program
we need in this course. Then click Open.
269
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program,we observe the digital tube and will find
that the number changes from 0 to 9, indicating that our experimental test is
successful. The physical connection diagram of the experiment is as below:

270
(2)The core code program
After the above hands-on operation, you must be very interested to know how we
program to control the the 7-segment Display on Arduino UNO.We will introduce
how our core code can be achieved:
1.In the setup() function, set the digital pins of the 7-segment digital tube
connected to the Arduino UNO to OUTPUT mode in turn through pinMode(i,
OUTPUT) in the for loop statement.

2.In the loop() function, set the 7-segment digital tube through the digital() function in
turn to display the numbers from 0 to 9.

271
2. Using graphical code blocks to program to control the

7-segment Display on Arduino UNO

272
(1)Connecting to GwBlock graphical editor
In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be

273
used later. It will show as below:

4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as

274
below:

7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

275
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

276
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_13_7segment
It will show as below:

5. Select the "13_7segment.gwblock" file. This file is the graphical code program for
our lesson. Click "Open" in the lower right corner.It will show as below:

277
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

278
8. After successfully running the program,we observe the digital tube and will find
that the number changes from 0 to 9, indicating that our experimental test is
successful. The physical connection diagram of the experiment is as below:

279
(3) Core code program
After the above hands-on operation, you must be very interested to know how we
program to control the the 7-segment Display with potentiometer on Arduino UNO
with graphical code blocks.We will introduce how our core code can be achieved:
In the GwBlock graphical editor, all code programs are executed from

.Initialize the 7-segment Display through the instruction

block .Set the 7-segment Display through the instruction block

in turn to display the numbers 0 to 9.

280
281
Lesson 14 Making A Simple Counter

In this lesson, we will learn how to make a simple counter with 4-digit
7-segment Display.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 1

4-digit 7-segment Display 1

2. The introduction of the 4-digit 7-segment Display

(1)The 4-digit 7-segment Display

The 4-digit 7-segment display module is also a kind of LED display screen. It
can be divided into a common positive display and a common negative display
according to its connection form. LED display panel (LED panel) is a display screen
used to display information by controlling the display mode of semiconductor light
emitting diodes. Such as text, graphics, images, animations, quotes, videos, video
signals, etc. It consists of a 12-pin 4-digit 7-segment common anode digital tube and a
control chip TM1637. A 4 * 8 shape LED display device composed of 32 LEDs
(including four decimal points), these segments are named a, b, c, d, e, f, g, h, dig1,

282
dig2, dig3, dig4.

(2)Working principle of the 4-digit 7-segment Display

Since all the segment selection lines are connected to the same I / O in parallel, it
is controlled by this I / O port. Therefore, if all 4-digit 7-segment LEDs are selected,
the 4-digit 7-segment LED will display the same characters. To make the 7-segment
LED of each bit display different characters, you must use dynamic scanning method
to turn on each 7-segment LED in turn, that is, only one 7-segment LED is selected to
display individual characters at each instant. During this lighting period, the segment
selection control I / O port outputs the segment selection code of the corresponding
character to be displayed, and the bit selection control I / O port outputs the bit
selection signal, sending the strobe level to the bit to be displayed (The common
cathode sends a low level, and the common anode sends a high level), so that the
corresponding character is displayed. In this way, the four-digit 7-segment LEDs are
turned on in turn, so that each digit displays the character that the digit should display.
Since the visual retention time of the human eye is 0.1 seconds, when the interval of
each display does not exceed 33ms, and it is maintained until the next display during
the display, the eye looks like 4 due to the visual retention effect of the human eye Bit
7 segment LED lights are all lit. When designing, pay attention to the interval time of
each display. Because the extinguishing time of one 7-segment LED cannot exceed

283
100ms, that is to say, the time used to light up other bits cannot exceed 100ms. When
displaying, the time t of each bit interval must meet the following formula: t ≦ 100ms
/ (N-1)
For example, if 4 bits are used now, that is, N = 4, then t ≦ 33ms can be
calculated from the formula, that is, the interval between each bit cannot exceed 33ms.
Of course, the time can also be set shorter, such as 5ms or 1ms. As shown in the
following figure:

What we use in this experiment is a common cathode 4-digit 7-segment display.


Its internal structure is as shown below:

The pin number is as follows:

284
3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. Use 220 Ω resistor. As shown in the following
figure:

285
4. Making a simple counter

We provide two different methods to make a simple counter. One is to program


on the Arduino UNO with C language through the Arduino IDE. You need to master
the C language; the other is to program on the Arduino UNO with the graphical code
block through GwBlock IDE.This method is very suitable for beginners who have not
mastered the advanced programming languages C and C++. We will introduce these
methods respectively.

1.Using C language to program to make a simple counter on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

286
3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the
user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_14_aSimpleCounter directory. Select_14_aSimpleCounter.ino. This file is the
code program we need in this course. Then click Open.

4.After opening, click to upload the code program to the Arduino UNO. If there is

287
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we will find that the digital tube will
display 4 digits, , and the digits will change and expand. This shows that our
experimental test is successful. The physical connection diagram of the experiment is
as bellow:

(2)Core code program


After the above hands-on operation, you must be very interested to know how we
use C language to program to make a simple counter on Arduino UNO.We will
introduce how our core code can be achieved:
1.In the setup() function, set btn1pin and btn2pin to INPUT_PULLUP mode
through pinMode() function, and set the pin connected to Arduino UNO to OUTPUT
mode through pinMode() function.

288
2.In the loop() function, set the counter to start counting through data5++. The
pickDigit(1) function is used to light up the nixie tube on the 4-digit 7-segment
display. The pickNumber(data5/1000%10) function is used to set the data displayed
on this bit.

289
2. Programming to make a simple counter on Arduino UNO

with graphical code blocks

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

290
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

291
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as below:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

292
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

293
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

294
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_14_aSimpleCounter
It will show as below:

5. Select the "14_aSimpleCounter.gwblock" file. This file is the graphical code


program for our lesson. Click "Open" in the lower right corner.It will show as below:

295
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

296
8.Click the button on the upper right corner.After successfully running the program,

we will find that the digital tube will display 4 digits, , and the digits keep changing .
This shows that our experimental test is successful. The physical connection diagram
of the experiment is as bellow:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to make a counter on Arduino UNO with graphical code blocks.We will
introduce how our core code can be achieved:
In the GwBlock graphical editor, all code programs are executed

from .Initialize the 4-digit 7-segment display through

instructions .Set the counter to start counting through the

instruction block . Sets the thousand-digit display data on the 4-digit

7-segment display through the instruction

block .

297
298
Lesson 15 Controlling the Servo Motor

In this lesson, we will learn how to control the Servo Motor.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

AD002 Servo 1

2. The introduction of the Servo Motor

(1) Servo Motor

Servo motor refers to the engine that controls mechanical component operation
in the servo system. It is a kind of auxiliary motor indirect transmission device. The
servo motor is a gear motor that can rotate only 180 degrees. It is controlled by
sending pulses from the microcontroller. These pulses tell the server where to move.
The servo motor system includes housing, circuit board, non-core motor, gearing and
position detection. Servo motor is shown in the figure:

299
(2)The working principle of the Servo Motor

The servo mechanism is an automatic control system that enables the object's
position, orientation, state and other output controlled quantities to follow arbitrary
changes in the input target (or given value). The servo mainly depends on Pulsefor
location. Basically, it can be understood that the servo motor receives an impulse and
rotates the angle corresponding to the impulse to realize displacement. Because the
servo motor itself has the function of sending out pulses, the servo motor rotates every
time at an angle, and a corresponding number of pulses will be sent out. In this way,
the pulses received by the servo motor form a response, or a closed loop. In this way,
the system will know how many pulses are sent to the servo motor and how many
pulses are received. In this way, it is possible to precisely control the rotation of the
motor, thereby achieving precise positioning
Arduino sends a PWM signal to a servomotor, which is then processed by an IC
on the circuit board to calculate the rotation direction of the drive motor, which is then
transmitted through a reduction gear to the swing arm. At the same time, the position
detector returns a position signal to determine whether the set position has been
reached or not.

300
The servo motor has three wires: power, ground, and signal. The power wire is
typically red, and should be connected to the 5V pin on the Arduino board. The
ground wire is typically black or brown and should be connected to a ground pin on
the Arduino board. Usually the signal pin is yellow, orange or white, and should be
connected to a digital pin on the Arduino board. Note that the servo motor draws a
considerable amount of power, if you need to drive more than one or two servos,
you'll probably need to power them with an extra supply (i.e. not the +5V pin on your
Arduino). Be sure to connect the grounds of the Arduino and external power supply
together.

301
3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

302
4. Controlling the Servo Motor

We provide two different methods to control the servo motor. One is to program
on the Arduino UNO with C language through the Arduino IDE. You need to master
the C language; the other is to program on the Arduino UNO with the graphical code
block through GwBlock IDE.This method is very suitable for beginners who have not
mastered the advanced programming languages C and C++. We will introduce these
methods respectively.

1.Using C language to program to control the servo motor on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

303
2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_15_servo directory. Select_15_servo.ino. This file is the code program we need
in this course. Then click Open.

304
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we observe the experiment and find that
the servo motor will rotate clockwise and counterclockwise, indicating that our
experimental test is successful. The physical connection diagram of the experiment is
as below:

305
(2)The core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to control the servo motor on Arduino UNO.We will
introduce how our core code can be achieved:
1.In the setup() function, the myservo.write(0) function initializes the servo
motor to 0 degrees.

2.In the loop() function, the myservo.write(180) function controls the servo motor
to rotate 180 degrees. If you want to control how much the servo motor rotates, you
only need to enter the corresponding angle value in the myservo.write() function.
Then the myservo.write() function will continue to control the servo motor to rotate
90 degrees, and then turn back to 0 degrees.

306
2. Programming to control the servo motor on Arduino UNO

with graphical code blocks

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

307
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

308
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as below:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

309
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

310
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

311
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_15_servo
It will show as below:

5. Select the "15_servo.gwblock" file. This file is the graphical code program for our
lesson. Click "Open" in the lower right corner.It will show as below:

312
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

313
8.Click the button on the upper right corner.After successfully running the program,

we observe the experiment and find that the servo motor will rotate clockwise and
counterclockwise by a certain angle, indicating that our experimental test is successful.
The physical connection diagram of the experiment is as below:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to control the servo motor on Arduino UNO with graphical code blocks.We
will introduce how our core code can be achieved:

314
In the GwBlock graphical editor, all code programs are executed from .

Initialize the servo motor through the instruction

block .The command

block controls the servo motor to turn to

0 degrees, which is also the initial position. In the while loop, the instruction

block controls the servo motor to

rotate 180 degrees. If you need to control the servo motor to rotate other degrees, you

can directly modify to other data.

315
Lesson 16 Making a Digital Thermometer

In this lesson, we will learn how to use thermistor and LCD1602 module to make
a digital thermometer.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

LCD1602 1

Adeept IIC Module 1

Male to Female Jumper Wires Several

Resistor(10KΩ) 1

Analog Temperature 1

Sensor(Thermistor)

2. The introduction of thermistor

(1) Thermistor
Thermistors are a type of sensitive components, which are divided into positive
temperature coefficient thermistors (PTC) and negative temperature coefficient
thermistors (NTC) according to different temperature coefficients. The typical
characteristic of the thermistor is that it is sensitive to temperature, showing different

316
resistance values ​ ​ at different temperatures. The positive temperature coefficient
thermistor (PTC) has a larger resistance value at a higher temperature, and the
negative temperature coefficient thermistor (NTC) has a lower resistance value at a
higher temperature. They both belong to semiconductor devices.
The main characteristics of the thermistor:
①High sensitivity:its temperature coefficient of resistance is 10 to 100 times
greater than that of metal, and it can detect the temperature change of 10-6℃;
②Wide operating temperature range:normal temperature device is suitable for

-55℃~315℃.High temperature device is suitable for temperature higher than 315℃

(currently up to 2000℃). Low temperature device is suitable for -273℃~-55℃;

③Small size:able to measure the temperature of voids, cavities and blood vessels
in the body that cannot be measured by other thermometers;
④ Easy to use:the resistance value can be arbitrarily selected from 0.1 to 100kΩ;
⑤Easy to process into complex shapes:can be mass produced;
⑥Good stability and strong overload capacity.

(2) Working principle

The thermistor will be in an inactive state for a long time; when the ambient
temperature and current are in the c zone, the heat dissipation power of the thermistor
is close to the heating power, so it may or may not operate. When the thermistor is at
the same ambient temperature, the operating time decreases sharply as the current
increases; the thermistor has a shorter operating time and a smaller maintenance
current and operating current when the ambient temperature is relatively high.

The use of the thermistor is like a normal fuse, which is used in series in the
circuit. When the circuit is working normally, the temperature of the thermistor is

317
close to room temperature, and the resistance is very small. The series connection in
the circuit will not hinder the passage of current; and when the circuit has an
overcurrent due to a fault, the temperature rises due to the increase in heating power.
When the temperature exceeds the switching temperature, the resistance will increase
sharply in an instant, and the current in the loop will quickly decrease to a safe value.
After the thermistor operates, the current in the circuit has been greatly reduced. Due
to the design of good performance of the polymer ptc thermistor, it can adjust its
sensitivity to temperature by changing its own switching temperature (ts), so it can
play two roles of over-temperature protection and over-current protection at the same
time.

A thermistor is a type of resistor whose resistance varies significantly with


temperature, more so than in standard resistors. In this experiment we use an MF52
NTC-type thermistor, and it is usually used as a temperature sensor.

The key parameters of an MF52 thermistor:

B-parameter: 3470.

25℃ resistance: 10kΩ.

The relationship between the resistance of thermistor and temperature is as


follows:

: the resistance of the thermistor at temperature T1

: the nominal resistance of the thermistor at room temperature T2

: 2.718281828459

: one of the important parameters of thermistor

: the Kelvin temperature that you want to measure

: Under the condition of a 25 ℃ (298.15K) room temperature, the standard


resistance of MF52 thermistor is 10K;

Kelvin temperature = 273.15 (absolute temperature) + degrees Celsius;

318
After transforming the above equation, we can get the following formula:

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. Use 10K Ω resistor. As shown in the following
figure:

319
4.How to make digital thermometer

We provide two different methods to read the temperature of the thermistor.One


is to program on the Arduino UNO with C language through the Arduino IDE. You
need to master the C language; the other is to program on the Arduino UNO with the
graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

1.Using C language to program to read the temperature of the

thermistor on LCD1602 on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

320
2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_16_thermistor directory. Select_16_thermistor.ino. This file is the code
program we need in this course. Then click Open.

321
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, it will be observed that the LCD1602
screen displays the currently detected temperature. This shows that our experimental
test is successful. The physical connection diagram of the experiment is as below:

322
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to measure temperature on Arduino UNO.We will introduce how our
core code can be achieved:
1.First, initialize the LCD through lcd.init() in the setup() function.

2.In the loop() method, read the value of the thermistor through
analogRead(thermistorPin). After the arithmetic processing, display the temperature
measured by the thermistor on the LCD with the lcd.print(tempC) function.

323
2. Using graphical code blocks to program and measure

temperature on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

324
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

325
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

326
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

327
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

328
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_16_thermistor
It will show as below:

5. Select the "16_thermistor.gwblock" file. This file is the graphical code program for
our lesson. Click "Open" in the lower right corner.It will show as below:

329
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

330
8.Click the button on the upper right corner.After successfully running the program,

we will observe the current temperature detected on the LCD1602 screen. This shows
that our experimental test is successful. The physical connection of the experiment is
as below:

331
(3)Core code program
After the above hands-on operation, you must be very interested to know how we
program to read the temperature value of the thermistor on Arduino UNO with
graphical code blocks.We will introduce how our core code can be achieved:
In the GwBlock graphical editor, all code programs are executed from

.Initialize the LCD through the instruction .In the while loop,

the instruction block will store the read thermistor data to

variable a.After calculation, the thermistor data will be output to the LCD1602 screen

through the instruction block .

332
333
Lesson 17 The Application of IR Remoter Controller

In this lesson, we will learn how to use the IR Remoter Controller.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

IR Receiver HX1838 1

Remote Controller 1

Male to Female Jumper Wires 3

2. The introduction of receiver and remote controller


(1)IR receiver and IR Remoter Controller

IR Remoter Controller is mainly composed of infrared transmitter (infrared


remote controller) and IR receiver.
The IR receiver HX1838 can receive signals from an infrared (IR) remote
controller. It has only three pins: signal, VCC and GND. So it is simple to connect
with an Arduino board.

334
The following figure shows an IR remote controller:

(2) Working principle


The signal from the IR Remoter Controller is a series of binary pulse codes. In
order to protect it from the interference of other infrared signals during wireless
transmission, it is usually modulated on a specific carrier frequency before being
emitted through the infrared emitting diode, and the infrared receiving device must
filter out other clutter. In addition, the signal of this specific frequency is received and
restored to a binary pulse code.This process is demodulation.
The built-in receiver tube converts the light signal emitted by the infrared
emission tube into a weak electrical signal. This signal is amplified by the IC's
internal amplifier, and then restored to the remote control transmitter after automatic
gain control, band pass filtering, demodulation, and waveform shaping. The original
code is input to the code recognition circuit on the appliance via the signal output pin
of the receiving head. When the remote control button is pressed, the remote control
sends out an infrared carrier signal, and the infrared receiver receives the signal,and
the program decodes the carrier signal.We will judge which key is pressed by the
difference of the data code.
In this experiment, we program the Arduino board to receive the infrared signals,

335
and then send the received data to Serial Monitor. In the program, we use the
Arduino-IRremote-master library (provided).

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

336
4.How to use IR Remoter Controller

We provide two different methods to control the IR Remoter Controller.One is to


program on the Arduino UNO with C language through the Arduino IDE. You need to
master the C language; the other is to program on the Arduino UNO with the
graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

337
1.Using C language to program to control the IR Remoter

Controller on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_17_IRRemoterController directory. Select_17_IRRemoterController.ino. This
file is the code program we need in this course. Then click Open.

338
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we need to open the serial monitor on the
Arduino software. When we press the button on the infrared remote control, the serial
monitor will print out the corresponding number. How to open the serial monitor? You

need to click the "Serial Monitor" button in the upper right corner, as shown

below:

339
6. After clicking , the serial monitor window will pop up. At this time, you need to

press the button on the IR Remoter Controller, and the corresponding button number
will be printed out in the serial monitor window. As shown below:

7. The physical connection diagram of the experiment is as below:

340
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to control the IR Remoter Controller on Arduino UNO.We
will introduce how our core code can be achieved:
1. Open the serial port through Serial.begin(115200) in the setup() method, and
initialize the IR receiver with the irrecv.enableIRIn() function.
2. In the loop() function, use the switch_irr(results.value) function to decode the
signal value of the IR receiver, and the Serial.println(irrecv_data) function will print
the decoded value on the serial port. .

2. Using graphical code blocks to program and control the IR

341
Remoter Controller on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the
block_py.ino file (open with Arduino). [Note]: We need to modify #define MPU6050
1 in the opened block_py.ino file to #define MPU6050 0, and #define BUZZER 1 to

#define BUZZER 0.Then click and upload the program to the Arduino UNO.

After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

342
3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be
used later. It will show as below:

4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

343
6.Click the "Connecting device" button in the upper right corner. It will show as
below:

7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

344
8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

(2)Run the code program for this course


Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

345
2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_17_IRRemoterController
It will show as below:

5. Select the "17_IRRemoterController.gwblock" file. This file is the graphical code

346
program for our lesson. Click "Open" in the lower right corner.It will show as below:

6.Click OK.It will show as below:

7.It will show as below after successfully opening:

8.Click the button on the upper right corner.Open the window of GUI info v1.0.py.

If you don't press the button of the IR Remoter Controller, it will print out -1. If you

347
press the button on the IR Remoter Controller, it will print out the number of the
corresponding button. As shown below:

9. The physical connection of the experiment is as below:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to control the IR Remoter Controller on Arduino UNO with graphical code
blocks.We will introduce how our core code can be achieved:
In the GwBlock graphical editor, all code programs are executed from

.Initialize the IR receiver through the instruction .The

348
command block can read the signal value of the IR

receiver.Print the corresponding remote controller key value on the command window

through the instruction block .

349
Lesson 18 The Application of DHT-11(Digital
Temperature & Humidity Sensor)

In this lesson, we will learn the application of the DHT-11(Digital Temperature


& Humidity Sensor).

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

LCD1602 1

Adeept IIC Module 1

Male to Female Jumper Wires Several

Adeept DHT-11 Temperature 1

& Humidity Sensor

2. The introduction of the DHT-11

(1) DHT-11(Digital Temperature & Humidity Sensor)

DHT11 is a temperature and humidity sensor with calibrated digital signal output.
It can be used to measure humidity and temperature, its precision humidity +-5%RH,
temperature +-2℃, range humidity 20-90%RH, temperature 0~50℃. It uses special

350
digital module acquisition technology and temperature and humidity sensing
technology to ensure the product has high reliability and excellent long-term stability.
The sensor consists of a resistive moisture sensing element and an NTC temperature
measuring element, and is connected to a high-performance 8-bit MCU. Therefore,
this product has the advantages of excellent quality, meteoric response, strong
anti-interference ability and high cost performance. Each DHT11 sensor is calibrated
in a highly accurate humidity calibration chamber. Calibration coefficients are stored
in the OTP memory in the form of a program, and these calibration coefficients are
called by the sensor during the processing of the detection signal. Single-wire serial
interface makes system integration easy and fast. Its ultra-small size and very low
power consumption make it the best choice for this kind of applications in demanding
applications.
Notes:
(1) Avoid the use of condensation.
(2) Long-term storage conditions: temperature 10-40℃, humidity below 60%
(3)Measurement Range: 20-95%RH, 0-50℃

(4)Humidity Accuracy: ±5%RH

(5)Temperature Accuracy: ±2℃

(6)‘+’: VCC (3.3~5.5V)

(7)‘-’: GND (0V)

(8)‘S’: data pin

351
(2) The features of DHT-11(Digital Temperature & Humidity

Sensor)

DHT11 uses the single bus protocol, which transmits 40 bits of data at a time, i.e.,
40 bits of data. Every time the data of DHT11 is read, it should be read 40 times at a
time, i.e., read 40 bits. Data format : 40bit data = 8-bit humidity integer + 8-bit
humidity decimal + 8-bit temperature integer + 8-bit temperature decimal + 8-bit
calibration. The first 16 bits of data are related to humidity, the middle 16 bits are
related to temperature, and the last eight bits are used for calibration.

(3) Principle of reading data of DHT-11(Digital Temperature &

Humidity Sensor)

The DHT-11(Digital Temperature & Humidity Sensor) we use in this lesson only
has 3 pins, and the 3 pins are used as VCC (+), GND (-), and DATA (out), respectively.
Since only high and low levels are transmitted to Raspberry Pi GPIO, how can we

352
read the temperature and humidity Numbers? With fewer pins, it needs a sequence
signal of high and low variation to express the value, as well as other signals such as
the start signal and so on. Let's first understand the timing signal of DHT11:
(1) Data frame format
DHT11 will send 40 bits (5 bytes) of data to the host. The first and second bytes
of data represent the temperature value. 3,4 bytes of data represent the humidity value;
The fifth byte data is the check code: data format :40bit data =8 bit humidity integer
+8 bit humidity decimal +8 bit temperature integer +8 bit temperature decimal +8 bit
check. If the data is correct, the sum of the first four bytes equals the last checksum.

(2) Handshake stage


By default, the DATA (out) foot is at a high level, and the host GPIO sends the
start signal. First, pull down the DATA foot at least 18ms, and then pull up the DATA
foot 20-40us to wait for the DHT11 response signal. Once DHT11 receives the start
signal, DHT11 will send a response signal to the host, at the same time, pull the
DATA foot down 80us as the response, and then DHT11 will pull up the DATA foot
80us.Then it's done.

353
(3) Data transmission stage
For sending humidity and temperature data once, DHT11 needs to send 40bits of
data. Each bit of data starts with a 50us low level, followed by a high-level timing
signal. A continuous 26us-28us means that the bit is 0. A continuous 70us means that
the bit is 1, and then continues with a 50us low level, followed by a high level of the
next bit.
Data "0" :

Data "1" :

(4) Data reception and verification

354
The 40bit data is encoded as below:

In order to ensure the accuracy of the received data, it is necessary to verify the
data. If byte1+byte2+byte3+byte4 == byte0, the received data will be correct. But the
DHT11 decimal doesn't work, so you have to worry about byte2 plus byte4. After
successful verification, we will verify the correctness of data reading results of the
temperature and humidity.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

355
4.Read the temperature and humidity value of
DHT11 sensor

We provide two different methods to read the temperature and humidity value of
DHT11 sensor.One is to program on the Arduino UNO with C language through the
Arduino IDE. You need to master the C language; the other is to program on the
Arduino UNO with the graphical code block through GwBlock IDE.This method is
very suitable for beginners who have not mastered the advanced programming
languages C and C++. We will introduce these methods respectively.

1.Using C language to program to read the temperature and

humidity value of DHT11 sensor on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

356
2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_18_DHT11 directory. Select_18_DHT11.ino. This file is the code program we
need in this course. Then click Open.

357
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we will observe that the Humidity and
Temp values are detected by the DHT11 sensor on the LCD1602 screen, indicating
that our experimental test is successful. The physical connection diagram of the
experiment is as below:

358
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to read the temperature and humidity value of DHT11
sensor on Arduino UNO.We will introduce how our core code can be achieved:
1.In the setup() function, the LCD1602 is initialized by lcd.init(), and the LCD1602
backlight can be set by the lcd.backlight() function.

2.In the loop() function, read the DHT11 data through DHT11.read(DHT11PIN);
output the humidity (Humidity) and temperature (Temp) data on the LCD1602 screen
through the lcd.print() function.

359
2. Using graphical code blocks to program and read the

temperature and humidity value of DHT11 sensor on Arduino

UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

360
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

361
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

362
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

363
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

364
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_18_DHT11
It will show as below:

5. Select the "18_DHT11.gwblock" file. This file is the graphical code program for
our lesson. Click "Open" in the lower right corner.It will show as below:

365
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

366
8. After successfully running the program, we will observe that the Humidity and
Temp values are detected by the DHT11 sensor on the LCD1602 screen, indicating
that our experimental test is successful. The physical connection diagram of the
experiment is as below:

(3)Core code program

367
After the above hands-on operation, you must be very interested to know how we
program to read the temperature and humidity value of DHT11 sensor on Arduino
UNO with graphical code blocks.We will introduce how our core code can be
achieved:

In the GwBlock graphical editor, all code programs are executed from .The

temperature data of DHT11 is read by the instruction

block , and the humidity data is

read by the instruction block . Finally,

the data of temperature and humidity is displayed on the LCD1602 screen

through and instruction block.

368
Lesson 19 The Application of the Ultrasonic Distance
Sensor

In this lesson, we will learn the application of ultrasonic distance sensor.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

LCD1602 1

Adeept IIC Module 1

Male to Female Jumper Wires Several

Ultrasonic Distance Sensor 1

2. The application of the Ultrasonic Distance Sensor

(1) Ultrasonic Distance Sensor

The model of the ultrasonic distance sensor we use is hc-sr04, it is mainly


composed of two left and right probes, looking like our human eyes. One probe is

369
responsible for transmitting sound waves for detection, and the other probe is
responsible for receiving sound waves for return. It has 4 pins, which are VCC; Trig
(control end - trigger signal input); Echo (receiver - recovery signal output);
Gnd(ground).

(2) The working principle of the Ultrasonic Distance Sensor

The method of detecting distance of ultrasonic wave is called echo detection


method,which ultrasonic emitter emits to a certain direction, in the moment of timer
timing starts at the same time, the ultrasonic wave in air, run into obstacles on the way
your face (objects) block was reflected immediately, ultrasonic receiver received the
ultrasonic reflected back to immediately stop timing. The propagation speed of
ultrasonic wave in the air is 340m/s. According to the time t recorded by the timer, the
distance s from the launch point to the obstacle surface can be calculated, that is,
s=340t/2. Under this principle of ultrasound, ultrasonic ranging module is widely used
in practical applications, such as car reversing radar, uav, and intelligent car.

370
3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

371
4. The application of the Ultrasonic Distance Sensor

We provide two different methods to read the distance of the obstacle detected by

372
the ultrasonic distance sensor.One is to program on the Arduino UNO with C
language through the Arduino IDE. You need to master the C language; the other is to
program on the Arduino UNO with the graphical code block through GwBlock
IDE.This method is very suitable for beginners who have not mastered the advanced
programming languages C and C++. We will introduce these methods respectively.

1.Using C language to program to read the value of ultrasonic

distance sensor on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
directory:Code\_19_ultrasonicDistanceSensor .Select_19_ultrasonicDistanceSensor.in
o. This file is the code program we need in this course. Then click Open.

373
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we will observe the obstacle distance
detected by the ultrasonic sensor displayed on the LCD1602 screen, indicating that
our experimental test is successful. The physical connection diagram of the
experiment is as below:

374
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to read the distance of the obstacle detected by the
ultrasonic distance sensor on Arduino UNO.We will introduce how our core code can
be achieved:
1.In the setup() function, set pingPin to INPUT mode by pinMode(pingPin, INPUT),
and set trigPin to OUTPUT mode by pinMode(trigPin, OUTPUT).

2.In the loop() function, the text information is displayed on the LCD1602 screen
through the lcd.print() function, and we set the display content to be adeept distance.

375
3.The detection distance of the ultrasonic ranging sensor can be calculated through the
ping() function.

2.Using graphical code blocks to program to read the value of

ultrasonic distance sensor on Arduino UNO

(1)Connecting to GwBlock graphical editor

376
In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

377
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

378
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

379
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

380
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_19_ultrasonicDistanceSensor
It will show as below:

5. Select the "19_ultrasonicDistanceSensor.gwblock" file. This file is the graphical


code program for our lesson. Click "Open" in the lower right corner.It will show as
below:

381
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

382
8.Click the button on the upper right corner. After successfully running the

program, we will observe the obstacle distance detected by the ultrasonic sensor
displayed on the LCD1602 screen, indicating that our experimental test is successful.
The physical connection diagram of the experiment is as below:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to read the distance of the obstacle detected by the ultrasonic distance sensor
on Arduino UNO with graphical code blocks.We will introduce how our core code
can be achieved:
In the GwBlock graphical editor, all code programs are executed from

.Obtain the data of the ultrasonic ranging sensor through the instruction

block , and display the acquired data on

the LCD1602 screen through .

383
384
Lesson 20 Application of MPU6050

In this lesson, we will learn the application of MPU6050.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

IR Receiver HX1838 1

Male to Female Jumper Wires 4

2. The introduction of MPU6050

(1) MPU6050

The MPU6050 is an integrated 6-axis motion processing component. Compared


with the multi-component solution, it eliminates the problem of the difference
between the axes when combining the gyroscope and the accelerator, and reduces a
lot of packaging space. The MPU6050 integrates a gyroscope, acceleration sensor,
and temperature sensor. It can accept the input of an external 3-axis compass through
the I2C bus and provide 9-axis output. It can be used to obtain the current acceleration
component and angular velocity component of the device.

385
(2) Sensing range of MPU6050

The MPU-6050 uses three 16-bit ADCs for the gyroscope and accelerometer
respectively.It converts the measured analog quantity into an digital quantity which
can be outputted.In order to accurately track fast and slow movements, the
measurement range of the sensor is user-controllable. The gyro's measurement range
is ±250, ±500, ±1000, ±2000°/ SEC (DPS).The accelerometer's measurement range is
±2, ±4, ±8, and ±16g. Mpu-6050 can operate at different voltages.VDD power supply
voltage of 2.5v ±5%, 3.0v ±5% or 3.3v ±5%.VDDIO power supply 1.8v ±5%. for
logical interface.

2. Using graphical code blocks to program to read the value of

MPU6050 on Arduino UNO


(1)Connecting to GwBlock graphical editor
In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the
block_py.ino file (open with Arduino). [Note]: We need to modify #define MPU6050

0 in the opened block_py.ino file to #define MPU6050 1.Then click and upload

386
the program to the Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

387
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

388
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

389
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

390
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_20_MPU6050
It will show as below:

5. Select the "20_MPU6050.gwblock" file. This file is the graphical code program for
our lesson. Click "Open" in the lower right corner.It will show as below:

391
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

392
5. Click the button on the upper right corner.After successfully running the

program, we open the GUI info v1.0.py window.It will display the X, Y, Z axis values
of the detected MPU6050,indicating that our experimental test is successful.

9. The physical connection of the experiment is as below:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to read the value of MPU6050 on Arduino UNO with graphical code
blocks.We will introduce how our core code can be achieved:

393
In the GwBlock graphical editor, all code programs are executed from

.Initialize the MPU6050 sensor through . Obtain the X, Y,

and Z axis data of the MPU6050 through the instruction

block .Finally print out the X, Y, and Z data through the

instruction .

(3) Features of MPU6050

1. Digital output of 6-axis or 9-axis rotation matrix, quaternion (quaternion), Euler


angle format (EulerAngleforma) fusion calculation data.
2. 3-axis angular velocity sensor (gyroscope) with 131 LSBs/°/sec/sensitivity and
full-scale sensing range of ±250, ±500, ±1000 and ±2000°/sec.
3. Programmable control, and the range of program control is ±2g, ±4g, ±8g and ±16g
3-axis accelerator.
4. The sensitivity between the axis of the accelerator and the gyroscope can be
removed to reduce the influence of the setting and the drift of the sensor.
5. Digital Motion Processing (DMP: Digital Motion Processing) engine can reduce
the load of complex fusion calculation data, sensor synchronization, posture sensing,

394
etc. The motion processing database supports the built-in operation time deviation and
magnetic sensor calibration calculation technology of Android, Linux and Windows,
eliminating the need for customers to perform additional calibration.
6. Temperature sensor with digital output.
7. Syncpin with digital input supports video electronic video stabilization technology
and GPS.
8. Programmable interrupt (interrupt) supports gesture recognition, panning, zooming
in and out of the screen, scrolling, rapid descent interruption, high-G interruption,
zero motion sensing, touch sensing, and shaking sensing functions.
9. VDD power supply voltage of 2.5V±5%, 3.0V±5%, 3.3V±5%; VDDIO is
1.8V±5%.
10. Gyroscope operating current: 5mA; gyroscope standby current: 5uA; accelerator
operating current: 500uA; accelerator power saving mode current: 40uA@10Hz.
11. I2C in fast mode up to 400kHz, or SPI serial host interface up to 20MHz.
12. The built-in oscillator only has a frequency change of ±1% within the operating
temperature range. Optional external clock input 32.768kHz or 19.2MHz.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

395
396
4. Application of MPU6050

We provide two different methods to read the value of MPU6050.One is to


program on the Arduino UNO with C language through the Arduino IDE. You need to
master the C language; the other is to program on the Arduino UNO with the
graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

1.Using C language to program to read the value of MPU6050 on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
397
Code\_20_MPU6050 directory. Select_20_MPU6050.ino. This file is the code
program we need in this course. Then click Open.

4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we need to open the serial monitor on the
Arduino software. When we press the swing MPU6050 sensor, the serial monitor will
print out the corresponding X, Y, and Z axis values. How to open the serial monitor?

You need to click the "Serial Monitor" button in the upper right corner, as shown

below:

398
6. After clicking, the serial monitor window will pop up, as shown below:

7. The physical connection diagram of the experiment is as below:

399
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to read the value of MPU6050 on Arduino UNO.We will
introduce how our core code can be achieved:
1.In the setup() function, the six-axis original value is read by the getMotion6()
function in the loop statement, and the accelerometer shift amount axo and gyroscope
shift amount gxo are calculated.

400
2.In the loop() function, print the angular acceleration values of agx, agy, agz through
count6Axle().

2. Using graphical code blocks to program to read the value of

MPU6050 on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the
block_py.ino file (open with Arduino). [Note]: We need to modify #define MPU6050

0 in the opened block_py.ino file to #define MPU6050 1, Then click and upload

401
the program to the Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

402
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

403
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

404
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

405
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_20_MPU6050
It will show as below:

5. Select the "20_MPU6050.gwblock" file. This file is the graphical code program for
our lesson. Click "Open" in the lower right corner.It will show as below:

406
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

407
8. Click the button on the upper right corner.After successfully running the

program, open the window of GUI info v1.0.py. It will display the X, Y, Z axis values
of the detected MPU6050, indicating that our experimental test is successful.

9. The physical connection diagram of the experiment is as follows:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to read the value of MPU6050 on Arduino UNO with graphical code
blocks.We will introduce how our core code can be achieved:

408
In the GwBlock graphical editor, all code programs are executed

from .Initialized MPU6050 through .Obtain the X, Y, and

Z axis data of the MPU6050 through the instruction block .Finally

print out the X, Y, and Z data through the instruction .

409
Lesson 21 The Application of the 4*4 Matrix
Keyboard

In this lesson, we will learn about the application of the 4*4 Matrix Keyboard.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

4*4 Matrix Keyboard 1

2. The introduction of 4*4 matrix keyboard

(1) The 4*4 Matrix Keyboard

The 4x4 matrix keyboard is a keyboard set arranged in a matrix used in Arduino
external devices. In a 4*4 matrix keyboard, each horizontal and vertical line is not
connected directly at the intersection, but is connected by a single key. In this way, a
port (such as port P1) can form 4*4=16 keys, which is twice as much as using port
line for keyboard directly. Moreover, the more lines, the more obvious the difference
is. For example, one more line can form a 20-key keyboard, while using port line can
only create one more key (9 keys). Thus it can be seen that it is reasonable to use the
matrix method to make the keyboard when the number of keys needed is large.

410
(2) The working principle of the 4*4 Matrix Keyboard

The keys are arranged at the intersection of the row and column lines, and the
row and column lines are connected to both ends of the key switch respectively. When
the key is not pressed, all input terminals are high level, which means no key is
pressed. The line output is low level. Once a key is pressed, the input line will be
pulled down. In this way, you can know whether a key is pressed by reading the state
of the input line. The line is connected to the +5V power supply through a pull-up
resistor.
A "line scan method" is used to determine which key on the matrix keyboard is
pressed
Step 1: make the line the input line of programming and the column line the
output line, pull down all the column lines, and judge the change of the line. If there is
a key pressed, the corresponding line pressed will be pulled down, otherwise all the

411
line lines will be at high level.
Step 2:after the first step is judged to have a key pressed, the mechanical jitter
will be eliminated after a delay of 10ms, and the row value will be read again. If the
line is still at a low level, the next step will be entered; otherwise, the first step will be
returned to re-judge.
Step 3: start scanning the position of the key, and use line by line scanning.
Every 1ms interval, pull down the first column, the second column, the third column
and the fourth column respectively. No matter which column you lower, the other
three columns are at high level. Read the row value to find the location of the key and
store the row and column values in it.
Step 4:find the row value and the column value from the register and combine
them to get the key value, which is coded from the first row to the fourth row from the
first row to the fourth row, from "0000" to "1111", and then display Decode. Finally,
the key number is displayed. Principle of dynamic scanning of digital tube: the 7
segments and the decimal point of the digital tube are all composed of LED blocks,
and the display mode is divided into static display and dynamic display. When the
digital tube is displayed in static mode, the bit selection signals of its total positive
tube are all low level, and the common segment selection lines of the four digital
tubes a, b, c, d, e, f, g and dp are respectively connected with the 8 I/O port lines of
CPLD. When the digital tube is displayed, only the low level should be sent to the
corresponding segment selection line. Dynamic display of digital tube in the way,
there can be only one at a time to light the digital tube display digital, the rest is in a
state of the gate, a selected code port signal changes, port signal segment code also
should make corresponding change. The stay time of each Character is usually 1-5 ms,
using visual inertia, one eye can see fairly stable on the digital tube digital display.

412
3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. Use 220 Ω resistor. As shown in the following
figure:

413
4.The Application of the 4*4 Matrix Keyboard

We provide two different methods to read the value of 4*4 matrix keyboard. One

414
is to program on the Arduino UNO with C language through the Arduino IDE. You
need to master the C language; the other is to program on the Arduino UNO with the
graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

1.Using C language to program to read the value of 4*4 matrix

keyboard on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_21_4x4MatrixKeyboard directory. Select21_4x4MatrixKeyboard.ino. This file
is the code program we need in this course. Then click Open.

415
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we need to open the serial monitor on the
Arduino software. When we press the number on the 4x4 matrix button module, the
serial monitor will print the corresponding value. How to open the serial monitor?

You need to click the "Serial Monitor" in the upper right corner, as shown below:

416
6. After clicking , the serial monitor window will pop up.Press the number on the

4x4 matrix button module, the serial monitor will print out the corresponding
value.As shown below:

7. The physical connection diagram of the experiment is as follows:

417
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to read the value of 4*4 matrix keyboard on Arduino
UNO.We will introduce how our core code can be achieved:
1.In the setup() function, open the serial port with Serial.begin(115200).

2.In the loop() function, read the key value of the 4x4 matrix key via
customKeypad.getKey().Output the key value on the serial port with
Serial.println(customKey).

418
2. Programming to read the value of 4*4 matrix keyboard on

Arduino UNO with graphical code blocks

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the
block_py.ino file (open with Arduino). [Note]: We need to modify #define KEY4x4

0 in the opened block_py.ino file to #define KEY4x4 1.Then click and upload

the program to the Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.It will show as

419
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

420
6.Click the "Connecting device" button in the upper right corner. It will show as
below:

7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

421
8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

(2)Run the code program for this course


Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

422
2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_21_4x4MatrixKeyboard
It will show as below:

5. Select the "21_4x4MatrixKeyboard.gwblock" file. This file is the graphical code

423
program for our lesson. Click "Open" in the lower right corner.It will show as below:

6.Click OK.It will show as below:

7.It will show as below after successfully opening:

8. Click the button on the upper right corner.Open the GUI info v1.0.py window.

When you press the key numbers on the 4x4 matrix keyboard, you will find that the

424
corresponding key values will also be displayed on the window, indicating that our
experimental test is successful.

9. The physical connection diagram of the experiment is as follows:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to read the value of 4*4 matrix keyboard on Arduino UNO with graphical
code blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .Get

425
the key value of the 4x4 matrix keyboard through the

instruction .Print out the key value

with .

426
Lesson 22 Controlling the DC Motor

In this lesson, we will learn how to control the DC Motor.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Adeept DC Motor Module 1

Male to Female Jumper Wires 4

2. The introduction of the DC Motor

(1) The DC Motor

A DC motor is a motor that converts DC electrical energy into mechanical energy.


Because of its good speed regulation performance, it is widely used in electric towing.
DC motors are divided into three categories: permanent magnet, other excitation, and
self-excitation according to the excitation mode. Self-excitation is divided into three
types: parallel excitation, series excitation, and compound excitation.
When DC power is supplied to the armature winding through the brush, the
N-pole conductor on the surface of the armature can flow current in the same
direction. According to the left-hand rule, the conductor will be subjected to

427
counterclockwise torque; a part of the conductor under the S pole of the armature
surface also flow current in the same direction, and the conductor will also be
subjected to a counterclockwise moment according to the left-hand rule. In this way,
the entire armature winding, that is, the rotor will rotate counterclockwise, and the
input DC energy is converted into mechanical energy output on the rotor shaft. It is
composed of stator and rotor, stator: base, main magnetic pole, commutation pole, and
brush device, etc. rotor (armature): armature core, armature winding, commutator,
rotating shaft and fan, etc.

(2)Working principle of the DC Motor

1. The DC power current flows along the positive pole of the power supply to the
left brush. The brush and the commutator rub against each other. The current flows
into the coil through the left commutator, flows out from the right side of the coil, and
passes through the right commutator And the brush on the right flows back to the
negative pole of the power supply, forming a closed loop.
2. Because the coil is in the magnetic field of the main magnetic pole, the coil
will be subjected to the electromagnetic force. The two sides of the coil have different
current directions (the current on the left flows inward and the right flows outward).
Electromagnetic forces of the same magnitude and opposite directions, these two
electromagnetic forces just form an electromagnetic torque. Under the pulling of the
electromagnetic torque, the coil starts to rotate. In the DC motor, the coil is embedded
428
in the rotor slot, and the motor starts to rotate.
3. The left and right commutator segments follow the shaft, and the brush is
stationary. After one turn, the right coil reaches the left and the left coil reaches the
right, but due to the presence of the commutator, it is now in the left coil The direction
of the current flows in the same direction as the current changed by the coil on the left,
so the direction of the electromagnetic force received does not change, and the same
is true on the right. Therefore, from the perspective of space, the direction of the
electromagnetic force received by the coil at the same position is always the same,
which ensures the cyclic rotation of the motor.
4. But for a coil, because the magnetic field is different when the coil is turned to
different positions, the electromagnetic force received by the coil is also constantly
changing, so the coil turns unstable, suddenly and slowly. Therefore, you can install
more coils to ensure that the coils are evenly and stably stressed.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following

429
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

4. Controlling MPU6050

We provide two different methods to control the DC motor.One is to program on


the Arduino UNO with C language through the Arduino IDE. You need to master the
C language; the other is to program on the Arduino UNO with the graphical code
430
block through GwBlock IDE.This method is very suitable for beginners who have not
mastered the advanced programming languages C and C++. We will introduce these
methods respectively.

1.Using C language to program to control DC Motor on Arduino

UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_22_motor directory. Select_22_motor.ino. This file is the code program we
need in this course. Then click Open.

431
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, the DC motor will turn up, indicating that
our course experiment is successful. The physical connection diagram of the
experiment is as follows:

432
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to control the DC motor on Arduino UNO.We will
introduce how our core code can be achieved:
1.In the setup() function, set motorIn1 and motorIn2 to OUTPUT mode with
pinMode() respectively. The clockwise (200) function can control the DC motor to
rotate at a speed of 200.

2.The clockwise() function can control the DC motor to rotate at a specific


speed.

433
2.Using graphical code blocks to program to control the DC

Motor on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the

434
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

435
6.Click the "Connecting device" button in the upper right corner. It will show as
below:

7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

436
8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

(2)Run the code program for this course


Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

437
2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_22_motor
It will show as below:

5. Select the "22_motor.gwblock" file. This file is the graphical code program for our

438
lesson. Click "Open" in the lower right corner.It will show as below:

6.Click OK.It will show as below:

7.It will show as below after successfully opening:

8. Click the button on the upper right corner.After successfully running the

program, the DC motor will rotate, indicating that our experimental test is successful.

439
The physical connection diagram of the experiment is as follows:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to control the DCmotor on Arduino UNO with graphical code blocks.We will
introduce how our core code can be achieved:
In the GwBlock graphical editor, all code programs are executed

from .Control the DC motor to rotate at a speed of 200 with the command

block .

440
Lesson 23 The Application of the PS2 Joystick
Module

In this lesson, we will learn the application of PS2 Joystick Module.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

LCD1602 1

Adeept IIC Module 1

Male to Female Jumper Wires Several

Adeept PS2 Joystick Module 1

2. The introduction of PS2 Joystick Module

(1)PS2 Joystick Module

The PS2 joystick module is an input device consisting of a joystick that can
rotate on the base and report its angle or direction to the device it controls. Joysticks
are commonly used to control video games and robots. We use the joystick PS2. It
consists of two sliding rheostats and a button. When the rocker is turned, the
resistance of the sliding rheostat will change, and the corresponding X/Y voltage

441
value will also change. If you press the rocker hard, the button will be triggered.
When pressed, the corresponding SW signal will go low.

(2)Working principle of the PS2 Joystick Module

The PS2 joystick module consists of two sliding rheostats and a button. When
the joystick is turned, the resistance of the sliding rheostat changes, and the
corresponding X/Y voltage value also changes. If you press the joystick, the button
will be pressed and the corresponding SW signal goes low. This module uses 5V
power supply. In the original state, the voltage read by X and Y is about 2.5V. When
pressed in the direction of the arrow, the voltage value increases with the maximum
value of 5V; when pressed in the opposite direction of the arrow, the voltage value is
reduced to a minimum of 0V.
The PS2 joystick module has two analog outputs and one digital output interface.
The output values correspond to the (X, Y) dual-axis offsets. The type is analog; the
key indicates whether the user presses on the Z axis. It is a digital switch. The

442
integrated power indicator of the module can display the working status; the
coordinate identifier is clear, concise and accurate positioning. In order to more easily
cooperate with standard interfaces such as expansion boards, the X and Y axis circuits
are led separately in the design to control the input of the joystick module's X, Y
values and to achieve a certain function under a specific value.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

443
4. Reading the value of PS2 Joystick Module

We provide two different methods to read the value of PS2 Joystick Module.One
is to program on the Arduino UNO with C language through the Arduino IDE. You
need to master the C language; the other is to program on the Arduino UNO with the
graphical code block through GwBlock IDE.This method is very suitable for

444
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

1.Using C language to program to read the value of PS2 Joystick

Module on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_23_joyStick directory. Select_23_joyStick.ino. This file is the code program
we need in this course. Then click Open.

445
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, you can toggle the PS2 joystick, and the
corresponding coordinate value on the LCD1602 screen will also change. The
physical connection diagram of the experiment is as follows:

446
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to read the value of PS2 Joystick Module on Arduino
UNO.We will introduce how our core code can be achieved:
1.In the setup() function, set JoyStick_Z to INPUT_PULLUP mode with
pinMode(JoyStick_Z, INPUT_PULLUP).

2.In the loop() function, read the X, Y, Z axis data on the PS2 joystick with the
analogRead() function. Display the X, Y, Z axis data on the LCD1602 screen with
lcd.print().

447
2.Using graphical code blocks to program to read the value of

PS2 Joystick Module on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

448
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

449
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

450
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

451
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

452
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_23_joyStick
It will show as below:

5. Select the "23_joyStick.gwblock" file. This file is the graphical code program for
our lesson. Click "Open" in the lower right corner.It will show as below:

453
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

454
8. Click the button on the upper right corner.After successfully running the

program, you can toggle the PS2 joystick, and the corresponding coordinate values on
the LCD1602 screen will also change. The physical connection diagram of the
experiment is as follows:

455
(3)Core code program
After the above hands-on operation, you must be very interested to know how we
program to read the value of PS2 Joystick Module on Arduino UNO with graphical
code blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .Use

the instruction to initialize the LCD1602. Read the X and Y axis values

with the instruction

block and . Then use

the and instructions to display the X and Y axis


data.

456
Lesson 24 Controlling LED with Tilt Switch

In this lesson, we will learn how to use tilt switch to control LED.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 1

LED 1

Tilt Switch 1

2.The introduction of tilt switch

(1)tilt switch

The tilt switch is also called a ball switch, which controls the connection or
connection of the circuit with the principle of the ball rolling contact with the guide
pin.The tilt switch is also called the ball switch. When the switch is tilted in the
appropriate direction, the contacts will be connected, tilting the switch the opposite
direction causes the metallic ball to move away from that set of contacts, thus
breaking that circuit.

457
(2)Working principle of tilt switch

The tilt switch is also called a ball switch, which controls the connection or
disconnection of the circuit by the principle that the ball rolls on the guide pin.The tilt
switch is also called the ball switch. When the switch is tilted in the appropriate
direction, the contacts will be connected, tilting the switch the opposite direction
causes the metallic ball to move away from that set of contacts, thus breaking that
circuit.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

458
4. Controlling LED with tilt switch

We provide two different methods to control LED with tilt switch.One is to


program on the Arduino UNO with C language through the Arduino IDE. You need to

459
master the C language; the other is to program on the Arduino UNO with the
graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

1.Using C language to program to control LED with tilt switch

on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_24_tiltSwitch directory. Select24_tiltSwitch.ino. This file is the code program
we need in this course. Then click Open.

460
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, you can tilt or tap the tilt switch with your
hand, and the LED will be on. The physical connection diagram of the experiment is
as follows:

461
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to control LED with tilt switch on Arduino UNO.We will
introduce how our core code can be achieved:
1.In the setup() function, set ledpin to OUTPUT mode with pinMode(ledpin,
OUTPUT); pinMode(tiltSwitchpin, INPUT_PULLUP) sets tiltSwitchpin to
INPUT_PULLUP mode.

2.In the loop() function, determine if the tilt switch is turned off by if(val==LOW). If
the tilt switch is turned off, then we turn off the LED with digitalWrite(ledpin, LOW);
if the tilt switch is closed, then we use digitalWrite( ledpin, HIGH) to turn on the
LED.

462
2.Using graphical code blocks to program to control LED with

tilt switch on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

463
3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be
used later. It will show as below:

4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

464
6.Click the "Connecting device" button in the upper right corner. It will show as
below:

7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

465
8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

(2)Run the code program for this course


Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

466
2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_24_tiltSwitch
It will show as below:

5. Select the "24_tiltSwitch.gwblock" file. This file is the graphical code program for

467
our lesson. Click "Open" in the lower right corner.It will show as below:

6.Click OK.It will show as below:

7.It will show as below after successfully opening:

468
8. Click the button on the upper right corner.After successfully running the

program, you can tilt or tap the tilt switch with your hand, and the LED will be on.
The physical connection diagram of the experiment is as follows:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to control LED with tilt switch on Arduino UNO with graphical code
blocks.We will introduce how our core code can be achieved:

469
In the GwBlock graphical editor, all code programs are executed from .Read

the state value of the tilt switch with the instruction

block .The instruction block will

judge the state value of a. When the state value equal to 0, it means that the tilt switch
is in the off state, and then turn off the LED with the instruction

block ; when the state value of a is not equal to 0,


it means that the tilt switch is closed, and the LED is turned on with the command

block .

470
Lesson 25 The Application of the 8*8 Dot-matrix
Module

In this lesson, we will learn the application of the 8*8 Dot-matrix Module.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

LCD1602 1

Adeept IIC Module 1

Male to Female Jumper Wires Several

Adeept Dot-matrix Display 1

Module

2. The introduction of the 8*8 Dot-matrix Module

(1)The 8*8 Dot-matrix Module

Our course uses an 8x8 dot matrix display module, which is composed of 64
light-emitting diodes, and each light-emitting diode is placed at the intersection of
row and column lines.Using the progressive scan method, when the scanning speed is
accelerated, for the persistence of vision, we will see the 8-line display.

471
(2)Working principle of the 8*8 Dot-matrix Module

8x8 dot matrix display module can be divided into two types: common anode
and common cathode according to different internal structures.
Common cathode: when a corresponding row is set to 1 level and a column is set
to 0 level, the corresponding diode is on; if the first point is to be lit, pin 1 (bit
selection signal) is connected to high Connect pin a (segment selection signal) to low
level, then the first point will be on.
Common anode: when a corresponding row is set to 0 level and a column is set
to 1 level, the corresponding diode will be on; if the first point is to be lit, pin 1 is
connected to low level and pin a High level, then the first point is on, the common
anode circuit is used in this experiment, so the bit selection signal is low when the
code is written, the segment selection signal is high, and the segment selection bit The
character selection is displayed in an array, from top to bottom for display from status
to high. The internal structure is as follows: the left is a common cathode, the right is
a common anode.

472
3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

473
4. The Application of the 8*8 Dot-matrix Module

We provide two different methods to display character on 8*8 dot-matrix


module.One is to program on the Arduino UNO with C language through the Arduino
IDE. You need to master the C language; the other is to program on the Arduino UNO
with the graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

1.Using C language to program to display character on 8*8

dot-matrix module on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

474
2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_25_ledMatrix directory. Select_25_ledMatrixk.ino. This file is the code
program we need in this course. Then click Open.

475
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we observe that the dot-matrix module will
display A, d, e, e, p, t in sequence. The physical connection diagram of the experiment
is as follows:

476
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to display character on 8*8 dot-matrix module on Arduino
UNO.We will introduce how our core code can be achieved:
1.Define the text you need to display in the array data[]: Adeept

2.In the loop () function, it is used to loop traversal through the indicator lights on the
8x8 dot matrix display module. If any indicator light is received, it is lit by
digitalWrite (latchPin, HIGH) and digitalWrite (latchPin, LOW).

477
2.Using graphical code blocks to program to display character

on 8*8 dot-matrix module on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

478
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

479
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

480
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

481
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

482
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_25_ledMatrixk
It will show as below:

5. Select the "25_ledMatrixk.gwblock" file. This file is the graphical code program for
our lesson. Click "Open" in the lower right corner.It will show as below:

483
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

484
8. Click the button on the upper right corner.After successfully running the

program, you can observe that the corresponding pattern will be displayed on the 8*8
dot-matrix module. The physical connection diagram of the experiment is as follows:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to display character on 8*8 dot-matrix module on Arduino UNO with
graphical code blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .You

can use the command block to control the display pattern of the 8*8
dot-matrix module.Initialize the data ports 12, 8, and 11 connected to the Arduino

UNO with the command block . In the

command block , you can display the picture you want by ticking the
led.

485
486
Lesson 26 Controlling the Stepper Motor

In this lesson, we will learn how to control the Stepper Motor.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

ULN2003-based Stepper 1

Motor Driver

Stepper Motor 1

2. The introduction of the Stepper Motor

(1)Stepper Motor

A stepper motor is a motor that converts electrical pulse signals into


corresponding angular or linear displacements. Each time a pulse signal is input, the
rotor rotates by an angle or a step forward. The output angular displacement or linear
displacement is proportional to the number of pulses input, and the rotation speed is
proportional to the pulse frequency. Therefore, stepper motors are also called pulse
motors. There are two types of steppers, unipolar and bipolar. It is important to know
which type to use. In this lesson, we will use a unipolar stepper type stepper motor.

487
(2) Working principle of the Stepper Motor

Stepper motor is also known as pulse motor, based on the most basic
electromagnet principle, it is a kind of free rotation electromagnet, its operation
principle is to rely on the change of air gap permeability to generate electromagnetic
torque. The stepper's axis is controlled by a series of solenoid coils that are charged
positively and negatively in a particular order to move it precisely forward or
backward at a small "step size." The advantage of a stepper motor is that it can be
precisely positioned, turn "one step" forward or backward, and turn continuously. The
biggest difference between stepping motor and other control motors is that it receives
digital control signals (electrical impulse signals) and converts them into
corresponding angular displacement or linear displacements. It is an executive
element to complete the transformation of digital mode. And it can be open loop
position control, input a pulse signal to get a specified position increment, such a
so-called incremental position control system compared with the traditional dc control system,
its cost is significantly reduced, almost no system adjustment. The angular displacement of

the stepper motor is strictly proportional to the number of input pulses and
synchronizes with the pulses in time. Therefore, as long as the number of pulses,
frequency and phase sequence of motor windings are controlled, the desired Angle,
speed and direction can be obtained.

(3) Stepper Motor Driver Module (Based on ULN2003A)

488
Due to low current, Arduino UNO development board's digital port is unable to
drive the stepping motor directly. Therefore, a driving circuit must be used to control
the stepper motor. The driver module based on ULN2003 is used in this lesson. There
are four LEDS on the module. The white socket in the middle is used to connect the
stepper motor. IN1, IN2, IN3, IN4 are used to connect with Arduino UNO
development board's digital port.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

489
4. How to control the Stepper Motor

We provide two different methods to control the stepper motor.One is to program


on the Arduino UNO with C language through the Arduino IDE. You need to master
the C language; the other is to program on the Arduino UNO with the graphical code
block through GwBlock IDE.This method is very suitable for beginners who have not
mastered the advanced programming languages C and C++. We will introduce these
methods respectively.

490
1.Using C language to program to control the Stepper Motor on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_26_steppermotor directory. Select_26_steppermotor.ino. This file is the code
program we need in this course. Then click Open.

491
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, you will observe that the stepper motor
will rotate. The physical connection diagram of the experiment is as follows:

492
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to control the stepper motor on Arduino UNO.We will
introduce how our core code can be achieved:
In the setup() function, set Pin0, Pin1, Pin2, and Pin3 to OUTPUT mode with the
pinMode() function. Then the Speed (15) is used to control the stepper motor to rotate
at a stepping speed of 15.And the stepper motor can be set to rotate 1024 degrees by
Step (1024).360 degrees is a circle.

2.Using graphical code blocks to program tocontrol the stepper

motor on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
493
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

494
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

495
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

496
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

497
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_26_steppermotor
It will show as below:

5. Select the "26_steppermotor.gwblock" file. This file is the graphical code program
for our lesson. Click "Open" in the lower right corner.It will show as below:

498
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

8. Click the button on the upper right corner.After running the program

successfully, you will observe that the stepper motor will rotate. The physical
connection diagram of the experiment is as follows:

499
(3)Core code program
After the above hands-on operation, you must be very interested to know how we
program to control the stepper motor on Arduino UNO with graphical code blocks.We
will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .The

instruction block can directly control the

stepper motor to rotate 1024 degrees at a step speed of 15. 360 degrees is a circle.

500
Lesson 27 Using Photoresistor to Measuring Light
intensity

In this lesson, we will learn how to use Photoresistor to measure light intensity.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

LCD1602 1

Adeept IIC Module 1

Male to Female Jumper Wires Several

Resistor(1KΩ) 1

Photoresistor 1

2. The introduction of the Photoresistance

(1)Photoresistance

Photovaristor (photovaristor), also known as photoresistor, is a kind of resistor


made by using the photoelectric effect of semiconductor to change the resistance
value with the intensity of incident light;If the incident light is strong, the resistance
decreases, and if the incident light is weak, the resistance increases. Photoresistors are

501
generally used for light measurement, light control, and photoelectric conversion
(converting changes in light into changes in electricity).
Photoresistors can be widely used in various light control circuits, such as the
control and adjustment of lights, and can also be used in light control switches.
In dark, dark conditions, the resistance of the photoresistor is very high. The
stronger the light, the smaller the resistance value. By measuring the voltage change
value on both sides of the photoresistor, the change of the photoresistor value can be
known and the light intensity value can be obtained. In the connection diagram, we
can find a voltage divider connected in series with the photoresistor.

In the above figure, RL is the photoresistor, R1 is the voltage-dividing resistor in


series, Vout=RLR1+RL∗ VinVout=RLR1+RL∗ Vin, in the dark, the resistance of RL
will be very large, so Vout will be very Large, close to 5V. Once the light is irradiated,
the value of RL will decrease rapidly, so Vout will decrease accordingly. It can be seen
from the above formula that R1 should not be too small, preferably around 1k~10k,
otherwise the ratio will not change significantly.
(2) Experimental principle

In this experiment, we first conduct a relatively simple experiment of using a


photoresistor. Since the photoresistor is a component that can change the resistance
value according to the light intensity, naturally the analog port is also required to read
the analog value. In this experiment, the PWM interface experiment can be used to

502
replace the potentiometer with a photoresistor to realize the LED light when the light
intensity is different. The brightness will also change accordingly.

A photoresistor is a light-controlled variable resistor. The resistance of a


photoresistor decreases with the increasing incident light intensity; in other words, it
exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector
circuits.

A photoresistor is made of a high resistance semiconductor. In the dark, a


photoresistor can have a resistance as high as a few megohms (MΩ), while in the light,
a photoresistor can have a resistance as low as a few hundred ohms. If incident light
on a photoresistor exceeds a certain frequency, photons absorbed by the
semiconductor give bound electrons enough energy to jump into the conduction band.
The resulting free electrons (and their hole partners) conduct electricity, thereby
lowering resistance. The resistance range and sensitivity of a photoresistor can
substantially differ among dissimilar devices. Moreover, unique photoresistors may
react substantially differently to photons within certain wavelength bands.

The schematic diagram of this experiment is shown below:

With the increase of the light intensity, the resistance of photoresistor will be
decreased. The voltage of GPIO port in the above figure will become high.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. The resistance is 1K Ω .As shown in the following
figure:

503
4.Using photoresistor to measure light intensity

We provide two different methods to obtain the light intensity.One is to program


on the Arduino UNO with C language through the Arduino IDE. You need to master
the C language; the other is to program on the Arduino UNO with the graphical code
block through GwBlock IDE.This method is very suitable for beginners who have not

504
mastered the advanced programming languages C and C++. We will introduce these
methods respectively.

1.Using C language to program to use Photoresistor to measure

light intensity on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_27_photoresistanc directory. Select_27_photoresistance.ino. This file is the
code program we need in this course. Then click Open.

505
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After running the program successfully, you will observe that the detected light
intensity displays on the LCD1602 screen. The physical connection diagram of the
experiment is as follows:

506
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to use Photoresistor to measure light intensity on Arduino
UNO.We will introduce how our core code can be achieved:
1.In the setup() function, displayed "Adeept test" on the LCD1602 screen with the
lcd.print(array1[positionCounter1]) function in the for loop statement, .

2.In the loop() function, display the data DATA of the photoresistor on the LCD1602
screen by calculating with the lcd.print(array2[positionCounter3]) function in the for
loop statement.

507
2.Using graphical code blocks to program to use Photoresistor to

measure light intensity on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

508
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

509
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

510
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

511
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

512
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_27_photoresistance
It will show as below:

5. Select the "27_photoresistance.gwblock" file. This file is the graphical code


program for our lesson. Click "Open" in the lower right corner.It will show as below:

513
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

514
8. Click the button on the upper right corner.After successfully running the

program, you will observe that the light intensity detected by the photoresistor will be
displayed on the LCD1602 screen. The physical connection diagram of the
experiment is as follows:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to use Photoresistor to measure light intensity on Arduino UNO with
graphical code blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .Read

the photoresistor data with the instruction

block .Display the photoresistor data on the LCD1602

screen with .

515
516
Lesson 28 Making Light Tracking System

In this lesson, we will learn how to use photoresistance and servo motor to
make light tracking system.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

LCD1602 1

Adeept IIC Module 1

Male to Female Jumper Wires Several

Resistor(1KΩ) 1

Photoresistor 1

AD002 Servo 1

2.Photoresistance and servo motor

(1)photoresistance

Please refer to Lesson 27, for we have introduced the Photoresistance in detail in
Lesson 27.

517
(2)servo motor

Please refer to Lesson 15, for we have introduced the servo motor in detail in
Lesson 15.

(3)Experimental principle

In this experiment, we need to fasten the photoresistor with the horn of servo.
First, we control the servo with a photoresistor to rotate from 0° to 180° to record the
intensity of illumination, and then the photoresistor will stop at the brightest position.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

518
4. How to make light tracking system.

We provide two different methods to use photoresistance and servo motor to


make light tracking system.One is to program on the Arduino UNO with C language
through the Arduino IDE. You need to master the C language; the other is to program
on the Arduino UNO with the graphical code block through GwBlock IDE.This
method is very suitable for beginners who have not mastered the advanced
programming languages C and C++. We will introduce these methods respectively.

1.Using C language to program to make light tracking system on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

519
2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_28_automatically_tracking_light_source directory.
Select_28_automatically_tracking_light_source.ino. This file is the code program we
need in this course. Then click Open.

520
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, you will observe that the servo motor will
rotate. If you change the light intensity, for example, you can cover the photoresistor
with a black cloth to see if the servo motor will rotate. The physical connection
diagram of the experiment is as follows:

521
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to use photoresistance and servo motor to make light
tracking system on Arduino UNO.We will introduce how our core code can be
achieved:
1.In the setup() function, bind the digital port 9 on the Arduino UNO by the
myservo.attach(9) function.

2.In the loop() function, read the data of the photoresistor by


analogRead(photocellPin), and then control the rotation of the servo motor by the
myservo.write(outputValue) function.

522
2. Using graphical code blocks to program to make light

tracking system on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

523
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

524
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

525
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

526
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

527
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_28_automatically_tracking_light
_source
It will show as below:

5. Select the "28_automatically_tracking_light_source.gwblock" file. This file is the


graphical code program for our lesson. Click "Open" in the lower right corner.It will
show as below:

528
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

8. Click the button on the upper right corner.After successfully running the

program, you will find that the servo motor will rotate. The physical connection
diagram of the experiment is as follows:

529
(3)Core code program
After the above hands-on operation, you must be very interested to know how we
program to use photoresistance and servo motor to make light tracking system on
Arduino UNO with graphical code blocks.We will introduce how our core code can
be achieved:
In the GwBlock graphical editor, all code programs are executed

from .Initialize the 9th pin with the

command .Read the data of the photoresistor

with .Control the rotation of the servo motor with the

command block .

530
531
Lesson 29 Making Frequency Meter

In this lesson, we will learn how to use potentiometer and NE555 timer to make
frequency meter.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Male to Female Jumper Wires Several

Potentiometer 1

NE555 Timer 1

Resistor(10KΩ) 1

Capacitor(104) 1

2.NE555 Timer

(1)NE555 Timer

The 555 integrated circuit is originally used as a timer, and that is why it is called
555 timer or 555 time-based circuit. It is widely used in various electronic products
because of its reliability, convenience and low price. There are dozens of components
in the 555 integrated circuit, such as divider, comparator, basic R-S trigger, discharge

532
tube, and buffer. This is a complex circuit and a hybrid composed of analog and
digital circuits.

(1)Working principle

As shown in the above figure, the 555 integrated circuit is dual in-line with 8 pins
package(DIP).

Pin 6 is the THRESHOLD for the input of upper comparator;


Pin 2 is TRIGGER for the input of lower comparator;
Pin 3 is the OUTPUT having two states of 0 and 1 decided by the input electrical
level;
Pin 7, the DISCHARGE which has two states of suspension and ground
connection also decided by input, is the output of the internal discharge tube;
Pin 4 is the RESET that outputs low level when supplied low voltage level;
Pin 5 is the CONTROL VOLTAGE that can change the upper and lower level
trigger value;

533
Pin 8 (Vcc) is the power supply;

Pin 1(GND) is the ground.

The schematic diagram used in the experiment is as shown below:

The circuit can generate a square wave signal that the frequency is adjustable.
The frequency can be calculated by the formula:

1.44
Frequency
RA  2RB   C

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

534
4. Making Frequency Meter

We provide two different methods to use Potentiometer and NE555 Timer to


make Frequency Meter.One is to program on the Arduino UNO with C language
through the Arduino IDE. You need to master the C language; the other is to program
535
on the Arduino UNO with the graphical code block through GwBlock IDE.This
method is very suitable for beginners who have not mastered the advanced
programming languages C and C++. We will introduce these methods respectively.

1.Using C language to program to make Frequency Meter on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_29_timer555 directory.
Select29_timer555.ino. This file is the code program we need in this course. Then
click Open.

536
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, we need to open the serial monitor on the
Arduino software. How to open the serial monitor? You need to click the "Serial

Monitor" button in the upper right corner, as shown below:

537
6. After clicking , the serial monitor window will pop up.Rotating the

potentiometer, the serial monitor will print out the corresponding value, as shown
below:

7. The physical connection diagram of the experiment is as follows:

538
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to use Potentiometer and NE555 Timer to make Frequency
Meter on Arduino UNO.We will introduce how our core code can be achieved:
1.In the setup() function, set the pin pin to INPUT mode with the pinMode() function.

2.In the loop() function, after calculation, print the values of Freq, HTime, and LTime
on the serial port of the Arduino software.

539
2. Using graphical code blocks to program to make Frequency

Meter on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

540
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

541
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

542
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

543
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

544
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_29_timer555
It will show as below:

5. Select the "29_timer555.gwblock" file. This file is the graphical code program for
our lesson. Click "Open" in the lower right corner.It will show as below:

545
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

8. Click the button on the upper right corner.After running the program

546
successfully, open the GUI info v1.0.py window. When you rotate the potentiometer,
you will find that the corresponding value will also be displayed on the window,
indicating that our experimental test is successful.

9. The physical connection diagram of the experiment is as follows:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we

547
program to use Potentiometer and NE555 Timer to make Frequency Meter on Arduino
UNO with graphical code blocks.We will introduce how our core code can be
achieved:

In the GwBlock graphical editor, all code programs are executed from .The

data obtained by the calculation with

instruction is stored in the variable b,

and then the value of the variable b is printed and outputted on the command window

with the instruction .

548
Lesson 30 The Application of the PIR Movement
Sensor

In this lesson, we will learn how to use PIR movement sensor to detect biological
intrusions.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 1

LED 1

PIR Movement Sensor 1

Male to Female Jumper Wires Several

2. The introduction of PIR Movement Sensor

(1) PIR Movement Sensor

The PIR movement sensor we use in this class is HCSR501. It is a kind of sensor
that can sense the infrared radiation of the target and make measurements based on
the physical properties of infrared. The figure below is the passive infrared sensor we
use in this class, also known as human infrared sensor. It has three pins, namely VCC,

549
OUT and GND. Two yellow knobs directly opposite the pin can adjust the sensitivity
and reception distance of the sensor. It can detect every living and non-living thing
whose temperature is above absolute zero. In addition, the PIR sensor has two
potentiometers: one for adjusting the sensor's sensitivity (or rather, the sensor's
sensing distance), and one for adjusting how long the output stays high when any
human movement is detected.

(2) The working principle of the PIR Movement Sensor

PIR movement sensor, also known as human infrared sensor, it can detect the
human body in the form of heat emission of infrared radiation, so can be used to
detect the presence of people or animals. The human body has a constant body
temperature, generally at 37 degrees, so it will emit a specific wavelength of about
10UM of infrared. The passive infrared probe is used to detect about 10UM of
infrared emitted by the human body. The infrared ray about 10UM emitted by the
human body is enhanced through the Fresnel filter and then gathered to the infrared
sensor. Infrared induction source usually adopts pyroelectric element, which will lose
the charge balance when it receives the human body's infrared radiation temperature
changes, and release the charge outward. After the subsequent circuit is detected and
processed, the alarm signal can be generated.
Within the range of the setting, the high level will be output when someone is
detected to be active, otherwise the low level will be output. It can repeatedly trigger
the output high level. After sensing the human body, keep the output high level for a
delay period and no longer sense, and re-detect after the delay is over. If someone is

550
active within its sensing range, its output will be It keeps high level until the person
leaves, and then changes the high level to low level (the sensor module will
automatically extend the delay time for each activity detected again after the end of a
delay period, and take the time of the last activity as the starting point of the delay
time).
(1) Pyroelectric effect
When some crystals are heated, an equal but opposite amount of charge will be
generated at both ends of the crystal. This phenomenon of electrical polarization due
to thermal change is called pyroelectric effect.
(2) Fresnel lens
The Fresnel lens is made according to the Fresnel principle. The Fresnel lens is
divided into two forms: refraction and reflection. Second, the detection area is divided
into several bright areas and dark areas, so that moving objects entering the detection
area can generate infrared signals on PIR in the form of temperature changes, so that
PIR can generate electrical signals of changes. The sensitivity of pyroelectric human
body infrared sensor (PIR) is greatly increased.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

551
552
4. PIR Movement Sensor

We provide two different methods to use PIR movement sensor to detect


biological intrusions.One is to program on the Arduino UNO with C language through
the Arduino IDE. You need to master the C language; the other is to program on the
Arduino UNO with the graphical code block through GwBlock IDE.This method is
very suitable for beginners who have not mastered the advanced programming
languages C and C++. We will introduce these methods respectively.

1.Using C language to program to detect biological intrusions on

Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the


user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
553
Code\_30_PIR_movement directory. Select30_PIR_movement.ino. This file is the
code program we need in this course. Then click Open.

4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After successfully running the program, when you are close to the PIR movement
sensor, the LED will be on, indicating that a biological intrusion has been detected;
when you are away from the PIR movement sensor, the LED will be off, indicating
that no biological intrusion has been detected. The physical connection diagram of the
experiment is as follows:

554
(2)Core code program
After the above hands-on operation, you must be very interested to know how we
use C language to program to use PIR movement sensor to detect biological intrusions
on Arduino UNO.We will introduce how our core code can be achieved:
1.In the setup() function, set the ledpin pin to OUTPUT mode and PIRpin to INPUT
mode with the pinMode() function;

2.In the loop() function,determine whether the PIR movement sensor detects a
biological approaching with if (digitalRead(PIRpin)==LOW), if
digitalRead(PIRpin)==LOW does not detect that someone is approaching, then the
LED will be off with digitalWrite(ledpin , LOW); if an intrusion is detected,the LED
will be on with digitalWrite(ledpin, HIGH).

555
2.Using graphical code blocks to program to detect biological

intrusions on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

556
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

557
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

558
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

559
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

560
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_30_PIR_movement
It will show as below:

5. Select the "30_PIR_movement.gwblock" file. This file is the graphical code


program for our lesson. Click "Open" in the lower right corner.It will show as below:

561
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

8. Click the button on the upper right corner.After successfully running the

562
program, when you are close to the PIR movement sensor, the LED will be on,
indicating that a biological intrusion has been detected; when you are away from the
PIR movement sensor, the LED will be off, indicating that no biological intrusion has
been detected. The physical connection diagram of the experiment is as follows:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to use PIR movement sensor to detect biological intrusions on Arduino UNO
with graphical code blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .In

the while loop statement, it is judged by the instruction


whether the PIR movement sensor detects biological intrusion. When PIRpin is equal
to 0, it means that no biological intrusion is detected. At this time, the LED is turned

off by the instruction ; when PIRpin is not equal

to 0, it means that a biological intrusion is detected, and the LED is controlled to light

up via commands .

563
564
Lesson 31 Using IR Remoter Controller to control
Relay

In this lesson, we will study how to use IR Remoter Controller to control Relay.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

IR Receiver HX1838 1

Remote Controller 1

Male to Female Jumper Wires 3

Relay Module 1

2. The introduction of IR remoter controller and


relay

(1)IR remoter controller

Please refer to Lesson 17, for we have introduced the IR remoter controller in detail
in Lesson 17.

565
(2)relay

Please refer to Lesson 4, for we have introduced the relay in detail in Lesson 4.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

566
4. Using IR Remoter Controller to control Relay

We provide two different methods to use IR Remoter Controller to control


Relay.One is to program on the Arduino UNO with C language through the Arduino
IDE. You need to master the C language; the other is to program on the Arduino UNO
with the graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

1.Using C language to program to use IR Remoter Controller to

control Relay on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

567
4. Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the
user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_31_control_a_relay_with_IR_remoter_controller directory.
Select31_control_a_relay_with_IR_remoter_controller.ino. This file is the code
program we need in this course. Then click Open.

568
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5. After running the program successfully, when you click the number 1 on the remote
control, it means to control the relay switch, then the LED_D indicator on the relay
will go out; when you click the number 0 on the remote control, it means that the
relay will be controlled to close and energize. The LED_D indicator of the relay will
be lit up. The physical connection diagram of the experiment is as follows:

(2)Core code program


After the above hands-on operation, you must be very interested to know how we
use C language to program to use IR Remoter Controller to control Relay on Arduino
UNO.We will introduce how our core code can be achieved:
1.In the setup() function, set the relayPin pin to OUTPUT mode with the

569
pinMode() function. Initialize the IR remoter controller by the irrecv.enableIRIn()
function, that is, turn on the IR remoter controller.
2.In the loop() function, use if(results.value==16750695) to determine whether
the 0 button of the remote controller is pressed. If button 0 is pressed,
digitalWrite(relayPin, LOW) will control the relay to turn on; If button 1 is pressed,
then digitalWrite(relayPin, HIGH) will control the relay to turn on.

2.Using graphical code blocks to program to use IR Remoter

Controller to control Relay on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

570
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

571
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

572
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

573
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

574
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_31_control_a_relay_with_IR_re
moter_controller
It will show as below:

5. Select the "31_control_a_relay_with_IR_remoter_controller.gwblock" file. This file


is the graphical code program for our lesson. Click "Open" in the lower right corner.It
will show as below:

575
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

576
8. Click the button on the upper right corner.After successfully running the

program, it means that our experimental test is successful. The physical connection
diagram of the experiment is as follows:

(3)Core code program


After the above hands-on operation, you must be very interested to know how we
program to use IR Remoter Controller to control Relay on Arduino UNO with
graphical code blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .First,

you need to use the command to initialize the IR remoter

controller; in the while loop, first use the command to read

the signal value of the infrared receiver.Use the if statement to determine the value 0
or 1of the key pressed by the remote controller.Control the relay to be turned on and

off with the command and

577
578
Lesson 32 Controlling RGB LED with IR Remoter
Controller

In this lesson, we will learn how to use IR Remoter Controller to control RGB
LED.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

Resistor(220Ω) 3

RGB LED 1

IR Receiver HX1838 1

Remote Controller 1

Male to Female Jumper Wires 3

2. IR Remoter Controller and RGB LED


(1) IR Remoter Controller

Please refer to Lesson 17, for we have introduced the IR remoter controller in detail
in Lesson 17.

579
(2)RGB LED

Please refer to Lesson 9, for we have introduced the RGB LED in detail in Lesson
9.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

580
4. Using IR Remoter Controller to control RGB LED

We provide two different methods to use IR Remoter Controller to control RGB


LED.One is to program on the Arduino UNO with C language through the Arduino
IDE. You need to master the C language; the other is to program on the Arduino UNO
with the graphical code block through GwBlock IDE.This method is very suitable for
beginners who have not mastered the advanced programming languages C and C++.
We will introduce these methods respectively.

1.Using C language to program to use IR Remoter Controller to

control RGB LED on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

581
5. Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the
user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_32_control_a_RGB_LED_with_IR_remoter_controller directory.
Select_32_control_a_RGB_LED_with_IR_remoter_controller.ino. This file is the
code program we need in this course. Then click Open.

582
4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5.After successfully running the program, we set the program to change the color of
the RGB LED with numbers from 0 to 9 on the remote controller. When you press
number 1 on the remote controller, the RGB LED will be turned on to red. When you
press the number 2, the RGB LED will turn to green.When you press the number 3,
the RGB LED will change to blue. It turns blue When you press the number 0, the
RGB LED will go out. The physical connection diagram of the experiment is as
follows:

(2)Core code program


After the above hands-on operation, you must be very interested to know how we
use C language to program to use IR Remoter Controller to control RGB LED on

583
Arduino UNO.We will introduce how our core code can be achieved:
1.In the setup() function, set the R, G, and B of the RGB LED to the OUTPUT mode
with the pinMode() function. Initialize the IR remoter controller with the
irrecv.enableIRIn() function, that is, turn on the IR remoter controller.

2.In the loop() function, read the signal value of the infrared receiver through the if
judgment.Control the RGB LED to become the corresponding color with the color(R,
G, B) function. If the values of R, G, and B are different, then the the color displayed
by RGB LED will be different. If you press button 1 on the remote controller and set
the displayed color value to red with the color(255,0,0) function, the RGB LED will
show red.

584
2.Using graphical code blocks to program to use IR Remoter

Controller to control RGB LED on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:

585
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the


websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

586
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

587
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

588
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

589
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_32_control_a_RGB_LED_with_
IR_remoter_controller
It will show as below:

5. Select the "32_control_a_RGB_LED_with_IR_remoter_controller.gwblock" file.


This file is the graphical code program for our lesson. Click "Open" in the lower right
corner.It will show as below:

590
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

591
8. Click the button on the upper right corner.When you press the number from 0 to

9 on the remote controller, the RGB LED color will change, indicating that our
experimental test is successful. The physical connection diagram of the experiment is
as follows:

592
(3)Core code program
After the above hands-on operation, you must be very interested to know how we
program to use IR Remoter Controller to control RGB LED on Arduino UNO with
graphical code blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .First,

you need to use the command to initialize the infrared receiving

sensor; at the same time, in the loop, first use the

command to read the signal value of the infrared receiver,

and then use the command to determine whether the button 0 of the

remote controller is clicked. If you click the button 0, the command will

modify the color of RGB LED.

593
594
Lesson 33 Controlling Stepper Motor with IR
Remoter Controller

In this lesson, we will learn how to use IR Remoter Controller to control stepper
motor.

1. Components used in this course

Components Quantity Picture

Arduino UNO 1

Breadboard 1

USB Cable 1

jumper wire Several

ULN2003-based Stepper 1

Motor Driver

Stepper Motor 1

IR Receiver HX1838 1

Remote Controller 1

Male to Female Jumper Wires Several

2. IR Remoter Controller and Stepper Motor


(1) IR Remoter Controller

Please refer to Lesson 17, for we have introduced the IR remoter controller in detail
595
in Lesson 17.
(2) Stepper Motor
Please refer to Lesson 26, for we have introduced the Stepper Motor in detail in
Lesson 26.

3.Wiring diagram (Circuit diagram)

Before the experiment, we connect them in the circuit as shown in the following
figure. When connecting the circuit, we should pay attention to the difference between
positive and negative electrodes. As shown in the following figure:

596
4. Using IR Remoter Controller to control Stepper
Motor

We provide two different methods to use IR Remoter Controller to control


stepper motor.One is to program on the Arduino UNO with C language through the
Arduino IDE. You need to master the C language; the other is to program on the
Arduino UNO with the graphical code block through GwBlock IDE.This method is
very suitable for beginners who have not mastered the advanced programming
languages C and C++. We will introduce these methods respectively.

1.Using C language to program to use IR Remoter Controller to

control stepper motor on Arduino UNO

(1)Compile and run the code program of this course


1.Open the Arduino IDE software, as shown below:

2.Click Open in the File drop-down menu:

597
3.Find the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 that we provide to the
user. Open the folder Adeept_Ultimate_Kit_For_Arduino_C_Code in it. Enter the
Code\_33_control_a_stepper_motor_with_IR_remoter_controller directory.
Select_33_control_a_stepper_motor_with_IR_remoter_controller.ino. This file is the
code program we need in this course. Then click Open.

4.After opening, click to upload the code program to the Arduino UNO. If there is
no error warning in the console below, it means that the Upload is successful.

5.After successfully running the program, we set the numbers from 0 to 9 on the
remote controller to control the state of the stepper motor in the program. When you
press the numbers from 1 to 9 on the remote controller, the stepper motor will move.
When you press 0, the stepper motor will stop. The physical connection diagram of

598
the experiment is as follows:

(2)Core code program


After the above hands-on operation, you must be very interested to know how we
use C language to program to use IR Remoter Controller to control stepper motor on
Arduino UNO.We will introduce how our core code can be achieved:
1.In the setup() function, set the Pin0, Pin1, Pin2, Pin3 pins to OUTPUT mode with
the pinMode() function; use the irrecv.enableIRIn() function to initialize the infrared
receiver.

2.In the loop() function, judge the key value received by the infrared receiver with
the switch statement and control the stepper motor to rotate. If you press button 1 on
IR remoter controller, the stepper motor will rotate clockwise at a step speed of 15;
3.Press the "*" button on the remote controller to change the direction of rotation of
the stepper motor. At this time, press the key value 1-9 on the remote controller, the
stepper motor will rotate counterclockwise; if you press the "#" button, you can

599
control the stepper motor to rotate clockwise. At this time, press the button value 1-9
on the remote controller, the stepper motor will rotate clockwise.;

2. Using graphical code blocks to program to control stepper

motor with IR Remoter Controller on Arduino UNO

(1)Connecting to GwBlock graphical editor


In the previous course "graphical programming of Arduino", we have introduced
in detail how to connect GwBlock. Here we will briefly explain the steps.
1.Open the directory of the folder we provide to the user:
Adeept_Ultimate_Kit_For_Arduino_V2_0\block_py. Double-click to open the

block_py.ino file (open with Arduino). Then click and upload the program to the

Arduino UNO. After successful Upload, it will show as below:

600
2.Open the folder Adeept_Ultimate_Kit_For_Arduino_V2_0 again.Then open the
websocket folder. Double-click to open the GUI info v1.0.py file.It will show as
below:

3.Remember the IP address: 192.168.3.184 (each user's IP is different) which will be


used later. It will show as below:

601
4.Enter the connected port number: COM4 in the input box of Adeept Arduino Robot,
and click the Connect button. It will show as below:

5.Enter the URL of the GwBlock graphical editor in the browser:


http://www.adeept.com/gwblock/?hd_mo=uno_r3.
After successfully entering the website, the interface is as follows:

6.Click the "Connecting device" button in the upper right corner. It will show as
below:

602
7.In the pop-up box, enter the IP address recorded in step 3: 192.168.3.184.Then click
the Connecting . It will show as below:

8.After the successful connection, a green connected prompt will appear in the lower
left corner. It Indicates that we have successfully connected to the GwBlock graphical
editor. It will show as below:

603
(2)Run the code program for this course
Now let us learn how to use the GwBlock graphical editor to open and run the
program for the course.
(1)Open and run the program for this course
1. After successfully connecting to the GwBlock graphical editor, click the button

in the upper right corner.It will show as below:

2. Click Import project file to import the external project file. After opening, a blank
page will appear. You need to modify the lower right corner area and select All Files.It
will show as below:

604
3.The file will then be displayed. It will show as below:

4.Open the Adeept_Ultimate_Kit_For_Arduino_V2_0 file that we provide to users,


and then open the folder:
Adeept_Ultimate_Kit_For_Arduino_C_Code\Code\_33_control_a_stepper_motor_wi
th_IR_remoter_controller
It will show as below:

5. Select the "_33_control_a_stepper_motor_with_IR_remoter_controller.gwblock"


file. This file is the graphical code program for our lesson. Click "Open" in the lower
right corner.It will show as below:

605
6.Click OK.It will show as below:

7.It will show as below after successfully opening:

606
8. Click the button on the upper right corner.When you press the numbers from 1

to 9 on the remote controller, you can control the stepper motor to rotate, indicating
that our experimental test is successful. The physical connection diagram of the
experiment is as follows:

607
(3)Core code program
After the above hands-on operation, you must be very interested to know how we
program to use IR Remoter Controller to control stepper motor on Arduino UNO with
graphical code blocks.We will introduce how our core code can be achieved:

In the GwBlock graphical editor, all code programs are executed from .First,

you need to use the command to initialize the infrared

receiving sensor; in the while loop, first use the command to

read the signal value of the infrared receiver, and use the command to

judge if the button "*" is pressed, then the stepper motor is controlled to rotate

counterclockwise with the command ; use the command

to judge if the button "#" is pressed, the stepper motor is controlled to

rotate clockwise with the command ; at this time, if you press the

button 1 of the remote controller, the command

will control the stepper motor to rotate

counterclockwise or clockwise at a step speed of 15.

608
609
Lesson 34 Controlling the Size of a Circle by

Potentiometer

1.Overview
In this lesson, we will collect the potentiometer data by programming the Arduino
UNO Board, and then send the data to the Processing through serial communication to
change the size of a circle.

3. Components

- 1 * Arduino UNO
- 1 * USB Cable
- 1 * 10kΩ Potentiometer
- 1 * Breadboard
- Several jumper wires

3.Principle
The experiment consists of two parts: first, acquire the data from Arduino; second,
process the data.

Arduino key function:

●write()
Writes binary data to the serial port. This data is sent as a byte or series of bytes;
to send the characters representing the digits of a number use the print() function
instead.

Syntax:

Serial.write(val)

Serial.write(str)

610
Serial.write(buf, len)

Parameters:

val: a value to send as a single byte

str: a string to send as a series of bytes

buf: an array to send as a series of bytes

len: the length of the buffer

Returns:

byte

write() will return the number of bytes written, though reading that number is optional

Processing key function:

●Name: size()

Description:

Defines the dimension of the display window in units of pixels. The size()
function must be the first line of code, or the first code inside setup(). Any code that
appears before the size() command may run more than once, which can lead to
confusing results.

The system variables width and height are set by the parameters passed to this
function. If size() is not used, the window will be given a default size of 100x100
pixels.

Syntax:

size(w, h)

size(w, h, renderer)

Parameters:

w int: width of the display window in units of pixels

h int: height of the display window in units of pixels

611
renderer

String: Either P2D, P3D, or PDF

Returns:

void

●Name: println()

Description:

The println() function writes to the console area, the black rectangle at the bottom
of the Processing environment. This function is often helpful for looking at the data a
program is producing. Each call to this function creates a new line of output. More
than one parameter can be passed into the function by separating them with commas.
Alternatively, individual elements can be separated with quotes ("") and joined with
the addition operator (+).

Before Processing 2.1, println() was used to write array data to the console. Now,
use printArray() to write array data to the console.

Note that the console is relatively slow. It works well for occasional messages,
but does not support high-speed, real-time output (such as at 60 frames per second).

Syntax:

println()

println(what)

println(variables)

Parameters:

what Object, String, float, char, boolean, or byte: data to print to console

variables Object[]: list of data, separated by commas

Returns:

void

●Name: background()

612
Description:

The background() function sets the color used for the background of the
Processing window. The default background is light gray. This function is typically
used within draw() to clear the display window at the beginning of each frame, but it
can be used inside setup() to set the background on the first frame of animation or if
the backgound need only be set once.

An image can also be used as the background for a sketch, although the image's
width and height must match that of the sketch window. Images used with
background() will ignore the current tint() setting. To resize an image to the size of the
sketch window, use image.resize(width, height).

It is not possible to use the transparency alpha parameter with background colors
on the main drawing surface. It can only be used along with a PGraphics object and
createGraphics().

Syntax:

background(rgb)

background(rgb, alpha)

background(gray)

background(gray, alpha)

background(v1, v2, v3)

background(v1, v2, v3, alpha)

background(image)

Parameters:

rgb int: any value of the color datatype

alpha float: opacity of the background

gray float: specifies a value between white and black

v1 float: red or hue value (depending on the current color mode)

v2 float: green or saturation value (depending on the current color mode)


613
v3 float: blue or brightness value (depending on the current color mode)

image PImage: PImage to set as background (must be same size as the sketch
window)

Returns:

void

●Name: fill()

Description:

Sets the color used to fill shapes. For example, if you run fill(204, 102, 0), all
subsequent shapes will be filled with orange. This color is either specified in terms of
the RGB or HSB color depending on the current colorMode(). (The default color
space is RGB, with each value in the range from 0 to 255.)

When using hexadecimal notation to specify a color, use "#" or "0x" before the
values (e.g., #CCFFAA or 0xFFCCFFAA). The # syntax uses six digits to specify a
color (just as colors are typically specified in HTML and CSS). When using the
hexadecimal notation starting with "0x", the hexadecimal value must be specified
with eight characters; the first two characters define the alpha component, and the
remainder define the red, green, and blue components.

The value for the "gray" parameter must be less than or equal to the current
maximum value as specified by colorMode(). The default maximum value is 255.

Syntax:

fill(rgb)

fill(rgb, alpha)

fill(gray)

fill(gray, alpha)

fill(v1, v2, v3)

fill(v1, v2, v3, alpha)

Parameters:

614
rgb int: color variable or hex value

alpha float: opacity of the fill

gray float: number specifying value between white and black

v1 float: red or hue value (depending on current color mode)

v2 float: green or saturation value (depending on current color mode)

v3 float: blue or brightness value (depending on current color mode)

Returns:

void

●Name:ellipse()

Description:

Draws an ellipse (oval) to the screen. An ellipse with equal width and height is a
circle. By default, the first two parameters set the location, and the third and fourth
parameters set the shape's width and height. The origin may be changed with the
ellipseMode() function.

Syntax:

ellipse(a, b, c, d)

Parameters:

a float: x-coordinate of the ellipse

b float: y-coordinate of the ellipse

c float: width of the ellipse by default

d float: height of the ellipse by default

Returns:

Void

Note:

1. In this experiment, my Arduino UNO board is connected to my computer port

615
COM26. But it may differ in your case. So please adjust it according to your actual
situation.

2. If Processing prompts that you need to install the related function library, please do
it.

4.Procedures

Step 1: Build the circuit

Step 2: Program
Step 3: Compile the program and upload to Arduino UNO board
Step 4: Run the Processing software (Processing_Potentiometer.pde)
Now, turn the knob of the potentiometer, and you will see a blue circle size to change
on the computer.

616
617
618
Lesson 35 Controlling the 3D Model by PS2 Joystick

1.Overview
In this lesson, we will collect the state of a joystick by programming the Arduino
UNO Board, and then send the data to the Processing through the serial
communication.

2. Components

- 1 * Arduino UNO
- 1 * USB Cable
- 1 * PS2 Joystick
- 1 * Breadboard
- Several jumper wires

3.Principle

The experiment consists of two parts: first, acquire the data from Arduino; second,
process the data.

Here use the Arduino UNO board to collect data of the joystick state, and upload
the data to the computer through the serial port. The data will be processed by
Processing and shown with 3D image.

Note:

1. In this experiment, my Arduino UNO board is connected to my computer port


COM26. But it may differ in your case. So please adjust it according to your actual
situation.

2. If the Processing does not run normally, you may need to install the related
function libraries.

4.Procedures

619
Step 1: Build the circuit

Step 2: Program
Step 3: Compile the program and upload to Arduino UNO board
Step 4: Run the Processing software (Processing_PS2Joystick.pde)
Move the joystick, and the 3D model will follow movement changes accordingly on
your computer.

620
621
Lesson 36 Snake Game

1.Overview
In this lesson, we will make a Snake Game based on the Processing, and play the
game with two buttons.

2.Components

- 1 * Arduino UNO
- 1 * USB Cable
- 2 * Button
- 1 * Breadboard
- Several jumper wires

3.Principle

The experiment consists of two parts: first, acquire the data from Arduino; second,
process the data.

Play the Snake Game:

1.When you press the right button, the snake will move to the right.

2.Press the left button, and the snake will move to the left.

Note:

1. You need to install the Sound library.

2. In this experiment, my Arduino UNO board is connected to my computer port


COM26. But it may differ in your case. So please adjust it according to your actual
situation.

3. If the Processing does not run normally, you may need to install the related
function libraries.

4.Procedures

622
Step 1: Build the circuit

Step 2: Program
Step 3: Compile the program and upload to Arduino UNO board
Step 4: Run the Processing software (Snake_Game_Processing_Button.pde)

623
624
Lesson 37 Star Wars

1.Overview
In this lesson, we will make a star wars game based on the Processing and play
the game with a PS2 joystick and a button connected to the Arduino UNO.

1. Components

- 1 * Arduino UNO
- 1 * USB Cable
- 1 * Button
- 1 * PS2 Joystick
- 1 * Breadboard
- Several jumper wires

4.Principle

The experiment consists of two parts: first, acquire the data from Arduino; second,
process the data.

Play the Star Wars Game:

1 When you press the button, the fighter aircraft will fire bullets

② When you operating the PS2 Joystick, you can change the position of movement of
the fighter aircraft.

Note:

1. In this experiment, my Arduino UNO board is connected to my computer port


COM26. But it may differ in your case. So please adjust it according to your actual
situation.

2. If the Processing does not run normally, you may need to install the related
function libraries.

625
5.Procedures

Step 1: Build the circuit

Step 2: Program
Step 3: Compile the program and upload to Arduino UNO board
Step 4: Run the Processing software (Processing_PS2Joystick_Button.pde)

626
627
628

You might also like