Sie sind auf Seite 1von 119

Preface

About SunFounder
SunFounder is a technology company focused on Raspberry Pi and Arduino open source
community development. Committed to the promotion of open source culture, we strive to
bring the fun of electronics making to people all around the world and enable everyone to
be a maker. Our products include learning kits, development boards, robots, sensor
modules and development tools. In addition to high quality products, SunFounder also
offers video tutorials to help you build your own project. If you have interest in open source
or making something cool, welcome to join us! Visit www.sunfounder.com for more!

About RFID Kit


This RFID kit is suitable for the SunFounder Uno, SunFounder Mega 2560, SunFounder
Duemilanove, and SunFounder Nano. All codes found in the user guide are compatible
with these boards.

Our SunFounder board is fully compatible with Arduino.

This kit includes some simple and complicated experiments, which is closely related with life.
Through these experiments, you can clearly know the principles behind some common
phenomenon and apply them well. For example, password lock and entrance card system.
You can also conduct these experiments by yourself to strengthen what you have learnt.

In this book, we will show you circuits with both realistic illustrations and schematic diagrams.
You can go to our official website www.sunfounder.com to download related materials
(code, Fritzing figures, etc.) by clicking LEARN -> Get Tutorials -> Arduino -> RFID Kit V2.0 for
Arduino.

Free Support
If you have any TECHNICAL questions, add a topic under FORUM section on our
website and we'll reply as soon as possible.

For NON-TECH questions like order and shipment issues, please send an email to
service@sunfounder.com. You're also welcomed to share your projects on FORUM.
Rept 3.0
Contents
Components List.............................................................................................................................................. 1
Get Started......................................................................................................................................................10
Lesson 1 Controlling LED by Button.......................................................................................................... 16
Lesson 2 Controlling LED by PWM............................................................................................................. 21
Lesson 3 Interactive LED Flowing Lights................................................................................................... 26
Lesson 4 I2C LCD1602................................................................................................................................... 28
Lesson 5 Buzzer............................................................................................................................................... 31
Lesson 6 Tilt Switch......................................................................................................................................... 34
Lesson 7 Building a Quiz Buzzer System................................................................................................... 37
Lesson 8 Serial Monitor................................................................................................................................. 40
Lesson 9 Photoresistor................................................................................................................................... 44
Lesson 10 Controlling Buzzer by Photoresistor....................................................................................... 47
Lesson 11 Flame Alarm................................................................................................................................ 50
Lesson 12 Making a Voltmeter.................................................................................................................. 53
Lesson 13 Sound Sensor............................................................................................................................... 55
Lesson 14 LM35 Temperature Sensor....................................................................................................... 57
Lesson 15 Water Level Detection............................................................................................................. 59
Lesson 16 7-Segment Display..................................................................................................................... 61
Lesson 17 Stopwatch 4-Digit 7-Segment Display.............................................................................. 66
Lesson 18 Dot-matrix Display...................................................................................................................... 69
Lesson 19 Rainbow LED................................................................................................................................ 74
Lesson 20 Driving 7-Segment Display by 74HC595...............................................................................76
Lesson 21 Vibration Switch.......................................................................................................................... 80
Lesson 22 Real-time Clock Module.......................................................................................................... 83
Lesson 23 Humiture Detection................................................................................................................... 86
Lesson 24 Relay.............................................................................................................................................. 90
Lesson 25 Stepper Motor............................................................................................................................. 93
Lesson 26 Servo.............................................................................................................................................. 98
Lesson 27 Joystick PS2................................................................................................................................ 102
Lesson 28 Infrared-Receiver..................................................................................................................... 105
Lesson 29 RFID Entrance Guard System................................................................................................107
Lesson 30 Password Lock.......................................................................................................................... 112
1
Components List
No. Name Qty. Component

1 I2C LCD1602 1

2 RTC-DS1302 1

3 Sound Sensor 1

9V Battery
4 1
Buckle

1
5 Breadboard 1

6 LED (red) 8

7 LED (green) 8

8 LED (yellow) 8

9 Resistor (220) 8
(red, red, black, black, brown)

10 Resistor (1K) 4
(brown, black, black, brown, brown)

11 Resistor (10K) 4
(brown, black, black, red, brown)

2
Potentiometer
12 1
(50K)

13 Active Buzzer 1

Passive Buzzer
14 1
Module

15 74HC595 2

16 IR Receiver 1

3
17 LM35 2

18 Flame Sensor 1

19 Photoresistor 2

20 Remote Control 1

Four-digit
21 Segment Display 1

4
22 Stepper Motor 1

Stepper Motor
23 1
Driver

24 Servo 1

25 Relay Module 1

7-segment
26 2
Display

5
27 Joystick PS2 1

28 Button 5

29 Tilt Switch 1

30 RFID Module 1

31 RFID Key Tag 1

6
32 Humiture Sensor 1

Water Level
33 Measurement 1
Module

4*4 Keypad
34 1
Module

8*8 Dot-matrix
35 1
Module

36 Vibration Switch 1

7
37 RGB LED 1

5-Pin Anti-reverse
38 2
Cable

4-Pin Anti-reverse
39 2
Cable

3-Pin Anti-reverse
40 2
Cable

Dupont Wire (F
41 10
to F)

8
Jumper Wire
42 30
(M to M)

43 USB Cable 1

Dupont wire
44 10
(M to F)

9
Get Started
Note:

Before starting your own project, you must download the file RFID Kit V2.0 for Arduino.zip on
our official website by visiting LEARN -> Get Tutorials -> RFID Kit V2.0 for Arduino and unzip it.

About this part, for your better learning, we've provided a video tutorial on our website
under VIDEO and you can check it out for more.

Arduino

Description

Arduino is an open source platform with simple software and hardware. You can pick it up
in short time even if you are a beginner. It provides an integrated development
environment (IDE) for code compiling, compatible with multiple control boards. So you can
just download the Arduino IDE, upload the sketches (i.e. the code files) to the board, and
then you can see relative experimental phenomena. For more information, refer to
http://www.arduino.cc.

SunFounder Arduino Board

10
Now, Sunfounder has four Arduino boards namely Sunfounder Uno R3 Board, Mega 2560
Board, Nano Board, and Mars Board. The Uno Board and the Mars Board share the same
kind of pins at the same position. And the pins of the first half part on the Mega 2560 are
the same as those on the Uno. The difference lies in that on the Mega 2560 board, the I2C
pin (SDA) and pin SCL don't correspond to pin A4 and A5 but to pin 20 and 21. On the
other hand, the Nano and the Uno also share the same kind of pins at the same position.
Though the Nano is in a smaller size, making it applicable for projects.

The following is the parameters of the four boards:

Board Uno R3 Mars Nano Mega 2560


Parameters

Microcontroller ATmega328P ATmega328P ATmega328P ATmega2560

USB connection Type B Type C Mini-B Type B

USB-to-Serial Chip MEGA16U2 FT232R PL2303 MEGA16U2

Power jack? Y Y N Y

11
Operating
5V 5V 5V 5V
Voltage

Input Voltage 7-12V 7-12V 7-12V 7-12V

14 (of which 6 14 (of which 14 (of which 6 54 (of which


Digital I/O Pins provide PWM 6 provide provide PWM 15 provide
output) PWM output) output) PWM output)

Analog Input Pins 6 6 8 16

DC Current per
20 mA 20mA 20 mA 20 mA
I/O Pin

12
Install Arduino IDE
The code in this kit is written based on Arduino, so you need to install the IDE first. Skip it if
you have done this.

Now go to the arduino.cc website and click DOWNLOAD. On the page, check the software
list on the right side under Download the Arduino Software.

Find the one that suits your operation system and click to download. There are two versions
of Arduino for Windows: Installer or ZIP file. You're recommended to download the former.
Just download the package, and run the executable file to start installation. It will
download the driver needed to run Arduino IDE. After downloading, follow the prompts to
install. For the details of installing steps, you can refer to the guide on Learning->Getting
Started with Arduino, scroll down and see Install the Arduino Software.

After installing, you will see Arduino icon on your desk. Double click to open it.

Add Libraries
Since in some code, the libraries needed are not included in Arduino, so you need to add
them before compiling.

13
Click Sketch -> Included Library -> Add .ZIP Library

Go to the folder of the zip file you've downloaded. Go to Library->Dht and click Open.

When you see "Library added to your libraries .Check 'include library' menu" appears, it
means the library has been added successfully. You may add the rest libraries needed in
the similar way.

14
Plug in the Board
Connect the control board to your computer with a USB cable. If you use Uno, Mega2560
or Mars as the control board, the system will automatically install the driver when you plug it
in. After a while, a prompt will show up at the bottom right corner telling you which port the
board locates at. If the control board is Nano, then you need to install the driver by yourself.
For more details, you can refer to WIKI on our website www.sunfounder.com.

For more details about Arduino IDE, go to Learning->Getting started->Foundation on the


arduino.cc and click Arduino Software (IDE) on the page
http://www.arduino.cc/en/Guide/Environment

If your sketch fails upload, on the same page click Troubleshooting


http://www.arduino.cc/en/Guide/Troubleshooting.

Notes:

If your computer is running on the Windows XP system, the new version IDE will prompt
errors when running the code. You are recommended to download the Arduino 1.0.5
or Arduino 1.0.6. Or you can also upgrade your Window system.

All the experiments in this kit are done with SunFounder Uno R3 board, but they are also
compatible with SunFounder Mega 2560, SunFounder Mars, SunFounder Nano and all
official Arduino Boards. All the code included in this kit works with these boards.

So what does COMPATIBLE mean here? It means you can use any of the three boards
to do the same experiment with the same wiring. Simply put, if the wire is connected to
Pin 12 of Uno in the user manual, likewise, you can connect it to Pin 12 on any other
official Arduino boards you are using. Then open the corresponding sketch and upload
them.

Now let's start to make the experiments!

15
Lesson 1 Controlling LED by Button
Introduction
In this experiment, we will learn how to turn an LED on/off 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 * SunFounder Uno board
- 1 * USB cable
- 1 * Button
- 1 * Resistor (10k)
- 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 break 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.

Pin 1 is connected to pin 2 and pin 3 to pin 4. So you just need to connect either of pin 1
and pin 2 to pin 3 or pin 4.

The following is the internal structure of a button. Since the pin 1 is connected to pin2, and
pin 3 to pin 4, the symbol on the right below is usually used to represent a button.

16
When the button is pressed, the 4 pins are connected, thus closing the circuit.

Generally, the button can be connected directly to the LED in a circuit to turn on or off the
LED, which is comparatively simple. However, sometimes the LED will brighten automatically
without any button pressed, which is caused by various kinds of external interference. In
order to avoid this interference, a pull-down resistor is used usually connect a 1K10K
resistor between the button and GND. It can be connected to GND to consume the
interference when the button is off.

This circuit connection is widely used in numerous circuits and electronic devices. We may
use the button to control a circuit later in many experiments (in or outside this kit maybe), so
you might get its principle, which is very simple, and application at the beginning of your
study.

Experimental Procedures
Step 1: Build the circuit

17
The schematic diagram

Step 2: Open the code file

In the folder RFID_Kit_v2.0_for_Arduino you just downloaded and unzipped, you can see the
folder for the corresponding lesson which includes two folders: code (the sketch) and
circuit (Fritzing file). Go to the code folder and find the .ino file (.ino is the format of the
sketch). Then double click to open it.

Step 3: Select the correct Board

18
and Port

Step 4: Upload
Click the Upload icon to upload the code to the board. The sketches can be uploaded to
the board when there is nothing wrong with them. During the upload, the TX LED and the
RX LED will be alternately flickering. It means the board is sending signal to the computer
and then receives the signal from the computer. After upload is completed, the two LEDs
will go out.

19
If "Done uploading" appears at the bottom of the window, it means the sketch has been
successfully uploaded. And if you see the pin 13(L) LED starts to flicker, it means the code
has been successfully run.

Note: The experimental steps for the subsequent lessons are the same. Here we just take
one lesson for example. You can modify the code as you like, but pay attention to save it
as another one for reference.

Now, press the button, and the LED on the SunFounder Uno board will light up.

Tips: For any TECHNICAL questions, add a topic under FORUM section on our website
www.sunfounder.com and we'll reply as soon as possible.

20
Lesson 2 Controlling LED by PWM
Introduction
In this lesson, lets try something a little easier gradually changing the luminance of an LED
through programming. Since the pulsing light looks like breathing, we give it a magical
name - breathing LED. Well accomplish this effect with pulse width modulation (PWM).

Components
- 1 * SunFounder Uno board
- 1 * Breadboard
- Jumper wires
- 1 * LED
- 1 * Resistor (220)
- 1 * USB cable

Principle
PWM
Pulse width modulation, or PWM, is a technique for getting analog results with digital means.
Digital control is used to create a square wave, a signal switched between on and off. This
on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by
changing the portion of the time the signal spends on versus the time that the signal spends
off. The duration of "on time" is called the pulse width. To get varying analog values, you
change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an
LED for example, the result is as if the signal is a steady voltage between 0 and 5V
controlling the brightness of the LED. (See the PWM description on the official website of
Arduino).

21
We can see from the top oscillogram that the amplitude of the DC voltage output is 5V.
However, the actual voltage output is only 3.75V through PWM because the high level only
takes up 75% of the total voltage within a period.

Here is an introduction to the three basic parameters of PWM:

1. Duty cycle describes the proportion of "on" time to the regular interval or period of time.

2. Period describes the reciprocal of pulses in one second.

22
3. The voltage amplitude here is 0V5V.

23
Experimental Procedures
Step 1: Build the circuit

The schematic diagram

24
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Here you should see the LED gets brighter and brighter, and then slowly dimmer, just like
breathing.

25
Lesson 3 Interactive LED Flowing Lights
Introduction
In this lesson, you will conduct a simple yet interesting experiment using LEDs to create
flowing LED lights. As the name implies, these flowing lights are made up of eight LEDs in a
row which successively light up and dim one after another, just like flowing water.

