Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #include <DHT.h>
- //change these according to where you connected the sensor and LEDs to
- #define DHTPIN 11 // pin of the temperature and humidity sensor
- #define LEDPIN 10 // pin of the LEDs
- #define LEDAMOUNT 74 // amount of LEDs i used
- #define DHTTYPE DHT22 // DHT 22 (AM2302) type of sensor im using
- DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
- //Variables
- int chk;
- float hum; //Stores humidity value
- float temp; //Stores temperature value
- int sensorPower = 12;
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDAMOUNT, LEDPIN, NEO_GRB + NEO_KHZ800);
- void setup(){
- Serial.begin(9600);
- dht.begin();//begin the temperature and humidity sensor
- digitalWrite(sensorPower, HIGH);
- strip.begin(); //begin with the LEDs
- strip.show(); // Initialize all pixels to 'off'
- }
- void loop() {
- //read the temperature and humidity from the sensor
- hum = dht.readHumidity();
- temp= dht.readTemperature();
- //recalculate the values to show neatly as colors
- int heat= (int)((temp-15)*10);
- int wet = (int)((hum-30)*4);
- //Print temp and humidity values to serial monitor
- Serial.print("Humidity: ");
- Serial.print(hum);
- Serial.print(" %, Temp: ");
- Serial.print(temp);
- Serial.println(" Celsius");
- //set the color for each individual light in this "for" loop
- for(int i = 0; i < 74; i++){
- strip.setPixelColor(i, heat, wet, 255-heat);
- }
- delay(5000); //delay 5 seconds
- strip.show(); //send the LED color to the arduino
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement