arduino df robot
TRANSCRIPT
-
8/10/2019 arduino df robot
1/14
-
8/10/2019 arduino df robot
2/14
2.SOS Beacon
The connection diagram is the same with Blinknig a LED tutorial.
3.Traffic Light
1234
56789
1011121314
/*# Description:# Turns on an LED on for one second, then off for one second, repeatedly.
*/
intledPin = 10;voidsetup() { pinMode(ledPin, OUTPUT);}voidloop() {
digitalWrite(ledPin,HIGH); delay(1000); digitalWrite(ledPin,LOW); delay(1000);}
12
345678
910111213
141516171819
202122232425
2627282930
31323334353637
383940
/*# Description:
# Send SOS Beacon by led*/intledPin = 10;voidsetup() { pinMode(ledPin, OUTPUT);}
voidloop() {
// S(...) three dot for(intx=0;x
-
8/10/2019 arduino df robot
3/14
4.Fading Light
The connection diagram is the same with Blinknig a LED tutorial.
1234
56789
1011121314
15161718192021
222324252627
282930313233
343536373839
404142434445
464748495051
5253545556
575859606162
6364656667
/* Traffic Light This code copied from the book Beginning-Arduino.*/
intcarRed = 12; //assign the car lightsintcarYellow = 11;intcarGreen = 10;intbutton = 9; //button pinintpedRed = 8; //assign the pedestrian lightsintpedGreen = 7;intcrossTime =5000; //time for pedestrian to crossunsigned longchangeTime;//time since button pressedvoidsetup() {
pinMode(carRed, OUTPUT); pinMode(carYellow, OUTPUT); pinMode(carGreen, OUTPUT); pinMode(pedRed, OUTPUT); pinMode(pedGreen, OUTPUT); pinMode(button, INPUT);
digitalWrite(carGreen, HIGH); //turn on the green lights
digitalWrite(pedRed, HIGH);}voidloop() { intstate = digitalRead(button); //check if button is pressed and it is over 5 seconds since last button press
if(state == HIGH && (millis() - changeTime)> 5000){ //call the function to change the lights changeLights(); }}voidchangeLights() { digitalWrite(carGreen, LOW); //green off digitalWrite(carYellow, HIGH); //yellow on delay(2000); //wait 2 seconds
digitalWrite(carYellow, LOW); //yellow off
digitalWrite(carRed, HIGH); //red on delay(1000); //wait 1 second till its safe
digitalWrite(pedRed, LOW); //ped red off digitalWrite(pedGreen, HIGH); //ped green on
delay(crossTime); //wait for preset time period
//flash the ped green for(intx=0; x
-
8/10/2019 arduino df robot
4/14
5.RGB LED
6.Alarm
1234
56789
1011121314
15161718192021
222324252627
282930313233
34353637
/* Fading Light This example shows how to fade an LED on pin 10 using the analogWrite() function.*/
intledPin = 10; // the pin that the LED is attached tovoidsetup() { // declare pin 9 to be an output: pinMode(ledPin,OUTPUT);
// initialize serial communication at 9600 bits per second: Serial.begin(9600);}voidloop(){
fadeOn(1000,5); fadeOff(1000,5);}voidfadeOn(unsigned inttime,intincreament){ //change the brightness by FOR statement for(byte value = 0 ; value < 255; value+=increament){
// print out the value: Serial.println(value); // set the brightness of pin 10: analogWrite(ledPin, value); delay(time/(255/5)); }
}voidfadeOff(unsigned inttime,intdecreament){ //change the brightness by FOR statement for(byte value = 255; value >0; value-=decreament){
Serial.println(value);
analogWrite(ledPin, value);delay(time/(255/5));
}}
123
456789
10
1112131415
161718192021
22
2324
/* RGB LED*/
intredPin = 9; // the pin that the red LED is attached tointgreenPin = 10; // the pin that the green LED is attached tointbluePin = 11; // the pin that the blue LED is attached tovoidsetup(){ pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);}voidloop(){ // call the function to change the colors of LED randomly.
colorRGB(random(0,255),random(0,255),random(0,255)); //R:0-255 G:0-255 B: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));}
?
?
converted by Web2PDFConvert.com
http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=File:5_RGB_LED.png -
8/10/2019 arduino df robot
5/14
7.Temperature Alarm
12
345678
910
111213
141516171819
20
/* Alarm
*/floatsinVal;inttoneVal;voidsetup(){ pinMode(8, OUTPUT);
}
voidloop(){ for(intx=0; x
-
8/10/2019 arduino df robot
6/14
8.Detecting vibration
1234
56789
1011121314
15161718192021
222324252627
282930313233
343536
/* Temperature Alarm*/floatsinVal;
inttoneVal;unsigned longtepTimer ;
voidsetup(){pinMode(8, OUTPUT);
Serial.begin(9600);}voidloop(){
intval;
doubledata;val=analogRead(0);data = (double) val * (5/10.24); // convert the voltage to temperture
if(data>27){ // If the temperture is over 27 degree, buzzer will alarm.
for(intx=0; x 500){ // output the temperture value per 500ms tepTimer = millis(); Serial.print("temperature: ");
Serial.print(data);
Serial.println("C");}
}
1
2
3456
789
101112
131415161718
192021
222324
2526272829
/*
Detecting vibration
*/intSensorLED = 13; //LED PINintSensorINPUT = 3; //Connect the sensor to digital Pin 3 which is Interrupts 1
unsigned charstate = 0;voidsetup() {
pinMode(SensorLED, OUTPUT);pinMode(SensorINPUT, INPUT);
// Trigger the blink function when the falling edge is detected attachInterrupt(1, blink, RISING);}
voidloop(){ if(state!=0){
state = 0;digitalWrite(SensorLED,HIGH);delay(500);
}else
digitalWrite(SensorLED,LOW);
}
voidblink(){ //Interrupts function state++;}
?
?
converted by Web2PDFConvert.com
http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=File:8_Detecting_vibration.png -
8/10/2019 arduino df robot
7/14
9.Ambient Light controlled LED
10.Moving a Servo
12
3456
789
101112
131415161718
192021
/* Ambient Light controlled LED
*/intLED = 13; //Led pinintval = 0;
voidsetup(){ pinMode(LED,OUTPUT);
Serial.begin(9600);}voidloop(){
val = analogRead(0); // read voltage valueSerial.println(val);if(val
-
8/10/2019 arduino df robot
8/14
11.Interact with Servo
12.RGB Light Dimmer
1234
56789
1011121314
15161718192021
22232425
// Moving a Servo// by BARRAGAN // This example code is in the public domain.
#include Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be createdintpos = 0; // variable to store the servo position
voidsetup() {myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
voidloop() {
for(pos = 0; pos < 180; pos += 1){ // goes from 0 degrees to 180 degrees // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'delay(15); // waits 15ms for the servo to reach the position
}}
12345
6789
10
111213141516
171819202122
/* Interact with Servo Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott */
#include Servo myservo; // create servo object to control a servo
intpotpin = 0; // analog pin used to connect the potentiometerintval; // variable to read the value from the analog pin
voidsetup() {myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
voidloop() {val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)myservo.write(val); // sets the servo position according to the scaled valuedelay(15); // waits for the servo to get there
}
?
?
converted by Web2PDFConvert.com
http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://people.interaction-ivrea.it/m.rinotthttp://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=File:11_Interact_with_Servo.pnghttp://barraganstudio.com/ -
8/10/2019 arduino df robot
9/14
13.Motor Fan
12345
6789
1011
121314151617
181920212223
24
2526272829
303132333435
363738394041
/* RGB Light Dimmer*/intredPin = 9; // R digital 9intgreenPin = 10; // G digital 10int
bluePin = 11; // B digital 11intpotRedPin = 0; // potentiometer 1 analog 0intpotGreenPin = 1; // potentiometer 2 analog 1intpotBluePin = 2; // potentiometer 3 analog 2voidsetup(){
pinMode(redPin,OUTPUT); pinMode(greenPin,OUTPUT); pinMode(bluePin,OUTPUT); Serial.begin(9600);}voidloop(){ intpotRed = analogRead(potRedPin);
intpotGreen = analogRead(potGreenPin);intpotBlue = analogRead(potBluePin);
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));}
?
converted by Web2PDFConvert.com
http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=File:13_Motor_Fan.pnghttp://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=File:12_RGB_Light_Dimmer.png -
8/10/2019 arduino df robot
10/14
-
8/10/2019 arduino df robot
11/14
15.Intrared controlled LED Matrix
123456
789
101112
131415161718
1920212223
24252627
/* Infrared controlled Light*/#include intRECV_PIN = 11;intledPin = 10;
boolean ledState = LOW;IRrecv irrecv(RECV_PIN);decode_results results;
voidsetup(){ Serial.begin(9600);
irrecv.enableIRIn();pinMode(ledPin,OUTPUT);
}voidloop() { if(irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if(results.value == 0xFD00FF){ ledState = !ledState;
digitalWrite(ledPin,ledState);
}irrecv.resume();}
}
?
converted by Web2PDFConvert.com
http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=File:15_Intrared_controlled_LED_Matrix.pnghttp://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=File:14_Infrared_controlled_Light_1.png -
8/10/2019 arduino df robot
12/14converted by Web2PDFConvert.com
http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=File:14_Infrared_controlled_Light_2.png -
8/10/2019 arduino df robot
13/14
Old Version
V2 wiki
V2 tutorial
Go Shopping Beginner Kit For Arduino v3.0(SKU:DFR0100)
Categories: Product Manual DFR Series
1234
56789
1011121314
15161718192021
222324252627
282930313233
343536373839
404142434445
464748495051
5253545556
575859606162
636465666768
697071727374
757677
#include intRECV_PIN = 11;IRrecv irrecv(RECV_PIN);decode_results results;
intcurrentNumber = 0;
longcodes[12]= // this array is used to store infrared codes{ 0xFD30CF,0xFD08F7, // 0 ,1
0xFD8877,0xFD48B7, // 2 ,3 0xFD28D7,0xFDA857, // 4 ,5 0xFD6897,0xFD18E7, // 6 ,7 0xFD9867,0xFD58A7, // 8 ,9 0xFD20DF,0xFD609F, // advance, move back
};intnumber[10][8] = //the array is used to store the number 0~9{ {0,0,0,1,0,0,0,1},//0 {0,1,1,1,1,1,0,1},//1 {0,0,1,0,0,0,1,1},//2
{0,0,1,0,1,0,0,1},//3 {0,1,0,0,1,1,0,1},//4 {1,0,0,0,1,0,0,1},//5 {1,0,0,0,0,0,0,1},//6 {0,0,1,1,1,1,0,1},//7 {0,0,0,0,0,0,0,1},//8
{0,0,0,0,1,1,0,1} //9};voidnumberShow(inti) { //this function is used to display numbers for(intpin = 2; pin
-
8/10/2019 arduino df robot
14/14
Privacy policy About Robot Wiki Disclaimers
This page was last modified on 30 June 2014, at 09:23.
This page has been accessed 2,392 times.
http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://localhost/var/www/apps/conversion/tmp/scratch_5//www.mediawiki.org/http://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=Robot_Wiki:General_disclaimerhttp://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=Robot_Wiki:Abouthttp://localhost/var/www/apps/conversion/tmp/scratch_5/wiki/index.php?title=Robot_Wiki:Privacy_policy