Vous êtes sur la page 1sur 58

www.bestqshop.

com Ebay store: b2cqshop , E-qstore


www.bestqshop.com Ebay store: b2cqshop , E-qstore
Arduino Starter kit Users Manual
What is the Arduino Starter Kit ?
Package Include:
1, 1 X Arduino Duemilnove ATmega 328 board
2, 1 X Prototyping Shield
3, 1 X Mini breadbord
4, 1 X bundle Breadboard Jump Wires (Approximately 70 pcs)
5, 1 X 9v power adapter
6, 1 X 40Pin Straight Male Headers
7, 1 X Universal board
8, 1 X IR Remote Control
9, 1 X InIrared Receiver
10, 1 X LM35 Temperature Sensor
11, 1 X Ambient Light sensor
12, 1 X Tilt switch sensor
13, 1 X 1602 LCD Dispaly ( deIault blue one, or you can choose the green one)
14, 1 X 7seg-4digit LED Display
15, 1 X Rotary Potentiometer
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
16, 1 X Buzzer
17, 5 X Mini Push Button
18, 1 X 2P Screw Terminal Block Connector 5mm
19, 4 X Red LED 3mm
20, 4 X Yellow LED 3mm
21, 4 X Green LED 3mm
22, 2 X Blue LED 3mm
23, 1 X color LED 5mm
24, 10 X 220O Resistors
25, 10 X 1 kO Resistors
26, 10 X 10 kO Resistors
27, 1x High quality electronic tool plastic Box
28, Email CD ROM inIormation( Lessons and User Manuals )
Mini SoIderIess Breadboard
The mini breadboard has 170 Tie points. It is Compatible with all kind oI
ProtoShield. Completely reusable,Reusable Ior Iast build a prototype oI an electronic
circuit. With Twin adhesive back, it could be fix and remove to any position easily. ts
Dimension: 45mm (L) X 34.5mm (W) X 9.5mm (H).
This mini breadboard has 10 rows 17 columns point. And the top and bottom Five row
columns are separate columns, with no internal connections made between them inside the
breadboard. The only Iive internal connections inside the breadboard are to any Iive vertical
consecutive holes . So the Iive point which are in one column is connected internally.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Start with Arduino
Overview
What is Arduino?
Arduino is a tool Ior making computers that can sense and control more oI the physical world
than your desktop computer. It's an open-source physical computing platIorm based on a simple
microcontroller board, and a development environment Ior writing soItware Ior the board.
Arduino can be used to develop interactive objects, taking inputs Irom a variety oI switches or
sensors, and controlling a variety oI lights, motors, and other physical outputs. Arduino projects
can be stand-alone, or they can be communicate with soItware running on your computer (e.g.
Flash, Processing, MaxMSP.) The boards can be assembled by hand or purchased preassembled;
the open-source IDE can be downloaded Ior Iree.
With this kit you can make a lot oI interesting projuct.
Features :
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
!, Tu,u \o'u_ commudd): !?\
?, D_u' TO lu: : !1 o |c| b ,ovd l"H ou,u)
3, /uu'o_ Tu,u lu: : b
4, Support SPI communication. program the microcontroller through the ICSP (In-Circuit
Serial Programming) header
5, For Input power supply : It can be powered via the USB connection or with an external
power supply.
Note : External (non-USB) power can come either Irom an AC-to-DC adapter (wall-wart) or
battery, And the recommended range is 5V to 9V DC.
6, Output voltage: 5V and 3. 3V and VIN.
VIN : The input voltage to the Arduino board when it's using an external power source (as
opposed to 5 volts Irom the USB connection or other regulated power source). You can supply
voltage through this pin, or, iI supplying voltage via the power jack, access it through this pin.
7, Using Atmel Atmega328 microprocessor controller .
8, Sizes (W * H): 70mm X 54mm.
Language Reference
The Arduino language is based on C / C . Arduino programs can be divided in three
main parts: structure, values (variables and constants), and functions.
You can check them in the Arduino website : http://arduino.cc/en/ReIerence/HomePage
+++++++++++++++++ bu:c C 'uu_uu_: ++++++++++++++++++++
Control Structures
if
if...else
for
switch case
while
do... while
break
continue
return
goto
lu| Syuux
:mco'ou)
| cu'y |uc:)
:u_' 'u commu)
+ + mu''u commu)
-du
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
-uc'ud
Operators
(assignment operator)
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
(modulo)
(equal to)
! (not equal to)
(less than)
~ (greater than)
(less than or equal to)
> (greater than or equal to)
&& (and)
,, (or)
! (not)
(increment)
-- (decrement)
(compound addition)
- (compound subtraction)
* (compound multiplication)
/ (compound division)
Data Types ( Variables )
void
boolean
char
unsigned char
byte
int
unsigned int
word
long
unsigned long
float
double
string - char array
String - object
array
Constants ( Variables )
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
HIGH [ LOW
It means a diIIerent meaning depending on whether a pin is set to INPUT or OUTPUT .
HIGH: means high potential ().
INPUT [ OUTPUT
INPUT : to be in a high-impedance state
OUTPUT : to be in a low-impedance state
true [ false
Ialse : is deIined as 0 (zero).
true : is oIten said to be deIined as 1, which is correct, but true has a wider deIinition.
Any integer which is non-:ero is TRUE, in a Boolean sense. So -1, 2 and -200 are all deIined
as true, too, in a Boolean sense.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++ /duuo luu_uu_ ++++++++++++++++++++
Structure
setup()
The setup() Iunction is called when a sketch starts. Use it to initialize variables, pin
modes, start using libraries, etc. The setup Iunction will only run once, aIter each powerup or reset
oI the Arduino board.
loop()
AIter creating a setup() Iunction, which initializes and sets the initial values, the loop()
Iunction does precisely what its name suggests, and loops consecutively, allowing your program to
change and respond. Use it to actively control the Arduino board.
Functions
Digital I/O
pinMode()
Syntax : pinMode(pin, mode)
ConIigures the speciIied pin to behave either as an input or an output. Digital pins :
( 0 ~ 13 ). Mode: either INPUT or OUTPUT
digitalWrite()
Syntax : digitalWrite(pin, value)
Write a HIGH or a LOW value to a digital pin. Digital pins : ( 0 ~ 13 ). value:
HIGH or LOW . For example: light a LED.
digitalRead()
Syntax : digitalWrite(pin, value)
Reads the value Irom a speciIied digital pin, either HIGH or LOW. Digital pins :
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
( 0 ~ 13 ). value: HIGH or LOW . For example : read the digital sensor`s value.
Analog I/O
analogRead()
Syntax : int analogReIerence(pin)
Reads the value Irom the speciIied analog pin. pins : 0 ~ 5 (Arduino Diecimila:
0 ~ 5 ; Arduino nano : 07). The Arduino board contains a 6 channel (8 channels on the Mini
and Nano, 16 on the Mega)
For example : in the analog sensor (10-bit analog to digital converter. ) , this means
that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023.
analogWrite() // PWM
Syntax : analogWrite(pin, value)
Writes an analog value (PWM wave) to a pin.
Pin : On most Arduino boards (those with the ATmega168 or ATmega328), this
Iunction works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2
through 13. Older Arduino boards with an ATmega8 only support analogWrite() on pins
9, 10, and 11.
value: the duty cycle: between 0 (always oII) and 255 (always on).
For example : in the analog sensor (10-bit analog to digital converter. ) , this means
that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023.
Time
delay()
Pauses the program Ior the amount oI time (in miliseconds) speciIied as parameter.
(There are 1000 milliseconds in a second.)
delayMicroseconds()
Pauses the program Ior the amount oI time (in microseconds) speciIied as parameter.
Math
min() : Calculates the minimum oI two numbers.
max() : Calculates the maximum oI two numbers.
abs() : Computes the absolute value oI a number.
constrain() : Constrains a number to be within a range.
map() : Re-maps a number Irom one range to another.
pow() : Calculates the value oI a number raised to a power.
sqrt() : Calculates the square root oI a number.
/*****************************************************************************/
How to use Arduino board
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Now, go ahead. Let.s begin with the actual operation oI this kit.
1. Ready
( 1 ). Find out the Prototype shield and mini breadboard from your
tool plastic Box . The item like the Iollowing picture:
( 2 ) Find out the arduino controller (Duemilnove ATmega 328 board) Irom your tool box too.
( 3 ). plug the Prototype shield to the Arduino 328 controller.
2. Download the Arduino Development Environment
Go to the Arduino website to download the soItware that can be run on your Operating
System.
http://arduino.cc/en/Main/SoItware
3. Download the USB Driver
1. First, Iind out the USB cable, and plug one side oI the cable to your arduino Atmage 328
board. ( such as the Iollowing picture ).
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
2 . And then , plug the other side to your computer`s USB interIace. ( such as the
Iollowing picture ).
3. At this time , the power LED oI Atmage 328 board will be light. And your computer
will will appear A dialog box like this picture. ( I am sorry the the Operating System showing
Chinese.)
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
4 . Choose Irom ' a list or speciIic location , and the click ' Next .
5, Iind out the Folder : arduino-0018\drivers\FTDI USB Drivers
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
6 , Then click ' Next .
7, Finally, click 'Finish.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
.
Now, you can connect your arduino board to the computer , and upload my programs to the
Arduino board.
3. Upload my programs
(1) Make sure you have the right item selected in the Tools > Board menu. In particular,
newer Arduino Duemilanove boards come with an ATmega328, while older ones have an
ATmega168. To check, read the text on the microcontroller (the larger chip) on your Arduino
board.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
(2) Check that the proper port is selected in the "Tools ~ Serial Port" menu (iI your port doesn't
appear, restart the IDE with the board connected to the computer).
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
For the ' Serial Port , you can check it in your computer`s Device Manager
(3) Write down your program to a new arduino Iile.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
(4) And then compile it.
Then it will show
(5) Upload the program to your board.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
When it show 'Done Uploading , That is great , the Arduino experiment works well .
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Experiment
Lesson 1 : Color LED Flashing
1. What is an LED ?
The internal structure OI LED.
The longer one lead is Anode ( '), the another one is Cathode (' --) .
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
2 , The wiring of LED
First Experiment:
Prepare: 1 X LED , 1 X 220-ohm resistor , some Jumper cable.
To build the circuit, grab an LED and attach its long, positive leg (called the anode) to pin 8
through a 220-ohm resistor . Connect the cathode (the shorter, negative leg) directly to ground.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Code : open the Iolder led1, and open the led1.pde
In the program below, the Iirst thing you do is to initialize pin 8 as an output pin with the line
pinMode(8, OUTPUT);
In the main loop, you turn the LED on with the line:
digitalWrite(8, HIGH);
This supplies 5 volts to pin 8. That creates a voltage diIIerence across the pins oI the LED, and
lights it up. Then you turn it oII with the line:
digitalWrite(8, LOW);
That takes pin 8 back to 0 volts, and turns the LED oII. In between the on and the oII, you want
enough time Ior a person to see the change, so the delay() commands tell the Arduino to do
nothing Ior 1000 milliseconds, or one second. When you use the delay() command, nothing else
happens Ior that amount oI time. Once you've understood the basic examples, check out the
BlinkWithoutDelay example to learn how to create a delay while doing other things.
int ledPin8 //|jjLED []IO ]
void setup()

pinMode(ledPin,OUTPUT);//|]IO [|[OUTPUT
]
void loop()

digitalWrite(ledPin,HIGH); //|PIN8 ]HIGH 5V (


delay(1000); //|}}[1000 1
digitalWrite(ledPin,LOW); //|PIN8 ]LOW 0V
delay(1000); //|}}[1000 1
]
From the code , We can know that arduino language start with setup() Iunction, and Use loop()
Iunction to actively control the Arduino board .
setup() Iunction is used to initialize variables, pin modes, start using libraries, etc. The setup
Iunction will only run once, aIter each powerup or reset oI the Arduino board.
loop() : AIter creating a setup() Iunction, the loop() Iunction does precisely what its name
suggests, and loops consecutively, allowing your program to change and respond. Use it to
actively control the Arduino board.
In this First Experiment, you can find that the LED flashes per 1 second.
Second Experiment:
Prepare: 6 X LED , 6 X 220-ohm resistor , some Jumper cable.
To build the circuit, attach LED to digital IO pin 1, 2, 3, 4, 5, 6 through 220-ohm resistor .
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Connect the cathode (the shorter, negative leg) directly to ground.
Code : open the Iolder led2, and open the led2.pde
Usually, we can see Billboard Ilashing various colors. This is because a variety oI LED
in diIerent localtion changing on or oII . In this experiment, we use LEDs to show as the billboard.
You can set the time and the sequence oI Ilashing, so that it show diIIerent eIIect.
//|Led (\IO ]
int Led1 1;
int Led2 2;
int Led3 3;
int Led4 4;
int Led5 5;
int Led6 6;
//led )||1 |[
void style_1(void)

unsigned char j;
for(j1;j<6;j++)//]200ms ]1~6 ]|(led )

digitalWrite(j,HIGH);//j ]|(led )
delay(200);//}200ms
]
for(j6;j>1;j--)//]200ms ]6~1 ]|(led )

