Kuman K1Arduino KIT Tutorials
Kuman K1Arduino KIT Tutorials
com kuman
Kuman is a professional manufacturer and exporter that is involved in the design, development,
production and marketing of arduino accessories, 3D printers, Raspberry Pi accessories. We are located
in shenzhen which is known as the chinese silicon valley. All of our products comply with international
quality standards and are greatly appreciated in a variety of different markets throughout the world.
Official website:http://www.kumantech.com
We're just happy that you're happy.
Happy
If you don't know how to express your
newfound joy, we've got a few
suggestions.
Tell your friends, hobbyists and family
Share your experience by writing a review on our online store
Connect with us on kumantech.com, facebook: kumantech, twitter: kumantech Instagram: kumantech
Not happy?
Our friendly customer care team will work hard
to put a smile back on your face.
Here's how we can connect:
Phone: +86 755 23021270 Mon-Sat 9:00-18:30
Email: [email protected]
We have a professional team in USA , Canada, UK, Germany, France, Italy ,Spain and Japan to work
with our Kuman China factory to give you 100% satisfied service.
Our Tutorial
This tutorial is geared for beginners. You will learn all the basic information about how to use arduino
controller board, sensors and components. If you want to study arduino in more depth,we recommend
that you read the arduino cookbook written by michael margolis.
Our after-sales
If you have any question,comment or suggestion about our company,product or tutorial,please don’t
hesitate to send an email: [email protected] are committed to continuous improvement so your
feedback is invaluable.
1
Http://www.kumantech.com kuman
Lesson Listing
Lesson0 lnstalling
IDE
Lesson1 Add Libraries
Lesson2 Blink
Lesson3 LED
Lesson4 button
Lesson5 Fire alarm test
Lesson6 8x8 dot matrix experiment
Lesson7 Active Buzzer module
Lesson8 Passive buzzer
2
Http://www.kumantech.com kuman
3
Http://www.kumantech.com kuman
Introduction:
If we want to learn and use the Arduino, necessary to manually install the driver first, fortunately the Arduino IDE
package shipped.
Here we introduce the method of installation:
1:We can have the Arduino website (www.Arduino.cc) to download,
4
Http://www.kumantech.com kuman
Download it here.
5
Http://www.kumantech.com kuman
Right click
on the
"unknown
device" and
then click
"new
driver"
6
Http://www.kumantech.com kuman
Boards and
Ports:
You are now ready to
Software, so whatever
application contained
within it.
it is connecting.
7
Http://www.kumantech.com kuman
from the 'Tools' menu, select Board and then 'Arduino Uno' or 'Leonardo' as appropriate.
Also on the 'Tools' menu, you will find the 'Serial Port' option. Select this option.
If you are using Windows, there will probably only be one option here and it will either say COM3 or
COM4. Even though there is only one option, you will still need to select it.
8
Http://www.kumantech.com kuman
9
Http://www.kumantech.com kuman
Once you are comfortable with the Arduino software and using the built-in functions, you may
Libraries are a collection of code that makes it easy for you to connect to a sensor, display, module, etc. For
example, the built-in LiquidCrystal library makes it easy to talk to character LCD displays. There are
hundreds of additional libraries available on the Internet for download. The built-in libraries and some of
these additional libraries are listed in the reference. To use these additional libraries, you will need to install
them.
To install a new library into your Arduino IDE, you can use the Library Manager (available from IDE version
1.6.2). Open the IDE and click Sketch > Include > Library > Manage Libraries.
10
Http://www.kumantech.com kuman
The library manager will open and you will find a list of libraries that are already installed or
ready for installation. In this example, we will install the Bridge library. Scroll down the list to find it, then
select the version of the library you want to install. Sometimes, only one version of the library is available. If
the version selection menu does not appear, don't worry; it is normal.
Finally click on install and wait for the IDE to install the new library. Downloading may take time depending
on your connection speed. Once it has finished, an Installed tag should appear next to the Bridge library. You
11
Http://www.kumantech.com kuman
You can now find the new library available in the Include Library menu. If you want to add your own library
the folder will be the following: .cpp file, .h file, often a keywords.txt file, examples folder, and other files
required by the library. Starting with version 1.0.5, you can install third-party libraries in the IDE. Do not
In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library.
You will be prompted to select the library you would like to add. Navigate to the .zip file's location and open
it.
Return to the Sketch > Import Library menu. You should now see the library at the bottom of the drop-down
menu. It is ready to be used in your sketch. The zip file will have been expanded in the libraries folder in your
NB: The Library will be available to use in sketches, but examples for the library will not be shown in the File
> Examples until after the IDE has restarted.
Manual installation
To install the library, first, quit the Arduino application. Then unzip the ZIP file containing the library. For
example, if you're installing a library called "ArduinoParty", uncompress ArduinoParty.zip. It should contain a
folder called ArduinoParty, with files like ArduinoParty.cpp and ArduinoParty.h inside. (If the .cpp and .h files
12
Http://www.kumantech.com kuman
aren't in a folder, you'll need to create one. In this case, you'd make a folder called "ArduinoParty" and move
into it all the files that were in the ZIP file, like ArduinoParty.cpp and ArduinoParty.h.)
Drag the ArduinoParty folder into this folder (your libraries folder). Under Windows, it will likely
be called "My Documents\Arduino\libraries". For Mac users, it will likely be called
"Documents/Arduino/libraries". On Linux, it will be the "libraries" folder in your sketchbook. Your Arduino
My Documents\Arduino\libraries\ArduinoParty\ArduinoParty.cpp
My Documents\Arduino\libraries\ArduinoParty\ArduinoParty.h
My Documents\Arduino\libraries\ArduinoParty\examples
Documents/Arduino/libraries/ArduinoParty/ArduinoPrty.cpp
Documents/Arduino/libraries/ArduinoParty/ArduinoParty.h
Documents/Arduino/libraries/ArduinoParty/examples
There may be more files than just the .cpp and .h files so make sure they're all there. (The library
won't work if you put the .cpp and .h files directly into the libraries folder or if they're nested in an
extra folder. For example: Documents\Arduino\libraries\ArduinoParty.cpp and
Documents\Arduino\libraries\ArduinoParty\ArduinoParty\ArduinoParty.cpp won't work.)
Restart the Arduino application. Make sure the new library appears in the Sketch > Import Library menu.
Summary
In this lesson, we will install all the libraries that we will use in the tutorial. Open the libraries folder and
install the ZIP files one by one so we won't need to do this step in the following lessons. We just connect
the component as the schematic and upload the code provided. Then the kit will work.
13
Http://www.kumantech.com kuman
Lesson2 Blink
Overview
In this lesson, you will learn how program your UNO R3 controller board to make the Arduino's built-in LED
blink.
Component Required
(1) x Arduino Uno R3
Principle
The UNO R3 board has rows of connectors along both sides that are used to connect to several electronic
It also has a single LED that you can control from your sketches. This LED is built onto the UNO R3 board and
is often referred to as the 'L' LED as this is how it is labeled on the board.
14
Http://www.kumantech.com kuman
You may find that your UNO R3 board 's 'L' LED already blinks when you connect it to a USB plug. This is
because the boards are generally shipped with the 'Blink' sketch pre-installed
In this lesson, we will reprogram the UNO R3 board with our own Blink sketch and then change the rate at
which it blinks.
In Lesson 0, you set up your Arduino IDE and made sure that you could find the right serial port for it to
connect to your UNO R3 board. The time has now come to put that connection to the test and program your
UNO R3 board.
The Arduino IDE includes a large collection of example sketches that you can load up and use. This includes
Load the 'Blink' sketch that you will find in the IDE's menu system under File > Examples > 01.Basics
When the sketch window opens, enlarge it so that you can see the entire sketch in the window
15
Http://www.kumantech.com kuman
The example sketches included with the Arduino IDE are 'read-only'. That is, you can upload them to an UNO
R3 board, but if you change them, you cannot save them as the same file.
Since we are going to change this sketch, the first thing you need to do is save your own copy.
From the File menu on the Arduino IDE, select 'Save As..' and then save the sketch with the name 'MyBlink'
You have saved your copy of 'Blink' in your sketchbook. This means that if you ever want to
find it again, you can just open it using the File > Sketchbook menu option.
16
Http://www.kumantech.com kuman
Attach your Arduino board to your computer with the USB cable and check that the 'Board Type' and 'Serial
Port' are set correctly. You may need to refer back to Lesson 0.
The Arduino IDE will show you the current settings for board at the bottom of the window.
Click on the 'Upload' button. The second button from the left on the toolbar.
If you watch the status area of the IDE, you will see a progress bar and a series of messages. At first, it will
say 'Compiling Sketch...'. This converts the sketch into a format suitable for uploading to the board.
Next, the status will change to 'Uploading'. At this point, the LEDs on the Arduino should start to flicker as
17
Http://www.kumantech.com kuman
The other message tells us that the sketch is using 1,084 bytes of the 32,256 bytes available.After the
'Compiling Sketch..' stage you could get the following error message.
It can mean that your board is not connected at all, or the drivers have not been installed (if necessary) or
Once the upload has completed, the board should restart and start blinking. Open the
code
Note that a huge part of this sketch is composed of comments. These are not actual program instructions;
rather, they just explain how the program works. They are there for your benefit.
Everything between /* and */ at the top of the sketch is a block comment; it explains what the sketch is for.
Single line comments start with // and everything up until the end of that line is considered a comment.
18
Http://www.kumantech.com kuman
As the comment above it explains, this is giving a name to the pin that the LED is attached to. This is 13 on
Next, we have the 'setup' function. Again, as the comment says, this is executed when the reset button is
pressed. It is also executed whenever the board resets for any reason, such as power first being applied to it,
or after a sketch has been uploaded.
void setup() {
pinMode(led, OUTPUT);
}
Every Arduino sketch must have a 'setup' function, and the place where you might want to add instructions
In this case, there is just one command there, which, as the comment states tells the Arduino board that we
It is also mandatory for a sketch to have a 'loop' function. Unlike the 'setup' function that only runs once,
after a reset, the 'loop' function will, after it has finished running its commands,
milliseconds (1 second), then turn the LED pin off and pause for another second.
You are now going to make your LED blink faster. As you might have guessed, the key to this lies in changing
19
Http://www.kumantech.com kuman
This delay period is in milliseconds, so if you want the LED to blink twice as fast, change the value from 1000
to 500. This would then pause for half a second each delay rather than a whole second.
Upload the sketch again and you should see the LED start to blink more quickly
Lesson 3 LED
Overview
In this lesson, you will learn how to change the brightness of an LED by using different values of resistor.
Component Required:
(1) x Ardino Uno R3
Component Introduction
BREADBOARD MB-102
20
Http://www.kumantech.com kuman
A breadboard enables you to prototype circuits quickly, without having to solder the connections. Below is
an example.
Breadboards come in various sizes and configurations. The simplest kind is just a grid of holes in a plastic
block. Inside are strips of metal that provide electrical connection between holes in the shorter rows.
Pushing the legs of two different components into the same row joins
them together electrically. A deep channel running down the middle indicates that there is a break in
connections there, meaning, you can push a chip in with the legs at either side of the channel without
connecting them together. Some breadboards have two strips of holes running along the long edges of the
board that are separated from the main grid. These have strips running down the length of the board inside
and provide a way to connect a common voltage. They are usually in pairs for +5 volts and ground. These
strips are referred to as rails and they enable you to connect power to many components or points in the
board.
While breadboards are great for prototyping, they have some limitations. Because the connections are push-
fit and temporary, they are not as reliable as soldered connections. If you are having intermittent problems
LED:
LEDs make great indicator lights. They use very little electricity and they pretty much last forever.
In this lesson, you will use perhaps the most common of all LEDs: a 5mm red LED. 5mm refers to the
diameter of the LED. Other common sizes are 3mm and 10mm.
You cannot directly connect an LED to a battery or voltage source because 1) the LED has a positive and a
negative lead and will not light if placed the wrong way and 2) an LED must be used with a resistor to limit or
21
Http://www.kumantech.com kuman
'choke' the amount of current flowing through it; otherwise, it will burn out!
be destroyed almost
There are two ways to tell which is the positive lead of the LED and which the negative.
Secondly, where the negative lead enters the body of the LED, there is a flat edge to the case of the LED.
If you happen to have an LED that has a flat side next to the longer lead, you should assume that the longer
lead is positive.
RESISTORS:
As the name suggests, resistors resist the flow of electricity. The higher the value of the resistor, the more it
resists and the less electrical current will flow through it. We are going to use this to control how much
electricity flows through the LED and therefore, how brightly it shines.
The unit of resistance is called the Ohm, which is usually shortened to Ω the Greek letter
Omega. Because an Ohm is a low value of resistance (it doesn't resist much at all), we also denote the
values of resistors in kΩ (1,000 Ω) and MΩ (1,000,000 Ω). These are called kilo-ohms and mega-ohms.
In this lesson, we are going to use three different values of resistor: 220Ω, 1kΩ and 10kΩ.
22
Http://www.kumantech.com kuman
These resistors all look the same, except that they have different colored stripes on them. These stripes tell
The resistor color code has three colored stripes and then a gold stripe at one end.
23
Http://www.kumantech.com kuman
Unlike LEDs, resistors do not have a positive and negative lead. They can be connected either way around.
Connection
Schematic
wiring diagram
24
Http://www.kumantech.com kuman
The UNO is a
convenient
source of 5
volts, which we
will use to
provide power
to the LED and
the resistor. You
do not need to
do anything
with your UNO,
except to plug it
into a USB
cable.
With the 220 Ω
resistor in place,
the LED should be quite bright. If you swap out the 220 Ω resistor for the 1kΩ resistor, then the LED will
appear a little dimmer. Finally, with the 10 kΩ resistor in place, the LED will be just about visible. Pull the red
jumper lead out of the breadboard and touch it into the hole and remove it, so that it acts like a switch. You
At the moment, you have 5V going to one leg of the resistor, the other leg of the resistor going to the
positive side of the LED and the other side of the LED going to GND. However, if we moved the resistor so
that it came after the LED, as shown below, the LED will still light.
You will probably want to put the 220Ω resistor back in place.
It does not matter which side of the LED we put the resistor, as long as it is there somewhere.6
25
Http://www.kumantech.com kuman
Lesson 4 button
Introduction
In this experiment, you will learn how to turn on/off an LED by using an I/O port and a button. The
"I/O port" refers to the INPUT and OUTPUT port. Here the INPUT port of the SunFounder Uno board
is used to read the output of an external device. Since the board itself has an LED (connected to Pin
13), so you can use this LED to do this experiment for convenience.
Components
- 1 * kuman Uno board
- 1 * USB cable
- 1 * Button
- 1 * Resistor (10k Ohm)
- Jumper wires
- 1 * Breadboard
Principle
26
Http://www.kumantech.com kuman
Button
Buttons are a common component used to control electronic devices. They are usually used as
switches to connect or disconnect circuits. Although buttons come in a variety of sizes and shapes,
the one used here is a 6mm mini-button as shown in the following pictures. Pins pointed out by the
arrows of same color are meant to be connected.
When the button is pressed, the pins pointed by the blue arrows will connect to the pins pointed by
the red arrows.
Generally, the button is directly connected in an LED circuit in order to turn on or off the LED. This
connection is relatively simple. However, sometimes the LED will light up automatically without
pressing the button, which is caused by various interferences. In order to avoid these external
interferences, a pull-down resistor is used, that is, to connect a 1K–10KΩ resistor between the
button port and GND. It is used to consume external interferences while connected to GND for as
long as the button switch is turned off.
This circuit connection is widely used in numerous circuits and electronic devices. For example, if
you press any button on your mobile phone, the backlight will light up.
Experimental Procedures
Step 1: Build the circuit
27
Http://www.kumantech.com kuman
Code:
28
Http://www.kumantech.com kuman
/**********************************/
const int keyPin = 12; //the number of the key pin
const int ledPin = 13;//the number of the led pin
/**********************************/
void setup()
{
pinMode(keyPin,INPUT);//initialize the key pin as input
pinMode(ledPin,OUTPUT);//initialize the led pin as output
}
/**********************************/
void loop()
{
//read the state of the key value
//and check if the kye is pressed
//if it is,the state is HIGH
if(digitalRead(keyPin) ==HIGH )
{
digitalWrite(ledPin,HIGH);//turn on the led
}
else
{
digitalWrite(ledPin,LOW);//turn off the led
}
}
/************************************/
29
Http://www.kumantech.com kuman
Long
feet
Flame
sensor
connection A5, short feet connect 5 v, A5 a 10 k resistor to the GND Pin connections, the positive connection of
the buzzer D8, negative connection GND, then download the code, can use the fire source close to the sensor, to
test the experiment
30
Http://www.kumantech.com kuman
Components:
- 1 * kuman Uno board
- 1 * USB cable
- 1 * Mini bread plate
- Jumper wires
- 1 * UNO extension plate
- 1 * buzzer
-1 * Flame sensor
-1 * resistance 10 k
Code:
31
Http://www.kumantech.com kuman
void loop()
{
val=analogRead(flame);//Simulated values of the flame sensor
Serial.println(val);//Output analog value, and print it out
if(val>=600)//When the analog value is greater than 600 when the buzzer sounds
{ digitalWrite(Beep,HIGH);
}
else { digitalWrite(Beep,LOW);
}
}
32
Http://www.kumantech.com kuman
diagram
2.8*8
dot
matrix
physical map
Figure
8x8
dot
matrix
LED
33
Http://www.kumantech.com kuman
appearance and pin diagram, its equivalent circuit as shown in figure (2), as long as its corresponding Y, X axis
forward bias, you can make LED shine. For example, if you want to make the upper left corner LED lit, then
LED generally use the scan type display, the actual use of three ways(1)spot scan
(2)Column scan
16 * 64=1024Hz period less than 1ms. If you use the second and the third way, frequency must be
greater than 16 * 8=128Hz period less than 7.8ms conforming to the requirements of the
persistence of vision. In addition a drive a column or row (eight LEDs) to an external driving circuit
improves the current, otherwise LED light degree would be enough.
4. Examples of 8*8 dot matrix applications
Pin pin pin point when internal lattice structure and shape are as follows, 8x8 dot matrix
consists of 64 light emitting diode, and each light emitting diode is placed in rows in line and
column intersection, corresponding to a set level, a column set to zero level, the corresponding
diode is bright; as to the first light, 9 high level 13 low level, the first point is bright; if the first line is
light, the 9 feet meets high level, and 13,3,4,10,6,11,15,16 these pins low level. So the first line will
be light to the first light column, 13 of the low level, and 9,14,8,12,1,7,2,5) to the high level, then
the first column will be lit.
Generally we use the dot matrix display Chinese characters is a 16 * 16 dot matrix font font, the
so-called 16 * 16, is each Chinese character in the longitudinal, cross each of the 16 points in the
region show. That is to say with four 8 * 8 dot matrix into a 16 * 16 dot matrix. As shown in the
following illustration, "you" is corresponding to light, because our lattice in the column is low level
effectively, and the row line is active high, so to show "you" word, it bit code information to take
anti, namely all columns (13 to 16 feet) send (1111011101111111,0xF7,0x7F ), and the first line (9
feet) to send a signal, then first send. Sending the second line to display data (13 to 16 feet) to send
1111011101111111,0xF7,0x7F, and the second line (14 feet) to send signal 1. By analogy, as long as
each row of data shows that the time interval is short enough, to suspend the effects of the use of
34
Http://www.kumantech.com kuman
human vision, so send 16 times scanning data after 16, you will see a "you" word; the second kind
of method of data sent is matrix signal sent to the line of the re scan the column is the same
reason. Similarly to the word "you" to illustrate, 16 (9,14,8,12 , 1,7,2,5) send
(0000000000000000,0x00,0x00) and the first column (13 feet) to send, "0". Similarly scanning the
second column. When the line of sent 16 data column scanning the 16 times a "you" word is
displayed the.
● ● ●
● ●
● ●
● ●
● ●
● ●
● ● ●
Therefore, formation of the column code to 00h, 00h, 3EH, 41h, 41h, 3EH, 00h, 00h; as long as the these
codes are respectively sent to the corresponding column above, you can achieve "0" digital display.
Components
35
Http://www.kumantech.com kuman
*******************************************************************************
Instance code:
//the pin to control ROW
const int row1 = 2; // the number of the row pin 9
const int row2 = 3; // the number of the row pin 14
const int row3 = 4; // the number of the row pin 8
const int row4 = 5; // the number of the row pin 12
const int row5 = 17; // the number of the row pin 1
const int row6 = 16; // the number of the row pin 7
const int row7 = 15; // the number of the row pin 2
const int row8 = 14; // the number of the row pin 5
//the pin to control COl
const int col1 = 6; // the number of the col pin 13
const int col2 = 7; // the number of the col pin 3
const int col3 = 8; // the number of the col pin 4
const int col4 = 9; // the number of the col pin 10
const int col5 = 10; // the number of the col pin 6
const int col6 = 11; // the number of the col pin 11
const int col7 = 12; // the number of the col pin 15
const int col8 = 13; // the number of the col pin 16
void setup(){
36
Http://www.kumantech.com kuman
int i = 0 ;
for(i=2;i<18;i++)
{
pinMode(i, OUTPUT);
}
pinMode(row5, OUTPUT);
pinMode(row6, OUTPUT);
pinMode(row7, OUTPUT);
pinMode(row8, OUTPUT);
for(i=2;i<18;i++) {
digitalWrite(i, LOW);
}
digitalWrite(row5, LOW);
digitalWrite(row6, LOW);
digitalWrite(row7, LOW);
digitalWrite(row8, LOW);
}
void loop(){
int i;
//the row # 1 and col # 1 of the LEDs turn on
digitalWrite(row1, HIGH);
digitalWrite(row2, LOW);
digitalWrite(row3, LOW);
digitalWrite(row4, LOW);
digitalWrite(row5, LOW);
digitalWrite(row6, LOW);
digitalWrite(row7, LOW);
digitalWrite(row8, LOW);
digitalWrite(col1, LOW);
digitalWrite(col2, HIGH);
digitalWrite(col3, HIGH);
digitalWrite(col4, HIGH);
digitalWrite(col5, HIGH);
digitalWrite(col6, HIGH);
digitalWrite(col7, HIGH);
digitalWrite(col8, HIGH);
delay(1000);
//turn off all
for(i=2;i<18;i++) {
digitalWrite(i, LOW);
}
delay(1000);
}
37
Http://www.kumantech.com kuman
***********************************************************************
The other experimental code is as follows:
Display A this letter, then the position in the dot matrix 1 through dynamic scanning display
code:
#define
display_array_size 8
// ascii 8x8 dot font
#define data_null 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // null char
#define data_ascii_A 0x02,0x0C,0x18,0x68,0x68,0x18,0x0C,0x02 /*"A",0*/
/**
**"A"
#define A { //
{0, 0, 0, 0, 0, 0, 1, 0}, //0x02
{0, 0, 0, 0, 1, 1, 0, 0}, //0x0C
{0, 0, 0, 1, 1, 0, 0, 0}, //0x18
{0, 1, 1, 0, 1, 0, 0, 0}, //0x68
{0, 1, 1, 0, 1, 0, 0, 0}, //0x68
{0, 0, 0, 1, 1, 0, 0, 0}, //0x18
{0, 0, 0, 0, 1, 1, 0, 0}, //0x0C
{0, 0, 0, 0, 0, 0, 1, 0} //0x02
}
**/
#define data_ascii_B 0x00,0x7E,0x52,0x52,0x52,0x52,0x2C,0x00 /*"B",1*/
#define data_ascii_C 0x00,0x3C,0x66,0x42,0x42,0x42,0x2C,0x00 /*"C",2*/
#define data_ascii_D 0x00,0x7E,0x42,0x42,0x42,0x66,0x3C,0x00 /*"D",3*/
#define data_ascii_E 0x00,0x7E,0x52,0x52,0x52,0x52,0x52,0x42 /*"E",4*/
#define data_ascii_F 0x00,0x7E,0x50,0x50,0x50,0x50,0x50,0x40 /*"F",5*/
#define data_ascii_G 0x00,0x3C,0x66,0x42,0x42,0x52,0x16,0x1E /*"G",6*/
#define data_ascii_H 0x00,0x7E,0x10,0x10,0x10,0x10,0x7E,0x00 /*"H",7*/
#define data_ascii_I 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00 /*"I",8*/
38
Http://www.kumantech.com kuman
// display array
byte data_ascii[][display_array_size] = {
data_null,
data_ascii_A, data_ascii_B,
data_ascii_C,
data_ascii_D,
data_ascii_E,
data_ascii_F,
data_ascii_G,
data_ascii_H,
data_ascii_I,
};
//the pin to control ROW
const int row1 = 2; // the number of the row pin 24
const int row2 = 3; // the number of the row pin 23
const int row3 = 4; // the number of the row pin 22
const int row4 = 5; // the number of the row pin 21
const int row5 = 17; // the number of the row pin 4
const int row6 = 16; // the number of the row pin 3
const int row7 = 15; // the number of the row pin 2
const int row8 = 14; // the number of the row pin 1
//the pin to control COl
const int col1 = 6; // the number of the col pin 20
const int col2 = 7; // the number of the col pin 19
const int col3 = 8; // the number of the col pin 18
const int col4 = 9; // the number of the col pin 17
const int col5 = 10; // the number of the col pin 16
const int col6 = 11; // the number of the col pin 15
const int col7 = 12; // the number of the col pin 14
const int col8 = 13; // the number of the col pin 13
39
Http://www.kumantech.com kuman
{
digitalWrite(j, HIGH); }
switch(colNum)
{
case 1: digitalWrite(col1, LOW); break;
case 2: digitalWrite(col2, LOW); break;
case 3: digitalWrite(col3, LOW); break;
case 4: digitalWrite(col4, LOW); break;
case 5: digitalWrite(col5, LOW); break;
case 6: digitalWrite(col6, LOW); break;
case 7: digitalWrite(col7, LOW); break;
case 8: digitalWrite(col8, LOW); break;
default: break;
}
for(j = 1 ;j < 9; j++)
{
temp = (0x80)&(temp) ;
if(temp==0)
{
temp = rowNum<<j;
continue;
}
switch(j)
{
case 1: digitalWrite(row1, HIGH); break;
case 2: digitalWrite(row2, HIGH); break;
case 3: digitalWrite(row3, HIGH); break;
case 4: digitalWrite(row4, HIGH); break;
case 5: digitalWrite(row5, HIGH); break;
case 6: digitalWrite(row6, HIGH); break;
case 7: digitalWrite(row7, HIGH); break;
case 8: digitalWrite(row8, HIGH); break;
default: break;
}
temp = rowNum<<j;
}
}
void setup(){
int i = 0 ;
for(i=2;i<18;i++)
{
pinMode(i, OUTPUT);
}
40
Http://www.kumantech.com kuman
for(i=2;i<18;i++) {
digitalWrite(i, LOW);
}
}
void loop(){
int t1;
int l;
int arrage;
for(arrage=0;arrage<10;arrage++)
{
for(l=0;l<512;l++)
{
for(t1=0;t1<8;t1++)
{
displayNum(data_ascii[arrage][t1],(t1+1));
}
}
}
}
Specifications:
Voltage: 5V
Color: Black + silver gray
Package dimension:
77x42x13mm
Weight: 5g
41
Http://www.kumantech.com kuman
Test Requires
Arduino Controller × 1
USB Cable × 1
Buzzer Module × 1
10K potentiometer(10K) × 1
Connection:
42
Http://www.kumantech.com kuman
We can use potentiometer to change delay time, then we can change buzzer frequency.
Here we add a button switch to control the buzzer, so we can simulate a simple doorbell, when the
Connect way:
Code:
43
Http://www.kumantech.com kuman
pinMode(speakerPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
// Read the key to an initial value, here in the circuit, I was in the default high, so the initial value is high;
buttonState = digitalRead(buttonPin);
/*If the button is high, then the buzzer does not ring;
Because I just started in the hardware circuit in the initial value is high, so the if condition was established, the
buzzer does not ring
*/
if (buttonState == HIGH) {
digitalWrite(speakerPin,LOW);
}
else {
//The value of the button here is low (also when the button is pressed).
digitalWrite(speakerPin,HIGH);
}
}
int speakerPin = 8;
byte song_table[] = { 30, 30, 30, 40, 50, 60, 70, 80, 90, 100,110, 120, 130, 140,
150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 250, 240, 230, 220, 210, 200, 190, 180,
170, 160, 150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 30, 30 };
int MAX = 50;
int count = 0;
void setup() {
pinMode(speakerPin, OUTPUT);
}
void loop() {
analogWrite(speakerPin,song_table[count]);
count ++;
if (count > MAX) {
count = 0;
44
Http://www.kumantech.com kuman
}
delay(50);
}
45
Http://www.kumantech.com kuman
A buzzer is a great tool in your experiments whenever you want to make some sounds.
Components
- 1 * KUMAN Uno board
- 1 * Breadboard
- 1 * USB data cable
- 1 * Buzzer (Active)
- Jumper wires
Experimental Principle
As a type of electronic buzzer with an integrated structure, buzzers, which are supplied by DC
power, are widely used in computers, printers, photocopiers, alarms, electronic toys, automotive
electronic devices, telephones, timers and other electronic products for voice devices. Buzzers
can be categorized as active and passive ones (see the following picture). Turn the pins of two
buzzers face up, and the one with a green circuit board is a passive buzzer, while the other
enclosed with a black tape is an active one
The
Experimental Procedures
Step 1: Build the circuit
46
Http://www.kumantech.com kuman
Code
// Buzzer
// buzzer make sounds
//Email:[email protected]
/***********************************/
int buzzer = 12;//the pin of the active buzzer
void setup()
{
pinMode(buzzer,OUTPUT);//initialize the buzzer pin as an output
}
void loop()
47
Http://www.kumantech.com kuman
{
unsigned char i; //define a variable
while(1)
{
//output an frequency
for(i=0;i<80;i++)
{
digitalWrite(buzzer,HIGH);
delay(1);//wait for 1ms
digitalWrite(buzzer,LOW);
delay(1);//wait for 1ms
}
//output another frequency
for(i=0;i<100;i++)
{
digitalWrite(buzzer,HIGH);
delay(2);//wait for 2ms
digitalWrite(buzzer,LOW);
delay(2);//wait for 2ms
}
}
}
/****************************************/
Arduino to complete the interactive works there are many, the most common also is the most commonly used is
sound and light show, the front has been with LED lights in doing the experiment, the experiment let everyone's
circuit sound, voice of the most common components is a buzzer and a speaker, the comparison of the two buzzer
is more simple and easier to use so we this experiment with buzzer.
Buzzer and its principle
(一)Introduction of buzzer
1 . The action of buzzer buzzer is an integrated structure of the electronic buzzer, DC
voltage power supply, widely used in computer, printers, photocopiers, alarm, electronic
toys, automotive electronics, telephone, timers, etc. electronic products for sound devices.
2 . Buzzer buzzer classification is divided into two types of piezoelectric buzzer and
electromagnetic buzzer。
3 . Buzzer circuit graphics symbol buzzer in the circuit with the letter "H" or "HA" (the old
standard with "FM", "LB", "JD", etc.)。
(二)Structure principle of buzzer
1The piezoelectric buzzer buzzer is mainly composed of a multi harmonic oscillator, a
piezoelectric buzzing piece, an impedance matching device and a resonance box, a shell
and the like.
The multi harmonic oscillator is composed of a transistor or an integrated circuit, when the
power supply is switched on, the 1.5~15V DC operating voltage is switched on, the multi
harmonic oscillator is played and the audio signal of the 1.5~2.5kHZ is output, and the
48
Http://www.kumantech.com kuman
49
Http://www.kumantech.com kuman
digitalWrite(buzzer,LOW);//No sound
delay(2);//delay 2ms
}
}
}
Download the program, the buzzer experiment is completed.
50
Http://www.kumantech.com kuman
This test uses the Arduino direct drive 1602 liquid crystal display text
1602 liquid crystal in the application is very wide, the initial 1602 liquid crystal is used HD44780 controller, and
now the 1602 modules of the various manufacturers are basically using a compatible with IC, so the
characteristics are basically the same.
Main technical parameters of 1602LCD
Display capacity is 16 x 2 characters;
Chip operating voltage is 4.5 ~ 5.5V;
Operating current is 2.0mA (5.0V);
The best operating voltage of the module is 5.0V;
Character size 2.95 x 4.35 (W * H) mm.
interface specification :
1, a group of two groups of power supply is a module of the power supply is a group of backlight power supply is
generally used 5V power supply. This test backlight using 3.3V power supply can work.
2 、 VL is a regulator of the contrast of the pin, series is not greater than 5K potentiometer to adjust. This
experiment uses 1K ohm resistor to set the contrast. Its connection points high potential and low potential
connection, the use of low potential connection, series 1K ohm resistance after GND.
3、RS is a lot of liquid crystal on the pin is the command / data selection pin the pin level is high when the data
indicated that the data will be carried out.。
4 、 RW is also a lot of liquid crystal on the pin is the choice of reading and writing the pin level is high is the
representation of the liquid crystal to read operation for the low time that the write operation.
5 、 E also a lot of liquid crystal module this pin is usually on the bus signal stability after the signal to a positive
pulse notice to read the data in this pin for the high level when the bus is not allowed to change.
51
Http://www.kumantech.com kuman
7、BLA is the back light source cathode, BLK is the back light source cathode.
1602 the basic operation of the liquid crystal is divided into the following four kinds:
52
Http://www.kumantech.com kuman
1602
direct
53
Http://www.kumantech.com kuman
communication with Arduino, according to the product manual description, divided into 8 connection method and
4 connection method, we first use the 8 connection method for the experiment.
Code as follows
int DI = 12;
int RW = 11;
int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};//Use an array to define the pins needed by the bus
int Enable = 2;
54
Http://www.kumantech.com kuman
int i = 0;
for (i=DB[0]; i <= DI; i++) //Bus assignment
{
digitalWrite(i,value & 01);//Because the 1602 liquid crystal signal recognition is D7-D0 (not D0-D7), here is
used to reverse the signal.
value >>= 1;
}
digitalWrite(Enable,LOW);
delayMicroseconds(1);
digitalWrite(Enable,HIGH);
delayMicroseconds(1); //delay 1ms
digitalWrite(Enable,LOW);
delayMicroseconds(1); // delay 1ms
}
55
Http://www.kumantech.com kuman
LcdDataWrite('W');
LcdDataWrite('e');
LcdDataWrite('l');
LcdDataWrite('c');
LcdDataWrite('o');
LcdDataWrite('m');
LcdDataWrite('e');
LcdDataWrite(' ');
LcdDataWrite('t');
LcdDataWrite('o');
delay(10);
LcdCommandWrite(0xc0+1); // Defines the cursor position as second rows and second positions
delay(10);
LcdDataWrite('g');
LcdDataWrite('e');
LcdDataWrite('e');
LcdDataWrite('k');
LcdDataWrite('-');
LcdDataWrite('w');
LcdDataWrite('o');
LcdDataWrite('r');
LcdDataWrite('k');
LcdDataWrite('s');
56
Http://www.kumantech.com kuman
LcdDataWrite('h');
LcdDataWrite('o');
LcdDataWrite('p');
delay(5000);
LcdCommandWrite(0x01); // The screen is empty, the cursor position is zero
delay(10);
LcdDataWrite('I');
LcdDataWrite(' ');
LcdDataWrite('a');
LcdDataWrite('m');
LcdDataWrite(' ');
LcdDataWrite('h');
LcdDataWrite('o');
LcdDataWrite('n');
LcdDataWrite('g');
LcdDataWrite('y');
LcdDataWrite('i');
delay(3000);
LcdCommandWrite(0x02); //Set the pattern for the new text to replace the old text, no new text display the same
place
delay(10);
LcdCommandWrite(0x80+5); //Defines the cursor position as the first line of the sixth position
delay(10);
LcdDataWrite('t');
LcdDataWrite('h');
LcdDataWrite('e');
LcdDataWrite(' ');
LcdDataWrite('a');
LcdDataWrite('d');
LcdDataWrite('m');
LcdDataWrite('i');
LcdDataWrite('n');
delay(5000);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ᄃ int DI = 12;
ᄃ int RW = 11;
ᄃ int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};//Use an array to define the pins needed by the bus
ᄃ int Enable = 2;
ᄃ
ᄃ void LcdCommandWrite(int value) {
ᄃ // Define all pins
57
Http://www.kumantech.com kuman
ᄃ int i = 0;
ᄃ for (i=DB[0]; i <= DI; i++) //Bus assignment
ᄃ{
ᄃ digitalWrite(i,value & 01);//Because the 1602 liquid crystal signal recognition is D7-D0 (not D0-D7),
here is used to reverse the signal.
ᄃ value >>= 1;
ᄃ }
ᄃ digitalWrite(Enable,LOW);
ᄃ delayMicroseconds(1);
ᄃ digitalWrite(Enable,HIGH);
ᄃ delayMicroseconds(1); // delay1ms
ᄃ digitalWrite(Enable,LOW);
ᄃ delayMicroseconds(1); // delay 1ms
ᄃ}
ᄃ
ᄃ void LcdDataWrite(int value) {
ᄃ // Define all pins
ᄃ int i = 0;
ᄃ digitalWrite(DI, HIGH);
ᄃ digitalWrite(RW, LOW);
ᄃ for (i=DB[0]; i <= DB[7]; i++) {
ᄃ digitalWrite(i,value & 01);
ᄃ value >>= 1;
ᄃ }
ᄃ digitalWrite(Enable,LOW);
ᄃ delayMicroseconds(1);
ᄃ digitalWrite(Enable,HIGH);
ᄃ delayMicroseconds(1);
ᄃ digitalWrite(Enable,LOW);
ᄃ delayMicroseconds(1); //delay 1ms
ᄃ}
ᄃ
ᄃ void setup (void) {
ᄃ int i = 0;
ᄃ for (i=Enable; i <= DI; i++) {
ᄃ pinMode(i,OUTPUT);
ᄃ }
ᄃ delay(100);
ᄃ // After a short pause, LCD
ᄃ // For LCD control needs
ᄃ LcdCommandWrite(0x38); // Set to 8-bit interface, 2 line display, 5x7 text size
ᄃ delay(64);
ᄃ LcdCommandWrite(0x38); // Set to 8-bit interface, 2 line display, 5x7 text size
ᄃ delay(50);
58
Http://www.kumantech.com kuman
59
Http://www.kumantech.com kuman
ᄃ LcdDataWrite('n');
ᄃ LcdDataWrite('o');
ᄃ LcdDataWrite('p');
ᄃ delay(5000);
ᄃ LcdCommandWrite(0x01); // The screen is empty, the cursor position is zero
ᄃ delay(10);
ᄃ LcdDataWrite('I');
ᄃ LcdDataWrite(' ');
ᄃ LcdDataWrite('a');
ᄃ LcdDataWrite('m');
ᄃ LcdDataWrite(' ');
ᄃ LcdDataWrite('k');
ᄃ LcdDataWrite('u');
ᄃ LcdDataWrite('m');
ᄃ LcdDataWrite('a');
ᄃ LcdDataWrite('n');
ᄃ delay(3000);
ᄃ LcdCommandWrite(0x02); /*Set the pattern for the new text to replace the old text, no new text display
the same place*/
ᄃ delay(10);
ᄃ LcdCommandWrite(0x80+5); //Defines the cursor position as the first line of the sixth position
ᄃ delay(10);
ᄃ LcdDataWrite('t');
ᄃ LcdDataWrite('h');
ᄃ LcdDataWrite('e');
ᄃ LcdDataWrite(' ');
ᄃ LcdDataWrite('a');
ᄃ LcdDataWrite('d');
ᄃ LcdDataWrite('m');
ᄃ LcdDataWrite('i');
ᄃ LcdDataWrite('n');
ᄃ delay(5000);
ᄃ}
60
Http://www.kumantech.com kuman
61
Http://www.kumantech.com kuman
After the hardware connection, the following code is uploaded to the control panel to see the effect.
int LCD1602_RS=12;
int LCD1602_RW=11;
int LCD1602_EN=10;
int DB[] = { 6, 7, 8, 9};
char str1[]="Welcome to";
char str2[]="geek-workshop";
char str3[]="this is the";
char str4[]="4-bit interface";
62
Http://www.kumantech.com kuman
int i,temp;
digitalWrite( LCD1602_RS,LOW);
digitalWrite( LCD1602_RW,LOW);
digitalWrite( LCD1602_EN,LOW);
digitalWrite( LCD1602_EN,HIGH);
delayMicroseconds(1);
digitalWrite( LCD1602_EN,LOW);
digitalWrite( LCD1602_EN,HIGH);
delayMicroseconds(1);
digitalWrite( LCD1602_EN,LOW);
}
digitalWrite( LCD1602_EN,HIGH);
delayMicroseconds(1);
63
Http://www.kumantech.com kuman
digitalWrite( LCD1602_EN,LOW);
digitalWrite( LCD1602_EN,HIGH);
delayMicroseconds(1);
digitalWrite( LCD1602_EN,LOW);
}
64
Http://www.kumantech.com kuman
}
delay(100);
LCD_Command_Write(0x28);//4 lines and 2 lines 5x7
delay(50);
LCD_Command_Write(0x06);
delay(50);
LCD_Command_Write(0x0c);
delay(50);
LCD_Command_Write(0x80);
delay(50);
LCD_Command_Write(0x01);
delay(50);
}
Common view copy code to save code print code
ᄃ int LCD1602_RS=12;
ᄃ int LCD1602_RW=11;
ᄃ int LCD1602_EN=10;
ᄃ int DB[] = { 6, 7, 8, 9};
ᄃ char str1[]="Welcome to";
ᄃ char str2[]="KUMAN Arduino";
ᄃ char str3[]="this is the";
ᄃ char str4[]="4-bit interface";
ᄃ
ᄃ void LCD_Command_Write(int command)
ᄃ{
ᄃ int i,temp;
65
Http://www.kumantech.com kuman
ᄃ digitalWrite( LCD1602_RS,LOW);
ᄃ digitalWrite( LCD1602_RW,LOW);
ᄃ digitalWrite( LCD1602_EN,LOW);
ᄃ
ᄃ temp=command & 0xf0;
ᄃ for (i=DB[0]; i <= 9; i++)
ᄃ {
ᄃ digitalWrite(i,temp & 0x80);
ᄃ temp <<= 1;
ᄃ }
ᄃ
ᄃ digitalWrite( LCD1602_EN,HIGH);
ᄃ delayMicroseconds(1);
ᄃ digitalWrite( LCD1602_EN,LOW);
ᄃ
ᄃ temp=(command & 0x0f)<<4;
ᄃ for (i=DB[0]; i <= 10; i++)
ᄃ {
ᄃ digitalWrite(i,temp & 0x80);
ᄃ temp <<= 1;
ᄃ }
ᄃ
ᄃ digitalWrite( LCD1602_EN,HIGH);
ᄃ delayMicroseconds(1);
ᄃ digitalWrite( LCD1602_EN,LOW);
ᄃ}
ᄃ
ᄃ void LCD_Data_Write(int dat)
ᄃ{
ᄃ int i=0,temp;
ᄃ digitalWrite( LCD1602_RS,HIGH);
ᄃ digitalWrite( LCD1602_RW,LOW);
ᄃ digitalWrite( LCD1602_EN,LOW);
ᄃ
ᄃ temp=dat & 0xf0;
ᄃ for (i=DB[0]; i <= 9; i++)
ᄃ {
ᄃ digitalWrite(i,temp & 0x80);
ᄃ temp <<= 1;
ᄃ }
ᄃ
ᄃ digitalWrite( LCD1602_EN,HIGH);
ᄃ delayMicroseconds(1);
ᄃ digitalWrite( LCD1602_EN,LOW);
66
Http://www.kumantech.com kuman
ᄃ
ᄃ temp=(dat & 0x0f)<<4;
ᄃ for (i=DB[0]; i <= 10; i++)
ᄃ {
ᄃ digitalWrite(i,temp & 0x80);
ᄃ temp <<= 1;
ᄃ }
ᄃ
ᄃ digitalWrite( LCD1602_EN,HIGH);
ᄃ delayMicroseconds(1);
ᄃ digitalWrite( LCD1602_EN,LOW);
ᄃ}
ᄃ
ᄃ void LCD_SET_XY( int x, int y )
ᄃ{
ᄃ int address;
ᄃ if (y ==0) address = 0x80 + x;
ᄃ else address = 0xC0 + x;
ᄃ LCD_Command_Write(address);
ᄃ}
ᄃ
ᄃ void LCD_Write_Char( int x,int y,int dat)
ᄃ{
ᄃ LCD_SET_XY( x, y );
ᄃ LCD_Data_Write(dat);
ᄃ}
ᄃ
ᄃ void LCD_Write_String(int X,int Y,char *s)
ᄃ{
ᄃ LCD_SET_XY( X, Y ); //Set address
ᄃ while (*s) / /Write string
ᄃ {
ᄃ LCD_Data_Write(*s);
ᄃ s ++;
ᄃ }
ᄃ}
ᄃ
ᄃ void setup (void)
ᄃ{
ᄃ int i = 0;
ᄃ for (i=6; i <= 12; i++)
ᄃ {
ᄃ pinMode(i,OUTPUT);
ᄃ }
67
Http://www.kumantech.com kuman
ᄃ delay(100);
ᄃ LCD_Command_Write(0x28);//4 lines and 2 lines 5x7
ᄃ delay(50);
ᄃ LCD_Command_Write(0x06);
ᄃ delay(50);
ᄃ LCD_Command_Write(0x0c);
ᄃ delay(50);
ᄃ LCD_Command_Write(0x80);
ᄃ delay(50);
ᄃ LCD_Command_Write(0x01);
ᄃ delay(50);
ᄃ
ᄃ}
ᄃ
ᄃ void loop (void)
ᄃ{
ᄃ LCD_Command_Write(0x01);
ᄃ delay(50);
ᄃ LCD_Write_String(3,0,str1);//First lines, fourth addresses from
ᄃ delay(50);
ᄃ LCD_Write_String(1,1,str2);//Second lines, second addresses from
ᄃ delay(5000);
ᄃ LCD_Command_Write(0x01);
ᄃ delay(50);
ᄃ LCD_Write_String(0,0,str3);
ᄃ delay(50);
ᄃ LCD_Write_String(0,1,str4);
ᄃ delay(5000);
ᄃ
ᄃ}
68
Http://www.kumantech.com kuman
Bread board *1
69
Http://www.kumantech.com kuman
70
Http://www.kumantech.com kuman
71
Http://www.kumantech.com kuman
Digital tube is a common display digital display, daily life, for example:
electromagnetic oven, full automatic washing machine, solar water temperature
display, electronic clock... And so on the number of not very few. To control the
display of digital control principle, it is necessary to
The cathode of field digital tube, digital tube display digital tube is a kind of
semiconductor light emitting devices, the basic unit is the light-emitting diode, digital
tube according to the number of segments is divided into seven segment digital tube
and eight digital tube, eight digital tube than seven segment digital tube more than a
light emitting diode unit (more than one decimal point), the use of eight digital tube.
According to the light emitting diode unit connection mode is divided into common
anode and cathode nixie tube. Yang digital tube is refers to all the light emitting diode
anode received together form a common anode (COM) digital tube anode in the
application should be public com received + 5V, when a light emitting diode for low
72
Http://www.kumantech.com kuman
electricity at ordinary times When a field of cathode for high electric power, the
corresponding field is not bright. Common cathode digital tube is all led to form a
common cathode (COM) digital tube. Common cathode digital tube in the application
should be COM to the ground GND, when a field light-emitting diode anode for high
power, the corresponding field is lit. When a field of anode for low power, the
corresponding field is not bright.
73
Http://www.kumantech.com kuman
We refer to the physical connection diagram to connect the circuit according to the schematic
diagram.
74
Http://www.kumantech.com kuman
Digital control of a total of seven sections show the number of segments, there is a
display of the decimal point. When the digital tube display digital, as long as the
corresponding period of light can be. For example: the digital tube display digital 1, C,
B section will be lit. In the main program every 2S display a number, 1 to 8 digital
display.
Reference source code:
//Set pin control all digital IO
int a=7;//Definition of digital interface 7 connected a segment digital tube
int b=6;// Definition of digital interface 6 connected B segment digital tubeint c=5;// Definition of digital interface
75
Http://www.kumantech.com kuman
76
Http://www.kumantech.com kuman
digitalWrite(d,HIGH);
digitalWrite(dp,LOW);
digitalWrite(f,LOW);
digitalWrite(e,LOW);
}
void digital_4(void) //Display number 4
{
digitalWrite(c,HIGH);
digitalWrite(b,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dp,LOW);
digitalWrite(a,LOW);
digitalWrite(e,LOW);
digitalWrite(d,LOW);
}
void digital_5(void) //Display number 5
{
unsigned char j;
digitalWrite(a,HIGH);
digitalWrite(b, LOW);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e, LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dp,LOW);
}
void digital_6(void) //Display number 6
{
unsigned char j;
for(j=7;j<=11;j++)
digitalWrite(j,HIGH);
digitalWrite(c,HIGH);
digitalWrite(dp,LOW);
digitalWrite(b,LOW);
}
void digital_7(void) //Display number7
{
unsigned char j;
for(j=5;j<=7;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
for(j=8;j<=11;j++)
77
Http://www.kumantech.com kuman
digitalWrite(j,LOW);
}
void digital_8(void) //Display number 8
{
unsigned char j;
for(j=5;j<=11;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
}
void digital_9(void) //Display number 5
{
unsigned char j;
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e, LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dp,LOW);
}
void setup()
{
int i;//defined variable
for(i=4;i<=11;i++)
pinMode(i,OUTPUT);//Set the 11 to 4 pin for the output mode
}
void loop()
{
while(1)
{
digital_0();//Display number 1
delay(1000);//delay 1s
digital_1();//Display number 1
delay(1000);//delay 1s
digital_2();//Display number2
delay(1000); //delay 1s
digital_3();//Display number3
delay(1000); //delay 1s
digital_4();//Display number 4
delay(1000); //delay 1s
digital_5();//Display number 5
delay(1000); //delay 1s
digital_6();//Display number 6
78
Http://www.kumantech.com kuman
delay(1000); //delay 1s
digital_7();//Display number7
delay(1000); //delay 1s
digital_8();//Display number 8
delay(1000); //delay 1s
digital_9();//Display number 9
delay(1000); //delay 1s
}
}
This experiment is the use of Arduino to drive a total of four digital tube. The limit of the
flow resistance is essential to drive the digital tube, the current limit resistor has two
kinds of connection, a total of 4 D1-D4. This connection is less demand resistance, but
will produce a different number of digital brightness will not be the same, 8 of the most
dark. This method is the other 8 pin, the brightness of the same, but with more
resistance 220 100 8 ohm resistor, so use 220 instead of 10. 0 ohm brightness will be
relatively high.
79
Http://www.kumantech.com kuman
4 digital tube a total of 12 pins, the decimal point is placed in front of the bottom, the
lower left corner of the 1, the other pins in the order of the counterclockwise rotation.
The upper left corner for the largest 12 pin.
80
Http://www.kumantech.com kuman
81
Http://www.kumantech.com kuman
82
Http://www.kumantech.com kuman
//display 1234
//Set cathode interface
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 6;
int g = 7;
int dp = 8;
//Set anode interface
int d4 = 9;
int d3 = 10;
int d2 = 11;
83
Http://www.kumantech.com kuman
int d1 = 12;
//Set variable
long n = 1230;
int x = 100;
int del = 55; //Here to fine tune the clock
void setup()
{
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(dp, OUTPUT);
}
/////////////////////////////////////////////////////////////
void loop()
{
Display(1, 1);
Display(2, 2);
Display(3, 3);
Display(4, 4);
}
///////////////////////////////////////////////////////////////
void WeiXuan(unsigned char n)//
{
switch(n)
{
case 1:
digitalWrite(d1,LOW);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
case 2:
digitalWrite(d1, HIGH);
digitalWrite(d2, LOW);
digitalWrite(d3, HIGH);
84
Http://www.kumantech.com kuman
digitalWrite(d4, HIGH);
break;
case 3:
digitalWrite(d1,HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, LOW);
digitalWrite(d4, HIGH);
break;
case 4:
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, LOW);
break;
default :
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
}
}
void Num_0()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
digitalWrite(dp,LOW);
}
void Num_1()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp,LOW);
}
85
Http://www.kumantech.com kuman
void Num_2()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
}
void Num_3()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
}
void Num_4()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
}
void Num_5()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
}
86
Http://www.kumantech.com kuman
void Num_6()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
}
void Num_7()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp,LOW);
}
void Num_8()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
}
void Num_9()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
}
87
Http://www.kumantech.com kuman
88
Http://www.kumantech.com kuman
Clear() ; //Vanishing
}
Copy the following code to download to the control panel to see the effect chart.
Experimental
results for
digital tube
display 1234,
Note: the
connection
when the
need for
patience,
careful, not
even any
wrong line,
when
garbled, first
check the
line.
89
Http://www.kumantech.com kuman
Wiring diagram:
Components
-1 * KUMAN Uno board
- 1 * USB data cable
- 1 * Tap on a module
- 1 * Jumper wires
Code:
int Led=13;//Define LED interface
int Shock=3//Define vibration sensor interface
int val;//Define numeric variable val
void setup()
{
pinMode(Led,OUTPUT);//Define LED as output interface
pinMode(Shock,INPUT);//Define vibration sensor as output interface
}
void loop()
90
Http://www.kumantech.com kuman
{
val=digitalRead(Shock);//Read the value of the value of the digital interface 3 to val
if(val==HIGH)//When the vibration sensor detects the signal, the LED flashes
{
digitalWrite(Led,LOW);
}
else
{
digitalWrite(Led,HIGH);
}
}
Lesson14 Tilt-Switch
Introduction
The tilt switch used here is a ball one with a metal ball inside. It is used to detect the small angle of
inclination.
Components
- 1 * Kuman Uno board
- 1 * USB data cable
- 1 * Tilt switch
- Several jumper wires
Experimental Principle
91
Http://www.kumantech.com kuman
The principle is very simple. When the switch tilts in a certain angle, the inside ball rolls down and
touches the two contacts which is connected to the outside pins, thus triggering circuits. Otherwise
the ball will stay away from the contacts, thus breaking the circuits.
Experimental Procedures
Step 1: Build the circuit
92
Http://www.kumantech.com kuman
Code
//tilt switch
//tilt the switch, and the LED attached to pin 13 on SunFounder Uno board will light up.
//tilt switch attach to pin2
//Email: [email protected]
//Website: www.sunfounder.com
/*****************************************/
const int ledPin = 13;//the led attach to
void setup()
{
pinMode(ledPin,OUTPUT);//initialize the ledPin as an output
pinMode(2,INPUT);//set pin2 as INPUT
digitalWrite(2, HIGH);//set pin2 as HIGH
}
/******************************************/
void loop()
{
93
Http://www.kumantech.com kuman
94
Http://www.kumantech.com kuman
USB line *1
Ultrasonic *1
Main technical parameters: the use of voltage: DC5V, static current: less than 2mA
level output: high 5V, level output: bottom 0V, induction angle: no more than 15
degrees, detection range: 2cm-450cm, high accuracy of up to 0.2cm
95
Http://www.kumantech.com kuman
Note:1.the module should not be charged connection, if you want to live connection, let the first
module of the GND connection, otherwise it will affect the normal operation of the module.
2, ranging, the area of the measured object is not less than 0.5 square meters and the plane as far
96
Http://www.kumantech.com kuman
Introduction
Ultrasonic ranging module HC - SR04 provides 2cm - 700cm non-contact measurement function, the
ranging accuracy can reach to 3mm.Ensured stable signal within 5m, gradually faded signal outside
5m till disappearing at 7m position.
The modules includes ultrasonic transmitters, receiver and control circuit. The basic principle of
work:
(1) Using IO trigger for at least 10us high level signal;
(2) The Module automatically sends eight 40 kHz and detect whether there is a pulse signal back.
(3) IF the signal back, through high level , time of high output IO duration is the time from sending
ultrasonic to returning. Test distance = (high level time×velocity of sound (340M/S) / 2.
Pin Function:
TRIG: Trigger Pulse Input
ECHO: Echo Pulse Output
97
Http://www.kumantech.com kuman
GND: Ground
VCC: 5V Supply
Features
Working Voltage DC5V
Working Current 16mA
Working Frequency 40Hz
Max Range 700cm, Ensured stable signal within 5m, gradually faded signal outside 5m till
disappearing at 7m position.
Min Range 2cm
Trigger Input Signal 10uS TTL pulse
Echo Output Signal Input TTL lever signal and the range in proportion
Dimension 46x20.5x15 mm
Pricinple:
The Timing diagram is shown below. You only need to supply a short 10uS pulse to the trigger input to start the
ranging, and then the module will send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo. The
Echo is a distance object that is pulse width and the range in proportion .You can calculate the range
through the time interval between sending trigger signal and receiving echo signal. Formula: uS / 58
= centimeters or uS / 148 =inch; or: the range = high level time * velocity (340M/S) / 2; we suggest
to use over 60ms measurement cycle, in order to prevent trigger signal to the echo signal.
Test Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
98
Http://www.kumantech.com kuman
void loop()
{
// Generates a pulse
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
rxTime = pulseIn(Echo, HIGH); //read the Receive time
// Serial.print("rxTime:");
// Serial.println(rxTime);
distance = (float)rxTime * 34 / 2000.0; //Converted into a distance ,cm
if(distance < 800 ) //filter interference signal
{
Serial.print("distance:");
Serial.print(distance); //print it the distance in serial monitor
Serial.println("CM");
lcd.setCursor(6, 0);
lcd.print(distance);//print it in LCD1602
lcd.print("CM");
delay(100);
}
}
99
Http://www.kumantech.com kuman
crystal, polycrystalline and glass, made of semiconductor materials such as plastic. This resistor has a series of
special electrical properties, the basic characteristics is the resistance changes with temperature has a very
significant changes, and volt ampere curve is nonlinear.
2:main features
On the high temperature sensitivity, thermal inertia of small, long life, small volume, simple structure and made of
various kinds of different shape and structure. Therefore, with the development of industrial and agricultural
production, science and technology, this element has been widely used, such as temperature measurement,
temperature control, temperature compensation, liquid level measurement, pressure measurement, fire alarm,
meteorological sounding, the switch circuit, overload protection, suppress voltage fluctuation, time delay,
amplitude stability, automatic gain adjustment, laser and microwave power measurement and so on.
3:characteristic parameter
The main characteristic parameters of the thermistor are the resistance temperature characteristic, the voltage
current characteristic and the thermal time constant.
4:Connection method
5 : Test
code
void setup() {
// initialize
serial
communication
at 9600 bits per
second:
Serial.begin(96
00);
}
// the loop
routine runs over
and over again
forever:
void loop() {
// read the input
on analog pin 0:
int sensorValue
=
analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}
100
Http://www.kumantech.com kuman
The above code onto your board, open the serial port window, you can see the following:
101
Http://www.kumantech.com kuman
Stepping motor is a kind of electric pulse into the angular displacement of the executive
body. Popular point of view: when the stepper driver receives a pulse signal, it drives the
stepper motor according to set the direction of rotation of a fixed angle (and step angle).
You can control the angular displacement by controlling the number of pulses and you
can control the the motor rotation speed and acceleration by controlling the pulse
frequently, so as to achieve the goal.
The following is the experimental use of the stepper motor
下载附件(130.89 KB)
下载附件(64.19 KB)
102
Http://www.kumantech.com kuman
Before using the stepper motor please carefully check the specification, to confirm that
the four phase or two phases, how to connect the various lines, this experiment used
the stepper motor is the four phase, the different colors of the line is defined as follows
picture:
103
Http://www.kumantech.com kuman
Diameter: 28mm
Voltage: 5V
5 line 4 phase can be used with ordinary ULN2003 chip driver, can also be connected to the use of 2 phase
The step into the motor no-load power consumption below 50mA, with 64 times the speed reducer, torque
output can drive heavy load, is very suitable for the development board to use. Note: the stepper motor with 64
times the speed reducer, and without reduction of stepper motor compared, speed is slower, is easy for observation,
the output shaft stick a piece of cardboard.
104
Http://www.kumantech.com kuman
ᄃᄃ
Step motor (five line four phase) driving board (UL2003) test board
105
Http://www.kumantech.com kuman
external SIZE:31×35mm
106
Http://www.kumantech.com kuman
The
下载附件(126.87 KB)
Download the code to the Arduino control panel to see the results.
/*
* Stepper motor with potentiometer rotation
* (or other sensors) using 0 analog inputs
* Use IDE Stepper.h comes with the Arduino library file
#include <Stepper.h>
// Here to set the stepper motor rotation is how many steps
#define STEPS 100
// attached toSet the step number and pin of the stepper motor
Stepper stepper(STEPS, 8, 9, 10, 11);
// Define variables used to store historical readings
int previous = 0;
void setup()
{
// Set the motor at a speed of 90 steps per minute
stepper.setSpeed(90);
}
void loop()
107
Http://www.kumantech.com kuman
{
int val = analogRead(0); // Get sensor readings
stepper.step(val - previous);// Move the number of steps for the current readings less historical readings
previous = val;// Save historical readings }
108
Http://www.kumantech.com kuman
109
Http://www.kumantech.com kuman
internal have a benchmark circuit, generating cycle for 20ms, width of 1.5ms reference signal, will get the DC bias
voltage and the potentiometer voltage compared with that obtained from the voltage difference output. Through the
IC circuit board judge the direction of rotation, and then drive - core motor starts to rotate, through the reduction
gear, the power is transmitted to the swing arm, also by a position detector back to signal, judge whether it has
already reached the location. It is suitable for the The control system which needs to be changed and can be kept in
a certain degree. When the motor speed is certain, the potentiometer is rotated by a cascade speed reduction gear,
the voltage difference is 0, the motor stops rotating, and the angle range of the
110
Http://www.kumantech.com kuman
Steering angle is adjusted PWM (pulse width modulation) signal duty cycle to achieve, standard PWM (pulse
width modulation) signal cycle is fixed to 20ms (50Hz), pulse width distribution should be between 1ms to 2ms,
but in fact pulse width can be from 0.5ms to 2.5ms, pulse width and steering angle of 0 degrees to 180 degrees.
There is a point worth noting, because the steering gear brand is different, for the same signal, different brands of
steering angle will be different.
After knowing the basic knowledge we can learn to control a servo motor, components of the experiments required
rarely need only steering gear A and a jumper bar can be.。
RB - 412 steering gear *1
111
Http://www.kumantech.com kuman
function Arduino function for steering control, the advantages of this control method is to control the 2 way
steering gear, because the Arduino comes with a function only the use of digital 9,10 interface.Arduino drive ability
is limited, need to control more than 1 of the steering gear The source.。
One method
The steering
gear is
connected to
the digital 9
interface.
Write a
program to
turn the
steering gear
to the user
input number
corresponding
to the number
of degrees of
the position,
and the angle
of the print
display to the
screen.
Reference to
source
program A:、
Int
servopin=9; / /
define digital
interface 9
connected servo signal line
112
Http://www.kumantech.com kuman
}
void setup()
{
pinMode(servopin,OUTPUT);//Set steering interface for output interface
Serial.begin(9600);//Connected to the serial port, the baud rate is 9600
Serial.println("servo=o_seral_simple ready" ) ;
}
void loop()//The number of 0 to 0 is converted to a 9 - to 180 angle, and the number of the corresponding number
of LED flashes
{
val=Serial.read();//Read the value of the serial port
if(val>'0'&&val<='9')
{
Val=val-'0'; / / the features into numerical variables
113
Http://www.kumantech.com kuman
void setup()
{
myservo.attach(9);//Definition of steering gear interface (9,10 can, shortcomings can only control 2)
}
void loop()
{
myservo.write(90);//Set the steering angle of the steering gear.
}
Above is to control the steering gear of the two methods, each has its own advantages and disadvantages of each
according to their own preferences and needs to be chosen.
114
Http://www.kumantech.com kuman
photosensitive resistance when the light intensity and the brightness of the LED lights
will have corresponding change.
The following is the required components:
Photosensitive resistor *1
Bread board *1
115
Http://www.kumantech.com kuman
Connected to the program can be written, the experimental program and the PWM
test program is similar to the PWM value in the value of the assignment, according to
our current circuit slightly modified (modified part see reference to source program).
Reference source program:
int potpin=0;//Define the analog interface 0 connect the photosensitive resistance
int ledpin=11;//Define digital interface 11 output PWM adjust LED brightness
int val=0;//Defined variable val
void setup()
{
pinMode(ledpin,OUTPUT);//Define digital interface 11 for output
Serial.begin(9600);//Set the baud rate to 9600
}
void loop()
{
val=analogRead(potpin);//Read the sensor's analog values and assign to val
Serial.println(val);//Display Val variable value
analogWrite(ledpin,val);// Turn on the LED and set the brightness (the maximum value of the PWM output is 255)
delay(10);//Delay 0.01 seconds
}
Here we return sensor values divided by 4. The reason is that the analog input
analogRead () function returns the value of the range is 0 to 1023, and simulation
output analogwrite () function of the output value range is 0 to 255. Downloaded
program and try to change the intensity of the environment where the
photosensitive resistance can see our lights there are corresponding changes. In the
daily life of photosensitive resistance application is very extensive of, usage is also a
lot of, we can
Introduction
116
Http://www.kumantech.com kuman
LM35 is a temperature sensor produced by National Semiconductor. It has very high operational
accuracy and a wide operating range. With small size, low cost and reliability, LM35 is widely
applied in engineering. Since it uses internal compensation, the output can begin with 0 ℃. LM35
has many different packages. Under the normal temperature, the LM35 requires no additional
calibration to reach the accuracy of plus or minus 1/4 ℃. The power supply mode can be classified
as single power source and positive-and-negative double power supply. Its pins are as shown
below.Under the positive-and-negative dual power supply mode, it can measure a negative
temperature. Under the single power supply mode and 25 ℃, the quiescent current is about 50μA
and it has a wide operation voltage range - between 4 to 20V, thus saving electricity.
Components
- 1* KUMAN Uno board
- 1 * Breadboard
- 1 * USB data cable
- 1 * LM35 Temperature Sensor
- 1 * I2C LCD1602
- Several jumper wires
Experimental Principle
The output voltage of the LM35 is proportional to Celsius temperature. When placed in 0 ℃
ambient temperature, it will output 0V. The output voltage will increase 10mV every time when the
temperature increases by 1℃. The calculation formula is as follows:
117
Http://www.kumantech.com kuman
Experimental Procedures
Step 1: Build the circuit
Note: Here you need to add a library. Refer to the file LiquidCrystal_I2C
Step 2: Compile the code
Step 3: Upload the sketch to the KUMAN Uno board
Now, you can see the current temperature displayed on the I2C LCD1602.
118
Http://www.kumantech.com kuman
*****************************************
* name:LM35 Temperature Sensor
* function:
* LM35 output voltage has a linear relation with the Celsius temperature, output of 0 v when 0 ℃,
* every increase 1 ℃, the output voltage increase 10 mv
*****************************************/
//lm35 attach to A0
/****************************************/
#define lmPin A0 //LM35 attach to
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
float tem = 0;
long lmVal = 0;
void setup()
{
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
}
void loop()
{
lmVal = analogRead(lmPin);//read the value of A0
tem = (lmVal * 0.0048828125 * 100);//5/1024=0.0048828125;1000/10=100
lcd.setCursor(5,0);//place the cursor on 5 column,0 row
lcd.print("LM35");//print"LM35"
119
Http://www.kumantech.com kuman
120
Http://www.kumantech.com kuman
2. 220Ωline
resistance*1
3.bread
board*1
4. Bread board
jump line*1tie
The
next
step
we in
121
Http://www.kumantech.com kuman
accordance with the following lights the principle graph links physical map. Here we
use the number 10 interface. Using light-emitting diode (LED), which is connected
with a current limiting resistor, here is a 220 ohm resistor, or the current Congress
burned light-emitting diodes.
The principle map lights:
Physicaldiagramconnectiondiagram:
122
Http://www.kumantech.com kuman
procedure is very simple and the Arduino comes with routine in the blink similar just
13 digital interface for 10 digital interface.。
-----------------------------------------------------------
Reference procedures are as follows:
int ledPin = 10; //Define number 10 interface
void setup()
{
pinMode(ledPin, OUTPUT);//The definition of small interface for output interface
}
void loop()
{
digitalWrite(ledPin, HIGH); //Light the lamp
delay(1000); //Delay 1 seconds
digitalWrite(ledPin, LOW); //Lights out
delay(1000); //Delay 1 seconds
}
---------------------------------------------------------
Download program you can see our 10 small lights flashing in the mouth, so that we
The experimental phenomenon for the LED
flashing, the interval is about one
123
Http://www.kumantech.com kuman
second.
Light flicker experiment is completed.
Lesson22 Infrared-Receiver
Introduction
An infrared-receiver is a component which receives infrared signals and can independently receive
infrared ray and output signals compatible with TTL level. It's similar to a normal plastic-packaged
transistor in size and suitable for all kinds of infrared remote control and infrared transmission.
Components
- 1 * KUMAN Uno board
- 1 * USB data cable
- 1 * Infrared-receiver module
- 1 * Remote controller
- 1 * 3-Pin anti-reverse cable
124
Http://www.kumantech.com kuman
Experimental Principle
Control a certain key (for example, Power key) via a remote controller by programming. When you
press the key, infrared rays will be emitted from the remote control and received by the infrared
receiver, and the LED on the KUMAN Uno board will light up. Connect an LED to pin 13 on the
KUMAN Uno board so that you can see remotely whether the Power key is pressed down.
Experimental Procedures
Step 1: Build the circuit
125
Http://www.kumantech.com kuman
Note: Here you need to add a library. Refer to the description in LIBRARY
Step 2: Compile the code
Step 3: Upload the sketch to the KUMAN Uno board
Now, press the Power key of a remote control, and both the LED attached and that connected to pin
13 on the KUMAN Uno board will light up. Then press any key, the LEDs will light out.
126
Http://www.kumantech.com kuman
1、 I
nfr
are
d
1, experimental device
127
Http://www.kumantech.com kuman
3、 Experimental principle
To decode a remote controller must be aware of the remote control of the encoding way. This product is
used to control the code of the way: NEC agreement. Following the introduction of the NEC protocol:
·NEC protocol description: features: (1) 8 address bits, 8 bit command
(two) for the 2 time in order to address the reliability address bit and the command bit
·Press the
launch
pulse at
once:
The image above shows a typical pulse sequence of NEC. Note: this first send LSB (the most low)
protocol. In the above pulse transmission of the address for the 0x59 command 0x16. a message is from
a high level of 9ms, then there is a low level of 4.5ms, and the command code. The address and
command code. Second times all bits are taken back, can be used for the confirmation of the message.
Because every point and it takes anti length repeat, you can ignore the if you are not interested. Take
128
Http://www.kumantech.com kuman
the counter, you can also expand the address and command, to every 16!
Key press a period of time before the release of the launch pulse:
A command sent once, even on the remote control button is still pressed. When the button has been
pressed, the first 110ms of the pulse and the image above, after each 110ms repeat code transmission.
·repetitive pulse
129
Http://www.kumantech.com kuman
130
Http://www.kumantech.com kuman
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
}
else
{
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
}
Serial.print(" ");
}
Serial.println("");
}
void setup()
{
pinMode(RECV_PIN, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
void loop()
{
if (irrecv.decode(&results))
{
// If it's been at least 1/4 second since the last
// IR received, toggle the relay
if (millis() - last > 250)
{
on = !on;
// digitalWrite(8, on ? HIGH : LOW);
digitalWrite(13, on ? HIGH : LOW);
dump(&results);
}
if (results.value == on1 )
digitalWrite(LED1, HIGH);
if (results.value == off1 )
131
Http://www.kumantech.com kuman
digitalWrite(LED1, LOW);
if (results.value == on2 )
digitalWrite(LED2, HIGH);
if (results.value == off2 )
digitalWrite(LED2, LOW);
if (results.value == on3 )
digitalWrite(LED3, HIGH);
if (results.value == off3 )
digitalWrite(LED3, LOW);
if (results.value == on4 )
digitalWrite(LED4, HIGH);
if (results.value == off4 )
digitalWrite(LED4, LOW);
if (results.value == on5 )
digitalWrite(LED5, HIGH);
if (results.value == off5 )
digitalWrite(LED5, LOW);
if (results.value == on6 )
digitalWrite(LED6, HIGH);
if (results.value == off6 )
digitalWrite(LED6, LOW);
last = millis();
irrecv.resume(); // Receive the next value
}
}
Lesson23 Potentiometer
A potentiometer is a simple knob that provides a variable resistance, which we can read
into the Arduino board as an analog value. In this example, that value controls the rate
at which an LED blinks.
We connect three wires to the Arduino board. The first goes to ground from one of the
outer pins of the potentiometer. The second goes from 5 volts to the other outer pin of
the potentiometer. The third goes from analog input 2 to the middle pin of the
potentiometer.
By turning the shaft of the potentiometer, we change the amount of resistence on either
side of the wiper which is connected to the center pin of the potentiometer. This
changes the relative "closeness" of that pin to 5 volts and ground, giving us a different
analog input. When the shaft is turned all the way in one direction, there are 0 volts
going to the pin, and we read 0. When the shaft is turned all the way in the other
132
Http://www.kumantech.com kuman
direction, there are 5 volts going to the pin and we read 1023. In between, analogRead()
returns a number between 0 and 1023 that is proportional to the amount of voltage
being applied to the pin.
Wiring diagram:
Components:
- 1 * kuman Uno board
- 1 * USB cable
- 1 * 10 k adjustable resistance
- Jumper wires
- 1 * Big bread board
Code:
* ------------------
133
Http://www.kumantech.com kuman
* pin 13. The amount of time the LED will be on and off depends on
*/
int val = 0; // variable to store the value coming from the sensor
void setup() {
void loop() {
134
Http://www.kumantech.com kuman
Description:
135
Http://www.kumantech.com kuman
Components
- 1 * kuman Uno board
- 1 * USB cable
- 1 * Analog Temp module
- Jumper wires
- 1 * Breadboard
Test Code:
#include <math.h>
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print(Thermister(analogRead(0))); // display Fahrenheit
Serial.println("c");
delay(500);
}
Thermistors are also can
measure temperature,
because it combines the
Steinhart - Hart Thermistor
equation, the test code
functions in the double
Thermister (int RawADC) is
just the embodiment of the
equation.
Take a look at the
experimental results:
136
Http://www.kumantech.com kuman
no??????
137
Http://www.kumantech.com kuman
SIG ---------------------------------- D3
Below is the wiring diagram:
Components
- 1 * kuman Uno board
- 1 * USB cable
- 1 * Touch module
- Jumper wires
- 1 * Breadboard
138
Http://www.kumantech.com kuman
digitalWrite(Led,LOW);
}
}
This is RGB 3
color LED module
for Arduino red
green blue
Material: PCB
RGB signal output
3 color: Red,
green, blue
Compatible with
Arduino DIY
project
Components
- 1 * kuman Uno board
- 1 * USB cable
- 1 * RGB module
- Jumper wires
139
Http://www.kumantech.com kuman
- 1 * Breadboard
int val;
void setup() {
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
for(val=255; val>0; val--)
{
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(1);
}
for(val=0; val<255; val++)
{
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(1);
}
Serial.println(val, DEC);
140