Skip to content

Commit 994d715

Browse files
committed
UV sensor example added
1 parent ec53d08 commit 994d715

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Vera Arduino UVM-30A
3+
4+
connect the sensor as follows :
5+
6+
+ >>> 5V
7+
- >>> GND
8+
out >>> A0
9+
10+
Contribution: epierre, bulldoglowell
11+
Cobverted to 1.4 by Henrik Ekblad
12+
13+
License: Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
14+
15+
*/
16+
17+
#include <MySensor.h>
18+
#include <SPI.h>
19+
20+
#define CHILD_ID_UV 0
21+
#define UV_SENSOR_ANALOG_PIN 0
22+
unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds)
23+
24+
MySensor gw;
25+
MyMessage uvMsg(CHILD_ID_UV, V_UV);
26+
int lastUV = -1;
27+
int uvIndexValue [13] = { 50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170, 3000};
28+
int uvIndex;
29+
30+
void setup()
31+
{
32+
gw.begin();
33+
34+
// Send the sketch version information to the gateway and Controller
35+
gw.sendSketchInfo("UV Sensor", "1.1");
36+
37+
// Register all sensors to gateway (they will be created as child devices)
38+
gw.present(CHILD_ID_UV, S_UV);
39+
40+
}
41+
42+
void loop()
43+
{
44+
uint16_t uv = analogRead(0);// Get UV value
45+
Serial.print("Uv reading: ");
46+
Serial.println(uv);
47+
for (int i = 0; i < 13; i++)
48+
{
49+
if (uv <= uvIndexValue[i])
50+
{
51+
uvIndex = i;
52+
break;
53+
}
54+
}
55+
Serial.print("Uv index: ");
56+
Serial.println(uvIndex);
57+
58+
if (uvIndex != lastUV) {
59+
gw.send(uvMsg.set(uvIndex));
60+
lastUV = uvIndex;
61+
}
62+
63+
gw.sleep(SLEEP_TIME);
64+
}

0 commit comments

Comments
 (0)