/*Write a program to emit lights from a Neopixel strip based on the condition using a Humidity and Temperature (DHT) sensor.
Logic-:
If the humidity and temperature value is below 45, all lights in NeoPixel canvas (strip) will emit green : indicating that the greenhouse’s plants are safe.
If the humidity and temperature value is above 45, all lights in NeoPixel canvas (strip) will emit red : indicating that the greenhouse’s plants are unsafe.*/
//IMP- ADD "attrs": { "rows": "1", "cols": "16", "matrixBrightness": "10" } AND Type in diagram.json
#include <DHT.h>. //library
int dht_pin = 2;
#include <Adafruit_NeoPixel.h>
int neo_pin = 9; //to get the input from the Arduino
int no_of_leds = 16;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(no_of_leds, neo_pin);//strip is variable
DHT dht(dht_pin, DHT22); //dht functions from the DHT library
void setup()
{
Serial.begin(9600);//sends signal between 2 components
Serial.println(" Humidity and Temperature Test!");
dht.begin(); //starts sensor functionality
strip.begin();
}
void loop() {
float humidity = dht.readHumidity(); //will hold the humidity value of the DHT sensor
float temperature = dht.readTemperature();
if (humidity<45 && temperature<45)
{
Set_color(strip.Color(0, 255, 0)); //green
delay(500);
}
else
{
Set_color(strip.Color(255, 0, 0)); //red
delay(500);
}
Serial.print(" Humidity: ");
Serial.print(humidity);
Serial.print("% Temperature in °C: ");
Serial.println(temperature);
}
//Define function; uint32_t is data_type
int Set_color(uint32_t col)
{
for(int i=0; i<no_of_leds; i++ )
{
strip.setPixelColor(i , col); //draw or set color to next LED
strip.show(); //show led color
delay(500);
}
}
//OUTPUT- click on DHT sensor and change temp and humidity to see changes in strip colors