From b41eb69e25f9586ab41f8175ccaaff8fdde4e9a4 Mon Sep 17 00:00:00 2001 From: Clemens Fries Date: Thu, 23 Feb 2017 23:04:29 +0100 Subject: Humidity indicator LED project --- README.adoc | 22 ++++++++-- humidity-led-indicator/humidity-led-indicator.ino | 51 +++++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 humidity-led-indicator/humidity-led-indicator.ino diff --git a/README.adoc b/README.adoc index 15cfd55..698e25a 100644 --- a/README.adoc +++ b/README.adoc @@ -4,7 +4,23 @@ Every now and then I create a small Arduino (test) project. I think I should publish the stuff here — this is mostly cargo cult code that has been hammered into some semi-working form. -Currently in this repository: +=== lighting/strobe.ino -lighting/strobe.ino:: - The code behind my https://xenoworld.de/2017/01/18/blink.html[fluorescent light demo]. +The code behind my https://xenoworld.de/2017/01/18/blink.html[fluorescent light demo]. + +=== humidity-led-indicator/ + +Code for a small project which uses a humidity sensor (DHT22) and an +APA102-RGB-LED to indicate if the current humidity is in an acceptable range. +*red* means it is too dry, *blue* means it is too humid, everything else is +something between yellow-orange and green. + +It would also switch off the LED if it was too dark in the room, so it would +not annoy me at night. + +At some point I will polish that code and move the whole thing from breadboard +to a more fixed setup. All components are here, but I haven't gotten around to +doing it yet. I'm targeting some ATTiny, though. + +The original file name was `sketch_humidity_cargo_cult.ino`, so take that into +account… diff --git a/humidity-led-indicator/humidity-led-indicator.ino b/humidity-led-indicator/humidity-led-indicator.ino new file mode 100644 index 0000000..9ecf34c --- /dev/null +++ b/humidity-led-indicator/humidity-led-indicator.ino @@ -0,0 +1,51 @@ +#include +#include +#include + +#define DHTPIN 2 // what digital pin we're connected to +#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 +DHT dht(DHTPIN, DHTTYPE); + +const int analogInPin = A0; // Analog input pin that the LDR is attached to + +#define NUM_LEDS 1 +#define DATA_PIN 11 +#define CLOCK_PIN 12 + +CRGB leds[NUM_LEDS]; + +CHSV temp; + +byte counter; + +void setup() +{ + FastLED.addLeds(leds, NUM_LEDS ); +} + +void loop() +{ + delay(2000); + + int ldrValue = analogRead(analogInPin); + int humidity = dht.readHumidity(); + + if (ldrValue > 1012) { + temp.val = 0; + } else { + temp.val = 255; + } + + if( humidity < 35 ) { + temp.hue = HUE_RED; + } else if(humidity > 60) { + temp.hue = HUE_BLUE; + } else { + temp.hue = map(humidity, 35, 60, HUE_RED, HUE_AQUA); + } + + temp.s = 255; + leds[0] = temp; + FastLED.show(); +} + -- cgit