├── README.md ├── Button ├── circuit │ ├── Controlling LED by Button.fzz │ └── Controlling LED by Button_bb.png └── code │ └── Button │ └── Button.ino ├── Simple_Creation_Light_Alarm └── Simple_Creation_Light_Alarm.ino ├── Tilt_Switch └── Tilt_Switch.ino ├── Buzzer └── Active.ino ├── Humiture_Sensor └── code │ ├── library │ └── Dht │ │ ├── dht.h │ │ ├── examples │ │ └── dht_test │ │ │ └── dht_test.ino │ │ └── dht.cpp │ └── dht_test │ └── dht_test.ino ├── Thermistor └── Thermistor.ino ├── Controlling_LED_by_Button └── Controlling_LED_by_Button.ino ├── Controlling_LED_by_Potentiometer └── Controlling_LED_by_Potentiometer.ino ├── photoTest └── photoTest.ino ├── Photoresistor └── photoTest.ino ├── Automatic_Light_Source_Tracking └── Automatic_Light_Source_Tracking.ino ├── Flowing_LED_Lights └── Flowing_LED_Lights.ino ├── servo └── servo.ino ├── LCD1602 └── LCD1602.ino ├── Blinking_LED └── Blinking_LED.ino └── RGB_LED └── RGB_LED.ino /README.md: -------------------------------------------------------------------------------- 1 | # Arduino 2 | Get latest tutorial code for Arduino 3 | -------------------------------------------------------------------------------- /Button/circuit/Controlling LED by Button.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/primerobotics/Arduino/HEAD/Button/circuit/Controlling LED by Button.fzz -------------------------------------------------------------------------------- /Button/circuit/Controlling LED by Button_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/primerobotics/Arduino/HEAD/Button/circuit/Controlling LED by Button_bb.png -------------------------------------------------------------------------------- /Simple_Creation_Light_Alarm/Simple_Creation_Light_Alarm.ino: -------------------------------------------------------------------------------- 1 | //Simple Creation - Light Alarm 2 | //Now, you can hear that the buzzer make sounds when the LED is shined. 3 | //Email: info@primerobotics.in 4 | //Website:www.primerobotics.in 5 | void setup() 6 | { 7 | Serial.begin(9600); // start serial port at 9600 bps: 8 | } 9 | void loop() 10 | { 11 | int n=analogRead(A0); //read the value from analog pin AO 12 | Serial.println(n); 13 | if(n>0) //If there is a voltage 14 | { 15 | pinMode(5,OUTPUT); //set the digital pin 5 as an output 16 | tone(5,10000); //Generates a square wave(10000 Hz frequency,50% duty cycle) on pin 5 17 | pinMode(5,INPUT); //set the pin 5 as an input 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Button/code/Button/Button.ino: -------------------------------------------------------------------------------- 1 | //Controlling Led By Button 2 | //Turns on and off a LED ,when pressings button attach to pin12 3 | //Email:info@primerobotics.in 4 | //Website:www.primerobotics.in 5 | /**********************************/ 6 | const int keyPin = 12; //the number of the key pin 7 | const int ledPin = 13;//the number of the led pin 8 | /**********************************/ 9 | void setup() 10 | { 11 | pinMode(keyPin,INPUT);//initialize the key pin as input 12 | pinMode(ledPin,OUTPUT);//initialize the led pin as output 13 | } 14 | /**********************************/ 15 | void loop() 16 | { 17 | //read the state of the key value 18 | //and check if the kye is pressed 19 | //if it is,the state is HIGH 20 | if(digitalRead(keyPin) ==HIGH ) 21 | { 22 | digitalWrite(ledPin,HIGH);//turn on the led 23 | } 24 | else 25 | { 26 | digitalWrite(ledPin,LOW);//turn off the led 27 | } 28 | } 29 | /************************************/ 30 | -------------------------------------------------------------------------------- /Tilt_Switch/Tilt_Switch.ino: -------------------------------------------------------------------------------- 1 | //tilt switch 2 | //tilt the switch, and the LED attached to pin 13 on SunFounder Uno board will light up. 3 | //tilt switch attach to pin2 4 | //Email: info@primerobotics.in 5 | //Website: www.primerobotics.in 6 | /*****************************************/ 7 | const int ledPin = 13;//the led attach to 8 | 9 | void setup() 10 | { 11 | pinMode(ledPin,OUTPUT);//initialize the ledPin as an output 12 | pinMode(2,INPUT);//set pin2 as INPUT 13 | digitalWrite(2, HIGH);//set pin2 as HIGH 14 | } 15 | /******************************************/ 16 | void loop() 17 | { 18 | int digitalVal = digitalRead(2);//Read the value of pin2 19 | if(HIGH == digitalVal)//if tilt switch is not breakover 20 | { 21 | digitalWrite(ledPin,LOW);//turn the led off 22 | } 23 | else ////if tilt switch breakover 24 | { 25 | digitalWrite(ledPin,HIGH);//turn the led on 26 | } 27 | } 28 | /**********************************************/ 29 | -------------------------------------------------------------------------------- /Buzzer/Active.ino: -------------------------------------------------------------------------------- 1 | /********************************* 2 | * name:buzzer 3 | * function: you should hear the buzzer make sounds. 4 | *************************************/ 5 | //Email: info@primerobotics.in 6 | //Website: www.primerobotics.in 7 | /************************************/ 8 | int buzzer = 12;//the pin of the active buzzer 9 | void setup() 10 | { 11 | pinMode(buzzer,OUTPUT);//initialize the buzzer pin as an output 12 | } 13 | void loop() 14 | { 15 | unsigned char i; 16 | while(1) 17 | { 18 | //output an frequency 19 | for(i=0;i<80;i++) 20 | { 21 | digitalWrite(buzzer,HIGH); 22 | delay(1);//wait for 1ms 23 | digitalWrite(buzzer,LOW); 24 | delay(1);//wait for 1ms 25 | } 26 | //output another frequency 27 | for(i=0;i<100;i++) 28 | { 29 | digitalWrite(buzzer,HIGH); 30 | delay(2);//wait for 2ms 31 | digitalWrite(buzzer,LOW); 32 | delay(2);//wait for 2ms 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Humiture_Sensor/code/library/Dht/dht.h: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: dht.h 3 | // AUTHOR: Rob Tillaart 4 | // VERSION: 0.1.09 5 | // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino 6 | // URL: http://arduino.cc/playground/Main/DHTLib 7 | // 8 | // HISTORY: 9 | // see dht.cpp file 10 | // 11 | 12 | #ifndef dht_h 13 | #define dht_h 14 | 15 | #if ARDUINO < 100 16 | #include 17 | #else 18 | #include 19 | #endif 20 | 21 | #define DHT_LIB_VERSION "0.1.09" 22 | 23 | #define DHTLIB_OK 0 24 | #define DHTLIB_ERROR_CHECKSUM -1 25 | #define DHTLIB_ERROR_TIMEOUT -2 26 | #define DHTLIB_INVALID_VALUE -999 27 | 28 | class dht 29 | { 30 | public: 31 | int read11(uint8_t pin); 32 | int read21(uint8_t pin); 33 | int read22(uint8_t pin); 34 | 35 | double humidity; 36 | double temperature; 37 | 38 | private: 39 | uint8_t bits[5]; // buffer to receive data 40 | int read(uint8_t pin); 41 | }; 42 | #endif 43 | // 44 | // END OF FILE 45 | // -------------------------------------------------------------------------------- /Humiture_Sensor/code/dht_test/dht_test.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | LiquidCrystal lcd(4, 5, 9, 10, 11, 12); 4 | 5 | dht DHT; 6 | 7 | #define DHT11_PIN 4 8 | 9 | void setup() 10 | { 11 | lcd.begin(16, 2); 12 | Serial.begin(9600); 13 | } 14 | 15 | void loop() 16 | { 17 | // READ DATA 18 | Serial.print("DHT11, \t"); 19 | //read the value returned from sensor 20 | int chk = DHT.read11(DHT11_PIN); 21 | switch (chk) 22 | { 23 | case DHTLIB_OK: 24 | Serial.print("OK,\t"); 25 | break; 26 | case DHTLIB_ERROR_CHECKSUM: 27 | Serial.print("Checksum error,\t"); 28 | break; 29 | case DHTLIB_ERROR_TIMEOUT: 30 | Serial.print("Time out error,\t"); 31 | break; 32 | default: 33 | Serial.print("Unknown error,\t"); 34 | break; 35 | } 36 | // DISPLAY DATA 37 | lcd.setCursor(0, 0); 38 | lcd.print("Tem:"); 39 | lcd.print(DHT.temperature,1); //print the temperature on lcd 40 | lcd.print(" C"); 41 | lcd.setCursor(0, 1); 42 | lcd.print("Hum:"); 43 | lcd.print(DHT.humidity,1); //print the humidity on lcd 44 | lcd.print(" %"); 45 | delay(200); //wait a while 46 | } 47 | -------------------------------------------------------------------------------- /Thermistor/Thermistor.ino: -------------------------------------------------------------------------------- 1 | /************************************ 2 | * name:thermistor 3 | * function:you can see current temperature displayed on the serial monitor. 4 | **************************************/ 5 | //Email: info@primerobotics.in 6 | //Website: www.primerobotics.in 7 | 8 | #define analogPin A0 //the thermistor attach to 9 | #define beta 3950 //the beta of the thermistor 10 | #define resistance 10 //the value of the pull-down resistor 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | } 16 | 17 | void loop() 18 | { 19 | //read thermistor value 20 | long a = analogRead(analogPin); 21 | //the calculating formula of temperature 22 | float tempC = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0; 23 | //float tempF = 1.8*tempC + 32.0;//convert centigrade to Fahrenheit 24 | Serial.print("TempC: ");//print" TempC: " 25 | Serial.print(tempC);//print Celsius temperature 26 | Serial.print(" C");//print the unit 27 | Serial.println(); 28 | //Serial.print("TempF: "); 29 | // Serial.print(tempF); 30 | // Serial.print(" F"); 31 | delay(200); //wait for 200 milliseconds 32 | } 33 | -------------------------------------------------------------------------------- /Controlling_LED_by_Button/Controlling_LED_by_Button.ino: -------------------------------------------------------------------------------- 1 | //Controlling Led By Button 2 | //Turns on and off a LED ,when pressings button attach to pin12 3 | //Email:info@primerobotics.in 4 | //Website:www.primerobotics.in 5 | 6 | /**********************************/ 7 | const int buttonPin = 12; //the button connect to pin 12 8 | const int ledPin = 13;//the led connect to pin13 9 | /**********************************/ 10 | int buttonState = 0; // variable for reading the pushbutton status 11 | 12 | void setup() 13 | { 14 | pinMode(buttonPin, INPUT); //initialize thebuttonPin as input 15 | pinMode(ledPin, OUTPUT); //initialize the led pin as output 16 | } 17 | /**********************************/ 18 | void loop() 19 | { 20 | //read the state of the button value 21 | buttonState = digitalRead(buttonPin); 22 | 23 | //and check if the key is pressed 24 | //if it is,the state is HIGH 25 | if (buttonState == HIGH ) 26 | { 27 | digitalWrite(ledPin, HIGH); //turn the led on 28 | } 29 | else 30 | { 31 | digitalWrite(ledPin, LOW); //turn the led off 32 | } 33 | } 34 | /************************************/ 35 | -------------------------------------------------------------------------------- /Controlling_LED_by_Potentiometer/Controlling_LED_by_Potentiometer.ino: -------------------------------------------------------------------------------- 1 | //Controlling led by potentiometer 2 | //Rotate the shaft of the potentiometer and you should see the luminance of the LED change. 3 | //Email:info@primerobotics.in 4 | //Website:www.primerobotics.in 5 | //2015.5.7 6 | /******************************************/ 7 | const int analogPin = 0;//the analog input pin attach to 8 | const int ledPin = 9;//the led attach to 9 | int inputValue = 0;//variable to store the value coming from sensor 10 | int outputValue = 0;//variable to store the output value 11 | /******************************************/ 12 | void setup() 13 | { 14 | Serial.begin(9600);//set the serial communication baudrate as 9600 15 | } 16 | /******************************************/ 17 | void loop() 18 | { 19 | inputValue = analogRead(analogPin);//read the value from the potentiometer 20 | Serial.print("Input: "); //print "Input" 21 | Serial.println(inputValue); //print inputValue 22 | outputValue = map(inputValue, 0, 1023, 0, 255); //Convert from 0-1023 proportional to the number of a number of from 0 to 255 23 | Serial.print("Output: "); //print "Output" 24 | Serial.println(outputValue); //print outputValue 25 | analogWrite(ledPin, outputValue); //turn the LED on depending on the output value 26 | delay(1000); 27 | } 28 | /*******************************************/ 29 | -------------------------------------------------------------------------------- /photoTest/photoTest.ino: -------------------------------------------------------------------------------- 1 | /************************************ 2 | * name:Photoresistor 3 | * function: if you shine the photoresistor with a certain light intensity, you will see several LEDs light up. 4 | * If you increase the light intensity, you will see more LEDs light up. 5 | * When you place it in dark environment, all the LEDs will go out. 6 | *********************************************/ 7 | //Email: info@primerobotics.in 8 | //Website: www.primerobotics.in 9 | 10 | const int NbrLEDs = 8;//8 leds 11 | const int ledPins[] = {5, 6, 7, 8, 9, 10, 11, 12};//8 leds attach to pin 5-12 respectively 12 | const int photocellPin = A0; //photoresistor attach to A0 13 | int sensorValue = 0; // value read from the sensor 14 | int ledLevel = 0; // sensor value converted into LED 'bars' 15 | 16 | void setup() 17 | { 18 | for (int led = 0; led < NbrLEDs; led++) 19 | { 20 | pinMode(ledPins[led], OUTPUT);// make all the LED pins outputs 21 | } 22 | } 23 | 24 | void loop() 25 | { 26 | sensorValue = analogRead(photocellPin); //read the value of A0 27 | ledLevel = map(sensorValue, 300, 1023, 0, NbrLEDs); // map to the number of LEDs 28 | for (int led = 0; led < NbrLEDs; led++)// 29 | { 30 | if (led < ledLevel ) //When led is smaller than ledLevel, run the following code. 31 | { 32 | digitalWrite(ledPins[led], HIGH); // turn on pins less than the level 33 | } 34 | else 35 | { 36 | digitalWrite(ledPins[led],LOW); // turn off pins higher than 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Photoresistor/photoTest.ino: -------------------------------------------------------------------------------- 1 | /************************************ 2 | * name:Photoresistor 3 | * function: if you shine the photoresistor with a certain light intensity, you will see several LEDs light up. 4 | * If you increase the light intensity, you will see more LEDs light up. 5 | * When you place it in dark environment, all the LEDs will go out. 6 | *********************************************/ 7 | //Email: info@primerobotics.in 8 | //Website: www.primerobotics.in 9 | 10 | const int NbrLEDs = 8;//8 leds 11 | const int ledPins[] = {5, 6, 7, 8, 9, 10, 11, 12};//8 leds attach to pin 5-12 respectively 12 | const int photocellPin = A0; //photoresistor attach to A0 13 | int sensorValue = 0; // value read from the sensor 14 | int ledLevel = 0; // sensor value converted into LED 'bars' 15 | 16 | void setup() 17 | { 18 | for (int led = 0; led < NbrLEDs; led++) 19 | { 20 | pinMode(ledPins[led], OUTPUT);// make all the LED pins outputs 21 | } 22 | } 23 | 24 | void loop() 25 | { 26 | sensorValue = analogRead(photocellPin); //read the value of A0 27 | ledLevel = map(sensorValue, 300, 1023, 0, NbrLEDs); // map to the number of LEDs 28 | for (int led = 0; led < NbrLEDs; led++)// 29 | { 30 | if (led < ledLevel ) //When led is smaller than ledLevel, run the following code. 31 | { 32 | digitalWrite(ledPins[led], HIGH); // turn on pins less than the level 33 | } 34 | else 35 | { 36 | digitalWrite(ledPins[led],LOW); // turn off pins higher than 37 | } 38 | } 39 | } 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Automatic_Light_Source_Tracking/Automatic_Light_Source_Tracking.ino: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * name : Automatically Tracking Light Source 3 | * function : if you use a flashlight to shine the photoresistor, 4 | * you will see the servo motor and the photoresistor rotate, 5 | * and finally stop at the direction of light source. 6 | ***********************************************************************/ 7 | //Email: info@primerobotics.in 8 | //Website: www.primerobotics.in 9 | 10 | #include 11 | const int photocellPin = A0; 12 | /************************************************/ 13 | Servo myservo;//create servo object to control a servo 14 | 15 | int outputValue = 0; 16 | int angle[] = {0,10, 20, 30, 40, 50, 60,70, 80, 90, 100,110,120,130,140,150,160,170,180}; 17 | int maxVal = 0; 18 | int maxPos = 0; 19 | /*************************************************/ 20 | void setup() 21 | { 22 | Serial.begin(9600); 23 | myservo.attach(9);//attachs the servo on pin 9 to servo object 24 | } 25 | /*************************************************/ 26 | void loop() 27 | { 28 | for(int i = 0; i < 19; i ++) 29 | { 30 | myservo.write(angle[i]);//write the angle to servo 31 | outputValue = analogRead(photocellPin);//read the value of A0 32 | Serial.println(outputValue);//print it 33 | if(outputValue > maxVal)//if the current value of A0 is greater than previous 34 | { 35 | maxVal = outputValue;//write down the value 36 | maxPos =i;// 37 | } 38 | delay(200); 39 | } 40 | myservo.write(angle[ maxPos]);//write the angle to servo which A0 has greatest value 41 | while(1); 42 | } 43 | -------------------------------------------------------------------------------- /Flowing_LED_Lights/Flowing_LED_Lights.ino: -------------------------------------------------------------------------------- 1 | //Flowing LED Lights 2 | /* Eight LEDs will light up one by one from left to right, and then go out one by one from right to left. 3 | After that, the LEDs will light up one by one from right to left, and then go out one by one from left to right. 4 | This process will repeat indefinitely.*/ 5 | //Email:info@primerobotics.in 6 | //Website:www.primerobotics.in 7 | /**************************************/ 8 | const int lowestPin = 2;//the lowest one attach to 9 | const int highestPin = 9;//the highest one attach to 10 | /**************************************/ 11 | void setup() 12 | { 13 | //set pins 2 through 9 as output 14 | for(int thisPin = lowestPin;thisPin <= highestPin;thisPin++) 15 | { 16 | pinMode(thisPin,OUTPUT); //initialize thisPin as an output 17 | } 18 | } 19 | /****************************************/ 20 | void loop() 21 | { 22 | //iterate over the pins 23 | //turn the led on from lowest to the highest 24 | for(int thisPin = lowestPin;thisPin <= highestPin;thisPin++) 25 | { 26 | digitalWrite(thisPin,HIGH);//turn this led on 27 | delay(100);//wait for 100 ms 28 | } 29 | //fade from the highest to the lowest 30 | for(int thisPin = highestPin;thisPin>=lowestPin;thisPin--) 31 | { 32 | digitalWrite(thisPin,LOW);//turn this led off 33 | delay(100);//wait for 100 ms 34 | } 35 | for(int thisPin = highestPin;thisPin>=lowestPin;thisPin--) 36 | { 37 | digitalWrite(thisPin,HIGH);//turn this led on 38 | delay(100);//wait for 100 ms 39 | } 40 | for(int thisPin = lowestPin;thisPin <= highestPin;thisPin++) 41 | { 42 | digitalWrite(thisPin,LOW);//turn this led off 43 | delay(100);//wait for 100 ms 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /servo/servo.ino: -------------------------------------------------------------------------------- 1 | /*********************************************** 2 | * name:Servo 3 | * function:you can see the servo motor rotate 90 degrees (rotate once every 15 degrees). 4 | * And then rotate in the opposite direction. 5 | ************************************************/ 6 | //Email: info@primerobotics.in 7 | //Website: www.primerobotics.in 8 | 9 | #include 10 | /************************************************/ 11 | Servo myservo;//create servo object to control a servo 12 | /************************************************/ 13 | void setup() 14 | { 15 | myservo.attach(9);//attachs the servo on pin 9 to servo object 16 | myservo.write(0);//back to 0 degrees 17 | delay(1000);//wait for a second 18 | } 19 | /*************************************************/ 20 | void loop() 21 | { 22 | myservo.write(15);//goes to 15 degrees 23 | delay(1000);//wait for a second 24 | myservo.write(30);//goes to 30 degrees 25 | delay(1000);//wait for a second.33 26 | myservo.write(45);//goes to 45 degrees 27 | delay(1000);//wait for a second.33 28 | myservo.write(60);//goes to 60 degrees 29 | delay(1000);//wait for a second.33 30 | myservo.write(75);//goes to 75 degrees 31 | delay(1000);//wait for a second.33 32 | myservo.write(90);//goes to 90 degrees 33 | delay(1000);//wait for a second 34 | myservo.write(75);//back to 75 degrees 35 | delay(1000);//wait for a second.33 36 | myservo.write(60);//back to 60 degrees 37 | delay(1000);//wait for a second.33 38 | myservo.write(45);//back to 45 degrees 39 | delay(1000);//wait for a second.33 40 | myservo.write(30);//back to 30 degrees 41 | delay(1000);//wait for a second.33 42 | myservo.write(15);//back to 15 degrees 43 | delay(1000);//wait for a second 44 | myservo.write(0);//back to 0 degrees 45 | delay(1000);//wait for a second 46 | } 47 | /**************************************************/ 48 | -------------------------------------------------------------------------------- /LCD1602/LCD1602.ino: -------------------------------------------------------------------------------- 1 | //LCD1602 2 | //You should now see your LCD1602 display the flowing characters "SUNFOUNDER" and "hello, world" 3 | //Email:info@primerobotics.in 4 | //Website:www.primerobotics.in 5 | //2015.5.7 6 | #include // include the library code 7 | /**********************************************************/ 8 | char array1[]=" SunFounder "; //the string to print on the LCD 9 | char array2[]="hello, world! "; //the string to print on the LCD 10 | int tim = 500; //the value of delay time 11 | // initialize the library with the numbers of the interface pins 12 | LiquidCrystal lcd(4, 6, 10, 11, 12, 13); 13 | /*********************************************************/ 14 | void setup() 15 | { 16 | lcd.begin(16, 2); // set up the LCD's number of columns and rows: 17 | } 18 | /*********************************************************/ 19 | void loop() 20 | { 21 | lcd.setCursor(15,0); // set the cursor to column 15, line 0 22 | for ( int positionCounter1 = 0; positionCounter1 < 26; positionCounter1++) 23 | { 24 | lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left. 25 | lcd.print(array1[positionCounter1]); // Print a message to the LCD. 26 | delay(tim); //wait for 250 ms 27 | } 28 | lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner. 29 | lcd.setCursor(15,1); // set the cursor to column 15, line 1 30 | for (int positionCounter2 = 0; positionCounter2 < 26; positionCounter2++) 31 | { 32 | lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left. 33 | lcd.print(array2[positionCounter2]); // Print a message to the LCD. 34 | delay(tim); //wait for 250 ms 35 | } 36 | lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner. 37 | } 38 | /************************************************************/ 39 | -------------------------------------------------------------------------------- /Blinking_LED/Blinking_LED.ino: -------------------------------------------------------------------------------- 1 | //RGB LED 2 | //The RGB LED will appear red, green, and blue first, then red, orange, yellow, green, blue, indigo, and purple. 3 | //Email:support@sunfounder.com 4 | //Website:www.sunfounder.com 5 | //2015.5.7 6 | /*************************************************************************/ 7 | const int redPin = 11; // R petal on RGB LED module connected to digital pin 11 8 | const int greenPin = 10; // G petal on RGB LED module connected to digital pin 10 9 | const int bluePin = 9; // B petal on RGB LED module connected to digital pin 9 10 | /**************************************************************************/ 11 | void setup() 12 | { 13 | pinMode(redPin, OUTPUT); // sets the redPin to be an output 14 | pinMode(greenPin, OUTPUT); // sets the greenPin to be an output 15 | pinMode(bluePin, OUTPUT); // sets the bluePin to be an output 16 | } 17 | /***************************************************************************/ 18 | void loop() // run over and over again 19 | { 20 | // Basic colors: 21 | color(255, 0, 0); // turn the RGB LED red 22 | delay(1000); // delay for 1 second 23 | color(0,255, 0); // turn the RGB LED green 24 | delay(1000); // delay for 1 second 25 | color(0, 0, 255); // turn the RGB LED blue 26 | delay(1000); // delay for 1 second 27 | // Example blended colors: 28 | color(255,0,252); // turn the RGB LED red 29 | delay(1000); // delay for 1 second 30 | color(237,109,0); // turn the RGB LED orange 31 | delay(1000); // delay for 1 second 32 | color(255,215,0); // turn the RGB LED yellow 33 | delay(1000); // delay for 1 second 34 | color(34,139,34); // turn the RGB LED green 35 | delay(1000); // delay for 1 second 36 | color(0,112,255); // turn the RGB LED blue 37 | delay(1000); // delay for 1 second 38 | color(0,46,90); // turn the RGB LED indigo 39 | delay(1000); // delay for 1 second 40 | color(128,0,128); // turn the RGB LED purple 41 | delay(1000); // delay for 1 second 42 | } 43 | /******************************************************/ 44 | void color (unsigned char red, unsigned char green, unsigned char blue)// the color generating function 45 | { 46 | analogWrite(redPin, red); 47 | analogWrite(greenPin, green); 48 | analogWrite(bluePin, blue); 49 | } 50 | -------------------------------------------------------------------------------- /RGB_LED/RGB_LED.ino: -------------------------------------------------------------------------------- 1 | //RGB LED 2 | //The RGB LED will appear red, green, and blue first, then red, orange, yellow, green, blue, indigo, and purple. 3 | //Email:info@primerobotics.in 4 | //Website:www.primerobotics.in 5 | //2015.5.7 6 | /*************************************************************************/ 7 | const int redPin = 11; // R petal on RGB LED module connected to digital pin 11 8 | const int greenPin = 10; // G petal on RGB LED module connected to digital pin 10 9 | const int bluePin = 9; // B petal on RGB LED module connected to digital pin 9 10 | /**************************************************************************/ 11 | void setup() 12 | { 13 | pinMode(redPin, OUTPUT); // sets the redPin to be an output 14 | pinMode(greenPin, OUTPUT); // sets the greenPin to be an output 15 | pinMode(bluePin, OUTPUT); // sets the bluePin to be an output 16 | } 17 | /***************************************************************************/ 18 | void loop() // run over and over again 19 | { 20 | // Basic colors: 21 | color(255, 0, 0); // turn the RGB LED red 22 | delay(1000); // delay for 1 second 23 | color(0,255, 0); // turn the RGB LED green 24 | delay(1000); // delay for 1 second 25 | color(0, 0, 255); // turn the RGB LED blue 26 | delay(1000); // delay for 1 second 27 | // Example blended colors: 28 | color(255,0,252); // turn the RGB LED red 29 | delay(1000); // delay for 1 second 30 | color(237,109,0); // turn the RGB LED orange 31 | delay(1000); // delay for 1 second 32 | color(255,215,0); // turn the RGB LED yellow 33 | delay(1000); // delay for 1 second 34 | color(34,139,34); // turn the RGB LED green 35 | delay(1000); // delay for 1 second 36 | color(0,112,255); // turn the RGB LED blue 37 | delay(1000); // delay for 1 second 38 | color(0,46,90); // turn the RGB LED indigo 39 | delay(1000); // delay for 1 second 40 | color(128,0,128); // turn the RGB LED purple 41 | delay(1000); // delay for 1 second 42 | } 43 | /******************************************************/ 44 | void color (unsigned char red, unsigned char green, unsigned char blue)// the color generating function 45 | { 46 | analogWrite(redPin, red); 47 | analogWrite(greenPin, green); 48 | analogWrite(bluePin, blue); 49 | } 50 | /******************************************************/ 51 | 52 | 53 | -------------------------------------------------------------------------------- /Humiture_Sensor/code/library/Dht/examples/dht_test/dht_test.ino: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: dht_test.ino 3 | // AUTHOR: Rob Tillaart 4 | // VERSION: 0.1.07 5 | // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino 6 | // URL: http://arduino.cc/playground/Main/DHTLib 7 | // 8 | // Released to the public domain 9 | // 10 | 11 | #include 12 | 13 | dht DHT; 14 | 15 | #define DHT11_PIN 4 16 | #define DHT21_PIN 5 17 | #define DHT22_PIN 6 18 | 19 | void setup() 20 | { 21 | Serial.begin(115200); 22 | Serial.println("DHT TEST PROGRAM "); 23 | Serial.print("LIBRARY VERSION: "); 24 | Serial.println(DHT_LIB_VERSION); 25 | Serial.println(); 26 | Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)"); 27 | } 28 | 29 | void loop() 30 | { 31 | // READ DATA 32 | Serial.print("DHT22, \t"); 33 | int chk = DHT.read22(DHT22_PIN); 34 | switch (chk) 35 | { 36 | case DHTLIB_OK: 37 | Serial.print("OK,\t"); 38 | break; 39 | case DHTLIB_ERROR_CHECKSUM: 40 | Serial.print("Checksum error,\t"); 41 | break; 42 | case DHTLIB_ERROR_TIMEOUT: 43 | Serial.print("Time out error,\t"); 44 | break; 45 | default: 46 | Serial.print("Unknown error,\t"); 47 | break; 48 | } 49 | // DISPLAY DATA 50 | Serial.print(DHT.humidity, 1); 51 | Serial.print(",\t"); 52 | Serial.println(DHT.temperature, 1); 53 | 54 | delay(1000); 55 | 56 | 57 | // READ DATA 58 | Serial.print("DHT21, \t"); 59 | chk = DHT.read21(DHT21_PIN); 60 | switch (chk) 61 | { 62 | case DHTLIB_OK: 63 | Serial.print("OK,\t"); 64 | break; 65 | case DHTLIB_ERROR_CHECKSUM: 66 | Serial.print("Checksum error,\t"); 67 | break; 68 | case DHTLIB_ERROR_TIMEOUT: 69 | Serial.print("Time out error,\t"); 70 | break; 71 | default: 72 | Serial.print("Unknown error,\t"); 73 | break; 74 | } 75 | // DISPLAY DATA 76 | Serial.print(DHT.humidity, 1); 77 | Serial.print(",\t"); 78 | Serial.println(DHT.temperature, 1); 79 | 80 | delay(1000); 81 | 82 | // READ DATA 83 | Serial.print("DHT11, \t"); 84 | chk = DHT.read11(DHT11_PIN); 85 | switch (chk) 86 | { 87 | case DHTLIB_OK: 88 | Serial.print("OK,\t"); 89 | break; 90 | case DHTLIB_ERROR_CHECKSUM: 91 | Serial.print("Checksum error,\t"); 92 | break; 93 | case DHTLIB_ERROR_TIMEOUT: 94 | Serial.print("Time out error,\t"); 95 | break; 96 | default: 97 | Serial.print("Unknown error,\t"); 98 | break; 99 | } 100 | // DISPLAY DATA 101 | Serial.print(DHT.humidity,1); 102 | Serial.print(",\t"); 103 | Serial.println(DHT.temperature,1); 104 | 105 | delay(1000); 106 | } 107 | // 108 | // END OF FILE 109 | // -------------------------------------------------------------------------------- /Humiture_Sensor/code/library/Dht/dht.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: dht.cpp 3 | // AUTHOR: Rob Tillaart 4 | // VERSION: 0.1.08 5 | // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino 6 | // URL: http://arduino.cc/playground/Main/DHTLib 7 | // 8 | // HISTORY: 9 | // 0.1.09 optimize size: timeout check + use of mask 10 | // 0.1.08 added formula for timeout based upon clockspeed 11 | // 0.1.07 added support for DHT21 12 | // 0.1.06 minimize footprint (2012-12-27) 13 | // 0.1.05 fixed negative temperature bug (thanks to Roseman) 14 | // 0.1.04 improved readability of code using DHTLIB_OK in code 15 | // 0.1.03 added error values for temp and humidity when read failed 16 | // 0.1.02 added error codes 17 | // 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011) 18 | // 0.1.0 by Rob Tillaart (01/04/2011) 19 | // 20 | // inspired by DHT11 library 21 | // 22 | // Released to the public domain 23 | // 24 | 25 | #include "dht.h" 26 | 27 | // #define TIMEOUT 10000 28 | // uint16_t for UNO, higher CPU speeds => exceed MAXINT. 29 | // works for DUE 30 | // 16 MHz => 10000 31 | // 84 MHz => 52500 32 | // 100MHz => 62500 33 | #define TIMEOUT (F_CPU/1600) 34 | 35 | 36 | ///////////////////////////////////////////////////// 37 | // 38 | // PUBLIC 39 | // 40 | 41 | // return values: 42 | // DHTLIB_OK 43 | // DHTLIB_ERROR_CHECKSUM 44 | // DHTLIB_ERROR_TIMEOUT 45 | int dht::read11(uint8_t pin) 46 | { 47 | // READ VALUES 48 | int rv = read(pin); 49 | if (rv != DHTLIB_OK) 50 | { 51 | humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered? 52 | temperature = DHTLIB_INVALID_VALUE; // invalid value 53 | return rv; 54 | } 55 | 56 | // CONVERT AND STORE 57 | humidity = bits[0]; // bits[1] == 0; 58 | temperature = bits[2]; // bits[3] == 0; 59 | 60 | // TEST CHECKSUM 61 | // bits[1] && bits[3] both 0 62 | uint8_t sum = bits[0] + bits[2]; 63 | if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM; 64 | 65 | return DHTLIB_OK; 66 | } 67 | 68 | // return values: 69 | // DHTLIB_OK 70 | // DHTLIB_ERROR_CHECKSUM 71 | // DHTLIB_ERROR_TIMEOUT 72 | int dht::read21(uint8_t pin) 73 | { 74 | return read22(pin); // dataformat identical to DHT22 75 | } 76 | 77 | // return values: 78 | // DHTLIB_OK 79 | // DHTLIB_ERROR_CHECKSUM 80 | // DHTLIB_ERROR_TIMEOUT 81 | int dht::read22(uint8_t pin) 82 | { 83 | // READ VALUES 84 | int rv = read(pin); 85 | if (rv != DHTLIB_OK) 86 | { 87 | humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered? 88 | temperature = DHTLIB_INVALID_VALUE; // invalid value 89 | return rv; // propagate error value 90 | } 91 | 92 | // CONVERT AND STORE 93 | humidity = word(bits[0], bits[1]) * 0.1; 94 | 95 | if (bits[2] & 0x80) // negative temperature 96 | { 97 | temperature = -0.1 * word(bits[2] & 0x7F, bits[3]); 98 | } 99 | else 100 | { 101 | temperature = 0.1 * word(bits[2], bits[3]); 102 | } 103 | 104 | // TEST CHECKSUM 105 | uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3]; 106 | if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM; 107 | 108 | return DHTLIB_OK; 109 | } 110 | 111 | ///////////////////////////////////////////////////// 112 | // 113 | // PRIVATE 114 | // 115 | 116 | // return values: 117 | // DHTLIB_OK 118 | // DHTLIB_ERROR_TIMEOUT 119 | int dht::read(uint8_t pin) 120 | { 121 | // INIT BUFFERVAR TO RECEIVE DATA 122 | uint8_t mask = 128; 123 | uint8_t idx = 0; 124 | 125 | // EMPTY BUFFER 126 | for (uint8_t i=0; i< 5; i++) bits[i] = 0; 127 | 128 | // REQUEST SAMPLE 129 | pinMode(pin, OUTPUT); 130 | digitalWrite(pin, LOW); 131 | delay(20); 132 | digitalWrite(pin, HIGH); 133 | delayMicroseconds(40); 134 | pinMode(pin, INPUT); 135 | 136 | // GET ACKNOWLEDGE or TIMEOUT 137 | unsigned int loopCnt = TIMEOUT; 138 | while(digitalRead(pin) == LOW) 139 | if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT; 140 | 141 | loopCnt = TIMEOUT; 142 | while(digitalRead(pin) == HIGH) 143 | if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT; 144 | 145 | // READ THE OUTPUT - 40 BITS => 5 BYTES 146 | for (uint8_t i=0; i<40; i++) 147 | { 148 | loopCnt = TIMEOUT; 149 | while(digitalRead(pin) == LOW) 150 | if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT; 151 | 152 | unsigned long t = micros(); 153 | 154 | loopCnt = TIMEOUT; 155 | while(digitalRead(pin) == HIGH) 156 | if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT; 157 | 158 | if ((micros() - t) > 40) bits[idx] |= mask; 159 | mask >>= 1; 160 | if (mask == 0) // next byte? 161 | { 162 | mask = 128; 163 | idx++; 164 | } 165 | } 166 | 167 | return DHTLIB_OK; 168 | } 169 | // 170 | // END OF FILE 171 | // --------------------------------------------------------------------------------