Devices & Components
Arduino Nano
DHT11 Temperature & Humidity Sensor (4 pins)
Adafruit NeoPixel Digital RGB LED Strip - Black 60 LED - BLACK PRODUCT ID: 1461
Software & Tools
Arduino IDE
Project description
Code
Arduino Sketch
c
1#include <Adafruit_NeoPixel.h> 2#include <Adafruit_Sensor.h> 3#include <DHT.h> 4#include <DHT_U.h> 5#define DHTTYPE DHT11 // DHT 11 6#define DHTPIN 3 7DHT_Unified dht(DHTPIN, DHTTYPE); 8#define PIN 2 // Neo 9Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800); 10void setup() { 11 Serial.begin(115200); 12 dht.begin(); 13 sensor_t sensor; 14 strip.begin(); 15 strip.setBrightness(100); 16 strip.show(); 17} 18void loop() { 19 sensors_event_t event; 20 dht.temperature().getEvent(&event); 21 Serial.print(F("Temperature: ")); 22 float temp1 = event.temperature; 23 Serial.print(temp1); 24 Serial.println(F("°C")); 25 26 dht.humidity().getEvent(&event); 27 Serial.print(F("Humidity: ")); 28 float hum1 = event.relative_humidity; 29 Serial.print(hum1); 30 Serial.println(F("%")); 31 if (temp1 >= 28 && temp1 < 31) { 32 strip.clear(); // Set all pixel colors to 'off' 33 for (int i = 0; i < 12; i++) { // For each pixel... 34 strip.setPixelColor(i, strip.Color(0, 150, 0)); 35 strip.show(); 36 } 37 } 38 else if (temp1 < 28) { 39 strip.clear(); 40 for (int i = 0; i < 12; i++) { // For each pixel... 41 strip.setPixelColor(i, strip.Color(0, 0, 150)); 42 strip.show(); 43 } 44 } 45 else { 46 strip.clear(); 47 for (int i = 0; i < 12; i++) { // For each pixel... 48 strip.setPixelColor(i, strip.Color(150, 0, 0)); 49 strip.show(); 50 } 51 } 52}
Comments
Only logged in users can leave comments