UV sensor test on IIC LCD

I tested this sensor with uno, and a IIC lcd module using the code (attached in the end), and got these results.
Code: Select all#include
#include
LiquidCrystal_I2C lcd(0x27, 20, 4);
int ReadUVintensityPin = A0; //Output from the sensor
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Booting...");
delay(1000);
pinMode(ReadUVintensityPin, INPUT);
Serial.begin(9600); //open serial port, set the baud rate to 9600 bps
Serial.println("Starting up...");
}
void loop() {
int uvLevel = averageAnalogRead(ReadUVintensityPin);
float outputVoltage = 5.0 * uvLevel / 1024;
float uvIntensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);
lcd.clear();
lcd.setCursor(0, 0);
Serial.print("UV: "); lcd.print("UV: ");
Serial.print(uvIntensity); lcd.print(uvIntensity);
Serial.print(" mW/cm^2"); lcd.print(" mW/cm^2");
Serial.println();
delay(100);
}
int averageAnalogRead(int pinToRead) {
byte numberOfReadings = 8;
unsigned int runningValue = 0;
for (int x = 0 ; x < numberOfReadings ; x++)
runningValue += analogRead(pinToRead);
runningValue /= numberOfReadings;
return (runningValue);
}
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
Thanks for the information, I will try to figure it out for more. Keep sharing such informative post keep suggesting such post.