Components
- 1* SunFounder Uno board
- 1 * Breadboard
- 8 * LED
- 8 * Resistor (220)
- 1 * Potentiometer
- 1 * USB cable
- Several jumper wires

Experimental Principle
The principle is quite simple, that is, to turn eight LEDs on in turn. And then change the time
interval of LED on and off by adjusting the potentiometer.

Experimental Procedures
Step 1: Build the circuit

26
The schematic diagram

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Here you should see eight LEDs light up one by one in turn. Adjust the potentiometer, and
you will find the time interval of LED lighting up changes.

27
Lesson 4 I2C LCD1602
Introduction
As we all know, though LCD and some other displays greatly enrich the man-machine
interaction, they share a common weakness. When they are connected to a controller,
multiple IOs will be occupied of the controller which has no so many outer ports. Also it
restricts other functions of the controller. Therefore, LCD1602 with an I2C bus is developed
to solve the problem.

I2C bus is a type of serial bus invented by PHLIPS. It is a high performance serial bus which
has bus ruling and high or low speed device synchronization function required by multiple-
host system. The blue potentiometer on the I2C LCD1602 (see the figure below) is used to
adjust the backlight for better display. IC uses only two bidirectional open-drain lines,
Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages
used are +5 V or +3.3 V although systems with other voltages are permitted.

Components
- 1 * SunFounder Uno board
- 1 * I2C LCD1602 module
- 1 * USB cable
- Several jump wires

Experimental Principle
In this experiment, we will let I2C LCD1602 display SunFounder" and hello, world" by
programming.

28
Experimental Procedures
Step 1: Build the circuit
The connection between the I2C LCD1602 and the SunFounder Uno board:

I2C LCD1602 SunFounder Uno

GND GND

VCC 5V

SDA A4

SCL A5

Note: The wiring of I2C LCD1602 is the same through the following lessons.

If you use a Mega2560 board, the wiring is different then.

29
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

You should now see your I2C LCD1602 display the flowing characters: "SunFounder" and
"hello, world".

30
Lesson 5 Buzzer
Introduction
A buzzer is a great tool in your experiments whenever you want to make some sounds. .

Components
- 1 * SunFounder 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 difference between an active buzzer and a passive buzzer:

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.

In this experiment, we use an active buzzer.

31
Experimental Procedures
Step 1: Build the circuit

The schematic diagram

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board
32
Now, you should hear the buzzer beep.

33
Lesson 6 Tilt Switch
Introduction
The tilt switch used here is a ball one with a metal ball inside. It is used to detect small angle
of inclination.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * Tilt switch
- Several jumper wires

Experimental Principle
The principle is very simple. When the switch is tilted in a certain angle, the ball inside rolls
down and touches the two contacts connected to the pins outside, thus triggering circuits.
Otherwise the ball will stay away from the contacts, thus breaking the circuits.

34
Experimental Procedures
Step 1: Build the circuit

The schematic diagram

35
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, tilt the switch, and the LED attached to pin 13 on SunFounder Uno board will light up.

36
Lesson 7 Building a Quiz Buzzer System
Introduction
In quiz shows, especially entertainment activities (e.g. competitive answering activities),
organizers often apply a buzzer system in order to accurately, fairly and visually determine
the seat number of a responder.

Now the system can illustrate the accuracy and equity of the judgment by data, which
improves the entertainment. At the same time, it is more fair and just. In this lesson, we will
use some buttons, buzzers, and LEDs to make a quiz buzzer system.

Components
- 1* SunFounder Uno board
- 1 * USB data cable
- 4 * Button
- 4 * LED
- 4 * Resistor (220)
- 1 * Active Buzzer
- Several jumper wires
- 1 * Breadboard

Experimental Principle
Button 1, 2 and 3 are answer buttons, and button 4 is the reset button. If button 1 is pressed
first, the buzzer will beep, the corresponding LED will light up and all the other LEDs will go
out. If you want to start another round, press button 4 to reset.

37
Experimental Procedures
Step 1: Build the circuit

The schematic diagram

38
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, first press button 4 to start. If you press button 1 first, you will see the corresponding LED
light up and the buzzer will beep. Then press button 4 again to reset before you press other
buttons.

39
Lesson 8 Serial Monitor
Introduction
In this experiment, you will learn how to turn on or off LEDs through a computer and the
Serial Monitor. Serial Monitor is used for communication between the Uno board and a
computer or other devices. It is a built-in software in the Arduino environment and you can
click the button on the upper right corner to open it. You can send and receive data via
the serial port on the Uno board and control the board by input from the keyboard.

In this experiment, since we use colored LEDs as loads, you can enter a color among red,
green, and blue on Serial Monitor in the IDE. The corresponding LED on the SunFounder Uno
board will then light up.

Components
- 1 * SunFounder Uno board
- 1 * Breadboard
- 3 * LED
- 3 * Resistor (220)
- Jumper wires
- 1 * USB cable

Principle
Here, the Serial Monitor serves as a transfer station for communication between your
computer and the SunFounder Uno board. First, the computer transfers data to the Serial
Monitor, and then the data is read by the SunFounder Uno board. Finally, the Uno will
perform related operations.

40
Experimental Procedures
Step 1: Build the circuit

The schematic diagram

41
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, click the Serial Monitor button at the upper right corner in the IDE. Then the Serial
Monitor window will pop up as shown below.

With this window, you can not only send data from your computer to the SunFounder Uno
board, but also receive data from the board and display it on the screen. When you open
the window, it will display "Please input any color of LED:". You can input a color here. If you
enter red, green, or blue, click Send, then the corresponding LED on the breadboard will
light up. However, if you enter any color other than these three, no LEDs will be on.

42
For example, if you input red, you will see the red LED light up.

43
Lesson 9 Photoresistor
Introduction
A photoresistor or photocell is a light-controlled variable resistor. The resistance of a
photoresistor decreases with increasing incident light intensity; in other words, it
exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits,
and light- and darkness-activated switching circuits.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * Photoresistor
- 1 * Resistor (10K)
- 8 * LED
- 8 * Resistor (220)
- Jumper wires
-1 * Breadboard

Experimental Principle
The resistance of a photoresistor changes with incident light intensity. If the light intensity
gets higher, the resistance decreases; if it gets lower, the resistance increases.

In this experiment, we will use eight LEDs to show the light intensity. The higher the light
intensity is, the more LEDs will light up. When the light intensity is high enough, all the LEDs
will be on. When there is no light, all the LEDs will go out.

44
Experimental Procedures
Step 1: Build the circuit

The schematic diagram

45
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, shine some light on the photoresistor, and you will see several LEDs light up. Shine
more light and you will see more LEDs light up. When you place it in a dark environment, all
the LEDs will go out.

Exploration
In addition to the above experiment, you can replace the photoresistor with a microphone
and use LEDs to indicate sound intensity. The higher the sound intensity gets, the more LEDs
will light up. You can realize this effect by yourself. Try now!

46
Lesson 10 Controlling Buzzer by Photoresistor
Introduction
Since you have learnt how to use a photoresistor, in this lesson, you will learn how to control
a buzzer to make it beep in different frequencies by the photoresistor.

