Screenshot 2024-05-07 165626|690x334
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
// Pin assignments
#define UV_SENSOR_PIN A0 // Analog pin for UV sensor
// Bluetooth module pins
#define BT_RX_PIN 2
#define BT_TX_PIN 3
SoftwareSerial BT(BT_RX_PIN, BT_TX_PIN); // RX, TX pins for Bluetooth module
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging
BT.begin(9600); // Initialize Bluetooth serial communication
lcd.init();
lcd.backlight();
}
void loop() {
// Read analog values from UV and IR sensors
int uvValue = analogRead(UV_SENSOR_PIN);
// Convert analog values to UV intensity (mW/cm^2)
float uvIntensity = map(uvValue, 0, 1023, 0, 15); // Assuming UV sensor range is 0-15 mW/cm^2
// Estimate wavelength based on intensity (replace with your calibration)
float uv_wavelength = estimate_wavelength(uvIntensity);
int light = analogRead(UV_SENSOR_PIN);
Serial.println();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("UV I:");
lcd.print(uvIntensity);
lcd.print(" mW/cm^2 ");
lcd.setCursor(0,1);
lcd.print("UV W:");
lcd.print(uv_wavelength);
lcd.print(" nm");
delay(1000);
// Send sensor readings via Bluetooth
BT.print(uvIntensity);
BT.print("|");
BT.print(uv_wavelength);
BT.print("|");
//delay(1000);
// Print sensor readings to serial monitor for debugging
Serial.print("UV Intensity: ");
Serial.print(uvIntensity);
Serial.print(" mW/cm^2 ");
Serial.print("UV Wavelength: ");
Serial.print(uv_wavelength);
Serial.println(" nm");
delay(1000); // Delay for stability
}
// Function to estimate wavelength based on intensity (replace with your calibration)
float estimate_wavelength(float intensity_voltage) {
// This is a placeholder function for demonstration purposes
// You need to replace it with your actual calibration algorithm
// that maps intensity to wavelength
// For simplicity, assume a linear relationship between intensity and wavelength
return intensity_voltage * 81; // Example calibration factor
}