digitalWrite(j,LOW);//j ]|(led )
delay(200);//}200ms
]
]
//)])|[
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
void flash(void)

unsigned char j,k;


for(k0;k<1;k++)//]))

for(j1;j<6;j++)//1~6 ]|(led )
digitalWrite(j,HIGH);//j ]|(led )
delay(200);//}200ms
for(j1;j<6;j++)//1~6 ]|(led )
digitalWrite(j,LOW);//j ]|(led )
delay(200);//}200ms
]
]
//led )||2 |[
void style_2(void)

unsigned char j,k;


k1;//k ({1
for(j3;j>1;j--)

digitalWrite(j,HIGH);//)
digitalWrite(j+k,HIGH);//)
delay(400);//}400ms
k +2;//k ,2
]
k5;//k 5
for(j1;j<3;j++)

digitalWrite(j,LOW);//)
digitalWrite(j+k,LOW);//)
delay(400);//}400ms
k -2;//k )2
]
]
//led )||3 |[
void style_3(void)

unsigned char j,k;//led )||3 |[


k5;//k 5
for(j1;j<3;j++)

digitalWrite(j,HIGH);//)
digitalWrite(j+k,HIGH);//)
delay(400);//}400ms
digitalWrite(j,LOW);//)
digitalWrite(j+k,LOW);//)
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
k -2;//k )2
]
k3;//k 3
for(j2;j>1;j--)

