Skip to content

Commit e6b3769

Browse files
committed
add guva uv sensor
1 parent e84f05c commit e6b3769

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.words": [
3+
"guva"
4+
]
5+
}

platformio.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@ board = uno
1414
framework = arduino
1515
lib_extra_dirs = ~/Documents/Arduino/libraries
1616
monitor_speed = 9600
17-
lib_deps =
18-
adafruit/Adafruit Unified Sensor@^1.1.4
19-
adafruit/Adafruit SI1145 Library@^1.1.1
17+
lib_deps = adafruit/Adafruit Unified Sensor@^1.1.4

src/main.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson (use v6.xx)
1111
#include <LiquidCrystal.h>
1212
#include <SoftwareSerial.h>
13-
#include "Adafruit_SI1145.h"
1413

1514
#define DEBUG true
1615

1716
#define DHT_PIN 4 // pin connected to data pin of DHT11
1817
#define DHT_TYPE DHT11 // Type of the DHT Sensor, DHT11/DHT22
18+
int uvAnalogIn = A0;
1919

2020
// initialize the library with the numbers of the interface pins
2121
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
2222

2323
DHT temperatureSensor(DHT_PIN, DHT_TYPE);
24-
Adafruit_SI1145 uvSensor = Adafruit_SI1145();
2524

2625
// ESP TX => Uno Pin 2
2726
// ESP RX => Uno Pin 3
@@ -87,6 +86,9 @@ String sendDataToWiFiBoard(String command, const int timeout, boolean debug)
8786
}
8887

8988
void setup() {
89+
// read from GUVA-S12SD
90+
pinMode(uvAnalogIn, INPUT);
91+
9092
Serial.begin(9600);
9193
wifi.begin(9600);
9294

@@ -130,15 +132,11 @@ void loop() {
130132
// read from DHT11
131133
temperatureSensor.begin();
132134

133-
if (!uvSensor.begin()) {
134-
Serial.println("Didn't find Si1145");
135-
}
136-
137135
float temperature = temperatureSensor.readTemperature(); // return temperature in °C
138136
float humidity = temperatureSensor.readHumidity(); // return humidity in %
139137
// Compute heat index in Celsius (isFahrenheit = false)
140138
float heatIndex = temperatureSensor.computeHeatIndex(temperature, humidity, false);
141-
float uvIndex = uvSensor.readUV(); // the index is multiplied by 100 so to get the
139+
float uvIndex = analogRead(uvAnalogIn);
142140

143141
// integer index, divide by 100!
144142
uvIndex /= 100.0;
@@ -149,17 +147,17 @@ void loop() {
149147
} else {
150148
// display Humidity on the LCD screen
151149
lcd.setCursor(0, 0);
152-
lcd.print("Humidity (%): ");
153-
lcd.print(String(humidity));
150+
lcd.print("Humidity:");
151+
lcd.print(String(humidity) + "%");
154152

155153
// display Temperature on the LCD screen
156154
lcd.setCursor(0, 1);
157-
lcd.print("Temp (C): ");
158-
lcd.print(String(temperature));
155+
lcd.print("Temp:");
156+
lcd.print(String(temperature) + "C");
159157

160158
// display UVIndex on the LCD screen
161-
lcd.setCursor(0, 2);
162-
lcd.print("UV: ");
159+
// lcd.setCursor(0, 2);
160+
lcd.print(" - UV:");
163161
lcd.print(String(uvIndex));
164162

165163
String preparedData = prepareDataForWiFi(humidity, temperature, heatIndex, uvIndex);

0 commit comments

Comments
 (0)