Compoment
- 1* SunFounder Uno board
- 1 * USB data cable
- 1 * Photoresistor
- 1 * Buzzer (Active)
- 1 * Resistor (10K)
- Several jumper wires
-1 * Breadboard

Experiment Principle
When you shine some light on the photoresistor, if the incident light gets stronger, the
resistance of the photoresistor will decrease; if the incident light becomes weaker, the
resistance will increase.

In this experiment, the output of the photoresistor is sent to pin A0 on the SunFounder Uno
board and then processed by the ADC on the board to output a digital signal. We use this
digital signal as the parameter of the delay() function in the sketch to make the buzzer
beep.

When the incident light is strong, the output value gets greater, thus the buzzer will beep
slowly; when incident light is weak, the output value is smaller, thus the buzzer will beep
sharply.

47
Experiment Procedures
Step 1: Build the circuit

The schematic diagram

48
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, place the photoresistor in a dark environment, and the buzzer will beep sharply; shine
a flashlight onto the photoresistor, and the beeping will slow down.

49
Lesson 11 Flame Alarm
Introduction
A flame sensor module performs detection by capturing infrared wavelengths from flame.
It can be used to detect and warn of flames. In this experiment, we use the sensor to make
a flame alarm.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * Flame sensor module
- 1 * Passive buzzer module
- 1 * 4-Pin anti-reverse cable
- 1 * 3-Pin anti-reverse cable
- 1 * Jump wire (F to F)

Experimental Principle
There are several types of flame sensors. In this experiment, we will use a far-infrared flame
sensor. It can detect infrared light with a wavelength ranging from 700nm to 1000nm. A far-
infrared flame probe converts the strength changes of the external infrared light into
current changes. And then it converts analog quantities into digital ones.

In this experiment, connect pin D0 to the digital port 8 of the SunFounder board. Then when
the flame sensor detects flame signals, the buzzer beeps and the corresponding LED lights
up. When it detects no flame signals, the buzzer stops and the LED goes out.

50
The schematic diagram of the module is as follows:

Experimental Procedures
Step 1: Build the circuit
The wiring between the flame sensor and SunFounder Uno board:

Flame Sensor SunFounder Uno

D0 8

A0 A0

VCC 5V

GND GND

The wiring between the passive buzzer and SunFounder Uno board:

Passive Buzzer SunFounder Uno

SIG 7

VCC 5V

GND GND

51
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, ignite a lighter near the flame sensor. Then the buzzer will beep, and the LED on the
flame sensor module and that attached to pin 13 of the SunFounder board will light up.

52
Lesson 12 Making a Voltmeter
Introduction
In this lesson, we will use a potentiometer and an I2C LCD1602 to make a voltmeter.

Components
- 1* SunFounder Uno board
- 1 * USB data cable
- 1 * Potentiometer (50K)
- 1 * I2C LCD1602
- Several jumper wires
- 1 * Breadboard

Experimental Principle
In this experiment, a potentiometer is used to divide voltage. Since the SunFounder Uno
board can only read digital signals, but what the sliding end of the potentiometer outputs
are analog signals, we need to convert these analog signals into digital ones with an
Analog-to-Digital Convertor (ADC). Fortunately, the SunFounder Uno board itself comes
with a 10-bit ADC which we can use to implement this conversion. Then display this digital
output voltage on the I2C LCD1602.

Experimental Procedures
Step 1: Build the circuit

53
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, adjust the potentiometer and you will see the voltage displayed on the I2C LCD1602
varies accordingly.

54
Lesson 13 Sound Sensor
Introduction
Sound Sensor is a component that receives sound waves and converts them into electrical
signals. It detects the sound intensity in the ambient environment like a microphone does.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * Sound Sensor module
- 1 * 3-Pin anti-reverse cable

Experimental Principle
The sensor has a capacitive electret microphone which is sensitive to sound. Sound waves
cause the thin film of the electret to vibrate and then the capacitance changes, thus
causing the corresponding voltage change. Since the change is extremely weak, it needs
to be amplified. LM358 here is a power amplifier of 100 times gain. Connect the SIG output
pin of the sound sensor to A0 of the SunFounder Uno board. Then you can see the value of
sound intensity on Serial Monitor, or display the wave forms on an oscilloscope if you have
connected one.

The schematic diagram of the module is as shown below:

55
Experimental Procedures
Step 1: Build the circuit

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now you can see the value of sound intensity on Serial Monitor. When the volume reaches
to a certain value, the LED attached to pin 13 on the SunFounder Uno board will light up.

56
Lesson 14 LM35 Temperature Sensor
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 50A and it has a wide operation
voltage range - between 4 to 20V, thus saving electricity.

Components
- 1* SunFounder 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 each time
the temperature increases by 1. The calculation formula is as follows:

57
Experimental Procedures
Step 1: Build the circuit

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, you can see the current temperature displayed on the I2C LCD1602.

58
Lesson 15 Water Level Detection
Introduction
In this lesson, we will use a water level sensor to measure the depth of the water and
display the result on I2C LCD1602.

Components
- 1 * SunFounder Uno board
- 1 * Breadboard
- 1 * USB data cable
- 1 * Water Level Sensor
- 1 * I2C LCD1602
- Several jumper wires

Experimental Principle
Water level sensor is a module that can sense the depth of water, whose core part is an
amplification circuit composed of a transistor and several comb-shape PCB cables. When
placed in water, the comb-shape cable will change its resistance with the depth of the
water and convert the depth signal into an electrical signal. With an ADC on the
SunFounder Uno board dealing with that signal, we can know the water depth changes.

Experimental Procedures
Step 1: Build the circuit

59
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, if you immerse the sensor in water, you can see the depth to which the sensor is
soaked displayed on the I2C LCD1602.

60
Lesson 16 7-Segment Display
Introduction
In this lesson, we will learn how to use a 7-segment display which consists of several
common cathode LEDs connected in parallel. It is a simple and common component for
displaying numbers or characters. The code used this time illuminates only one LED per unit
time. The high refresh rate higher than the resolution speed of the naked eye enables us
to see the numbers clearly. The 7-segment display also has the advantage of high and
uniform luminance.

Components
- 1 * SunFounder Uno board
- 1 * 7-segment display (Common Cathode)
- 8 * Resistor (220)
- 1 * USB cable
- Jumper wires
- 1 * Breadboard

Experimental Principle
The 7-segment display consists of seven LEDs arranged in a rectangular fashion. Each of the
seven LEDs is called a segment because, when illuminated, the segment forms part of a
numerical digit (both Decimal and Hex) to be displayed. An additional 8th dot LED is
sometimes used within the same package, thus allowing the indication of a decimal point
(DP) when two or more 7-segment displays are connected together to display numbers
greater than nine.

Each of the seven LEDs in the display is given a positional segment with one of its
connection pins being brought straight out of the rectangular plastic package. These LED

61
pins are labeled from a through to g representing each individual LED. The other LED pins
are connected together and wired to form a common pin.

