.
Before getting started make sure doyou have
1 Agrumino Kit
1 Micro usb cable for upload sketch with Arduino Ide
1 Adafruit VEML6075 (or similar)
1 Cable 4 pin Male Jumper to Grove 4 pin
1 Breadboard (only for test)
Setup Page https://bit.ly/3qgYQ43
Optional:
1 Battery 3.7 V with JST 2.0 connector (1200mAh or higher)
To carry the device with you and have a long autonomy.
Step 1: Description and ConnectionVery useful to protectyourskinfrom the sun's rays.
In the first you need to connect Agrumino Lemon like a Fritzing example
This will allow us to acquire the following data with high precision:
- Uva
- Uvb
- UV Index
Without Lifely Agrumino UvMeter
With Lifely Agrumino Uv Meter
Let's go to create free account on the site https://www.cloudmqtt.com/ or another broker Mqtt of your choice.
Now that we have created an account, need to create NEW instance
after let's take note of the data provided by the broker:
- MqttUser
- MqttPassword
- Mqtt Server Name
- Mqtt port
Now import sketch from github link, change parameters on ////MQTT SETUP//// section with your personal WiFi data and personal Mqtt Instance.
Now upload the sketch on Lifely Agrumino Lemon with Arduino IDE.
Topic inside a sketch are already defined, but they can be modify.
/*Agrumino_pocket_UvMeter.ino - Sample project for Agrumino Lemon.
Created by gabriele.foddis@lifely.cc - Stay tuned on lifely.cc -
This sketch read and send all data with MQTT on your smartphone.
Have fun !!!*/
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Agrumino.h>
#include <Wire.h>
#include "Adafruit_VEML6075.h"
#define SERIAL_BAUD 115200
#define DELAY 1000 ///ms Time
#define WAITING_TIME 3000 ///ms Time to have valid data
#define SLEEP_TIME_SEC 1800 ///(s Time)for Agrumino Sleep (max 3600ms)
#define CLIENT ///your mqtt client
Adafruit_VEML6075 uv = Adafruit_VEML6075();
Agrumino agrumino;
////////MQTT SETUP///////
const char* ssid = ""; ///Your ssid
const char* password = ""; ///Your WiFi Password
const char* mqttServer = "m24.cloudmqtt.com"; ///Your Mqtt Server
const int mqttPort = ; ///Mqtt Port
const char* mqttUser = ""; ///Mqtt User
const char* mqttPassword = ""; ///Mqtt password
#define TOPIC_INDEX "/Agrumino/UVMeter/UVindex" ///setup topic for mqtt message "Index UV"
#define TOPIC_INDEX_VALUE "/Agrumino/UVMeter/UVvalue" ///setup topic for mqtt message "Index UV"
#define TOPIC_WARNING "/Agrumino/UVMeter/Warning" ///setup topic for mqtt message "Warning message"
#define TOPIC_BATTERY_L "/Agrumino/UVMeter/Battery" ///setup topic for mqtt message "Battery Voltage"
WiFiClient CLIENT;
PubSubClient client(CLIENT);
/////////////////
void setup() {
agrumino.setup();
agrumino.turnBoardOn();
Serial.begin(SERIAL_BAUD);
if (! uv.begin()) {
Serial.println("Check wiring on sensor UV");
}
Serial.println("VEML6075 sensor ok");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(200);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
client.setServer(mqttServer, mqttPort);
//client.setCallback(callback);
while (!client.connected()) {
Serial.println("Connecting to MQTT...");
if (client.connect("ESP8266Client", mqttUser, mqttPassword )) {
Serial.println("connected");
blinkLedConectionOk();
delay(500);
} else {
Serial.print("Failed with state ");
Serial.print(client.state());
delay(500);
}
}
uv.setIntegrationTime(VEML6075_200MS); ////Integration time for Lifely Agrumino Lemon is 200ms
Serial.print("Integration time set to ");
switch (uv.getIntegrationTime()) {
case VEML6075_50MS: Serial.print("50"); break;
case VEML6075_100MS: Serial.print("100"); break;
case VEML6075_200MS: Serial.print("200"); break;
case VEML6075_400MS: Serial.print("400"); break;
case VEML6075_800MS: Serial.print("800"); break;
}
Serial.println("ms");
// Set the high dynamic mode
uv.setHighDynamic(false);
// Get the mode
if (uv.getHighDynamic()) {
Serial.println("High dynamic reading mode");
} else {
Serial.println("Normal dynamic reading mode");
}
uv.setForcedMode(false);
if (uv.getForcedMode()) {
Serial.println("Forced reading mode");
} else {
Serial.println("Continuous reading mode");
}
// Set the calibration coefficients
uv.setCoefficients(2.22, 1.33, // UVA_A and UVA_B coefficients
2.95, 1.74, // UVB_C and UVB_D coefficients
0.001461, 0.002591); // UVA and UVB responses
}
void readDataFromAgrumino() {
boolean isAttachedToUSB = agrumino.isAttachedToUSB();
boolean isBatteryCharging = agrumino.isBatteryCharging();
boolean isButtonPressed = agrumino.isButtonPressed();
float temperature = agrumino.readTempC();
unsigned int soilMoisture = agrumino.readSoil();
float illuminance = agrumino.readLux();
float batteryVoltage = agrumino.readBatteryVoltage();
unsigned int batteryLevel = agrumino.readBatteryLevel();
Serial.println("Data from Agrumino Sensors");
Serial.println("isAttachedToUSB: " + String(isAttachedToUSB));
Serial.println("isBatteryCharging: " + String(isBatteryCharging));
Serial.println("isButtonPressed: " + String(isButtonPressed));
Serial.println("temperature: " + String(temperature) + "°C");
Serial.println("soilMoisture: " + String(soilMoisture) + "%");
Serial.println("illuminance : " + String(illuminance) + " lux");
Serial.println("batteryVoltage : " + String(batteryVoltage) + " V");
Serial.println("batteryLevel : " + String(batteryLevel) + "%");
Serial.println("End");
Serial.println("#########################\n");
}
void printDataFromVeml6075() {
Serial.println("Data from Uv Sensor");
Serial.print("Raw UVA reading: "); Serial.println(uv.readUVA());
Serial.print("Raw UVB reading: "); Serial.println(uv.readUVB());
Serial.print("UV Index reading: "); Serial.println(uv.readUVI());
Serial.println("end data");
Serial.println("");
int uvindex = uv.readUVI();
client.publish(TOPIC_INDEX_VALUE, (String(uv.readUVI()) + String("")).c_str());
client.publish(TOPIC_BATTERY_L, (String(agrumino.readBatteryLevel()) + String("")).c_str());
Serial.println("Warning Message");
if (uvindex < 1.99) {
client.publish(TOPIC_INDEX, "Low Level");
client.publish(TOPIC_WARNING, "Low level, wear sunglasses and hat");
Serial.println("Low level, wear sunglasses and hat");
blinkLedMessageOk();
delay(DELAY);
}
else if (uvindex > 2.99 || uvindex < 4.99) {
client.publish(TOPIC_INDEX, "Medium/Low level");
client.publish(TOPIC_WARNING, "Medium/Low level, wear sunglasses, hat and SFP 15+");
Serial.println("Medium/Low level, wear sunglasses, hat and SFP 15+");
blinkLedMessageOk();
delay(DELAY);
}
else if (uvindex > 5 || uvindex < 6.99) {
client.publish(TOPIC_INDEX, "High level");
client.publish(TOPIC_WARNING, "High level, wear sunglasses, hat and SFP 30+");
Serial.println("High level, wear sunglasses, hat and SFP 30+");
blinkLedMessageOk();
delay(DELAY);
}
else if (uvindex > 7 || uvindex < 11) {
client.publish(TOPIC_INDEX, "Very high level");
client.publish(TOPIC_WARNING, "Very high level, wear sunglasses, hat, sunscreen SFP 30 +, possibly avoid the sun");
Serial.println("Very high level, wear sunglasses, hat, sunscreen SFP 30 +, possibly avoid the sun");
blinkLedMessageOk();
delay(DELAY);
}
else if (uvindex > 11) {
client.publish(TOPIC_INDEX, "Extreme level");
client.publish(TOPIC_WARNING, "Extreme level,very dangerous, take all possible precautions, it would be better to stay inside");
Serial.println("Extreme level,very dangerous, take all possible precautions, it would be better to stay inside");
blinkLedMessageOk();
delay(DELAY);
Serial.println("");
}
}
void loop() {
delay(WAITING_TIME);
client.loop();
// readDataFromAgrumino(); ///uncomment for print data into a serial monitor
printDataFromVeml6075();
// delaySec(SLEEP_TIME_SEC); // The ESP8266 stays powered, executes the loop repeatedly
deepSleepSec(SLEEP_TIME_SEC); // ESP8266 enter in deepSleep and after the selected time starts back from setup() and then loop()
Serial.print("Bye Bye.... I'm sleep");
delay(DELAY);
agrumino.turnBoardOff();
}
void delaySec(int sec) {
delay (sec * 1000);
}
void deepSleepSec(int sec) {
ESP.deepSleep(sec * 1000000); // microseconds
}
void blinkLedConectionOk() {
agrumino.turnLedOn();
delay(100);
agrumino.turnLedOff();
delay(100);
agrumino.turnLedOn();
delay(100);
agrumino.turnLedOff();
agrumino.turnLedOn();
delay(100);
agrumino.turnLedOff();
delay(100);
agrumino.turnLedOn();
delay(100);
agrumino.turnLedOff();
}
void blinkLedMessageOk() {
agrumino.turnLedOn();
delay(200);
agrumino.turnLedOff();
delay(200);
agrumino.turnLedOn();
delay(200);
agrumino.turnLedOff();
}
Step 4: Setup Android APP Mqtt Dash and show Data
Download app with link in section "Component and App" and after write your personal Mqtt instance data and also write the same topics written in the sketch.
and now your Agrumino UVMeter is Ready to use......
The dashboard can be customized with other data, such as temperature, soil moisture and brightness trasmitted by built-in sensors on Agrumino
In this sketch the device sends messages to warn of the severity radiation and writes tips to protect us.
The messagescan be customized.
if (uvindex < 1.99) {
client.publish(TOPIC_INDEX, "Low Level");
client.publish(TOPIC_WARNING, "Low level, wear sunglasses and hat");
Serial.println("Low level, wear sunglasses and hat");
blinkLedMessageOk();
delay(DELAY);
}
else if (uvindex > 2.99 || uvindex < 4.99) {
client.publish(TOPIC_INDEX, "Medium/Low level");
client.publish(TOPIC_WARNING, "Medium/Low level, wear sunglasses, hat and SFP 15+");
Serial.println("Medium/Low level, wear sunglasses, hat and SFP 15+");
blinkLedMessageOk();
delay(DELAY);
}
else if (uvindex > 5 || uvindex < 6.99) {
client.publish(TOPIC_INDEX, "High level");
client.publish(TOPIC_WARNING, "High level, wear sunglasses, hat and SFP 30+");
Serial.println("High level, wear sunglasses, hat and SFP 30+");
blinkLedMessageOk();
delay(DELAY);
}
else if (uvindex > 7 || uvindex < 11) {
client.publish(TOPIC_INDEX, "Very high level");
client.publish(TOPIC_WARNING, "Very high level, wear sunglasses, hat, sunscreen SFP 30 +, possibly avoid the sun");
Serial.println("Very high level, wear sunglasses, hat, sunscreen SFP 30 +, possibly avoid the sun");
blinkLedMessageOk();
delay(DELAY);
}
else if (uvindex > 11) {
client.publish(TOPIC_INDEX, "Extreme level");
client.publish(TOPIC_WARNING, "Extreme level,very dangerous, take all possible precautions, it would be better to stay inside");
Serial.println("Extreme level,very dangerous, take all possible precautions, it would be better to stay inside");
blinkLedMessageOk();
delay(DELAY);
Serial.println("");
}
Data on Arduino IDE Serial monitorWith this simple example you can build a very accurate pocket UvMeter.
This should be seen as the start of your larger project,.
I hope it will be interesting for you !!
Do you have original ideas that you can realize with Agrumino Lemon ???
Write me!!!!
Thank you....
See you soon!!!
Comments
Please log in or sign up to comment.