digitalWrite(j,HIGH);//)
digitalWrite(j+k,HIGH);//)
delay(400);//}400ms
digitalWrite(j,LOW);//)
digitalWrite(j+k,LOW);//)
k +2;//k ,2
]
]
void setup()

unsigned char i;
for(i1;i<6;i++)//]1~6 ^\]|
pinMode(i,OUTPUT);//i ^]|
]
void loop()

style_1();//|1
flash();//])
style_2();//|2
flash();//])
style_3();//|3
flash();//])
]
In this Experiment, you can learn the ' Ior statements
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
The Code :
for(i1;i<6;i++)// Set the digital IO pins(1, 2, 3, 4, 5, 6) configured as ~OUTPUT
pinMode(i,OUTPUT);// Set the digital pins(i) configured as ~OUTPUT
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Lesson 2 : buzzer Speaker.
1. What is an buzzer?
Features:
1) High sound pressure with low power consumption
2) Compact, lightweight
3) No-contact design makes element highly reliable and eliminates noise problem
4) Easily mountable
5) A wide variety oI tones can be generated depending on casing design
Applications:
1) Telephone ringers
2) ConIirmation tones in various oIIice automation equipment
3) Used in a variety oI consumer products such as microwave ovens and reIrigerators
4) Clocks, toys games
5) Automobiles
In this experiment, because oI the internal buzzer with a drive circuit, it can be used directly.
Prepare: 1 X buzzer Speaker , some Jumper cable.
To build the circuit, attach buzzer to digital IO pin 7 . Connect the cathode (the shorter,
negative leg) directly to ground.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Code : open the Iolder buzzer, and open the buzzer.pde
In this program, you will hear the Ambulance siren.
int buzzer7;//|jj,[]IO ]
void setup()