So by forward biasing the appropriate pins of the LED segments in a particular order, some
segments will be lit and others will stay off allowing the desired character or number to be
displayed. Therefore it can display each of the ten decimal digits from 0 to 9 on the same
7-segment display.

The displays common pin is generally used to identify the type of 7-segment display. As
each LED has two connecting pins, the "Anode" and "Cathode", there are two types of LED
7-segment display: Common Cathode (CC) and Common Anode (CA).

The difference between the two types, as their names suggest, is that the common
cathode display has all the cathodes of the 7 segments connected directly together while
the common anode one has all the anodes connected.

The Common Cathode In the common cathode display, the connected cathodes of the
LED segments are joined together to logic "0" or ground. Each individual segment is
energized by the application of a "HIGH" or logic "1" signal via a current limiting resistor so
the individual anode terminal (a-g) is forward biased.

Common Cathode 7-Segment Display

The Common Anode In the common anode display, the connected anodes of the LED
segments are joined together to logic "1". Each individual segment is energized by applying
a ground, logic "0" or "LOW" signal via a suitable current limiting resistor to the cathode of
the particular segment (a-g).
62
Common Anode 7-Segment Display

Experimental Procedures
Step 1: Build the circuit

The wiring between the 7-segment display and the SunFounder Uno board:

7-Segment Display SunFounder Uno

a 7

b 6

c 5

d 11

e 10

f 8

g 9

dp 4

"-" GND

63
The schematic diagram

64
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

You should now see the 7-segment display showing characters circularly from 0 to 9 and
then A to F, back and forth.

65
Lesson 17 Stopwatch 4-Digit 7-Segment Display
Introduction
In this lesson, we will use a 4-digit 7-segment display to make a stopwatch.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * 4-Digit 7-Segment Display
- Several jumper wires
- 1 * Breadboard
- 8 * Resister (220)

Experimental Principle
When a 7-segment display is used, if it is a common anode display, connect the anode pin
to power source; if it is a common cathode one, connect the cathode pin to GND. When a
4-digit 7-segment display is used, the common anode or common cathode pin is to control
the digit displayed. There is only one digit working. However, based on the principle of
Persistence of Vision, we can see four 7-segment displays all displaying numbers. This is
because the electronic scanning speed is too fast for us to notice interval.

The schematic diagram of the 4-digit 7-segment display is as shown below:

66
Experimental Procedures
Step 1: Build the circuit
The wiring between the 4-digit 7-segment display and the SunFounder Uno board is as
shown below:

4-Digit 7-Segment Display SunFounder Uno


a 2
b 3
c 4
d 5
e 6
f 7
g 8
p 9
D1 13
D2 12
D3 11
D4 10

67
The schematic diagram

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, you can see the number increases by one per second on the 4-digit 7-segment
display.

68
Lesson 18 Dot-matrix Display
Introduction
With low-voltage scanning, LED dot-matrix displays have various advantages such as
power saving, long service life, low cost, high brightness, view of a wide angle, long visual
range, waterproof capability, and numerous specifications. They can meet the needs of
different applications and thus have a broad development prospect. This time, we will
conduct an LED dot-matrix experiment to experience its charm firsthand.

Components
- 1 * SunFounder Uno board
- 1 * 8*8 dot-matrix
- 8 * Resistor (220)
- 1 * Breadboard
- Jumper wires
- 2 * 74HC595
- 1 * USB cable

Principle
The external view of a dot-matrix is as follows:

For pin definition:

Define row and column numbering first (only for a dot-matrix whose model number ends
with BS)

69
Pin numbering corresponding to the above rows and columns:

COL 1 2 3 4 5 6 7 8

Pin No. 13 3 4 10 6 11 15 16

ROW 1 2 3 4 5 6 7 8

Pin No. 9 14 8 12 1 7 2 5

The display principle of the 8*8 dot-matrix:

The 8*8 dot-matrix is made up of sixty-four LEDs and each LED is placed at the cross point of
a row and a column. When the electrical level of a certain row is High and the electrical
level of a certain column is Low, then the corresponding LED will light up; if you want to light
the LED on the first dot, you should set ROW 1 to high level and COL 1 to low level, then the
LED on the first dot will light up; if you want to light the LEDs on the first row, you should set
ROW 1 to high level and COL (1, 2, 3, 4, 5, 6, 7, 8) to low level, then all the LEDs on the first
row will light up; if you want to light the LEDs on the first column, you should set COL 1 to low
level and ROW (1, 2, 3, 4, 5, 6, 7, 8) to high level, then all the LEDs on the first column will
light up.

The principle of 74HC595 has been illustrated previously. One chip is used to control the
rows of the dot-matrix while the other is to control the columns.

70
The schematic diagram

Experimental Procedures
Step 1: Build the circuit
Since the wiring in this experiment is a little complex, let's complete it step by step.
1) Plug the necessary devices and components on the breadboard. Then connect pin16
and pin 10 of the two 74HC595 to 5V of the control board, and pin 8 and pin 13 to GND.

71
2) Then connect pin 11 of the two 74HC595, then to pin 12 of Uno. Connect pin 12 of the
two chips and then to Uno pin 8. Pin 14 of the 74HC595 on the left to pin 9 of that one
on the right, and pin 14 of the 74HC595 on the right side to pin 11 of Uno.

3) The 74HC595 on the left controls rows of the dot matrix. To avoid burning the matrix, we
add a 220Ohm current-limiting resistor to each row. The connection of 74HC595 pins
with dot matrix ones are done in a sequence: Q0-Q7 of the 74HC595 respectively to pin
5, 2, 7, 1, 12, 8, 14, and pin 9 (corresponding to row 8 to 1).

72
4) The 74HC595 on the right controls columns of the dot matrix. Pin Q0-Q7 of the 74HC595
are connected to pin 13, 3, 4, 10, 6, 11, 15, and 16.

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

The dot-matrix will display 0 to 9 and then A to F circularly, back and forth.

73
Lesson 19 Rainbow LED
Introduction
RGB LED modules can emit various colors of light. Three LEDs of red, green, and blue are
packaged into a transparent or semitransparent plastic shell with four pins led out. The
three primary colors of red, green, and blue can be mixed and compose all kinds of colors
by brightness, so you can make an RGB LED emit colorful light by controlling the circuit.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * RGB LED module
- 1 * 4-Pin anti-reverse cable

Experimental Principle
In this experiment, we will use PWM technology to control the brightness of RGB. We've
described the concept in Lesson 2 of this kit. You may check the information, if necessary.

Each of the three color channels: red, green, and blue, has 255 stages of brightness. When
the three primary colors are all 0, the LED light is turned off. When the colors are all 255, the
LED gets brightest. Here we input any value between 0 and 255 to the three pins of the
RGB LED to make it display different colors.

RGB LEDs can be categorized into common anode LED and common cathode LED. In this
experiment, we use a common cathode RGB LED. See the schematic diagram as below:

74
Experimental Procedures
Step 1: Build the circuit

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

You should now see the 7-segment display cycle from 0 to F.

75
Lesson 20 Driving 7-Segment Display by 74HC595
Introduction
In this experiment, we will learn how to use 74HC595 to drive a single 7-segment display to
display numbers.

