From 994d715b4e575a8ae2d8778c70915629fa765146 Mon Sep 17 00:00:00 2001 From: Henrik Ekblad Date: Sun, 17 Aug 2014 14:45:38 +0200 Subject: [PATCH] UV sensor example added --- .../MySensors/examples/UVSensor/UVSensor.ino | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 libraries/MySensors/examples/UVSensor/UVSensor.ino diff --git a/libraries/MySensors/examples/UVSensor/UVSensor.ino b/libraries/MySensors/examples/UVSensor/UVSensor.ino new file mode 100644 index 0000000..52358ad --- /dev/null +++ b/libraries/MySensors/examples/UVSensor/UVSensor.ino @@ -0,0 +1,64 @@ +/* + Vera Arduino UVM-30A + + connect the sensor as follows : + + + >>> 5V + - >>> GND + out >>> A0 + + Contribution: epierre, bulldoglowell + Cobverted to 1.4 by Henrik Ekblad + + License: Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) + +*/ + +#include +#include + +#define CHILD_ID_UV 0 +#define UV_SENSOR_ANALOG_PIN 0 +unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) + +MySensor gw; +MyMessage uvMsg(CHILD_ID_UV, V_UV); +int lastUV = -1; +int uvIndexValue [13] = { 50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170, 3000}; +int uvIndex; + +void setup() +{ + gw.begin(); + + // Send the sketch version information to the gateway and Controller + gw.sendSketchInfo("UV Sensor", "1.1"); + + // Register all sensors to gateway (they will be created as child devices) + gw.present(CHILD_ID_UV, S_UV); + +} + +void loop() +{ + uint16_t uv = analogRead(0);// Get UV value + Serial.print("Uv reading: "); + Serial.println(uv); + for (int i = 0; i < 13; i++) + { + if (uv <= uvIndexValue[i]) + { + uvIndex = i; + break; + } + } + Serial.print("Uv index: "); + Serial.println(uvIndex); + + if (uvIndex != lastUV) { + gw.send(uvMsg.set(uvIndex)); + lastUV = uvIndex; + } + + gw.sleep(SLEEP_TIME); +}