Kuman K1Arduino KIT Tutorials
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
2
Http://www.kumantech.com kuman
3
Http://www.kumantech.com kuman
4
Http://www.kumantech.com kuman
5
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
Lesson9 1602 liquid crystal experiment
Lesson 10 74HC595 experiment
Lesson 11 digital tube display experiment
Lesson12 Four bit digital tube
Lesson13 Hit module
Lesson14 Tilt-Switch
Lesson15 ultrasonic distance measuring module
Lesson16 thermal resistance
Lesson17 step motor test
Lesson18 steering gear control experiment
Lesson19 photosensitive lamp experiment
Lesson20 LM35 Temperature Sensor
Lesson21 LED Scintillation test
Lesson22 Infrared-Receiver
Lesson23 Potentiometer
Lesson 24 Analog temperature sensor
Lesson 25 Touch module
Lesson 26 3 color - full color LED Module
6
Http://www.kumantech.com kuman
Download it here.
7
Http://www.kumantech.com kuman
After the download is a compressed package, and then extract
2:Connect the motherboard and the computer, check the "device manager".
Right click on the "unknown device" and then click "new driver"
8
Http://www.kumantech.com kuman
9
Http://www.kumantech.com kuman
Here you can see "Arduino Uno (com3)", it is proved that drive successful installation.
This will start the Arduino IDE, but before you can start programming, you have to tell the Arduino software which
10
Http://www.kumantech.com kuman
type of Arduino board you are using and also select the port to which it is connecting.
To tell the Arduino IDE which type of board you are using. 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.
11
Http://www.kumantech.com kuman
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).
12
Http://www.kumantech.com kuman
Open the IDE and click Sketch > Include > Library > Manage Libraries.
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 can
close the library manager.
13
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 open a
new issue on github.
Importing a .zip Library
Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of the library. Inside 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 unzip the downloaded
library; leave it as-is.
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
Arduino sketches directory.
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 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.)
14
Http://www.kumantech.com kuman
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 library folder should now look like this
(on Windows):
My Documents\Arduino\libraries\ArduinoParty\ArduinoParty.cpp
My Documents\Arduino\libraries\ArduinoParty\ArduinoParty.h
My 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. That's it.
You've installed a library!
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.
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
15
Http://www.kumantech.com kuman
The UNO R3 board has rows of connectors along both sides that are used to connect to several electronic devices
and plug-in 'shields' that extends its capability.
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.
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 an
example sketch for making the 'L' LED blink.
Load the 'Blink' sketch that you will find in the IDE's menu system under File > Examples > 01.Basics
16
Http://www.kumantech.com kuman
When the sketch window opens, enlarge it so that you can see the entire sketch in the window
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'
17
Http://www.kumantech.com kuman
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.
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.
18
Http://www.kumantech.com kuman
Next, the status will change to 'Uploading'. At this point, the LEDs on the Arduino should start to flicker as the
sketch is transferred.
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 that the
wrong serial port is selected.
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.
19
Http://www.kumantech.com kuman
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.
As the comment above it explains, this is giving a name to the pin that the LED is attached to. This is 13 on most
Arduinos, including the UNO and Leonardo.
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() {
}
Every Arduino sketch must have a 'setup' function, and the place where you might want to add instructions of
your own is between the { and the }.
In this case, there is just one command there, which, as the comment states tells the Arduino board that we are
going to use the LED pin as an output.
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,
You are now going to make your LED blink faster. As you might have guessed, the key to this lies in changing the
parameter in () for the 'delay' command.
20
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
A breadboard enables you to prototype circuits quickly, without having to solder the connections. Below is an
example.
21
Http://www.kumantech.com kuman
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 with a
circuit, it could be due to a poor connection on a breadboard.
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 'choke' the
amount of current flowing through it; otherwise, it will burn out!
22
Http://www.kumantech.com kuman
I If you do not use a resistor with an LED, then it may well be destroyed almost immediately, as too much current
will flow through, heating it and destroying the 'junction' where the light is produced.
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Ω.
These resistors all look the same, except that they have different colored stripes on them. These stripes tell you
the value of the resistor.
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
24
Http://www.kumantech.com kuman
wiring diagram
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Ω
25
Http://www.kumantech.com kuman
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 should just be able to notice the difference.
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
Lesson 4 button
26
Http://www.kumantech.com kuman
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 * USB cable
- 1 * Button
- Jumper wires
- 1 * Breadboard
Principle
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.
27
Http://www.kumantech.com kuman
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
28
Http://www.kumantech.com kuman
29
Http://www.kumantech.com kuman
Now, press the button, and the LED on the KUMAN Uno board will light up.
Code:
30
Http://www.kumantech.com kuman
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
}
}
/************************************/
31
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
32
Http://www.kumantech.com kuman
Components:
- 1 * USB cable
- Jumper wires
Code:
void loop()
{
33
Http://www.kumantech.com kuman
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);
}
}
34
Http://www.kumantech.com kuman
35
Http://www.kumantech.com kuman
Figure 8 x 8 dot matrix LED 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 X0=0, Y0=1 can be placed on the X axis or Y axis
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
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
36
Http://www.kumantech.com kuman
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
- 1 * Breadboard
- Jumper wires
37
Http://www.kumantech.com kuman
- 8x8 dot matrix
- 8 * Resistor (220R)
- 1 * USB cable
*******************************************************************************
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
38
Http://www.kumantech.com kuman
void setup(){
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);
}
39
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*/
40
Http://www.kumantech.com kuman
#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*/
// 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
41
Http://www.kumantech.com kuman
digitalWrite(row7, LOW);
digitalWrite(row8, LOW);
for(j=6;j<14;j++)
{
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++)
42
Http://www.kumantech.com kuman
{
pinMode(i, OUTPUT);
}
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:
43
Http://www.kumantech.com kuman
Voltage: 5V
Color: Black + silver gray
Package dimension: 77x42x13mm
Weight: 5g
Test Requires
Arduino Controller × 1
USB Cable × 1
Buzzer Module × 1
10K potentiometer(10K) × 1
Connection:
44
Http://www.kumantech.com kuman
We can use potentiometer to change delay time, then we can change buzzer frequency.
45
Http://www.kumantech.com kuman
Here we add a button switch to control the buzzer, so we can simulate a simple doorbell, when the
Connect way:
Code:
46
Http://www.kumantech.com kuman
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;
}
delay(50);
}
47
Http://www.kumantech.com kuman
Introduction
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
An active buzzer has a built-in oscillating source, so it will make sounds when electrified. But a
passive buzzer does not have such source, so it will not tweet if DC signals are used; instead, you
need to use square waves whose frequency is between 2K and 5K to drive it. The active buzzer is
often more expensive than the passive one because of multiple built-in oscillating circuits.
48
Http://www.kumantech.com kuman
Experimental Procedures
49
Http://www.kumantech.com kuman
Step 2: Compile the code
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()
{
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
50
Http://www.kumantech.com kuman
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
impedance matching device drives the piezoelectric buzzer to sound.。
The piezoelectric buzzing piece is made of lead zirconium titanate or lead magnesium
acid lead piezoelectric ceramic material, which is plated with silver electrode on both sides
of the ceramic sheet, and then is adhered to the brass sheet or stainless steel sheet after
polarization and aging treatment.。
2 . The electromagnetic buzzer is composed of an oscillator, an electromagnetic coil, a
magnet, a vibrating diaphragm and an outer shell, etc. the audio signal of the oscillator is
connected with an electromagnetic coil, and the electromagnetic coil generates a magnetic
field.
What is the difference between active and passive buzzer
Here the "source" is not a power source, but refers to the source of the shock. That is, the
source of the active buzzer inside with a source, so as long as a power will be called.
The source is not a source of internal power, so if you use a DC signal can not make it a
tweet. You must use the 2K~5K square wave to drive it.
Active buzzer is often more expensive than passive, just because there are multiple shock
circuit
The advantages of passive buzzer is: 1. Cheap, 2. The voice frequency controllable can make
"to send a cable Raschig" effect. In some special cases, and led a MUX control active buzzer
of the advantages of program control convenient.
51
Http://www.kumantech.com kuman
pinMode(buzzer,OUTPUT);//Set the digital IO foot mode, OUTPUT for the output
}
void loop()
{
unsigned char i,j;// defined variable
while(1)
{
for(i=0;i<80;i++)//Output a frequency of sound
{
digitalWrite(buzzer,HIGH);//Hair sound
delay(1);//delay 1ms
digitalWrite(buzzer,LOW);//No sound
delay(1);//delay 1ms
}
for(i=0;i<100;i++)//Output another frequency of sound
{
digitalWrite(buzzer,HIGH);//Hair sound
delay(2);//delay 2ms
digitalWrite(buzzer,LOW);//No sound
delay(2);//delay 2ms
}
}
}
Download the program, the buzzer experiment is completed.
52
Http://www.kumantech.com kuman
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.
6、D7 - D0 8 two-way parallel bus, used to transmit commands and data.
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:
53
Http://www.kumantech.com kuman
1602 direct 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.
54
Http://www.kumantech.com kuman
Code as follows
55
Http://www.kumantech.com kuman
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;
56
Http://www.kumantech.com kuman
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);
LcdCommandWrite(0x38); //Set to 8-bit interface, 2 line display, 5x7 text size
delay(20);
LcdCommandWrite(0x06); // Input mode setting
// Auto increment, no display shift
delay(20);
LcdCommandWrite(0x0E); // Display settings
// Turn on the display, the cursor shows, no flicker
delay(20);
LcdCommandWrite(0x01); // The screen is empty, the cursor position is zero
delay(100);
LcdCommandWrite(0x80); // Display settings
// Turn on the display, the cursor shows, no flicker
delay(20);
}
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');
57
Http://www.kumantech.com kuman
LcdDataWrite('k');
LcdDataWrite('-');
LcdDataWrite('w');
LcdDataWrite('o');
LcdDataWrite('r');
LcdDataWrite('k');
LcdDataWrite('s');
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);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58
Http://www.kumantech.com kuman
////////
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
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);
59
Http://www.kumantech.com kuman
}
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);
LcdCommandWrite(0x38); //Set to 8-bit interface, 2 line display, 5x7 text size
delay(20);
LcdCommandWrite(0x06); //Input mode setting
// Auto increment, no display shift
delay(20);
LcdCommandWrite(0x0E); // Display settings
// Turn on the display, the cursor shows, no flicker
delay(20);
LcdCommandWrite(0x01); //The screen is empty, the cursor position is zero
delay(100);
LcdCommandWrite(0x80); //Display settings
// Turn on the display, the cursor shows, no flicker
delay(20);
}
void loop (void) {
LcdCommandWrite(0x01); // The screen is empty, the cursor position is zero
delay(10);
LcdCommandWrite(0x80+3);
delay(10);
/ / write a welcome message
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('k');
LcdDataWrite('u');
60
Http://www.kumantech.com kuman
LcdDataWrite('m');
LcdDataWrite('a');
LcdDataWrite('n');
LcdDataWrite('A');
LcdDataWrite('r');
LcdDataWrite('d');
LcdDataWrite('u');
LcdDataWrite('i');
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);
}
61
Http://www.kumantech.com kuman
Under normal use, the 8 bit access to the basic Arduino digital port is full, and if you want to pick a few sensors on
the no port, and how to deal with this situation, we can use the 4 bit access method.
4 bit connection method of the hardware connection method as shown below
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
digitalWrite( LCD1602_EN,HIGH);
delayMicroseconds(1);
digitalWrite( LCD1602_EN,LOW);
digitalWrite( LCD1602_EN,HIGH);
delayMicroseconds(1);
digitalWrite( LCD1602_EN,LOW);
}
63
Http://www.kumantech.com kuman
digitalWrite( LCD1602_EN,HIGH);
delayMicroseconds(1);
digitalWrite( LCD1602_EN,LOW);
digitalWrite( LCD1602_EN,HIGH);
delayMicroseconds(1);
digitalWrite( LCD1602_EN,LOW);
}
64
Http://www.kumantech.com kuman
for (i=6; i <= 12; i++)
{
pinMode(i,OUTPUT);
}
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);
65
Http://www.kumantech.com kuman
void LCD_Command_Write(int command)
{
int i,temp;
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;
}
66
Http://www.kumantech.com kuman
digitalWrite( LCD1602_EN,HIGH);
delayMicroseconds(1);
digitalWrite( LCD1602_EN,LOW);
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++)
67
Http://www.kumantech.com kuman
{
pinMode(i,OUTPUT);
}
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
O?? The answer is eight, but our Arduino 168 have several I / O port?? with analog interface is 20., the eight lights
occupied too many resources, we 74HC595 is to reduce use of the number of I / O port. With 74HC595, we can
use three digital I / O port to control 8 LED lights. Wouldn't it be wonderful, too?
Here are the components that we need to prepare.
In 74HC595 chip *1
Bread board *1
69
Http://www.kumantech.com kuman
70
Http://www.kumantech.com kuman
void updateLEDs(int value)
{
digitalWrite(latch, LOW);//
shiftOut(data, clock, MSBFIRST, ~value);//Serial data output, high priority
digitalWrite(latch, HIGH);//Latch
}
You can see 8 lights flashing beautiful scene download program.
The experimental phenomenon is to see the eight bit LED display eight bit binary number, loop self plus 1
Each of the digital tube is composed of light-emitting diodes, so when using the same as the light-emitting diode,
but also to connect the current limit resistance, otherwise the current will burn the light emitting diode. This
experiment with a common cathode digital tube, common cathode digital tube in the application should be GND,
when a field light-emitting diode anode for low power, the corresponding field points out,
We begin to prepare the experimental components。
Eight segment digital tube *1
71
Http://www.kumantech.com kuman
We refer to the physical connection diagram to connect the circuit according to the schematic diagram.
72
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
5 connected C segment digital tube
int d=10;// Definition of digital interface 10 connected D segment digital tube
int e=11;// Definition of digital interface 11 connected e segment digital tube
int f=8;// Definition of digital interface 8 connected f segment digital tube
int g=9;// Definition of digital interface 9 connected g segment digital tube
int dp=4;// Definition of digital interface 4 connected DP segment digital tube
void digital_0(void) //Display number 5
{
unsigned char j;
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
73
Http://www.kumantech.com kuman
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
digitalWrite(dp,LOW);
}
void digital_1(void) //Display number 1
{
unsigned char j;
digitalWrite(c,HIGH);//Digital interface to the 5 pin high, lit C segment
digitalWrite(b,HIGH);//Light B segment
for(j=7;j<=11;j++)//Extinguish the rest
digitalWrite(j,LOW);
digitalWrite(dp,LOW);//Put out the DP segment of the decimal point
}
void digital_2(void) //Display number 2
{
unsigned char j;
digitalWrite(b,HIGH);
digitalWrite(a,HIGH);
for(j=9;j<=11;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
digitalWrite(c,LOW);
digitalWrite(f,LOW);
}
void digital_3(void) //Display number3
{
digitalWrite(g,HIGH);
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
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);
74
Http://www.kumantech.com kuman
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++)
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;
75
Http://www.kumantech.com kuman
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
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
}
}
76
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.
77
Http://www.kumantech.com kuman
78
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;
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);
79
Http://www.kumantech.com kuman
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);
digitalWrite(d4, HIGH);
break;
case 3:
digitalWrite(d1,HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, LOW);
digitalWrite(d4, HIGH);
break;
case 4:
80
Http://www.kumantech.com kuman
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);
}
void Num_2()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
81
Http://www.kumantech.com kuman
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);
}
void Num_6()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
82
Http://www.kumantech.com kuman
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);
}
void Clear() // Clear the screen
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
83
Http://www.kumantech.com kuman
digitalWrite(dp,LOW);
}
void pickNumber(unsigned char n)//Choose the number of
{
switch(n)
{
case 0:Num_0();
break;
case 1:Num_1();
break;
case 2:Num_2();
break;
case 3:Num_3();
break;
case 4:Num_4();
break;
case 5:Num_5();
break;
case 6:Num_6();
break;
case 7:Num_7();
break;
case 8:Num_8();
break;
case 9:Num_9();
break;
default:Clear();
break;
}
}
void Display(unsigned char x, unsigned char Number)//Show that x is the coordinate, Number is the number
{
WeiXuan(x);
pickNumber(Number);
delay(1);
Clear() ; //Vanishing
}
Copy the following code to download to the control panel to see the effect chart.
84
Http://www.kumantech.com kuman
Note: the connection when the need for patience, careful, not even any wrong line, when garbled, first check the
line.
85
Http://www.kumantech.com kuman
Hit Temperature module can connect UNO R3 PIN13, make hit test.
Pin 13’s LED,use hit module connect Pin 3. When hit module test there is hit, led can be bright.
Wiring diagram:
Components
- 1 * Tap on a module
- 1 * Jumper wires
86
Http://www.kumantech.com kuman
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()
{
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 * Tilt switch
Experimental Principle
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.
87
Http://www.kumantech.com kuman
Experimental Procedures
88
Http://www.kumantech.com kuman
Now, tilt the switch, and the LED attached to pin 13 on Kuman Uno board will light up.
89
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()
{
int digitalVal = digitalRead(2);//Read the value of pin2
if(HIGH == digitalVal)//if tilt switch is not breakover
{
digitalWrite(ledPin,LOW);//turn the led off
}
else ////if tilt switch breakover
{
digitalWrite(ledPin,HIGH);//turn the led on
}
}
/*****************/
Experimental components
USB line *1
Ultrasonic *1
90
Http://www.kumantech.com kuman
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
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
as possible to level, otherwise the results of the measurement.
91
Http://www.kumantech.com kuman
const int TrigPin = 2;
const int EchoPin = 3;
float cm;
void setup()
{
Serial.begin(9600);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
}
void loop()
{
digitalWrite(TrigPin, LOW); //Low high and low level to send a short pulse to TrigPin
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
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:
92
Http://www.kumantech.com kuman
TRIG: Trigger Pulse Input
ECHO: Echo Pulse Output
GND: Ground
VCC: 5V Supply
Features
Max Range 700cm, Ensured stable signal within 5m, gradually faded signal outside 5m till
disappearing at 7m position.
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.
93
Http://www.kumantech.com kuman
Test Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
float distance;
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
pinMode(Echo,INPUT);
94
Http://www.kumantech.com kuman
pinMode(Trig,OUTPUT);
void loop()
// Generates a pulse
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
// Serial.print("rxTime:");
// Serial.println(rxTime);
Serial.print("distance:");
95
Http://www.kumantech.com kuman
Serial.println("CM");
lcd.setCursor(6, 0);
lcd.print(distance);//print it in LCD1602
lcd.print("CM");
delay(100);
96
Http://www.kumantech.com kuman
5:Test code
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
The above code onto your board, open the serial port window, you can see the following:
97
Http://www.kumantech.com kuman
98
Http://www.kumantech.com kuman
2011-9-6 17:20:53 上传
下载附件 (130.89 KB)
2011-9-6 17:42:20 上传
下载附件 (64.19 KB)
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:
99
Http://www.kumantech.com kuman
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.
100
Http://www.kumantech.com kuman
Step motor (five line four phase) driving board (UL2003) test board
101
Http://www.kumantech.com kuman
external SIZE:31×35mm
2011-9-5 23:06:50 上传
102
Http://www.kumantech.com kuman
下载附件 (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()
{
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 }
103
Http://www.kumantech.com kuman
19. void setup()
20. {
21. // 设置电机每分钟的转速为 90 步
22. stepper.setSpeed(90);
23. }
24.
25. void loop()
26. {
27. // 获取传感器读数
28. int val = analogRead(0);
29.
30. // 移动步数为当前读数减去历史读数
31. stepper.step(val - previous);
32.
33. // 保存历史读数
34. previous = val;
35. }
‘
104
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.
105
Http://www.kumantech.com kuman
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
106
Http://www.kumantech.com kuman
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.
107
Http://www.kumantech.com kuman
{
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
108
Http://www.kumantech.com kuman
{
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.
109
Http://www.kumantech.com kuman
Bread board *1
110
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
111
Http://www.kumantech.com kuman
Introduction
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.
112
Http://www.kumantech.com kuman
Components
- 1 * Breadboard
- 1 * I2C LCD1602
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:
Experimental Procedures
113
Http://www.kumantech.com kuman
Note: Here you need to add a library. Refer to the file LiquidCrystal_I2C
Now, you can see the current temperature displayed on the I2C LCD1602.
114
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
115
Http://www.kumantech.com kuman
lcd.print("LM35");//print"LM35"
lcd.setCursor(0,1);//place the cursor on 0 column,1 row
lcd.print("Tem= ");//print"Tem= "
lcd.setCursor(5,1);//place the cursor on 5 column,1 row
lcd.print(tem);//print tem
lcd.print(char(223));//print the unit" ℃ "
lcd.print("C");
delay(200);//delay 200ms}
2. 220Ωline resistance*1
116
Http://www.kumantech.com kuman
3.bread board*1
The next step we in 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:
117
Http://www.kumantech.com kuman
Physicaldiagramconnectiondiagram:
In accordance with the above link circuit, you can start writing programs, we still allow the LED lights flashing, lit 1
seconds out 1 seconds. This procedure is very simple and the Arduino comes with routine in the blink similar just
13 digital interface for 10 digital interface.。
-----------------------------------------------------------
118
Http://www.kumantech.com kuman
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
second.
119
Http://www.kumantech.com kuman
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 * Infrared-receiver module
- 1 * Remote controller
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.
120
Http://www.kumantech.com kuman
Experimental Procedures
121
Http://www.kumantech.com kuman
Note: Here you need to add a library. Refer to the description in LIBRARY
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.
122
Http://www.kumantech.com kuman
123
Http://www.kumantech.com kuman
1, experimental device
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
124
Http://www.kumantech.com kuman
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
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
Note: pulse waveform of integration into the receiving head, because integration receiving head to disobey
decoding, signal amplifying and shaping, so pay attention to: in the absence of infrared signal, and the output end
of the signal for a high level to low level, so its output signal level just and a transmitting terminal are anti.
Receiving pulse end we can seen by the oscilloscope and see the waveform of program understanding.
125
Http://www.kumantech.com kuman
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
long on1 = 0x00FFA25D;
long off1 = 0x00FFE01F;
long on2 = 0x00FF629D;
long off2 = 0x00FFA857;
long on3 = 0x00FFE21D;
long off3 = 0x00FF906F;
long on4 = 0x00FF22DD;
long off4 = 0x00FF6897;
long on5 = 0x00FF02FD;
long off5 = 0x00FF9867;
long on6 = 0x00FFC23D;
long off6 = 0x00FFB047;
IRrecv irrecv(RECV_PIN);
decode_results results;
// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
// decode_results *results = (decode_results *)v
void dump(decode_results *results) {
int count = results->rawlen;
if (results->decode_type == UNKNOWN)
{
Serial.println("Could not decode message");
}
else
{
if (results->decode_type == NEC)
{
Serial.print("Decoded NEC: ");
}
else if (results->decode_type == SONY)
{
Serial.print("Decoded SONY: ");
}
else if (results->decode_type == RC5)
{
Serial.print("Decoded RC5: ");
126
Http://www.kumantech.com kuman
}
else if (results->decode_type == RC6)
{
Serial.print("Decoded RC6: ");
}
Serial.print(results->value, HEX);
Serial.print(" (");
Serial.print(results->bits, DEC);
Serial.println(" bits)");
}
Serial.print("Raw (");
Serial.print(count, DEC);
Serial.print("): ");
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);
127
Http://www.kumantech.com kuman
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 )
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
}
}
128
Http://www.kumantech.com kuman
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 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 * USB cable
- 1 * 10 k adjustable resistance
129
Http://www.kumantech.com kuman
- Jumper wires
Code:
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time
}
130
Http://www.kumantech.com kuman
Description:
131
Http://www.kumantech.com kuman
Components
- 1 * USB cable
- 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 );
132
Http://www.kumantech.com kuman
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:
133
Http://www.kumantech.com kuman
134
Http://www.kumantech.com kuman
This is a direct use control switch module, when a finger touch screen printing
white circles, the SIG pin will output a high level, when fingers left, SIG pin
output low level.
Components
135
Http://www.kumantech.com kuman
- 1 * USB cable
- 1 * Touch module
- Jumper wires
- 1 * Breadboard
Touch module in this experiment, we use D3 pin is high/low signal detection, when the D3 pin
signal is high, D13 pin is high, when the D3 pin signal is low, D13 pin is low. Here we choose "D13
pin" because the pin come with the LED on the main board.
Test code:
136
Http://www.kumantech.com kuman
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 * USB cable
- 1 * RGB module
137
Http://www.kumantech.com kuman
- Jumper wires
- 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);
138