Generally speaking, there are two methods to drive a 7-segment display. One is to connect
8 pins directly to eight ports on the SunFounder Uno board, just as we did previously. The
other is to connect 74HC595 to three ports of the SunFounder Uno board and connect the
7-segment display to 74HC595. In this experiment, we will use the latter method. The
advantage of this method is that you can save five ports, which is very important
considering the SunFounder Uno boards limited ports.

Components
- 8 * Resistor (220)
- 1 * 74HC595
- 1 * SunFounder Uno board
- Several Jumper wires (M to M)
- 1 * Breadboard
- 1 * USB cable
- 1 * 7-segment display

Experimental Principle
74HC595
74HC595 has an 8-bit shift register and memory with a three-state output function. Its main
function is to transform serial data input into parallel data output so that you can save the
I/O ports of MCU. 74HC595 is mainly used in multipath LED indication or multi-bit segment
display driving. At the same time, it supports three-state output. When the 13th pin is at high
level, there will be no output from 74HC595. With a data latching function, 74HC595 does
not affect the instant output during the shifting process; with a data output function,
74HC595 enables you to cascade 74HC595 more conveniently.

76
The pins of 74HC595 and their functions:
Q0-Q7: Pins for 8-bit parallel data output, able to control 8 LEDs or the 8 pins of a 7-segment
display directly.
Q7: Series output pin connected to DS pin of the next 74HC595 to connect multiple 595s in
series
MR: Reset pin, effective at low level; here it is directly connected to 5V.
SH: Time sequence input of shift register. On the rising edge, the data in shift register moves
successively one bit, i.e. data in Q1 moves to Q2, and so forth. While on the falling edge,
the data in shift register remains unchanged.
ST: Time sequence input of memory register. On the rising edge, data in the shift register
moves into memory register.
OE: Output enable pin, effective at low level, connected to the ground directly.
Ds: Serial data input pin
VCC: The power supply
GND: The ground

Here the shiftout() function is applied, which comes with the SunFounder IDE when
programming. Simply input a number from 0 to 255 and the memory register can transform
it into an 8-bit binary number and output it in parallel. This allows you to easily control the 8
pins of the 7-segment display and create any pattern you want.

Experimental Procedures
Step 1: Build the circuit

The wiring between the 7-segment display, 74HC595 and Uno board is as shown below:

7-Segment Display 74HC595 SunFounder Uno


a Q7

b Q6

c Q5

d Q4

e Q3

f Q2

g Q1

DP Q0

77
VCC 5V

DS 11

CE GND

ST 12

SH 8

MR 5V

Q7 N/C

GND GND

- GND

78
The schematic diagram

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now you can see the 7-segment display show from 0 to 9 and then A to F, back and forth.

79
Lesson 21 Vibration Switch
Introduction
A vibration switch is a device that recognizes the amplitude of the vibration to which it is
exposed and provides some sort of response when this amplitude exceeds a
predetermined threshold value. The switch response is typically an electrical contact
closure or contact opening. The electrical contact may be either an electromechanical
relay or solid-state triac.

Components
- 1*SunFounder Uno board
- 1*USB data cable
- 1* vibration switch module
- Jumper wires

Experimental Principle
The main principle of vibration switch is that, conductive vibration spring and trigger pin are
precisely placed in switch ontology and bond to curing position through adhesive.
Normally, the spring and the trigger pin do not contact. Once shook, the spring will shake
and contact with trigger pin to conduct and generate trigger signals.

With the LED attached to pin 13, connect the vibration switch to digital pin D8. When the
vibration switch inducts vibration signals, pin SIG will output low level, and the LED on the
module and the LED attached to pin 13 will light up. The schematic diagram of the
vibration switch module is shown as follows.

80
Experimental Procedures
Step 1: Build the circuit

81
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, shake the switch module, and you should see the LED attached to pin 13 on the
SunFounder Uno board and the LED on the module light up.

82
Lesson 22 Real-time Clock Module
Introduction
Nowadays there are many popular serial clock circuits such as DS1302, DS1307, PCF8485,
etc. They are widely used for simple interface, low cost, and ease of use. In this lesson, we
will use the DS1302 real-time clock (RTC) module to obtain current date and time.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * RTC-DS1302 module
- 1 * I2C LCD1602 module
- 1 * 5-Pin anti-reverse cable
- 1 * 4-Pin anti-reverse cable
- 1 * Dupont wire (F to F)

Experimental Principle
DS1302 is a trickle charging clock chip, launched by DALLAS in America. With a built-in real-
time clock/calendar and a 31-byte static RAM, it can communicate with MCU through
simple serial interfaces. The real-time clock/calendar circuit provides information about
second, minute, hour, day, week, month, and year. DS1302 can automatically adjust the
number of days per month and days in leap year. You can determine to use a 24-hour or
12-hour system by AM/PM selection. It can simply communicate with MCU in a synchronous
serial way and only needs to use three interface cables: Reset (RST) cable, I/O data (SDA)
cable and serial clock (SCL) cable.

83
The schematic diagram

Experimental Procedures
Step 1: Build the circuit
The wiring between DS1302 and SunFounder Uno board is as shown below:

DS1302 SunFounder Uno

SCL 7

SDA 6

RST 5

VCC 5v

GND GND

84
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, you can see the current date and time displayed on the I2C LCD1602.

85
Lesson 23 Humiture Detection
Introduction
The digital temperature and humidity sensor DHT11 is a composite sensor that contains a
calibrated digital signal output of temperature and humidity. The technology of a
dedicated digital modules collection and the temperature and humidity sensing
technology are applied to ensure that the product has high reliability and excellent long-
term stability.

The sensor includes a resistive sense of wet component and an NTC temperature
measurement device, and is connected with a high-performance 8-bit microcontroller.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * Humiture sensor module
- 1 * I2C LCD1602
- 1 * 3-Pin anti-reverse cable
- 1 * 4-Pin anti-reverse cable
- 1 * Dupont wire (F to F)

Experimental Principle
Only three pins are available for use: VCC, GND, and DATA. The communication process
begins with the DATA line sending start signals to DHT11, and DHT11 receives the signals and
returns an answer signal. Then the host receives the answer signal and begins to receive 40-
bit humiture data (8-bit humidity integer + 8-bit humidity decimal + 8-bit temperature
integer + 8-bit temperature decimal + 8-bit checksum).

86
For more information, please refer to the datasheet of DHT11.

The schematic diagram

Experimental Procedures
Step 1: Build the circuit

87
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

88
Now, you can see the current value of humidity and temperature displayed on the I2C
LCD1602.

89
Lesson 24 Relay
Introduction
As we know relay is a device which is used to provide connection between two or more
points or device in response to the input signal applied. In another words relay provide
isolation between the controller and the device as we know devices may work on AC as
well as on DC. However, they receive signals from microcontroller which works on DC
hence we require a relay to bridge the gap. Relay is extremely useful when you need to
control a large amount of current or voltage with small electrical signal.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * Relay module
- 1 * 3-Pin anti-reverse cable

Experimental Principle
Relay There are 5 parts in every relay:

