DF ROBOT DFR0100 User manual

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 1/23
DFRduinoBeginnerKitForArduino(SKU:DFR0100)
DFRduinoBeginnerKitForArduinoV3
SKU:DFR0100
FromRobotWiki
Contents
1Introduction
2GettingStartedwithArduino
3Tutorial
3.11.BlinkingaLED
3.22.SOSBeacon
3.33.TrafficLight
3.44.FadingLight
3.55.RGBLED
3.66.Alarm
3.77.TemperatureAlarm
3.88.Detectingvibration
3.99.AmbientLight
controlledLED
3.1010.MovingaServo
3.1111.InteractwithServo
3.1212.RGBLightDimmer
3.1313.MotorFan
3.1414.Infraredcontrolled
Light
3.1515.Intraredcontrolled
LEDMatrix
4OldVersion
Introduction
Welcometotheelectronicinteractionworld!DFRobotproudlypresentstheArduinobeginnerkitforthosewhoare
interestedinlearningaboutArduino.StartingfrombasicLEDcontroltomoreadvancedIRremotecontrol,thiskit
willguideyouthroughtheworldofmicrocontrollersandphysicalcomputing.
ADFRduinoUNOR3(CompatiblewithArduinoUno),themoststableandcommonlyusedArduinoprocessor,
togetherwithDFRobot'sbestsellingprototypeshieldareincludedinthiskit.

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 2/23
GettingStartedwithArduino
Introduction(http://arduino.cc/en/Guide/Introduction):WhatArduinoisandwhyyou'dwanttouseit.
Installation:StepbystepinstructionsforsettinguptheArduinosoftwareandconnectingittoanArduinoUno.
Windows(http://arduino.cc/en/Guide/Windows)MacOSX(http://arduino.cc/en/Guide/MacOSX)
Environment(http://arduino.cc/en/Guide/Environment):DescriptionoftheArduinodevelopmentenvironmentand
howtochangethedefaultlanguage.
Libraries(http://arduino.cc/en/Guide/Libraries):UsingandinstallingArduinolibraries.
Tutorial
1.BlinkingaLED
?
1
2
3
4
5
6
7
8
9
10
11
/*
#Description:
#TurnsonanLEDonforonesecond,thenoffforonesecond,repeatedly.
*/
intledPin=10;
voidsetup(){
pinMode(ledPin,OUTPUT);
}
voidloop(){
digitalWrite(ledPin,HIGH);
delay(1000);

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 3/23
12
13
14
digitalWrite(ledPin,LOW);
delay(1000);
}
2.SOSBeacon
TheconnectiondiagramisthesamewithBlinknigaLEDtutorial.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
#Description:
#SendSOSBeaconbyled
*/
intledPin=10;
voidsetup(){
pinMode(ledPin,OUTPUT);
}
voidloop(){
//S(...)threedot
for(intx=0;x<3;x++){
digitalWrite(ledPin,HIGH);
delay(150);
digitalWrite(ledPin,LOW);
delay(100);
}
delay(100);
//O(‐‐‐)threedash
for(intx=0;x<3;x++){
digitalWrite(ledPin,HIGH);
delay(400);
digitalWrite(ledPin,LOW);
delay(100);
}
delay(100);
//S(...)threedot
for(intx=0;x<3;x++){
digitalWrite(ledPin,HIGH);
delay(150);
digitalWrite(ledPin,LOW);

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 4/23
36
37
38
39
40
delay(100);
}
delay(5000);
}
3.TrafficLight
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
TrafficLight
ThiscodecopiedfromthebookBeginning‐Arduino.
*/
intcarRed=12;//assignthecarlights
intcarYellow=11;
intcarGreen=10;
intbutton=9;//buttonpin
intpedRed=8;//assignthepedestrianlights
intpedGreen=7;
intcrossTime=5000;//timeforpedestriantocross
unsignedlongchangeTime;//timesincebuttonpressed
voidsetup(){
pinMode(carRed,OUTPUT);

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 5/23
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
pinMode(carYellow,OUTPUT);
pinMode(carGreen,OUTPUT);
pinMode(pedRed,OUTPUT);
pinMode(pedGreen,OUTPUT);
pinMode(button,INPUT);
digitalWrite(carGreen,HIGH);//turnonthegreenlights
digitalWrite(pedRed,HIGH);
}
voidloop(){
intstate=digitalRead(button);
//checkifbuttonispressedanditisover5secondssincelastbuttonpress
if(state==HIGH&&(millis()‐changeTime)>5000){
//callthefunctiontochangethelights
changeLights();
}
}
voidchangeLights(){
digitalWrite(carGreen,LOW);//greenoff
digitalWrite(carYellow,HIGH);//yellowon
delay(2000);//wait2seconds
digitalWrite(carYellow,LOW);//yellowoff
digitalWrite(carRed,HIGH);//redon
delay(1000);//wait1secondtillitssafe
digitalWrite(pedRed,LOW);//pedredoff
digitalWrite(pedGreen,HIGH);//pedgreenon
delay(crossTime);//waitforpresettimeperiod
//flashthepedgreen
for(intx=0;x<10;x++){
digitalWrite(pedGreen,HIGH);
delay(250);
digitalWrite(pedGreen,LOW);
delay(250);
}
digitalWrite(pedRed,HIGH);//turnpedredon
delay(500);
digitalWrite(carRed,LOW);//redoff
digitalWrite(carYellow,HIGH);//yellowon

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 6/23
61
62
63
64
65
66
67
delay(1000);
digitalWrite(carYellow,LOW);//yellowoff
digitalWrite(carGreen,HIGH);
changeTime=millis();//recordthetimesincelastchangeoflights
//thenreturntothemainprogramloop
}
4.FadingLight
TheconnectiondiagramisthesamewithBlinknigaLEDtutorial.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
FadingLight
ThisexampleshowshowtofadeanLEDonpin10usingtheanalogWrite()function.
*/
intledPin=10;//thepinthattheLEDisattachedto
voidsetup(){
//declarepin9tobeanoutput:
pinMode(ledPin,OUTPUT);
//initializeserialcommunicationat9600bitspersecond:
Serial.begin(9600);
}
voidloop(){
fadeOn(1000,5);
fadeOff(1000,5);
}
voidfadeOn(unsignedinttime,intincreament){
//changethebrightnessbyFORstatement
for(bytevalue=0;value<255;value+=increament){
//printoutthevalue:
Serial.println(value);
//setthebrightnessofpin10:
analogWrite(ledPin,value);
delay(time/(255/5));
}
}

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 7/23
30
31
32
33
34
35
36
37
voidfadeOff(unsignedinttime,intdecreament){
//changethebrightnessbyFORstatement
for(bytevalue=255;value>0;value‐=decreament){
Serial.println(value);
analogWrite(ledPin,value);
delay(time/(255/5));
}
}
5.RGBLED
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
RGBLED
*/
intredPin=9;//thepinthattheredLEDisattachedto
intgreenPin=10;//thepinthatthegreenLEDisattachedto
intbluePin=11;//thepinthattheblueLEDisattachedto
voidsetup(){
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
}
voidloop(){

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 8/23
15
16
17
18
19
20
21
22
23
24
//callthefunctiontochangethecolorsofLEDrandomly.
colorRGB(random(0,255),random(0,255),random(0,255));//R:0‐255G:0‐255B:0‐255
delay(1000);
}
voidcolorRGB(intred,intgreen,intblue){
analogWrite(redPin,constrain(red,0,255));
analogWrite(greenPin,constrain(green,0,255));
analogWrite(bluePin,constrain(blue,0,255));
}
6.Alarm
?
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
Alarm
*/
floatsinVal;
inttoneVal;
voidsetup(){
pinMode(8,OUTPUT);
}
voidloop(){
for(intx=0;x<180;x++){
//convertdegreestoradiansthenobtainvalue

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 9/23
14
15
16
17
18
19
20
sinVal=(sin(x*(3.1412/180)));
//generateafrequencyfromthesinvalue
toneVal=2000+(int(sinVal*1000));
tone(8,toneVal);
delay(2);
}
}
7.TemperatureAlarm
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
TemperatureAlarm
*/
floatsinVal;
inttoneVal;
unsignedlongtepTimer;
voidsetup(){
pinMode(8,OUTPUT);
Serial.begin(9600);
}
voidloop(){
intval;
doubledata;
val=analogRead(0);

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 10/23
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
data=(double)val*(5/10.24);//convertthevoltagetotemperture
if(data>27){//Ifthetempertureisover27degree,buzzerwillalarm.
for(intx=0;x<180;x++){
sinVal=(sin(x*(3.1412/180)));
toneVal=2000+(int(sinVal*1000));
tone(8,toneVal);
delay(2);
}
}else{//Ifthetemperturnisbelow27degree,buzzerwillnotalarm
noTone(8);
}
if(millis()‐tepTimer>500){//outputthetemperturevalueper500ms
tepTimer=millis();
Serial.print("temperature:");
Serial.print(data);
Serial.println("C");
}
}
8.Detectingvibration
?

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 11/23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
Detectingvibration
*/
intSensorLED=13;//LEDPIN
intSensorINPUT=3;//ConnectthesensortodigitalPin3whichisInterrupts1
unsignedcharstate=0;
voidsetup(){
pinMode(SensorLED,OUTPUT);
pinMode(SensorINPUT,INPUT);
//Triggertheblinkfunctionwhenthefallingedgeisdetected
attachInterrupt(1,blink,RISING);
}
voidloop(){
if(state!=0){
state=0;
digitalWrite(SensorLED,HIGH);
delay(500);
}
else
digitalWrite(SensorLED,LOW);
}
voidblink(){//Interruptsfunction
state++;
}
9.AmbientLightcontrolledLED

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 12/23
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
AmbientLightcontrolledLED
*/
intLED=13;//Ledpin
intval=0;
voidsetup(){
pinMode(LED,OUTPUT);
Serial.begin(9600);
}
voidloop(){
val=analogRead(0);//readvoltagevalue
Serial.println(val);
if(val<1000){//ifthevalueislessthan1000,LEDturnsoff
digitalWrite(LED,LOW);
}else{//ifthevalueismorethan1000,LEDturnson
digitalWrite(LED,HIGH);
}
delay(10);
}
10.MovingaServo

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 13/23
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//MovingaServo
//byBARRAGAN<http://barraganstudio.com>
//Thisexamplecodeisinthepublicdomain.
#include<Servo.h>
Servomyservo;//createservoobjecttocontrolaservo
//amaximumofeightservoobjectscanbecreated
intpos=0;//variabletostoretheservoposition
voidsetup(){
myservo.attach(9);//attachestheservoonpin9totheservoobject
}
voidloop(){
for(pos=0;pos<180;pos+=1){//goesfrom0degreesto180degrees
//instepsof1degree
myservo.write(pos);//tellservotogotopositioninvariable'pos'
delay(15);//waits15msfortheservotoreachtheposition
}
for(pos=180;pos>=1;pos‐=1){//goesfrom180degreesto0
degrees
myservo.write(pos);//tellservotogotopositioninvariable'pos'
delay(15);//waits15msfortheservotoreachtheposition
}
}

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 14/23
11.InteractwithServo
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
InteractwithServo
Controllingaservopositionusingapotentiometer(variableresistor)
byMichalRinott<http://people.interaction‐ivrea.it/m.rinott>
*/
#include<Servo.h>
Servomyservo;//createservoobjecttocontrolaservo
intpotpin=0;//analogpinusedtoconnectthepotentiometer
intval;//variabletoreadthevaluefromtheanalogpin
voidsetup(){
myservo.attach(9);//attachestheservoonpin9totheservoobject
}
voidloop(){
val=analogRead(potpin);//readsthevalueofthepotentiometer(valuebetween0and
1023)
val=map(val,0,1023,0,179);//scaleittouseitwiththeservo(valuebetween0and
180)
myservo.write(val);//setstheservopositionaccordingtothescaledvalue
delay(15);//waitsfortheservotogetthere
}

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 15/23
12.RGBLightDimmer
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
RGBLightDimmer
*/
intredPin=9;//R–digital9
intgreenPin=10;//G–digital10
intbluePin=11;//B–digital11
intpotRedPin=0;//potentiometer1–analog0
intpotGreenPin=1;//potentiometer2–analog1
intpotBluePin=2;//potentiometer3–analog2
voidsetup(){
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
Serial.begin(9600);
}
voidloop(){
intpotRed=analogRead(potRedPin);
intpotGreen=analogRead(potGreenPin);
intpotBlue=analogRead(potBluePin);

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 16/23
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
intval1=map(potRed,0,1023,0,255);
intval2=map(potGreen,0,1023,0,255);
intval3=map(potBlue,0,1023,0,255);
Serial.print("Red:");
Serial.print(val1);
Serial.print("Green:");
Serial.print(val2);
Serial.print("Blue:");
Serial.println(val3);
colorRGB(val1,val2,val3);
}
voidcolorRGB(intred,intgreen,intblue){
analogWrite(redPin,constrain(red,0,255));
analogWrite(greenPin,constrain(green,0,255));
analogWrite(bluePin,constrain(blue,0,255));
}
13.MotorFan
?
1
2
/*
MotorFan

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 17/23
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
*/
intbuttonPin=2;//buttonpin‐‐Digital2
intrelayPin=3;//relaypin‐‐Digital3
intrelayState=HIGH;
intbuttonState;
intlastButtonState=LOW;
longlastDebounceTime=0;
longdebounceDelay=50;
voidsetup(){
pinMode(buttonPin,INPUT);
pinMode(relayPin,OUTPUT);
digitalWrite(relayPin,relayState);
}
voidloop(){
//readthestateoftheswitchintoalocalvariable:
intreading=digitalRead(buttonPin);
//checktoseeifyoujustpressedthebutton
//(i.e.theinputwentfromLOWtoHIGH),andyou'vewaited
//longenoughsincethelastpresstoignoreanynoise:
//Iftheswitchchanged,duetonoiseorpressing:
if(reading!=lastButtonState){
lastDebounceTime=millis();
}
if((millis()‐lastDebounceTime)>debounceDelay){
//whateverthereadingisat,it'sbeenthereforlonger
//thanthedebouncedelay,sotakeitastheactualcurrentstate:
//ifthebuttonstatehaschanged:
if(reading!=buttonState){
buttonState=reading;
//onlytoggletheRelayifthenewbuttonstateisHIGH
if(buttonState==HIGH){
relayState=!relayState;
}
}
}
//settherelay:

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 18/23
48
49
50
51
52
53
digitalWrite(relayPin,relayState);
//savethereading.Nexttimethroughtheloop,
//it'llbethelastButtonState:
lastButtonState=reading;
}
14.InfraredcontrolledLight

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 19/23
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
InfraredcontrolledLight
*/
#include<IRremote.h>
intRECV_PIN=11;
intledPin=10;
booleanledState=LOW;
IRrecvirrecv(RECV_PIN);
decode_resultsresults;
voidsetup(){
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(ledPin,OUTPUT);
}
voidloop(){
if(irrecv.decode(&results)){
Serial.println(results.value,HEX);

25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 20/23
21
22
23
24
25
26
27
if(results.value==0xFD00FF){
ledState=!ledState;
digitalWrite(ledPin,ledState);
}
irrecv.resume();
}
}
15.IntraredcontrolledLEDMatrix
Table of contents
Other DF ROBOT Robotics manuals

DF ROBOT
DF ROBOT ROB0118 User manual

DF ROBOT
DF ROBOT Insectbot Hexa Programming manual

DF ROBOT
DF ROBOT Maqueen Mechanic-Beetle Operation instructions

DF ROBOT
DF ROBOT MiniQ II User manual

DF ROBOT
DF ROBOT MBT0021-EN User manual

DF ROBOT
DF ROBOT Robot Beginner Kit with Arduino User manual

DF ROBOT
DF ROBOT DEVASTATOR User manual

DF ROBOT
DF ROBOT HCR User manual

DF ROBOT
DF ROBOT Flamewheel Robot User manual

DF ROBOT
DF ROBOT Cherokey 4WD Basic Kit User manual