pinMode(buzzer,OUTPUT);//|]IO ]|[OUTPUT
]
void loop()

unsigned char i,j;//


while(1)

for(i0;i<80;i++)//[[),

digitalWrite(buzzer,HIGH);//),
delay(1);//}1ms
digitalWrite(buzzer,LOW);//),
delay(1);//}ms
]
for(i0;i<100;i++)//,[[),

digitalWrite(buzzer,HIGH);//),
delay(2);//}2ms
digitalWrite(buzzer,LOW);//),
delay(2);//}2ms
]
]
]
In this experiment, you will use the Control Structures while .
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
while loops will loop continuously, and inIinitely, until the expression inside the parenthesis,
() becomes Ialse. Something must change the tested variable, or the while loop will never exit.
This could be in your code, such as an incremented variable, or an external condition, such as
testing a sensor.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Lesson 3 : Button
1. What is an Button ?
The back and Iront oI the Button
When the button was not pressed, it`s pin 4 and pin 1 is connecting in a circuit, and pin 3 and
pin 2 is connectiong.
When the button was pressed, all oI it`s pins are connecting in the circuit.
First Experiment:
Prepare: 1 X button (momentary button or switch), 1 X LED , 1 X 220-ohm
resistor , some Jumper cable.
To build the circuit, grab an LED and attach its long, positive leg (called the anode) to pin 7
through a 220-ohm resistor . Connect the cathode (the shorter, negative leg) directly to ground.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
The switch wire like the Iollowing picture, one point is to the 5 volt supply, the other connect to
Analog Pin 1
Code : open the Iolder key1, and open the key1.pde
In the program, when we press the button, the led will light. Otherway, it will turn oII.
int key7;//|jj|j[]IO ]
void setup()

pinMode(key,OUTPUT);//|]IO ]|[
]
void loop()

int i;//
while(1)

ianalogRead(1);//,]||1 j
if(i>512)//;j,512l0.25V
digitalWrite(key,HIGH);//|]])led )
else
digitalWrite(key,LOW);//|]],led )
]
]
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Lesson 4 : preemptive response device
1. Do a funny project.
Experiment:
Prepare: 3 X key, 1 X buzzer , 1 X red LED , ! X green LED . 2 X 220-ohm resistor ,
some Jumper cable.
To build the circuit, attach each key`s pin 1 to the 5 Volt supply, pin 2 to the board`s Analog
Pin 1 (key 1), pin 2 (key 2), pin 3 (key 3).
The LED attach to Digital pin 8 (red LED), pin 7 (green LED) through 220-ohm resistor.
The buzzer connect to Digital pin 5.
Code : open the Iolder KBL , and open the KBL.pde
int RedLed8;///]|-)
int GreenLed7;//]|,)
int i;//i
int j0;//j
void buzzer()//,j),|]

