25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 From Robot Wiki Contents 1 Introduction 2 Getting Started with Arduino 3 Tutorial 3.1 1.Blinking a LED 3.2 2.SOS Beacon 3.3 3.Traffic Light 3.4 4.Fading Light 3.5 5.RGB LED 3.6 6.Alarm 3.7 7.Temperature Alarm 3.8 8.Detecting vibration 3.9 9.Ambient Light controlled LED 3.10 10.Moving a Servo 3.11 11.Interact with Servo 3.12 12.RGB Light Dimmer 3.13 13.Motor Fan 3.14 14.
5/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki Getting Started with Arduino Introduction (http://arduino.cc/en/Guide/Introduction): What Arduino is and why you'd want to use it. Installation: Stepbystep instructions for setting up the Arduino software and connecting it to an Arduino Uno. Windows (http://arduino.cc/en/Guide/Windows) Mac OS X (http://arduino.cc/en/Guide/MacOSX) Environment (http://arduino.
25/06/2015 12 13 14} DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki digitalWrite(ledPin,LOW); delay(1000); 2.SOS Beacon The connection diagram is the same with Blinknig a LED tutorial. ? 1 /* 2 # Description: 3 # Send SOS Beacon by led 4 */ 5 int ledPin = 10; 6 void setup() { 7 pinMode(ledPin, OUTPUT); 8 } 9 void loop() { 10 11 // S(...
25/06/2015 36 37 38 39 40} DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki delay(100); } delay(5000); 3.Traffic Light ? 1 /* 2 Traffic Light 3 This code copied from the book Beginning‐Arduino.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 16 pinMode(carYellow, OUTPUT); 17 pinMode(carGreen, OUTPUT); 18 pinMode(pedRed, OUTPUT); 19 pinMode(pedGreen, OUTPUT); 20 pinMode(button, INPUT); 21 digitalWrite(carGreen, HIGH); //turn on the green lights 22 digitalWrite(pedRed, HIGH); 23} 24 25void loop() { 26 int state = digitalRead(button); 27 //check if button is pressed and it is over 5 seconds since last button press 28 if(state == HIGH && (millis() ‐ changeTime)> 5000){ 29 //
25/06/2015 61 62 63 64 65 66 67} DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki delay(1000); digitalWrite(carYellow, LOW); //yellow off digitalWrite(carGreen, HIGH); changeTime = millis(); //record the time since last change of lights //then return to the main program loop 4.Fading Light The connection diagram is the same with Blinknig a LED tutorial. ? 1 /* 2 Fading Light 3 This example shows how to fade an LED on pin 10 using the analogWrite() function.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 30void fadeOff(unsigned int time,int decreament){ 31 //change the brightness by FOR statement 32 for (byte value = 255; value >0; value‐=decreament){ 33 Serial.println(value); 34 analogWrite(ledPin, value); 35 delay(time/(255/5)); 36 } 37} 5.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 15 // call the function to change the colors of LED randomly. 16 colorRGB(random(0,255),random(0,255),random(0,255)); //R:0‐255 G:0‐255 B:0‐255 17 delay(1000); 18} 19 20void colorRGB(int red, int green, int blue){ 21 analogWrite(redPin,constrain(red,0,255)); 22 analogWrite(greenPin,constrain(green,0,255)); 23 analogWrite(bluePin,constrain(blue,0,255)); 24} 6.
25/06/2015 14 15 16 17 18 19 20} DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki sinVal = (sin(x*(3.1412/180))); // generate a frequency from the sin value toneVal = 2000+(int(sinVal*1000)); tone(8, toneVal); delay(2); } 7.Temperature Alarm ? 1 /* 2 Temperature Alarm 3 */ 4 float sinVal; 5 int toneVal; 6 unsigned long tepTimer ; 7 8 void setup(){ 9 pinMode(8, OUTPUT); 10 Serial.begin(9600); 11} 12 13void loop(){ 14 int val; 15 double data; 16 val=analogRead(0); http://www.dfrobot.
25/06/2015 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36} DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki data = (double) val * (5/10.24); if(data>27){ // convert the voltage to temperture // If the temperture is over 27 degree, buzzer will alarm. for(int x=0; x<180; x++){ sinVal = (sin(x*(3.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 1 /* 2 Detecting vibration 3 */ 4 5 int SensorLED = 13; //LED PIN 6 int SensorINPUT = 3; //Connect the sensor to digital Pin 3 which is Interrupts 1 7 unsigned char state = 0; 8 9 void setup() { 10 pinMode(SensorLED, OUTPUT); 11 pinMode(SensorINPUT, INPUT); 12 13 // Trigger the blink function when the falling edge is detected 14 attachInterrupt(1, blink, RISING); 15 } 16 17void loop(){ 18 if(state!=0){ 19 state = 0; 20 digitalWrite(S
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki ? 1 /* 2 Ambient Light controlled LED 3 */ 4 int LED = 13; //Led pin 5 int val = 0; 6 7 void setup(){ 8 pinMode(LED,OUTPUT); 9 Serial.begin(9600); 10} 11 12void loop(){ 13 val = analogRead(0); // read voltage value 14 Serial.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki ? // Moving a Servo 1 // by BARRAGAN 2 // This example code is in the public domain. 3 4 #include 5 Servo myservo; // create servo object to control a servo 6 // a maximum of eight servo objects can be created 7 int pos = 0; // variable to store the servo position 8 9 void setup() { 10 myservo.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 11.Interact with Servo ? /* 1 Interact with Servo 2 Controlling a servo position using a potentiometer (variable resistor) 3 by Michal Rinott 4 */ 5 6 #include 7 Servo myservo; // create servo object to control a servo 8 9 int potpin = 0; // analog pin used to connect the potentiometer 10int val; // variable to read the value from the analog pin 11 12void setup() { 13 myservo.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 12.RGB Light Dimmer ? 1 /* 2 RGB Light Dimmer 3 */ 4 int redPin = 9; // R – digital 9 5 int greenPin = 10; // G – digital 10 6 int bluePin = 11; // B – digital 11 7 int potRedPin = 0; // potentiometer 1 – analog 0 8 int potGreenPin = 1; // potentiometer 2 – analog 1 9 int potBluePin = 2; // potentiometer 3 – analog 2 10 11void setup(){ 12 pinMode(redPin,OUTPUT); 13 pinMode(greenPin,OUTPUT); 14 pinMode(bluePin,OUTPUT); 15 Serial.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 23 int val1 = map(potRed,0,1023,0,255); 24 int val2 = map(potGreen,0,1023,0,255); 25 int val3 = map(potBlue,0,1023,0,255); 26 27 Serial.print("Red:"); 28 Serial.print(val1); 29 Serial.print("Green:"); 30 Serial.print(val2); 31 Serial.print("Blue:"); 32 Serial.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 3 */ 4 5 int buttonPin = 2; // button pin ‐‐ Digital 2 6 int relayPin = 3; // relay pin ‐‐ Digital 3 7 int relayState = HIGH; 8 int buttonState; 9 int lastButtonState = LOW; 10long lastDebounceTime = 0; 11long debounceDelay = 50; 12 13void setup() { 14 pinMode(buttonPin, INPUT); 15 pinMode(relayPin, OUTPUT); 16 17 digitalWrite(relayPin, relayState); 18} 19void loop() { 20 // read the state of the switch into a local variable: 21 int
25/06/2015 48 49 50 51 52 53} DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki digitalWrite(relayPin, relayState); // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonState = reading; 14.Infrared controlled Light http://www.dfrobot.com/wiki/index.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki ? 1 /* 2 Infrared controlled Light 3 */ 4 #include 5 int RECV_PIN = 11; 6 int ledPin = 10; 7 boolean ledState = LOW; 8 IRrecv irrecv(RECV_PIN); 9 decode_results results; 10 11void setup(){ 12 Serial.begin(9600); 13 irrecv.enableIRIn(); 14 pinMode(ledPin,OUTPUT); 15} 16 17void loop() { 18 if (irrecv.decode(&results)) { 19 Serial.println(results.value, HEX); 20 http://www.dfrobot.com/wiki/index.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 21 if(results.value == 0xFD00FF){ 22 ledState = !ledState; 23 digitalWrite(ledPin,ledState); 24 } 25 irrecv.resume(); 26 } 27} 15.Intrared controlled LED Matrix http://www.dfrobot.com/wiki/index.
25/06/2015 ? 1 #include
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 24 {1,0,0,0,1,0,0,1},//5 25 {1,0,0,0,0,0,0,1},//6 26 {0,0,1,1,1,1,0,1},//7 27 {0,0,0,0,0,0,0,1},//8 28 {0,0,0,0,1,1,0,1} //9 29}; 30 31void numberShow(int i) { //this function is used to display numbers 32 for(int pin = 2; pin <= 9 ; pin++){ 33 digitalWrite(pin, number[i][pin ‐ 2]); 34 } 35} 36 37void setup(){ 38 Serial.begin(9600); 39 irrecv.
25/06/2015 DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki 69 Serial.println(currentNumber); 70 break; 71 } 72 } 73 74 Serial.println(results.value, HEX); 75 irrecv.resume(); 76 } 77} Old Version V2 wiki (http://www.dfrobot.com/wiki/index.php?title=DFRduino_Beginner_Kit_For_Arduino_(SKU:DFR0100)) V2 tutorial (http://www.dfrobot.com/wiki/index.php?title=Tutorial) Go Shopping Beginner Kit For Arduino v3.0(SKU:DFR0100) (http://www.dfrobot.com/index.