1. Electromagnet It consists of an iron core wounded by coil of wires. When electricity is


passed through, it becomes magnetic. Therefore, it is called electromagnet.

2. Armature The movable magnetic strip is known as armature. When current flows
through them, the coil is it energized thus producing a magnetic field which is used to
make or break the normally open (N/O) or normally close (N/C) points. And the armature
can be moved with direct current (DC) as well as alternating current (AC).

3. Spring When no currents flow through the coil on the electromagnet, the spring pulls
the armature away so the circuit cannot be completed.

4. Set of electrical contacts There are two contact points:


Normally open - connected when the relay is activated, and disconnected when it is
inactive.
Normally close not connected when the relay is activated, and connected when it is
inactive.
5. Molded frame Relays are covered with plastic for protection.
90
Working of Relay
The working principle of relay is simple. When power is supplied to the relay, currents start
flowing through the control coil; as a result, the electromagnet starts energizing. Then the
armature is attracted to the coil, pulling down the moving contact together thus
connecting with the normally open contacts. So the circuit with the load is energized. Then
breaking the circuit would a similar case, as the moving contact will be pulled up to the
normally closed contacts under the force of the spring. In this way, the switching on and off
of the relay can control the state of a load circuit.

So in this experiment, hook the SIG to the SunFounder Uno board. Send a low level to SIG;
the PNP transistor is energized and the coil of the relay is electrified. Thus, the normally open
contact of the relay is closed, while the normally closed contact of the relay will be off the
public port. Send a high level to SIG; the transistor will be de-energized and the relay will
restore to the initial state.

91
Experimental Procedures
Step 1: Build the circuit

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, you may hear the ticktock. That's the normally closed contact opened and the
normally open contact closed.

92
Lesson 25 Stepper Motor
Introduction
Stepper motors, due to their unique design, can be controlled to a high degree of
accuracy without any feedback mechanisms. The shaft of a stepper, mounted with a series
of magnets, is controlled by a series of electromagnetic coils that are charged positively
and negatively in a specific sequence, precisely moving it forward or backward in small
"steps".

There are two types of steppers, unipolars and bipolars, and it is very important to know
which type you are working with. In this experiment, we will use a unipolar stepper.

SunFounder board or other MCUs cannot directly drive stepper motors. A driver circuit is
necessary, so we use a stepper motor driver board (as shown in the following picture) to
drive the stepper motor.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * Stepper Motor
- 1 * Stepper Motor Driver
- Several jumper wires
93
Experimental Principle
The stepper motor is a four-phase one, which uses a unipolarity DC power supply. As long
as you electrify all phase windings of the stepper motor by an appropriate timing sequence,
you can make the motor rotate step by step. The schematic diagram of a four-phase
reactive stepper motor is as shown below:

In the figure, in the middle of the motor is a rotor a gear-shaped permanent magnet.
Around the rotor, 0 to 5 are teeth. Then more outside, there are 8 magnetic poles, with
each two opposite ones connected by coil winding. So they form four pairs from A to D,
which is called a phase. It has four lead wires to be connected with switches SA, SB, SC, and
SD. Therefore, the four phases are in parallel in the circuit, and the two magnetic poles in
one phase are in series.

Here's how a 4-phase stepper motor works:

At the beginning, switch SB is power on, switch SA, SC, and SD is power off, and B-phase
magnetic poles align with tooth 0 and 3 of the rotor. At the same time, tooth 1 and 4
generate staggered teeth with C- and D-phase poles. Tooth 2 and 5 generate staggered
teeth with D- and A-phase poles. When switch SC is power on, switch SB, SA, and SD is power
off, the rotor rotates under magnetic field of C-phase winding and that between tooth 1

94
and 4. Then tooth 1 and 4 align with the magnetic poles of C-phase winding. While tooth 0
and 3 generate staggered teeth with A- and B-phase poles, and tooth 2 and 5 generate
staggered teeth with the magnetic poles of A- and D-phase poles. The similar situation
goes on and on. Energize the A, B, C and D phases in turn, and the rotor will rotate in the
order of A, B, C and D.

The four-phase stepper motor has three operating modes: single four-step, double four-step,
and eight-step. The step angle for the single four-step and double four-step are the same,
but the driving torque for the single four-step is smaller. The step angle of the eight-step is
half that of the single four-step and double four-step. Thus, the eight-step operating mode
can keep high driving torque and improve control accuracy. In this experiment, we let the
stepper motor work in the eight-step mode.

To apply the motor in the circuit, a driver board needs to be used. Stepper Motor Driver-
ULN2003 is a 7-channel inverter circuit. That is, when the input end is at high level, the
output end of ULN2003 is at low level, and vice versa. If we supply high level to IN1, and low
level to IN2, IN3 and IN4, then the output end OUT1 is at low level, and all the other output
ends are at high level. So D1 lights up, switch SA is power on, and the stepper motor rotates
one step. The similar case repeats on and on. Therefore, just give the stepper motor a
specific timing sequence, it will rotate step by step. The ULN2003 here is used to provide
particular timing sequences for the stepper motor.

The internal schematic diagram of the Stepper Motor Driver is as follows.

95
Experimental Procedures
Step 1: Build the circuit
The wiring between Stepper Motor Driver board and SunFounder Uno board:

Stepper Motor Driver SunFounder Uno

D 11

C 10

B 9

A 8

GND GND

VCC 5v

96
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, you should see the rocker arm of the stepper motor spin clockwise and
counterclockwise alternately.

97
Lesson 26 Servo
Introduction
Servo is a type of geared motor that can only rotate 180 degrees. It is controlled by sending
electrical pulses from your SunFounder board. These pulses tell the servo what position it
should move to.

A servo has three wires: the brown wire is GND, the red one is VCC, and the orange one is
signal line.

Components
- 1* SunFounder Uno board
- 1 * USB data cable
- 1 * Servo
- Several jumper wires (M to M)

Experimental Principle

Servo
A servo is generally composed of the following parts: case, shaft, gear train, adjustable
potentiometer, DC motor, and control circuit board.

It works like this: The SunFounder Uno board sends out PWM signals to the servo, and then
the control circuit in the servo receives the signals through the signal pin and controls the
motor inside to turn. As a result, the motor drives the gear chain and then motivates the
shaft after deceleration. The shaft and adjustable potentiometer of the servo are
connected together. When the shaft rotates, it drives the pot, so the pot outputs a voltage
signal to the circuit board. Then the board determines the direction and speed of rotation
based on the current position, so it can stop exactly at the right position as defined and
hold there.

98
Experimental Procedures
Step 1: Build the circuit

The schematic diagram

99
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, you can see the rocker arm of the servo rotate and stop at 90 degrees (15 degrees
each time). And then it rotates in the opposite direction.

100
101
Lesson 27 Joystick PS2
Introduction
A joystick is an input device consisting of a stick that pivots on a base and reports its angle
or direction to the device it is controlling. Joysticks are often used to control video games
and robots. A Joystick PS2 is used here.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * Joystick PS2 module
- 1 * 5-Pin anti-reverse cable