for(i0;i<80;i++)
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore

digitalWrite(5,HIGH);//),
delay(1);//}1ms
digitalWrite(5,LOW);//),
delay(1);//}ms
]
]
void key_scan()//|j|||]

int key_1,key_2,key_3;//
key_1analogRead(1);//,]||][j
key_2analogRead(2);//,]||][j
key_3analogRead(3);//,]||][j
if(key_1<204&&key_2<204&&key_3<204)//;,|jj, 204l||j[ 1V
)}||j|

return;//7]
]
if(key_1>818)//;|j1 [j,,818l||j[4V)}|j1 |

delay(10);//j||]}100ms |])}
if(key_1>818)//;|j1 [j,,818l||j[4V)}|j1 ]
|

buzzer();//,),
digitalWrite(RedLed,HIGH);//-)
digitalWrite(GreenLed,LOW);//,),
]
else //||]]

return;//7]
]
]
if(key_2>818)//;|j2 [j,,818l||j[4V)}|j2 |

delay(10);//j||]}100ms |])}
if(key_2>818)//;|j2 [j,,818l||j[4V)}|j2 ]
|

buzzer();//,),
digitalWrite(RedLed,LOW);//-),
digitalWrite(GreenLed,HIGH);//,)
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
]
else //||]]

return;//7]
]
]
if(key_3>818)//;|j3 [j,,818l||j[4V)}|j3 |

delay(10);//j||]}100ms |])}
if(key_3>818)//;|j3 [j,,818l||j[4V)}|j3 ]
|

buzzer();//,),
digitalWrite(RedLed,LOW);//-),
digitalWrite(GreenLed,LOW);//,),
]
else //||]]

return;//7]
]
]
]
void setup()

for(i5;i<8;i++)

pinMode(i,OUTPUT);//|5~8 ]||[
]
]
void loop()

while(1)

key_scan();//j'|||j
]
]
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Lesson 5 : 7seg-4digit LED Display
1. What is an 7seg-4digit LED Display?
In the Iollowing picture, there are other LED displays.
The internal structure OI LED display. This is the Common cathode 7seg-4digit LED
Display that we will use in this Experiment.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
First Experiment:
Prepare: 1 X 7seg-4digit LED Display , 8 X 220-ohm resistor , some Jumper
cable.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
To build the circuit, attach the LED display`s (through a 220-ohm resistor) Pin 11, 7, 4, 2, 1,
10, 5, 3 to your Arduino board`s digital Pin 12, 11, 10, 9, 8, 7, 6, 5 .
Attach the LED display`s 12, 9, 8, 6 to the Ardiuno board`s digital Pin 4, 3, 2, 1 .
Code : open the Iolder digitaltube1 , and open the digitaltube1.pde
In the program, It will loop to show the number Irom 0 to 9
//|jj,|[]IO ]
int a 12;
int b 11;
int c 10;
int d 9;
int e 8;
int f 7;
int g 6;
int dp 5;
int ls1 1; //|({](
int ls2 2; //{](
int ls3 3; //{](
int ls4 4; //|{](
//]0 , 11111100
void digital_0(void)

unsigned char j;
digitalWrite(dp,LOW);//]5 ]],])DP |
digitalWrite(g,LOW);//,g |
for(j7;j<12;j++)//))_|
digitalWrite(j,HIGH);
]
//]1 , 01100000
void digital_1(void)

unsigned char j;
digitalWrite(a,LOW);
for(j5;j<9;j++)
digitalWrite(j,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
]
//]2
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
void digital_2(void)

unsigned char j;
digitalWrite(c,LOW);
digitalWrite(f,LOW);
digitalWrite(dp,LOW);
for(j11;j<12;j++)
digitalWrite(j,HIGH);
for(j8;j<9;j++)
digitalWrite(j,HIGH);
digitalWrite(g,HIGH);
]
//]3 22
void digital_3(void)

unsigned char j;
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(dp,LOW);
for(j9;j<13;j++)
digitalWrite(j,HIGH);
digitalWrite(g,HIGH);
]
//]4
void digital_4(void)

digitalWrite(a,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(dp,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
]
//]5
void digital_5(void)

unsigned char j;
digitalWrite(b,LOW);
digitalWrite(e,LOW);
digitalWrite(dp,LOW);
digitalWrite(a,HIGH);
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
for(j6;j<7;j++)
digitalWrite(j,HIGH);
for(j9;j<10;j++)
digitalWrite(j,HIGH);
]
//]6
void digital_6(void)

unsigned char j;
digitalWrite(b,LOW);
digitalWrite(dp,LOW);
digitalWrite(a,HIGH);
for(j6;j<10;j++)
digitalWrite(j,HIGH);
]
//]7
void digital_7(void)

unsigned char j;
for(j5;j<9;j++)
digitalWrite(j,LOW);
for(j10;j<12;j++)
digitalWrite(j,HIGH);
]
//]8
void digital_8(void)

