Adeep-Arduino Project Book
Adeep-Arduino Project Book
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
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.
5
The following is a detailed introduction to the development board of Arduino
Uno R3 model:
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.
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.
8
Using an external power supply of 7-12V to power the Arduino.
Restart the Arduino and start the program from the beginning.
(9) Microcontroller:
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
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.
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/
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
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.
16
(1)Menu bar
(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
(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 :
(3)New :
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 :
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.
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
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.
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
(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:
29
(6) Wait for the Python installation to complete and click "Close" to close.
(1) Press Win+R shortcut key to open CMD under Windows 10:
31
(3) Enter the command in the window:
pip install pyserial
Press the Enter and wait for the installation to complete.
(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".
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:
(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.
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:
(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
【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
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 1
LED 1
(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:
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.
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:
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.
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
Arduino UNO
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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.
67
5. Drag to the right below .Find the instruction under the
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
8. Find the loop judgment instruction under the Loops code instruction
module, as shown below:
69
10.We need to determine whether the condition is TRUE, find under the code
11.When the condition is True, control the LED on and off by setting the high and low
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
then you can enter the number of time to delay in . We enter 2 to control the
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:
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
can enter the number of the time to delay in .We enter 2 to control the LED to be
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
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(1KΩ) 1
Active Buzzer 1
NPN Transistor(8050) 1
75
(2) Working principle of the Buzzer
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.
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.
on Arduino UNO
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).
82
2.Programming and controlling the Active Buzzer on Arduino
block_py.ino file (opened with Arduino). Then click and upload the program to
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:
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:
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
6.By knowing that the pin of the active buzzer is connected to port 8 in "3. Wiring
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:
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
12.Set buzzerPin to a high level, then you can make the active buzzer sound. Find the
90
13.In the instruction module , drag variable into the editing
14.Use a delay command to control the active buzzer to continue to be on for a period
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
18.Use a delay command to control the active buzzer to continue to be off for a period
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:
94
95
Lesson 3 Controlling LED with Button
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 1
LED 1
Resistor(10KΩ) 1
Button(Large) 1
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.
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.
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.
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.
Arduino UNO
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:
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.
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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.
107
3.Click Create variable under Variables in the toolbar of the code instruction block to
create variables.
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
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:
the right editing area .You need to initialize ledpin to Output mode and btnpin
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
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
111
13. Drag the instruction to the instruction in the editing area on the
14.Determine whether the status of btnpin is low (0). 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
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
17.If the state of the ledpin pin is set to the low state through the
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 1
LED 1
Relay Module 1
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.
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.
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
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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:
In the GwBlock graphical editor, all code programs are executed from .
block , and the relayPin is set to the Output mode through the
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
Arduino UNO 1
Breadboard 1
USB Cable 1
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
134
3.Wiring diagram (Circuit diagram)
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.
Arduino UNO
136
2.Click Open in the File drop-down menu:
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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:
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 .
block , and the ledpin is set to the Output mode through the
statement, read the voltage value input by the potentiometer through the instruction
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
obtained value is less than 500, then set the ledpin to Low-level through the
148
Lesson 6 Making a Flowing LED with LED
In this lesson, we will learn how to make Flowing LED with LED.
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 8
LED 8
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.
149
making 8 LEDs flash out of the effect of Flowing Lights.
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.
Arduino UNO
151
2.Click Open in the File drop-down menu:
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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:
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
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 10
Potentiometer(10KΩ) 1
(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:
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.
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
176
6.Click OK.It will show as below:
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:
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
block , and the pin numbers are set to the Output mode
statement, set the pin number from 2 to 11 to Low-level through the instruction
179
Lesson 8 Making Breathing LED with LED
In this lesson, we will learn how to make Breathing LED with LED.
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 1
LED 1
(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
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.
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.
Arduino UNO
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.
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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
0.015s. Decrease the brightness of LED with PWM through the instruction
197
198
Lesson 9 The Application of the RGB LED
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 3
RGB LED 1
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.
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)
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.
on Arduino UNO
202
2.Click Open in the File drop-down menu:
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:
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.
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
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:
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
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:
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:
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
213
In the while loop statement, the values of R, G, and B are set by
214
215
Lesson 10 The Application of the Passive Buzzer
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 1
Passive Buzzer 1
PNP Transistor(8550) 1
(1) Buzzer
216
(2)Working principle of the Buzzer
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.
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.
Arduino UNO
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.
223
Arduino UNO
block_py.ino file (open with Arduino). Then click and upload the program to the
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
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:
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:
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:
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:
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:
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:
In the GwBlock graphical editor, all code programs are executed from .First
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
LCD1602 1
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.
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.
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
236
1.Using C language to program to display characters on
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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
text information displayed on the LCD screen for 2s. Finally, the instruction block
248
display at last.
249
Lesson 12 Making Voltmeter
In this lesson, we will learn how to make voltmeter with LCD1602, I2C and
potentiometer.
Arduino UNO 1
Breadboard 1
USB Cable 1
LCD1602 1
Potentiometer 1
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
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
Arduino UNO
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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 .
264
Lesson 13 The Application of the 7-segment Display
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 1
7-segment Display 1
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)
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.
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.
on Arduino UNO
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
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
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:
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
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:
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:
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
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 1
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.
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:
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
Arduino UNO
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:
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
295
6.Click OK.It will show as below:
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:
block .
297
298
Lesson 15 Controlling the Servo Motor
Arduino UNO 1
Breadboard 1
USB Cable 1
AD002 Servo 1
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.
Arduino UNO
303
2.Click Open in the File drop-down menu:
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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:
314
In the GwBlock graphical editor, all code programs are executed from .
0 degrees, which is also the initial position. In the while loop, the instruction
rotate 180 degrees. If you need to control the servo motor to rotate other degrees, you
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
LCD1602 1
Resistor(10KΩ) 1
Analog Temperature 1
Sensor(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
③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.
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.
B-parameter: 3470.
: 2.718281828459
318
After transforming the above equation, we can get the following formula:
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
320
2.Click Open in the File drop-down menu:
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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,
variable a.After calculation, the thermistor data will be output to the LCD1602 screen
332
333
Lesson 17 The Application of IR Remoter Controller
Arduino UNO 1
Breadboard 1
USB Cable 1
IR Receiver HX1838 1
Remote Controller 1
334
The following figure shows an IR remote controller:
335
and then send the received data to Serial Monitor. In the program, we use the
Arduino-IRremote-master library (provided).
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
337
1.Using C language to program to control the IR Remoter
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:
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. .
341
Remoter Controller on Arduino UNO
#define BUZZER 0.Then click and upload the program to the Arduino UNO.
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:
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:
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:
346
program for our lesson. Click "Open" in the lower right corner.It will show as below:
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:
348
command block can read the signal value of the IR
receiver.Print the corresponding remote controller key value on the command window
349
Lesson 18 The Application of DHT-11(Digital
Temperature & Humidity Sensor)
Arduino UNO 1
Breadboard 1
USB Cable 1
LCD1602 1
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℃
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.
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.
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" :
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.
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.
356
2.Click Open in the File drop-down menu:
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
UNO
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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:
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
368
Lesson 19 The Application of the Ultrasonic Distance
Sensor
Arduino UNO 1
Breadboard 1
USB Cable 1
LCD1602 1
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).
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.
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.
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
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:
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
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:
381
6.Click OK.It will show as below:
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:
.Obtain the data of the ultrasonic ranging sensor through the instruction
383
384
Lesson 20 Application of MPU6050
Arduino UNO 1
Breadboard 1
USB Cable 1
IR Receiver HX1838 1
(1) MPU6050
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.
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:
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:
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
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:
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:
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.
393
In the GwBlock graphical editor, all code programs are executed from
instruction .
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.
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
Arduino UNO
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:
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().
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:
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:
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
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:
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:
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.
408
In the GwBlock graphical editor, all code programs are executed
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
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.
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:
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
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:
419
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:
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:
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:
423
program for our lesson. Click "Open" in the lower right corner.It will show as below:
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.
In the GwBlock graphical editor, all code programs are executed from .Get
425
the key value of the 4x4 matrix keyboard through the
with .
426
Lesson 22 Controlling the DC Motor
Arduino UNO 1
Breadboard 1
USB Cable 1
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.
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.
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
UNO
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.
433
2.Using graphical code blocks to program to control the DC
block_py.ino file (open with Arduino). Then click and upload the program to the
434
websocket folder. Double-click to open the GUI info v1.0.py file.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:
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:
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:
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:
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:
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
Arduino UNO 1
Breadboard 1
USB Cable 1
LCD1602 1
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.
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.
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.
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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
456
Lesson 24 Controlling LED with Tilt Switch
In this lesson, we will learn how to use tilt switch to control LED.
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 1
LED 1
Tilt Switch 1
(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.
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
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.
on Arduino UNO
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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:
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:
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:
469
In the GwBlock graphical editor, all code programs are executed from .Read
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 .
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
LCD1602 1
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
474
2.Click Open in the File drop-down menu:
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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:
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
command block , you can display the picture you want by ticking the
led.
485
486
Lesson 26 Controlling the Stepper Motor
Arduino UNO 1
Breadboard 1
USB Cable 1
ULN2003-based Stepper 1
Motor Driver
Stepper Motor 1
(1)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.
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.
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
490
1.Using C language to program to control the Stepper Motor on
Arduino UNO
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.
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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
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:
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:
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
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
LCD1602 1
Resistor(1KΩ) 1
Photoresistor 1
(1)Photoresistance
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.
502
replace the potentiometer with a photoresistor to realize the LED light when the light
intensity is different. The brightness will also change accordingly.
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.
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
504
mastered the advanced programming languages C and C++. We will introduce these
methods respectively.
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
513
6.Click OK.It will show as below:
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:
In the GwBlock graphical editor, all code programs are executed from .Read
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
LCD1602 1
Resistor(1KΩ) 1
Photoresistor 1
AD002 Servo 1
(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.
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.
Arduino UNO
519
2.Click Open in the File drop-down menu:
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.
522
2. Using graphical code blocks to program to make light
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
528
6.Click OK.It will show as below:
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
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
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).
533
Pin 8 (Vcc) is the power supply;
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
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
Arduino UNO
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
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:
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
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:
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.
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
and then the value of the variable b is printed and outputted on the command window
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 1
LED 1
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.
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.
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
Arduino UNO
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
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
561
6.Click OK.It will show as below:
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:
In the GwBlock graphical editor, all code programs are executed from .In
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
IR Receiver HX1838 1
Remote Controller 1
Relay Module 1
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.
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
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:
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.
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
575
6.Click OK.It will show as below:
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:
In the GwBlock graphical editor, all code programs are executed from .First,
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
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
Resistor(220Ω) 3
RGB LED 1
IR Receiver HX1838 1
Remote Controller 1
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.
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
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:
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
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
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:
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
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:
590
6.Click OK.It will show as below:
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,
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
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.
Arduino UNO 1
Breadboard 1
USB Cable 1
ULN2003-based Stepper 1
Motor Driver
Stepper Motor 1
IR Receiver HX1838 1
Remote Controller 1
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.
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
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.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.;
block_py.ino file (open with Arduino). Then click and upload the program to the
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:
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:
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
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:
605
6.Click OK.It will show as below:
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,
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
rotate clockwise with the command ; at this time, if you press the
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.
●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:
Returns:
byte
write() will return the number of bytes written, though reading that number is optional
●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:
611
renderer
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
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(image)
Parameters:
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)
Parameters:
614
rgb int: color variable or hex value
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:
Returns:
Void
Note:
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 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:
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.
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:
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.
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:
2. If the Processing does not run normally, you may need to install the related
function libraries.
625
5.Procedures
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