Developing Communities Be Good Do Good
Chandler 85248
chandan
// modified by cdas // to calculate UV index directly
#include <math.h>
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 0;
const int colorG = 255;
const int colorB = 0;
void setup() {
Serial.begin(115200); // set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// Print a message to the LCD.
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Greetings from ");
lcd.setCursor(0,1); lcd.print("CSL ");
delay(10000);
}
void loop() {
int sensorValue;
long sum=0;
for(int i=0;i<1024;i++)// accumulate readings for 1024 times {
sensorValue=analogRead(1);
sum=sensorValue+sum;
delay(2);
}
long meanVal = sum/1024; // get mean value
Serial.print("The current UV index is:");
Serial.print((meanVal*1000/4.3-83)/21);
// get a detailed calculating expression for UV index in schematic files.
Serial.print("\n");
if(meanVal < 45){
lcd.setRGB(0,255,0);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Low UV Level!");
lcd.setCursor(0,1);
lcd.print("Less than 45!");
delay(1000);
}
else if(meanVal > 45){
lcd.setRGB(255,0,0);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("UV Level > 45");
lcd.setCursor(0,1);
lcd.print("Wear Sun Screen!");
delay(1000);
} else{
lcd.noDisplay();
delay(500);
lcd.display();
delay(500);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// lcd.setCursor(0, 1);
// print the number of seconds since reset:
// lcd.print(millis()/1000); }
}
/********************************************************************************************************* END FILE*********************************************************************************************************/
Copyright 2019 Chandan Shamala Library. All rights reserved.
Chandler 85248
chandan