unsigned char j;
digitalWrite(dp,LOW);
for(j6;j<12;j++)
digitalWrite(j,HIGH);
]
//]9
void digital_9(void)

unsigned char j;
digitalWrite(e,LOW);
digitalWrite(dp,LOW);
for(j9;j<12;j++)
digitalWrite(j,HIGH);
for(j6;j<7;j++)
digitalWrite(j,HIGH);
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
]
//----------------------------
void Display(unsigned char mun)

switch (mun)
case 0:
digital_0();//]0
break;
case 1:
digital_1();
break;
case 2:
digital_2();
break;
case 3:
digital_3();
break;
case 4:
digital_4();
break;
case 5:
digital_5();
break;
case 6:
digital_6();
break;
case 7:
digital_7();
break;
case 8:
digital_8();
break;
case 9:
digital_9();
break;
default: return;
// if nothing else matches, do the default
// default is optional
]
]
void setup()

www.bestqshop.com Ebay store: b2cqshop , E-qstore


www.bestqshop.com Ebay store: b2cqshop , E-qstore
int i;//
for(i1;i<12;i++)
pinMode(i,OUTPUT);//|112 ]|[
]
void loop()

unsigned char i, j, t;
while(1)

t 1;
for(j0; j<4 ; j++)

digitalWrite(ls1,LOW); //,](|[
]
for(i0; i<9 ; i++)

if(t1) //{](]

digitalWrite(ls4,HIGH);
digitalWrite(ls3,HIGH);
digitalWrite(ls2,HIGH);
digitalWrite(ls1,LOW);
]
if(t2) //{](]

digitalWrite(ls4,HIGH);
digitalWrite(ls3,HIGH);
digitalWrite(ls1,HIGH);
digitalWrite(ls2,LOW);
]
if(t3) //{](]

digitalWrite(ls4,HIGH);
digitalWrite(ls2,HIGH);
digitalWrite(ls1,HIGH);
digitalWrite(ls3,LOW);
]
if(t4) //|{](]

t 0;
digitalWrite(ls3,HIGH);
digitalWrite(ls2,HIGH);
digitalWrite(ls1,HIGH);
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
digitalWrite(ls4,LOW);
]
Display(i);
delay(2000);//}2s
t++;
for(j0; j<4 ; j++)

