/* ML8511 UV Sensor Read Example Connections: Sensor Pin -> Arduino Pin 3.3V = 3.3V OUT = A0 GND = GND EN = A1 3.3V = A1 */ //Hardware pin definitions int UVOUT = A0; //Output int REF_3V3 = A1; //3.3V power on the Arduino board void setup() { Serial.begin(9600); pinMode(UVOUT, INPUT); pinMode(REF_3V3, INPUT); } void loop() { int uvLevel = smoothAnalogRead(UVOUT); int refLevel = smoothAnalogRead(REF_3V3); float outputVoltage = 3.3 / refLevel * uvLevel; float uvIntensity = (outputVoltage - 0.99) * 15.0 / (2.9 - 0.99); Serial.print("UV Level: "); Serial.println(uvLevel); Serial.print("Voltage: "); Serial.println(outputVoltage); Serial.print("UV Intensity (mW/cm^2): "); Serial.println(uvIntensity); delay(100); } //returns the average read in order to smooth out anomalies int smoothAnalogRead(int pinToRead) { byte numberOfReadings = 8; unsigned int runningValue = 0; for(int x = 0 ; x < numberOfReadings ; x++) runningValue += analogRead(pinToRead); runningValue /= numberOfReadings; return(runningValue); }