Experimental Principle
This module has two analog outputs (corresponding to X and Y coordinates) and one
digital output representing whether it is pressed on Z axis.

102
Experimental Procedures
Step 1: Build the circuit
The wiring between the Joystick PS2 and SunFounder Uno board:

Joystick PS2 SunFounder Uno

GND GND

VCC 5V

Bt 7

x A0

y A1

103
Step 2: Open the code file
Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, push the joystick and the coordinates of X and Y axes displayed on Serial Monitor will
change accordingly; press down the joystick, and the coordinate of Z=0 will also be
displayed.

104
Lesson 28 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
with a normal plastic-packaged transistor in size and it is suitable for all kinds of infrared
remote control and infrared transmission.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * Infrared-receiver module
- 1 * Remote controller
- 1 * 3-Pin anti-reverse cable

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 SunFounder Uno board will light up. Connect
an LED to pin 13 on the SunFounder Uno board so that you can see remotely whether the
Power key is pressed down.

105
Experimental Procedures
Step 1: Build the circuit

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

Now, press the Power key of a remote control, and both the LED attached and that
connected to pin 13 on the SunFounder Uno board will light up. Then press any other key,
and the LEDs will go out.

106
Lesson 29 RFID Entrance Guard System
Introduction
RFID is short for radio frequency identification. It is a wireless application to transfer data in
the purpose of identifying and tracking tags. In this experiment, we will use an RFID module,
a relay, and an I2C LCD1602 to assemble an entrance guard system.

Components
- 1 * SunFounder Uno board
- 1 * USB data cable
- 1 * RFID module
- 1 * RFID key tag
- 1 * Relay
- 1 * I2C LCD1602
- Several jumper wires
- 1 * 3-Pin anti-reverse cable
- 1 * 4-Pin anti-reverse cable
- 1 * Breadboard

Experimental Principle
First, you need to know the ID of the RFID key tag and write the ID to the rfidTest file.
Compile the code. We can see "Welcome!" display on the I2C LCD1602. Swipe the RFID key
ring on the RFID module. If the password is correct, the normally open contact of the relay
will be closed and the LCD will display a string ID:5AE4C955 "hello SunFounder", and then
"Welcome!" two seconds later; if the password is incorrect, the normally open contact of
the relay will be disconnected and the LCD will display a string "Hello unknown guy" , and
then "Welcome!" two seconds later

107
Note: For this module, please use a 3.3V power supply, or it will get burnt.

Experimental Procedures
Step 1: Build the circuit
The wiring between RFID and SunFounder Uno is as follows:

RFID SunFounder Uno

VCC 3.3V

RST 2

GND GND

MISO 3

MOSI 4

SCK 5

NSS 6

IRQ 7

The wiring between I2C LCD1602 and SunFounder Uno:

I2C LCD1602 SunFounder Uno

GND GND

VCC 5v

SDA A4

SCL A5

The wiring between Relay Module and SunFounder Uno:

Relay Module SunFounder Uno

SIG 8

VCC 5V

GND GND

108
Step 2: Open the code file getId
Step 3: Select the correct Board and Port, and upload the sketch to the SunFounder Uno
board

Then place the RFID key tag in the induction zone of the RFID module. You will see the
following values printed on Serial Monitor:

109
Step 4: Now, you may know the ID of your RFID key tag (e.g. my magnetic card ID is
5AE4C955).

Open the rfidTest file and replace the ID in the sketch with the ID you just note down (divide
the ID into four parts and fill them according to the following format), as follows:

Step 5: Upload this sketch to SunFounder Uno board

Now, swipe the RFID key tag on the RFID module. If the password is correct, the LCD will
display a string ID:5AE4C955 Hello SunFounder, and then display "Welcome!" two
seconds later. If the password is incorrect, the LCD will display a string Hello unknown guy,
and then display "Welcome!" two seconds later.

110
111
Lesson 30 Password Lock
Introduction
After having learnt so many modules separately, lets use these modules together to make
some funny interactive works! In this lesson, we will use an I2C LCD1602, a relay module, a
potentiometer and a keypad to assemble a simple password lock. It is built based on a
SunFounder microcontroller and can be applied in security doors.

Components
- 1* SunFounder Uno board
- 1 * USB data cable
- 1 * Relay module
- 1 * I2C LCD1602
- 1 * Keypad
- Several jumper wires
- 1 * 3-Pin anti-reverse cable
- 1 * Breadboard

Experimental Principle
Set a password (for example 123456) by programming. The I2C LCD1602 displays
"Welcome!" after power on. At this point, the normally open contact of the relay is
disconnected, and the indicator LED on the relay module keeps off. Press the asterisk "*"
key to input the password, and then press "#".

If the password is correct, the normally open contact of the relay will be closed and the
indicator light will be on. The I2C LCD1602 will display "Input Correctly" "Please Come In". If
you input other contents, the I2C LCD1602 will display "Input Error!" "Please Again", and the
relay will keep the initial state. Two seconds later, the I2C LCD1602 displays "Welcome!".

112
NOTE: Through programming, we've set the four keys in the first row (with pins at the top as
shown in the figure above) as 1, 2, 3, 4; those in the second row as 5, 6, 7, 8; in the third as 9,
A, B, C; and in the fourth as D, *, 0, #.

Experimental Procedures
Step 1: Build the circuit
The wiring between the I2C LCD1602 and the SunFounder board:

I2C LCD1602 SunFounder Uno

GND GND

VCC 5v

SDA A4

SCL A5

The wiring between the relay module and the SunFounder board:

Relay Module SunFounder Uno

SIG 3

VCC 5V

GND GND

113
The wiring between the keypad and the SunFounder board:

Keypad SunFounder Uno

X1 8

X2 9

X3 10

X4 11

Y1 4

Y2 5

Y3 6

Y4 7

Step 2: Open the code file


Step 3: Select the correct Board and Port
Step 4: Upload the sketch to the SunFounder Uno board

114
Now, the I2C LCD1602 will display "Welcome!" after power on. At this point, the indicator
LED on the relay keeps off. When you press "*" key, it will prompt "Input Your Code:". If you
enter 123456 and press # key to confirm, the indicator LED on the relay module will light
up. The I2C LCD1602 will display "Input Correctly" "Please Come In". Two seconds later,
"Welcome!" will be displayed on the I2C LCD1602. But if you input other contents, it will
display "Input Error!" "Please Again", and the relay will keep the initial state. Two seconds
later, the I2C LCD1602 displays "Welcome!".

Tips: For any TECHNICAL questions, add a topic under FORUM section on our website
www.sunfounder.com and we'll reply as soon as possible. For NON-TECH questions like order
issues, please email service@sunfounder.com.

115
Copyright Notice

All contents including but not limited to texts, images, and code in this manual are owned
by the SunFounder Company. You should only use it for personal study, investigation,
enjoyment, or other non-commercial or nonprofit purposes, under the related regulations
and copyrights laws, without infringing the legal rights of the author and relevant right
holders. For any individual or organization that uses these for commercial profit without
permission, the Company reserves the right to take legal action.

116

Das könnte Ihnen auch gefallen