digitalWrite(ls1,LOW); //,](|[
]
]
]
]
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Lesson 6 : Tilt Switch
1. What is an Tilt Switch?
Tilt Switch, you can call it Shaking Switch or Position Switch .
Usually we can easy to buy these style oI tilt switch : SW-200D.SW-460.SW-300DA and
so on.
In the experiment , we use SW-200D . SW-200D as the ball type single-directional tilt sensor
trigger switch..
the product when the wizard power side (silver pin side A) tilt angle is greater than 15 degrees,
in order to open OFF state, when the product is tilted to change the level oI the state, the trigger
terminal (gold-plated pin terminal C) below the level oI angle greater than 15 degree angle, Ior the
closed-circuit ON state. Horizontal, the swaying can be easily triggered. The silver pin down,
the shaking is not easy trigger.
First Experiment:
Prepare: 1 X Tilt Switch , 1 X LED , 1 X 220-ohm resistor , some Jumper cable.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
To build the circuit, grab an LED and attach its long, positive leg (called the anode) to pin 8
through a 220-ohm resistor . Connect the cathode (the shorter, negative leg) directly to ground.
Attach the Tilt Switch`s silver pin to the 5 volt supply, the other side to Analog Pin 5 .
Code : open the Iolder sketchjun04d , and open the sketchjun04d.pde
In the program, when we press the button, the led will light. Otherway, it will turn oII.
void setup()

pinMode(8,OUTPUT);//|]8 ]|[
]
void loop()

int i;//i
while(1)

ianalogRead(5);//,]||5 j
if(i>200)//;,5122.5V

digitalWrite(8,HIGH);//)led )
]
else//|

digitalWrite(8,LOW);//,led )
]
]
]
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Lesson 7 : Ambient Light sensor
1. What is an Ambient Light sensor ?
In the light intensity is strong , it`s resistance decreases; however , when the light is weak, this
sensor`s resistance increases.
First Experiment:
Prepare: 1 XAmbient Light sensor , 1 X buzzer , some Jumper cable.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
To build the circuit, attach buzzer`s long, positive leg (called the anode) to pin 6 through a
Ambient Light sensor . Connect the cathode (the shorter, negative leg) directly to ground.
Attach the Tilt Switch`s silver pin to the 5 volt supply, the other side to Analog Pin 5 .
Code : open the Iolder sketchjun17b , and open the sketchjun17b.pde
In the program, when the Light is stronger, the resistance oI sensor will be smaller, and
then the buzzer speak louder.
void setup()

pinMode(6,OUTPUT);
]
void loop()

while(1)

char i,j;
while(1)

for(i0;i<80;i++) //[[),

digitalWrite(6,HIGH);
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
delay(1);
digitalWrite(6,LOW);
delay(1);
]
for(i0;i<100;i++) //,[[),

digitalWrite(6,HIGH);
delay(2);
digitalWrite(6,LOW);
delay(2);
]
]
]
]
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Lesson 8 : 1602 LCD
1. What is 1602 LCD?
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
First Experiment:
Prepare: 1 X LCD Screen , 1 X 10k Potentiometer , some Jumper cable.
To build the circuit, To wire your LED screen to your Arduino, connect the Iollowing pins:
lCD lS ,u o d_u' ,u !?
lCD luu|' ,u o d_u' ,u !!
lCD D1 ,u o d_u' ,u
lCD D ,u o d_u' ,u 1
lCD Db ,u o d_u' ,u 3
lCD D ,u o d_u' ,u ?
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
/ddouu''y, u !0l ,o o \ uud 0\D, | ': , ou,u) o lCD :cu':
\O ,u ,u3).
Code : open the Iolder lcd1602 , and open the lcd1602.pde
/`
` The circuit:
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
` LCD RS pin to digital pin 12
` LCD Enable pin to digital pin 11
` LCD D4 pin to digital pin 5
` LCD D5 pin to digital pin 4
` LCD D6 pin to digital pin 3
` LCD D7 pin to digital pin 2
` 10K resistor:
` ends to +5V and ground
` wiper to LCD VO pin (pin 3)
`/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
]
void loop()
lcd.setCursor(0,0); // ||/
lcd.print("OK: ");
lcd.setCursor(5,0); // ||/
lcd.print("Arduino!");
lcd.setCursor(0,1); // ||/
lcd.print("Yes,B2CQSHOP");
delay(500);
]
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Lesson 9 : LM35 Temperature Sensor
1. What is LM35 Temperature Sensor ?
The LM35 series are precision integrated-circuit temperature sensors, whose output voltage
is linearly proportional to the Celsius (Centigrade) temperature.
Connection Diagrams
Calibrated directly in Celsius (Centigrade) , Linear 10.0 mV/C scale Iactor
First Experiment:
Prepare: 1 X LM35 Temperature Sensor , 1 X 1602 LCD display , some Jumper cable.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Please check the Lesson 8 : 1602 LCD , to wire your LED screen to your Arduino .
Attach the LM35`s Pin Vout ( the middle pin) to your arduino`s /uu'o_ lu 0 . \cc o
v , 0ud o you uduuo |oud`: _ud
Code : open the Iolder sketchjun17b , and open the sketchjun17b.pde
In the program, when the Light is stronger, the resistance oI sensor will be smaller, and
then the buzzer speak louder.
/`
The circuit:
` LCD RS pin to digital pin 12
` LCD Enable pin to digital pin 11
` LCD D4 pin to digital pin 5
` LCD D5 pin to digital pin 4
` LCD D6 pin to digital pin 3
` LCD D7 pin to digital pin 2
` 10K resistor:
` ends to +5V and ground
` wiper to LCD VO pin (pin 3)
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
`/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//tempeter
int val;
int dat;
void setup()
Serial.begin(9600);
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
]
void loop()
valanalogRead(0);
dat(125`val)>>8; //,,[j
lcd.setCursor(0,0);
lcd.print("Tep: ");
lcd.setCursor(6,0);
lcd.print(dat);
lcd.setCursor(10,0);
lcd.print("'C");
delay(10);
lcd.setCursor(0,1);
if(dat>18)

lcd.print("Warm! B2CQSHOP");
]
else

