Professional Documents
Culture Documents
1
1.Introduction
keyestudio super learning kit is suitable for Arduino
2.Component List
board.
1 LED - Blue 5
2
2 LED - Red 5
3 LED - Yellow 5
4 LED - RGB 1
5 220Ω Resistor 8
6 10KΩ Resistor 5
7 1KΩ resistor 5
10KΩ
8 1
Potentiometer
9 Buzzer (Active) 1
3
10 Buzzer (Passive) 1
Large Button
11 4
Switch
13 Photo Resistor 3
14 Flame Sensor 1
IC 74HC595N
16 1
16-pin DIP
7-seg LED
17 1
Segment Display
4
7-seg LED
18 1
Segment Display
21 IR Receiver 1
22 IR Remote Control 1
23 Servo Motor 1
24 Stepper Driver 1
25 Stepper Motor 1
5
26 Joystick Module 1
27 Relay Module 1
ADXL345
Three Axis
30 1
Acceleration Modul
HC-SR04
31 1
Ultrasonic Sensor
6
DS3231 Clock
32 1
Module
DHT11
33 Temperature and 1
Humidity Sensor
Soil Humidity
34 1
Sensor
RC522 RFID
35 1
Module
36 RFID Card 1
37 Access Key 1
38 Pin Headers 40
7
830-hole
39 1
Breadboard
40 Dupont Wire 10
41 Jumper Wire 30
6-cell AA Battery
42 1
Case
43 USB Cable 1
8
3.Install Arduino IDE and Driver
below
9
There are two versions of IDE for WINDOWS system, you can
suggest you use the first one that installs directly everything
drivers. With the Zip package you need to install the drivers
portable installation.
10
(2)keyestudio V4.0 Development Board
s a UART-to-USB converter.
11
It has 14 digital input/output pins (of which 6 can be used a
button.
12
It contains everything needed to support the microcontroller;
13
Microcontroller ATmega328P-PU
Operating Voltage 5V
Input Voltage
DC7-12V
(recommended)
14 (D0-D13)
output)
PWM Digital I/O Pins 6 (D3, D5, D6, D9, D10, D11)
32 KB (ATmega328P-PU) of
bootloader
SRAM 2 KB (ATmega328P-PU)
EEPROM 1 KB (ATmega328P-PU)
LED_BUILTIN D13
14
Keyestudio Mega 2560 R3 is a microcontroller board based on
jack, 1 ICSP header, and a reset button. The built-in ICSP port
head and Vin GND pins. To facilitate wiring, a 0.5 m USB wire
15
Specialized Functions of Some Pins:
D19 (RX1) and D18 (TX1); Serial 2: D17 (RX2) and D16
(RX) and transmit (TX) TTL serial data. Pins 0 and 1 are also
16
2. PWM Pins (Pulse-Width Modulation): D2 to D13, and D44
(interrupt 5), D19 (interrupt 4), D20 (interrupt 3), and D21
theSPI library. The SPI pins are also broken out on the ICSP
17
If install unsuccessfully, or you intend to install manually,
18
Click“OK”to enter the following page, click“browse my
below
19
There is a DRIVERS folder in Arduino software installed
follow my way)
20
Open device manager, we will find the yellow exclamation
successfully.
21
22
The installation method of keyestudio MEGA 2560 board and
23
To avoid the errors when uploading the program to the board,
you need to select the correct Arduino board that matches the
Then select the correct COM port (you can see the
installed)
24
Before uploading the program to the board, let’s demonstrate
25
A- Used to verify whether there is any compiling mistakes or
not.
serial monitor.
26
(6)Start First Program
shown below
27
Set board and COM port, the corresponding board and COM
28
Click to start compiling the program, check errors.
29
Upload the program successfully, the onboard LED lights on
for 1s, lights off for 1s. Congratulation, you finish the first
program.
30
4.How to Add a Library?
libraries .
31
Step 2 Enter it to find out libraries folder, this folder is the
32
33
You just need to replicate and paste above libraries into the
shown below
34
5.Project Details
1.Introduction
test of your Arduino and PC, but also a primer project for you
2.Hardware Required
USB cable*1
35
3.Sample Code
instruction.
/*
Project 1
Hello World
http//www.keyestudio.com
*/
void setup()
void loop()
36
Arduino, and assign them to Val.
“R”.
{ // if it’s “R”,
}}//
///////////////////////////////////////////////////////////////
4.Test Result
you!
37
Project 2: LED Blinking
1.Introduction
2. Hardware Required
Red M5 LED*1
220Ω Resistor*1
Breadboard*1
USB cable*1
38
3. Little Knowledge
positive and negative poles. The short leg is negative pole, the
39
The units larger than ohms are kiloohms (KΩ) and megaohms
you must also pay attention to its power. In the project, the
any circuit design. The breadboard has many holes into which circuit
is shown below:
40
The bread board has strips of metal which run underneath
the board and connect the holes on the top of the board. The
metal strips are laid out as shown below. Note that the top
41
To use the bread board, the legs of components are placed
4.Circuit Connection
link. Here we use digital pin 10. We connect LED to a 220 ohm
42
Connection for V4.0
43
Connection for 2560
44
5.Sample Code
/*
Project 2
Blink
http//www.keyestudio.com
*/
void setup()
void loop()
//////////////////////////////////////////////////////////////////
45
6.Test Result
Thank you!
46
Project 3: PWM
1.Introduction
cycle of PMW.
2.Working Principle
47
load; being off, it's not. With adequate bandwidth, any analog
voltage value
Width
Level
Cycle
48
1. The amplitude of pulse width (minimum / maximum)
second)
LED", using digital signal to control digital pin, also one about
potentiometer.
3.Hardware Required
Red M5 LED*1
220Ω Resistor
Breadboard*1
USB cable*1
4.Circuit Connection
49
Connection for V4.0
50
5.Sample Code
/*
Project 3
pwm
http//www.keyestudio.com
*/
void setup() {
pinMode(ledPin,OUTPUT);
51
}
void loop(){
analogWrite(ledPin, value);
delay(5);
analogWrite(ledPin, value);
delay(5);
//////////////////////////////////////////////////////////////////
6.Test Result
52
Project 4: Traffic Light
1.Introduction
53
In the previous program, we have done the LED blinking
than an LED.
2.Hardware Required
USB Cable *1
Red M5 LED*1
Yellow M5 LED*1
Blue M5 LED*1
220Ω Resistor *3
Breadboard*1
3.Circuit Connection
54
Connection for V4.0
55
4..Sample Code
system.
/*
Project 4
traffic light
56
http//www.keyestudio.com
*/
void setup()
“output”
void loop()
57
digitalWrite(yellowled, LOW);// turn off yellow LED
//////////////////////////////////////////////////////////////////
5.Test Result
The blue light will be on for 5 seconds, and then off, followed
by the yellow light blinking for 3 times, and then the red light
58
Project 5: LED Chasing Effect
1.Introduction
59
We can see many billboards composed of colorful LEDs. They
2.Hardware Required
Red LED*6
220Ω Resistor *6
USB cable*1
3.Circuit Connection
60
Connection for V4.0
61
Connection for 2560
62
4.Sample Code
/*
Project 5
http//www.keyestudio.com
*/
63
void setup()
void loop()
digitalWrite(i, LOW); // set I/O pins as “low”, turn off LEDs one
by one.
delay(200); // delay
one by one
delay(200); // delay
64
//////////////////////////////////////////////////////////////////
5.Test Result
65
Project 6: Button-Controlled LED
1.Introduction
(conducting) state.
2.Hardware Required
66
V4.0 Board or MEGA 2650 Board*1
Button switch*1
Red M5 LED*1
220ΩResistor*1
10KΩ Resistor*1
Breadboard*1
USB cable*1
3. Little Knowledge
contact goes back to initial state, that is, off state. The pressure is
67
Schematic Diagrams:
68
4. Circuit Connection
69
Connection for 2560
70
5.Sample Code
the LED will be on. Based on the previous study, the coding
use an if () statement.
Arduino program.
can program pin 11 to output high level and turn on the LED.
When pin 7 outputs low level, pin 11 also outputs low level
/*
Project 6
Button
http//www.keyestudio.com
*/
71
int val;// define val
void setup()
void loop()
{ digitalWrite(ledpin,LOW);}
else
{ digitalWrite(ledpin,HIGH);}
//////////////////////////////////////////////////////////////////
6.Test Result
experiment is completed.
72
The simple principle of this experiment is widely used in a
73
Project 7: Active Buzzer
1.Introduction
2.Hardware Required
Buzzer*1
Breadboard*1
USB cable*1
74
3. Little Knowledge
There are two kinds of buzzer, active buzzer and passive buzzer.
4.Circuit Connection
75
Connection for V4.0
76
When connecting the circuit, pay attention to the positive and
negative poles of the buzzer. In the photo, you can see there
are red and black lines. When the circuit is finished, you can
5.Sample Code
high/low level.
/*
Project 7
Active Buzzer
http//www.keyestudio.com
77
*/
void setup()
void loop()
//////////////////////////////////////////////////////////////////
6.Test Result
78
Project 8: Passive Buzzer
1.Introduction
79
previous experiment has something to do with LED. However,
simple.
2.Hardware Required
Passive Buzzer*1
Breadboard*1
USB cable*1
3. Little knowledge
between the two buzzers, but when the pins of the two
buzzers are placed up, the passive buzzer comes with green
80
circuit board, and the one sealed with vinyl is an active
buzzer.
4. Circuit Connection
81
Connection for 2560
5.Sample Code
82
/*
Project 8
Passive Buzzer
http//www.keyestudio.com
*/
void setup()
output
void loop()
while(1)
{ digitalWrite(buzzer,HIGH);// sound
delay(1);//delay1ms
digitalWrite(buzzer,LOW);//not sound
delay(1);//ms delay
83
{ digitalWrite(buzzer,HIGH);// sound
delay(2);//2ms delay
digitalWrite(buzzer,LOW);//not sound
delay(2);//2ms delay
}}}
//////////////////////////////////////////////////////////////////
6.Test Result
84
Project 9: RGB LED
1.Introduction
red (R), green (G), and blue (B) and integrating them. RGB
2.Hardware Required
USB Cable * 1
RGB LED * 1
Resistor *3
3. Little Knowledge
85
The monitors mostly adopt the RGB color standard, and all the
RGB.
4.Circuit Connection
86
Connection for V4.0
87
Connection for 2560
5.Sample Code
/*
Project 9
RGB
http//www.keyestudio.com
*/
int redpin = 11; //select the pin for the red LED
int bluepin =10; // select the pin for the blue LED
88
int greenpin =9;// select the pin for the green LED
int val;
void setup() {
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
Serial.begin(9600);
void loop()
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(1);
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
89
delay(1);
Serial.println(val, DEC);
//////////////////////////////////////////////////////////////////
6.Test Result
Directly copy the above code into arduino IDE, and click
upload, wait for a few seconds, you can see a full-color LED.
90
Project 10: Photo Resistor
1.Introduction
2.Hardware Required
Photo Resistor*1
Red M5 LED*1
91
10KΩ Resistor*1
220Ω Resistor*1
Breadboard*1
USB cable*1
3. Little Knowledge
switches, etc.
photovaristor application.
92
Photovaristor is an element that can change its resistance as
4.Circuit Connection
93
Connection for 2560
94
5.Sample Code
/*
Project 10
Photo Resistor
http//www.keyestudio.com
*/
photovaristor
void setup()
void loop()
95
assign it to val
value 255)
//////////////////////////////////////////////////////////////////
6.Test Result
one.
96
Project 11: Flame Sensor
1.Introduction
97
Flame sensor (infrared receiving triode) is specially used for
to flame.
2.Hardware Required
Flame Sensor *1
Buzzer *1
10K Resistor *1
USB cable*1
2. Little Knowledge
accordingly.
98
connect one end of a jumper wire to a clip which is electrically
shown below
4.Experiment Principle
When it's approaching a fire, the voltage value read from the
analog port will differ. If you use a multimeter, you can see
99
around 0.3V; when there is fire approaching, the voltage it
reads is around 1.0V. The nearer the fire is, the higher the
voltage is.
5.Circuit Connection
100
Connection for V4.0
101
Connection for MEGA 2560
102
6.Sample Code
/*
Project 11
Flame
http//www.keyestudio.com
*/
void setup()
void loop()
if(val>=600)// when the analog value is larger than 600, the buzzer
will buzz
103
{
digitalWrite(Beep,HIGH);
}else
digitalWrite(Beep,LOW);
delay(500);
//////////////////////////////////////////////////////////////////
7.Test Result
104
Project 12: LM35 Temperature Sensor
1.Introduction
temperature sensor.
2. Working Principle
105
LM35 temperature sensor can produce different voltage by
different temperature
formula is as follows:
3.Hardware Required
LM35*1
Breadboard*1
106
USB cable*
4.Circuit Connection
107
Connection for 2560
108
5.Sample Code
/*
Project 12
LM35
http//www.keyestudio.com
*/
sensor
void setup()
void loop()
109
Serial.print("Tep");// output and display characters
//////////////////////////////////////////////////////////////////
6.Test Result
110
111
Project 13: Tilt Switch
1.Introduction
control the LED light by reading the state of the ball switch.
2.Working Principle
112
according to the voltage value of the analog port, whether it's
3.Hardware Required
Ball switch*1
Led *1
220Ω Resistor*1
10KΩ resistor*1
USB cable*1
4.Circuit Connection
113
Connection for V4.0
114
5.Sample Code
/*
Project 13
Tilt Switch
http//www.keyestudio.com
*/
void setup()
115
}
void loop()
while(1)
else// otherwise
}}}
//////////////////////////////////////////////////////////////////
6.Test Result
the LED will be on. If there is no tilt, the LED will be off.
control.
116
Experiment now is completed. Thank you!
1.Introduction
117
What is an infrared receiver?
2.Working Principle
118
Infrared receiver has 3 pins. When you use it, connect VOUT
4.Hardware Required
119
Infrared Remote Controller *1
Infrared Receiver *1
LED *6
220ΩResistor *6
USB cable*1
5.Circuit Connection
11, connect the LEDs with resistors and connect the resistors
to pin 2,3,4,5,6,7.
120
Connection for V4.0
121
Connection for 2560
122
6.Experimental Principle
you must first know how it's coded. The coding method we
• NEC protocol
7.Features
8.Protocol is as below
immediately released
123
The picture above shows a typical pulse train of the NEC
set the gain of the earlier IR receivers. This AGC burst is then
transmitted twice. The second time all bits are inverted and
124
A command is transmitted only once, even when the key on
the remote
• Repeat pulse
Note when the pulse enters the integrated receiver, there will
you need to make sure the level of the output is just the
low level. You can see the pulse of the receiving end in
125
9.Sample Code
/*
Project 14
Remote
http//www.keyestudio.com
*/
#include <IRremote.h>
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
126
long off4 = 0x00FF38C7;
IRrecv irrecv(RECV_PIN);
decode_results results;
if (results->decode_type == UNKNOWN)
else
if (results->decode_type == NEC)
127
Serial.print("Decoded NEC: ");
Serial.print(results->value, HEX);
Serial.print(" (");
Serial.print(results->bits, DEC);
Serial.println(" bits)");
Serial.print("Raw (");
Serial.print(count, DEC);
Serial.print("): ");
128
for (int i = 0; i < count; i++)
if ((i % 2) == 1) {
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
else
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
Serial.print(" ");
Serial.println("");
void setup()
pinMode(RECV_PIN, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
129
pinMode(13, OUTPUT);
Serial.begin(9600);
int on = 0;
void loop()
if (irrecv.decode(&results))
on = !on;
dump(&results);
if (results.value == on1 )
digitalWrite(LED1, HIGH);
if (results.value == off1 )
130
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();
131
irrecv.resume(); // Receive the next value
//////////////////////////////////////////////////////////////////
https//github.com/shirriff/Arduino-IRremote
10.Test Result
132
Done uploading, open the serial monitor, you can see the
result as below.
133
1.Introduction
2.Hardware Required
Potentiometer *1
Breadboard*1
USB cable*1
3.Potentiometer Features
level and low level). The analog quantity is different. Its data
134
state presents a linear state such as 1 to 1000.
4.Circuit Connection
screen.
experiments.
135
Connection for 2560
136
5.Sample Code
among 0 to 1023.
First, you need to set the baud rate in voidsetup (). Displaying
baud rate of the Arduino should match the one in the PC's
no display at all.
window, there is a button for baud rate set up. The set up
/*
Project 15
137
Potentiometer
http//www.keyestudio.com
*/
void setup()
void loop()
assign it to val
//////////////////////////////////////////////////////////////////
138
6.Test Result
The Sample Code uses the built-in LED connected to pin 13.
Each time the device reads a value, the LED blinks. When you
139
Project 16: 74HC595 chip
1.Introduction
140
put it simply, 74HC595 chip is a combination of
tri-state output.
2.Hardware Required
74HC595 chip*1
Red M5 LED*4
Green M5 LED*4
220Ω Resistor*8
Breadboard*1
USB cable*1
141
3. Pins Description:
8 GND GND
9 MR Serial Output
142
12 ST_CP Storage Register Clock Input
VCC and GND are used to supply power for chip, the
pin by bit.
transmitted.
register.
143
experiment, we connect to VCC to keep high level.
chip cascade.
4.Circuit Connection
144
Connection for 2560 R3
145
The circuit may seem complicated, but once you wire it in
5.Sample Code
/*
Project 16
74hc595
http//www.keyestudio.com
146
*/
int ledState = 0;
void setup()
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
void loop()
updateLEDs(i);
delay(500);
147
{
digitalWrite(latch, LOW);//
level first
//////////////////////////////////////////////////////////////////
6.Test Result
148
Project 17: 1-digit LED Segment Display
1.Introduction
2.Hardware Required
220Ω Resistor*8
Breadboard*1
USB cable*1
149
3.The display principle of the 1-digit LED Segment Display
8-segment display has one more LED unit ( for decimal point
the one that combine all the anodes of LED units into one
150
Each segment of the display consists of an LED. So when you
4.Circuit Connection
151
Connection for V4.0
152
Connection for 2560
153
5.Sample Code
time, the longer the delay time, the longer the displaying
154
time.
/*
Project 17
http//www.keyestudio.com
*/
unsigned char j;
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
155
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
digitalWrite(dp,LOW);
unsigned char j;
digitalWrite(j,LOW);
unsigned char j;
digitalWrite(b,HIGH);
digitalWrite(a,HIGH);
for(j=9;j<=11;j++)
156
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
digitalWrite(c,LOW);
digitalWrite(f,LOW);
{digitalWrite(g,HIGH);
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(dp,LOW);
digitalWrite(f,LOW);
digitalWrite(e,LOW);
{digitalWrite(c,HIGH);
digitalWrite(b,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dp,LOW);
digitalWrite(a,LOW);
157
digitalWrite(e,LOW);
digitalWrite(d,LOW);
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);
unsigned char j;
for(j=7;j<=11;j++)
digitalWrite(j,HIGH);
digitalWrite(c,HIGH);
digitalWrite(dp,LOW);
158
digitalWrite(b,LOW);
unsigned char j;
for(j=5;j<=7;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
for(j=8;j<=11;j++)
digitalWrite(j,LOW);
unsigned char j;
for(j=5;j<=11;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
unsigned char j;
digitalWrite(a,HIGH);
159
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e, LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dp,LOW);
void setup()
for(i=4;i<=11;i++)
void loop()
while(1)
160
digital_2();// display number 2
}}
//////////////////////////////////////////////////////////////////
6.Test Result
161
Project 18: 4-digit LED Segment Display
1.Introduction
162
In this experiment, we use an Arduino to drive a common
resistors.
2.Hardware Required
220Ω Resistor*8
Breadboard*1
163
USB cable*1
For 4-digit display, there are 12 pins in total. When you place
the decimal point downward, the pin on the lower left part is
164
4.Circuit Connection
165
Connection for V4.0
166
Connection for 2560 R3
5.Sample Code
/*
Project 18
http//www.keyestudio.com
167
*/
// display 1234
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 6;
int g = 7;
int dp = 8;
int d4 = 9;
int d3 = 10;
int d2 = 11;
int d1 = 12;
// set variable
long n = 1230;
int x = 100;
void setup()
168
{
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(dp, OUTPUT);
/////////////////////////////////////////////////////////////
void loop()
Display(1, 1);
Display(2, 2);
Display(3, 3);
Display(4, 4);
169
}
///////////////////////////////////////////////////////////////
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);
170
digitalWrite(d4, HIGH);
break;
case 4:
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, LOW);
break;
default :
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
void Num_0()
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
171
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);
172
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
void Num_3()
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
void Num_4()
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
173
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);
174
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(dp,LOW);
void Num_7()
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp,LOW);
void Num_8()
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
175
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);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
176
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp,LOW);
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();
177
break;
case 7:Num_7();
break;
case 8:Num_8();
break;
case 9:Num_9();
break;
default:Clear();
break;
WeiXuan(x);
pickNumber(Number);
delay(1);
//////////////////////////////////////////////////////////
6.Test Result
178
Download the above code to the controller board, you can see
179
1.Introduction
2.Hardware Required
8 * Resistor (220Ω)
1 * Breadboard
1 * USB Cable
180
The 8*8 dot-matrix is made up of sixty-four LEDs, and each
lighten. If you want to light the LED on the first dot, you
If you want to light LEDs on the first row, you should set pin 9
level.
If you want to light the LEDs on the first column, set pin 13 to
181
4.Circuit Connection
182
Connection for 2560 R3
183
5.Sample Code for displaying “0”
/*
Project 19
8*8 dot-matrix
http//www.keyestudio.com
184
*/
unsigned char
Text[]={0x00,0x1c,0x22,0x22,0x22,0x22,0x22,0x1c};
drawing function
{ clear_();
digitalWrite(x+2, HIGH);
digitalWrite(y+10, LOW);
delay(1);
function
for(i=0;i<8;i++)
data=Text[i];
for(j=0;j<8;j++)
data>>=1;
185
}
void setup(){
int i = 0 ;
for(i=2;i<18;i++)
pinMode(i, OUTPUT);
clear_();
void loop()
{ show_num();
{for(int i=2;i<10;i++)
digitalWrite(i, LOW);
for(int i=0;i<8;i++)
digitalWrite(i+10, HIGH);
//////////////////////////////////////////////////////////
186
6.Test Result
Burn the program into V4.0 board, the dot-matrix will display
0.
187
Project 20: 1602 LCD
1.Introduction
188
3.Pin description of 1602 LCD
No No
Mark Pin description Mark Pin description
. .
Select
Select
5 R/W 13 D6 Date I/O
read/write(H/L)
4.Interface Description
189
1. Two power pins, one for module power, another one for
for backlight.
190
6. D0-D7 is 8-bit bidirectional parallel bus, used for
7. BLA is anode for back light; BLK, cathode for back light.
RS=H, R/W=L,
Write inp outp
D0-D7=data, E=high none
data ut ut
pulse
6.Hardware Required
1 * 1602 LCD
1 * Potentiometer
1 * Breadboard
191
1 * USB Cable
7.Connection
192
Connection for 2560 R3
193
8.Sample Code A
/*
Project 20.1
LCD1602
http//www.keyestudio.com
*/
194
int DI = 12;
int RW = 11;
for bus
int Enable = 2;
int i = 0;
D7-D0( not D0-D7) for signal identification; here, it’s used for
signal inversion.
value >>= 1;
digitalWrite(Enable,LOW);
delayMicroseconds(1);
digitalWrite(Enable,HIGH);
digitalWrite(Enable,LOW);
195
}
int i = 0;
digitalWrite(DI, HIGH);
digitalWrite(RW, LOW);
value >>= 1;
digitalWrite(Enable,LOW);
delayMicroseconds(1);
digitalWrite(Enable,HIGH);
delayMicroseconds(1);
digitalWrite(Enable,LOW);
int i = 0;
196
pinMode(i,OUTPUT);
delay(100);
delay(64);
delay(50);
delay(20);
ng
delay(20);
flickering
delay(20);
197
LcdCommandWrite(0x01); // clear the scree, cursor position
returns to 0
delay(100);
flickering
delay(20);
position returns to 0
delay(10);
LcdCommandWrite(0x80+3);
delay(10);
LcdDataWrite('W');
LcdDataWrite('e');
LcdDataWrite('l');
LcdDataWrite('c');
LcdDataWrite('o');
198
LcdDataWrite('m');
LcdDataWrite('e');
LcdDataWrite(' ');
LcdDataWrite('t');
LcdDataWrite('o');
delay(10);
delay(10);
LcdDataWrite('k');
LcdDataWrite('e');
LcdDataWrite('y');
LcdDataWrite('e');
LcdDataWrite('s');
LcdDataWrite('t');
LcdDataWrite('u');
LcdDataWrite('d');
LcdDataWrite('i');
LcdDataWrite('o');
delay(5000);
returns to 0
199
delay(10);
LcdDataWrite('I');
LcdDataWrite(' ');
LcdDataWrite('a');
LcdDataWrite('m');
LcdDataWrite(' ');
LcdDataWrite('h');
LcdDataWrite('u');
LcdDataWrite('n');
LcdDataWrite('t');
LcdDataWrite('e');
LcdDataWrite('r');
delay(3000);
replay old ones, where there is no new ones remain the same
delay(10);
delay(10);
LcdDataWrite('t');
LcdDataWrite('h');
LcdDataWrite('e');
200
LcdDataWrite(' ');
LcdDataWrite('w');
LcdDataWrite('o');
LcdDataWrite('r');
LcdDataWrite('l');
LcdDataWrite('d');
delay(5000);
//////////////////////////////////////////////////////////
When using this module, 8-bit connection uses all the digital
201
Connection for V4.0
202
Connection for 2560 R3
203
After the connection, upload below code to the controller
9.Sample Code B
/*
Project 20.2
LCD1602
204
http//www.keyestudio.com
*/
* 10K resistor
http//www.arduino.cc/en/Tutorial/LiquidCrystal
*/
#include <LiquidCrystal.h>
void setup() {
205
// set up the LCD's number of columns and rows
lcd.begin(16, 2);
lcd.print("hello, world!");
void loop() {
0)
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
//////////////////////////////////////////////////////////
206
207
Project 21: Servo Control
1.Introduction
you.
2.Working Principle
accordingly and drive the core-less motor. The gear then pass
208
has reached the commanded position according to the
feedback signal.
Brown one is for GND, red one for power positive, orange one
209
signal.
But note that for different brand motor, the same signal may
3.Hardware Required
9G Servo Motor*1
210
USB cable*1
the motor.
used.
4.Method 1
211
Connection for V4.0
212
Connection for 2560 R3
Sample Code A
/*
Project 21.1
servo
213
http//www.keyestudio.com
*/
int val;
pulse function
“high”
pulse width
“low”
delay(20-pulsewidth/1000);
void setup()
214
Serial.begin(9600);// connect to serial port, set baud rate at
“9600”
Serial.println("servo=o_seral_simple ready" ) ;
if(val>='0'&&val<='9')
variable
Serial.print(val,DEC);
Serial.println();
commanded position
}}}
//////////////////////////////////////////////////////////
215
5.Method 2
pin 9 or 10.
Note the written form of the above statements are " servo
(9).
Sample Code B
/*
216
Project 21.2
servo
http//www.keyestudio.com
*/
#include <Servo.h>
void setup()
void loop()
//////////////////////////////////////////////////////////
Above are the two methods to control the servo. You can
6.Test Result
217
Project 22: Stepper Motor
1.Introduction
218
to it in the proper sequence.
2.Hardware Required
Stepper Motor*1
Jumper Wire *1
USB cable*1
219
3.Features
pulse.
energized)
and this error is non cumulative from one step to the next.
costly to control.
• Model 28BYJ-48
220
• Rated Voltage 5VDC
• Number of Phase 4
• Frequency 100Hz
• DC Resistance 50Ω±7%(25℃)
• Insulation Grade A
5.Circuit Connection
221
Connection for V4.0
222
6.Sample Code
/*
Project 22
Stepper Motor
http//www.keyestudio.com
*/
#include <Stepper.h>
int previous = 0;
void setup()
stepper.setSpeed(90);
void loop()
stepper.step(val - previous);
previous = val;
223
//////////////////////////////////////////////////////////
7.Test Result
1.Introduction
224
from a moving person or moving animal, and output
switching signals.
2.Hardware Required
Jumper Wire *1
USB cable*1
3.Specification
225
• Working Temperature -20 ~ 85 ℃
4.Circuit Connection
226
Connection for MEGA 2560 R3
5.Sample Code
/*
Project 23
227
PIR
http//www.keyestudio.com
*/
byte sensorPin = 3;
void setup()
pinMode(sensorPin,INPUT);
pinMode(indicator,OUTPUT);
Serial.begin(9600);
void loop()
digitalWrite(indicator,state);
delay(500);
//////////////////////////////////////////////////////////
228
6.Test Result
229
Project 24: Analog Gas Sensor
1.Introduction
230
This sensor is suitable for LPG, I-butane, propane, methane,
2.Hardware Required
Jumper Wire *1
USB cable*1
3.Specification
• Power Supply 5V
4.Circuit Connection
231
Connection for V4.0
232
5.Sample Code
/*
Project 24
Gas
http//www.keyestudio.com
*/
void setup()
void loop()
{int val;
233
delay(100);
//////////////////////////////////////////////////////////
6.Test Result
1.Introduction
234
up to +-16 g. Digital output data is formatted as 16-bit twos
2.Hardware Required
ADXL345 Sensor*1
Jumper Wire *1
USB cable*1
3.Specification
standby@ 2.5V
• Free-Fall Detection
235
4.Circuit Connection
236
5.Sample Code
/*
Project 25
ADXL345
http//www.keyestudio.com
*/
#include <Wire.h>
237
device is 8 bit but shift to the
// right by 1 bit to
int accelerometer_data[3];
// void because this only tells the cip to send data to its output
register
Wire.beginTransmission(address);
// Connect to device
Wire.write(reg);
// Send data
Wire.endTransmission();
238
// microcontroller reads data from the sensor's input register
int i = 0;
Wire.beginTransmission(address);
// Connect to device
Wire.write(reg);
Wire.endTransmission();
// Connect to device
Wire.beginTransmission(address);
Wire.requestFrom(address, count);
requested
data[i] = c;
i++;
239
Wire.endTransmission();
void init_adxl345() {
byte data = 0;
mode +_ 16g
register
if(data==0xE5)
else
240
void read_adxl345() {
byte bytes[6];
memset(bytes,0,6);
i2c_read(ADXL345_ADDRESS, ADXL345_REGISTER_XLSB,
6, bytes);
// Unpack data
accelerometer_data[i] = (int)bytes[2*i] +
void setup() {
Wire.begin();
Serial.begin(9600);
accelerometer_data[i] = 0;
init_adxl345();
241
}
void loop() {
read_adxl345();
Serial.print("ACCEL ");
Serial.print(float(accelerometer_data[0])*3.9/1000);//3.9m
Serial.print("\t");
Serial.print(float(accelerometer_data[1])*3.9/1000);
Serial.print("\t");
Serial.print(float(accelerometer_data[2])*3.9/1000);
Serial.print("\n");
delay(100);
//////////////////////////////////////////////////////////////////
6.Test Result
Wiring as the above diagram and power on, then upload the
code and open the serial monitor, it will display the triaxial
242
below.
243
244
Project 26: HC-SR04 Ultrasonic Sensor
1.Introduction
2.Hardware Required
245
Ultrasonic Sensor*1
Jumper Wire *1
USB cable*1
3.Specification
• Working Voltage DC 5V
• Max Range 4m
• Echo Output Signal Input TTL lever signal and the range in
proportion
4.Circuit Connection
246
Connection for V4.0
247
5.Sample Code
/*
Project 26
Ultrasonic
http//www.keyestudio.com
*/
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
248
pinMode(echoPin, INPUT);
required)
void loop() {
the
of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
sound.
distance = duration/58.2;
minimumRange){
249
to indicate "out of range" */
Serial.println("-1");
digitalWrite(LEDPin, HIGH);
else {
and
Serial.println(distance);
digitalWrite(LEDPin, LOW);
delay(50);
//////////////////////////////////////////////////////////
6.Test Result
After upload well the code to V4.0 board, then open the serial
monitor.
near and far), it will detect the distance of object. The value
250
251
Project 27: Joystick Module
1.Introduction
2.Hardware Required
Joystick Module*1
Jumper Wire *1
USB cable*1
3.Specification
252
• Interface Analog x2, Digital x1
4.Circuit Connection
253
Connection for MEGA 2560 R3
5.Sample Code
/*
Project 27
joystick
http//www.keyestudio.com
*/
void setup()
254
pinMode(JoyStick_Z, INPUT);
void loop()
int x,y,z;
x=analogRead(JoyStick_X);
y=analogRead(JoyStick_Y);
z=digitalRead(JoyStick_Z);
Serial.print(x ,DEC);
Serial.print(",");
Serial.print(y ,DEC);
Serial.print(",");
Serial.println(z ,DEC);
delay(100);
//////////////////////////////////////////////////////////
6.Test Result
Wiring well and uploading the code, open the serial monitor
and set the baud rate to 9600, push the joystick, you will see
255
256
Project 28: 5V Relay Module
1.Introduction
2.Hardware Required
Relay Module*1
Jumper Wire *1
USB cable*1
257
3.Specification
• Type Digital
• Digital Interface
4.Circuit Connection
258
Connection for V4.0
5.Sample Code
/*
259
keyestudio super learning kit
Project 28
Relay
http//www.keyestudio.com
*/
int Relay = 8;
void setup()
void loop()
delay(2000);
delay(2000);
//////////////////////////////////////////////////////////
6.Test Result
260
Project 29: DS3231 Clock Module
1.Introduction
precision.
261
timing. The integrated oscillator ensures the
components.
2.Hardware Required
Jumper Wire *1
USB cable*1
3.Specification
262
provides leap year compensation until 2100.
4.Circuit Connection
connect ‘SDA’ to Arduino A4, ‘SCL’ to A5, ‘+’ to VCC and ‘-’
to GND as follows
263
Connection for MEGA 2560 R3
264
5.Sample Code
/*
Project 29
clock
http//www.keyestudio.com
*/
#include <Wire.h>
#include "DS3231.h"
265
char weekDay[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
"Sat" };
0 and goes to 6)
port and you can check time here or make a change to the
time as needed.
void setup ()
Wire.begin();
RTC.begin();
void loop ()
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
266
Serial.print("/");
Serial.print(now.date(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(weekDay[now.dayOfWeek()]);
Serial.println();
delay(1000);
//////////////////////////////////////////////////////////
6.Test Result
267
268
Project 30: DHT11 Temperature and Humidity Sensor
1.Introduction
269
calibrated digital signal output with the temperature and
2.Hardware Required
DHT11 sensor*1
270
Jumper Wire *1
USB cable*1
3.Specification
• Supply Voltage +5 V
• Interface digital
4.Circuit Connection
271
Connection for MEGA 2560 R3
5.Sample Code
272
/*
Project 30
DHT11
http//www.keyestudio.com
*/
#include <dht11.h>
dht11 DHT;
#define DHT11_PIN 4
void setup(){
Serial.begin(9600);
Serial.println(DHT11LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity
(%),\tTemperature (C)");
void loop(){
int chk;
273
Serial.print("DHT11, \t");
switch (chk){
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
break;
default:
Serial.print("Unknown error,\t");
break;
// DISPLAT DATA
Serial.print(DHT.humidity,1);
Serial.print(",\t");
Serial.println(DHT.temperature,1);
delay(1000);
274
}
//////////////////////////////////////////////////////////
6.Test Result
Then open the serial monitor and set the baud rate to 9600,
275
Project 31: Soil Humidity Sensor
1.Introduction
276
by the sensor will decrease; otherwise, it will increase.
The sensor is set with two probes inserted into the soil, then
with the current go through the soil, the sensor will get
content.
process to prolong its service life. Insert it into the soil and
then use the AD converter to read it. With the help of this
2.Hardware Required
277
V4.0 Board or MEGA 2650 Board*1
Jumper Wire *1
USB cable*1
3.Specification
output voltage)
4.Circuit Connection
278
Connection for V4.0
279
5.Sample Code
/*
Project 31
http//www.keyestudio.com
*/
void setup(){
Serial.begin(57600);
void loop(){
Serial.println(analogRead(0));
delay(100);
280
}
//////////////////////////////////////////////////////////
6.Test Result
1.Introduction
281
equipment development, development of advanced
molds.
2.Hardware Required
RFID Module*1
Jumper Wire *1
USB cable*1
3.Specification
282
7. Environmental Operating Temperature -20-80 degrees
Celsius
4.Circuit Connection
283
Connection for 2560 R3
5.Sample Code
/*
284
keyestudio super learning kit
Project 32
RFID
http//www.keyestudio.com
*/
#include <SPI.h>
#define MAX_LEN 16
//MF522command word
command
285
//Mifare_One Card command word
#define MI_OK 0
#define MI_NOTAGERR 1
#define MI_ERR 2
286
//------------------MFRC522 Register---------------
//Page 1:Command
287
#define TxModeReg 0x12
//Page 2:CFG
288
#define GsNReg 0x27
//Page 3:TestRegister
289
#define Reserved31 0x3C
uchar serNum[5];
uchar writeDate[16] ={'T', 'e', 'n', 'g', ' ', 'B', 'o', 0, 0, 0, 0, 0, 0, 0, 0,0};
};
};
void setup() {
SPI.begin();
290
pinMode(chipSelectPin,OUTPUT); // Set digital pin 10 as OUTPUT
Power-down
digitalWrite(NRSTPD, HIGH);
MFRC522_Init();
void loop()
uchar i,tmp;
uchar status;
uchar str[MAX_LEN];
uchar RC_size;
291
if (status == MI_OK)
status = MFRC522_Anticoll(str);
if (status == MI_OK)
Serial.print(serNum[0],BIN);
Serial.print(serNum[1],BIN);
Serial.print(serNum[2],BIN);
Serial.print(serNum[3],BIN);
Serial.print(serNum[4],BIN);
Serial.println(" ");
RC_size = MFRC522_SelectTag(serNum);
if (RC_size != 0)
{}
292
// write data card
if (status == MI_OK)
// write data
Serial.print(blockAddr/4,DEC);
// write data
blockAddr = blockAddr - 3 ;
if(status == MI_OK)
Serial.println("OK!");
293
// read card
if (status == MI_OK)
// read data
blockAddr = blockAddr - 3 ;
if (status == MI_OK)
");
Serial.print(str[i]);
Serial.println(" ");
Serial.println(" ");
294
}
digitalWrite(chipSelectPin, LOW);
SPI.transfer((addr<<1)&0x7E);
SPI.transfer(val);
digitalWrite(chipSelectPin, HIGH);
uchar val;
digitalWrite(chipSelectPin, LOW);
SPI.transfer(((addr<<1)&0x7E) | 0x80);
295
val =SPI.transfer(0x00);
digitalWrite(chipSelectPin, HIGH);
return val;
uchar tmp;
tmp = Read_MFRC522(reg);
uchar tmp;
tmp = Read_MFRC522(reg);
296
}
void AntennaOn(void)
uchar temp;
temp = Read_MFRC522(TxControlReg);
SetBitMask(TxControlReg, 0x03);
void AntennaOff(void)
ClearBitMask(TxControlReg, 0x03);
void MFRC522_Reset(void)
297
Write_MFRC522(CommandReg, PCD_RESETPHASE);
void MFRC522_Init(void)
digitalWrite(NRSTPD,HIGH);
MFRC522_Reset();
6.78MHz/TPreScaler
Write_MFRC522(TReloadRegL, 30);
Write_MFRC522(TReloadRegH, 0);
298
uchar MFRC522_Request(uchar reqMode, uchar *TagType)
uchar status;
BitFramingReg[2..0] ???
TagType[0] = reqMode;
&backBits);
status = MI_ERR;
return status;
299
{
uchar lastBits;
uchar n;
uint i;
switch (command)
irqEn = 0x12;
waitIRq = 0x10;
break;
irqEn = 0x77;
waitIRq = 0x30;
break;
300
default:
break;
command ???
Write_MFRC522(FIFODataReg, sendData[i]);
// execute command
Write_MFRC522(CommandReg, command);
if (command == PCD_TRANSCEIVE)
301
SetBitMask(BitFramingReg, 0x80); //StartSend=1,transmission of data
starts
do
//CommIrqReg[7..0]
n = Read_MFRC522(CommIrqReg);
i--;
if (i != 0)
ProtecolErr
302
{
status = MI_OK;
if (command == PCD_TRANSCEIVE)
n = Read_MFRC522(FIFOLevelReg);
if (lastBits)
else
*backLen = n*8;
if (n == 0)
303
n = 1;
if (n > MAX_LEN)
n = MAX_LEN;
backData[i] = Read_MFRC522(FIFODataReg);
else
status = MI_ERR;
304
//Write_MFRC522(CommandReg, PCD_IDLE);
return status;
uchar status;
uchar i;
uchar serNumCheck=0;
uint unLen;
serNum[0] = PICC_ANTICOLL;
serNum[1] = 0x20;
if (status == MI_OK)
305
{
serNumCheck ^= serNum[i];
if (serNumCheck != serNum[i])
status = MI_ERR;
return status;
uchar i, n;
//Write_MFRC522(CommandReg, PCD_IDLE);
306
// write data into FIFO
Write_MFRC522(FIFODataReg, *(pIndata+i));
Write_MFRC522(CommandReg, PCD_CALCCRC);
i = 0xFF;
do
n = Read_MFRC522(DivIrqReg);
i--;
pOutData[0] = Read_MFRC522(CRCResultRegL);
pOutData[1] = Read_MFRC522(CRCResultRegM);
307
{
uchar i;
uchar status;
uchar size;
uint recvBits;
uchar buffer[9];
buffer[0] = PICC_SElECTTAG;
buffer[1] = 0x70;
buffer[i+2] = *(serNum+i);
size = buffer[0];
308
else
size = 0;
return size;
*serNum)
uchar status;
uint recvBits;
uchar i;
uchar buff[12];
number
buff[0] = authMode;
buff[1] = BlockAddr;
309
buff[i+2] = *(Sectorkey+i);
buff[i+8] = *(serNum+i);
status = MI_ERR;
return status;
uchar status;
uint unLen;
recvData[0] = PICC_READ;
310
recvData[1] = blockAddr;
CalulateCRC(recvData,2, &recvData[2]);
&unLen);
status = MI_ERR;
return status;
uchar status;
uint recvBits;
uchar i;
uchar buff[18];
buff[0] = PICC_WRITE;
buff[1] = blockAddr;
311
CalulateCRC(buff, 2, &buff[2]);
status = MI_ERR;
if (status == MI_OK)
buff[i] = *(writeData+i);
status = MI_ERR;
312
return status;
void MFRC522_Halt(void)
uchar status;
uint unLen;
uchar buff[4];
buff[0] = PICC_HALT;
buff[1] = 0;
CalulateCRC(buff, 2, &buff[2]);
//////////////////////////////////////////////////////////
Note if you want to use MEGA 2560 R3, please in the code
change
313
6.Test Result
module will write data to the IC card and read the card’s data,
you can see the data on the monitor window. Shown below.
314
6. Resources
https://fs.keyestudio.com/KS0077-78-79
315