Hello everyone,
I'm having trouble with a project where I'm using an ML8511 UV sensor, an OLED display, and an ESP32. Unfortunately, I'm unable to connect to the web, and the sensor readings are not accurate. I've tried several troubleshooting steps, but I'm still stuck.
Could someone please help me review my code and offer suggestions?
Thank you
#include <WiFi.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Arduino.h>
#include <ML8511.h>
#define ANALOGPIN 15
#define ENABLEPIN 4
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_RESET);
ML8511 light(ANALOGPIN, ENABLEPIN);
const char* ssid = "ssid";
const char* password = "pas";
WiFiServer server(80);
void setup()
{
Serial.println("UV UltraViolet ML8511");
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
display.display();
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// manually enable / disable the sensor.
light.enable();
light.setDUVfactor(1.80); // calibrate your sensor
Serial.print("\tmW cm^2");
Serial.print("\t Index");
Serial.println();
}
void loop()
{
float UV = light.getUV();
float UVI = light.estimateDUVindex(UV);
Serial.print(UV, 4);
Serial.print("\t");
Serial.print(UVI, 1);
Serial.println();
delay(1000);
// Draw vertical line in the middle of the display
display.drawLine(SCREEN_WIDTH / 2, 0, SCREEN_WIDTH / 2, SCREEN_HEIGHT, WHITE);
// Display Intensity
display.setCursor(0,0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Intensity");
display.setCursor(8,13);
display.setTextSize(1.9);
display.setTextColor(WHITE);
display.println(UV, 4);
display.setCursor(5,25);
display.setTextSize(1.5);
display.setTextColor(WHITE);
display.println("mW/cm^2");
// Display DUV Index
display.setCursor(SCREEN_WIDTH / 2 + 23, 0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Index");
display.setCursor(SCREEN_WIDTH / 2 + 26, 15);
display.setTextSize(1.5);
display.setTextColor(WHITE);
display.println(UVI, 1);
display.display();
delay(300);
display.clearDisplay();
}