lcd.print("Cold! B2CQSHOP");
]
delay(500);
]
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Lesson 10 : Infrared Remote Control
1. What is Infrared Receiver (IRM3638) ?
To know more about how to control IR Remote Control. You should have a knowledge oI the
\lC looco'
\lC looco' luu: : ( |,:.:|,o_c:.comkuo'd_uc.|m )
8 | udd:: uud 8 | commuud 'u_|
/dd:: uud commuud u uu:md c o 'u|'y
lu': d:uuc modu'uou
Cu uucy o 38k|z
b m o !.!?m: o ?.?m:
Hodu'uou:
T| \lC ,ooco' u:: ,u': d:uuc ucodu_ o | |:. luc| ,u':
: u b0: 'ou_ 38k|z cu |u: u|ou ?! cyc':). / 'o_cu' ! uk:
?.?m: o uu:m, |' u 'o_cu' 0 : ou'y |u' o |u, |u_ !.!?m:.
T| commudd cu duycyc' : !1 o !3.
Protocol :
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
The picture above shows a pulse train oI the NEC protocol. With this protocol the LSB is
transmitted Iirst. In this case Address $59 and Command $16 is transmitted. A message is started
by a 9ms AGC burst, which was used to set the gain oI the earlier IR receivers. This AGC burst is
then Iollowed by a 4.5ms space, which is then Iollowed by the Address and Command. Address
and Command are transmitted twice. The second time all bits are inverted and can be used Ior
veriIication oI the received message. The total transmission time is constant because every bit is
repeated with its inverted length. II you're not interested in this reliability you can ignore the
inverted values, or you can expand the Address and Command to 16 bits each!
A command is transmitted only once, even when the key on the remote control remains
pressed. Every 110ms a repeat code is transmitted Ior as long as the key remains down. This
repeat code is simply a 9ms AGC pulse Iollowed by a 2.25ms space and a 560s burst.
In this Experiment, we will use a little diIIerent IR Remote Control , which use WD6122
chip . ( Extended NEC protocol )
Pay attention: When there is no infrared signals, the receiver`s output is High ; while,
it receives an signal, its output is LOW . We can check the received pulse through the
Oscilloscope, analyse the program according to the waveform.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
The Command Values oI the IR Remote Control`s key like the Iollowing picture.
First Experiment:
Prepare: 1 X InIrared Receiver (IRM3638) , 1 X IR Remote Control , 1 X 10 kO
Resistors , some Jumper cable.
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
Please check the Lesson 8 : 1602 LCD , to wire your LED screen to your Arduino .
Attach the InIrared Receiver`s Pin Vout to your arduino`s digital Pin 8 , Please check the
Iollowing picture.
Code : open the Iolder IR , and open the IR.pde
In the program, when you press the key oI the IR Remote Control, the 1602 LCD will show
the commond value oI the key.
#include LiquidCrystal.h~
#deIine IRIN 8 //-(||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int PulseWidth0;//]]
int ircode0x00;// j),(j
char adrLcode0x00;//((
char adrHcode0x00;//(((
void timer1init(void)//},|/]

TCCR1A 0X00;
TCCR1B 0X05;//},})
TCCR1C 0X00;
TCNT1 0X00;
TIMSK1 0X00; //)},('}
}
void remotedeal(void)//||(;]

//]|
lcd.clear(); //
delay(1);
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
lcd.setCursor(0,0);
lcd.print(ircode,HEX);//16 j
lcd.setCursor(0,1);
lcd.print(adrLcode,HEX);//16 j
}
char logicvalue()//)})j0T1]

TCNT1 0X00;
while(!(digitalRead(8))); //]|
PulseWidthTCNT1;
TCNT10;
iI(PulseWidth~7&&PulseWidth10)//]560us

while(digitalRead(8));//]|
PulseWidthTCNT1;
TCNT10;
iI(PulseWidth~7&&PulseWidth10)//|(]560us
return 0;
else iI(PulseWidth~25&&PulseWidth27) //|(]1.7ms
return 1;
}
return -1;
}
void pulsedeal()//||j;(T((],]

int i;
int j;
ircode0x00;//
adrLcode0x00;//
adrHcode0x00;//
//|jj,,('[j),(j
Ior(i 0 ; i 16; i)

iI(logicvalue() 1) //1
ircode , (1i);//]jj
}
//|jj,,('[((
Ior(i 0 ; i 8; i)

iI(logicvalue() 1) //1
adrLcode , (1i);//]jj
}
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore
//|jj,,('[(((
Ior(j 0 ; j 8; j)

iI(logicvalue() 1) //1
adrHcode , (1j);//]jj
}
}
void remotedecode(void)//(]

TCNT10X00;
while(digitalRead(8))//]|

iI(TCNT1~1563) //]|}[100ms]}||j|

ircode0x00II;// j),(j
adrLcode0x00;//j(jj
adrHcode0x00;//j()j
return;
}
}
//;]|}[100ms
TCNT10X00;
while(!(digitalRead(8))); //]|
PulseWidthTCNT1;
TCNT10;
iI(PulseWidth~140&&PulseWidth141)//9ms

while(digitalRead(8));//]|
PulseWidthTCNT1;
TCNT10;
iI(PulseWidth~68&&PulseWidth72)//4.5ms

pulsedeal();
return;
}
else iI(PulseWidth~34&&PulseWidth36)//2.25ms

while(!(digitalRead(8)));//]|
PulseWidthTCNT1;
TCNT10;
iI(PulseWidth~7&&PulseWidth10)//560us
www.bestqshop.com Ebay store: b2cqshop , E-qstore
www.bestqshop.com Ebay store: b2cqshop , E-qstore

return;
}
}
}
}
void
setup()

unsigned char i;
pinMode(IRIN,INPUT);//|-(||]
lcd.begin(16, 2);
}
void loop()

timer1init();//},|/
while(1)

remotedecode(); //(
remotedeal(); //||(;
}
}

Vous aimerez peut-être aussi