Advertisement
Guest User

arduino code

a guest
Apr 21st, 2016
131
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None
  1. #include <Adafruit_NeoPixel.h>
  2. #include <DHT.h>
  3.  
  4. //change these according to where you connected the sensor and LEDs to
  5. #define DHTPIN 11     // pin of the temperature and humidity sensor
  6. #define LEDPIN 10     // pin of the LEDs
  7. #define LEDAMOUNT 74  // amount of LEDs i used
  8.  
  9.  
  10. #define DHTTYPE DHT22   // DHT 22  (AM2302) type of sensor im using
  11. DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
  12.  
  13. //Variables
  14. int chk;
  15. float hum;  //Stores humidity value
  16. float temp; //Stores temperature value
  17. int sensorPower = 12;
  18.  
  19. Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDAMOUNT, LEDPIN, NEO_GRB + NEO_KHZ800);
  20.  
  21. void setup(){
  22.   Serial.begin(9600);
  23.   dht.begin();//begin the temperature and humidity sensor
  24.   digitalWrite(sensorPower, HIGH);
  25.   strip.begin(); //begin with the LEDs
  26.   strip.show(); // Initialize all pixels to 'off'
  27.  
  28. }
  29.  
  30. void loop() {
  31.     //read the temperature and humidity from the sensor
  32.     hum = dht.readHumidity();
  33.     temp= dht.readTemperature();
  34.  
  35.     //recalculate the values to show neatly as colors
  36.     int heat= (int)((temp-15)*10);
  37.     int wet = (int)((hum-30)*4);
  38.    
  39.     //Print temp and humidity values to serial monitor
  40.     Serial.print("Humidity: ");
  41.     Serial.print(hum);
  42.     Serial.print(" %, Temp: ");
  43.     Serial.print(temp);
  44.     Serial.println(" Celsius");
  45.  
  46.     //set the color for each individual light in this "for" loop
  47.     for(int i = 0; i < 74; i++){
  48.         strip.setPixelColor(i, heat, wet, 255-heat);
  49.     }
  50.    
  51.     delay(5000); //delay 5 seconds
  52.     strip.show(); //send the LED color to the arduino
  53. }
Advertisement
RAW Paste Data Copied
Advertisement