Skip to content

Instantly share code, notes, and snippets.

@dangpzanco
Created May 14, 2018 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dangpzanco/1cbdf80b1b09dead988072ba59330c51 to your computer and use it in GitHub Desktop.
Save dangpzanco/1cbdf80b1b09dead988072ba59330c51 to your computer and use it in GitHub Desktop.
UV meter in Arduino Uno
void setup()
{
// open serial port, set the baud rate to 9600 bps
Serial.begin(115200);
}
void loop()
{
float UVIndex;
// Connect UV sensors to Analog 0
int32_t sensorValue = analogRead(0);
float voltValue = 5.0f * (sensorValue) / 1024.0f;
if(voltValue <= 200e-3)
UVIndex = voltValue/0.2f;
else
UVIndex = 2.0f*voltValue/0.2f;
// Print the value to serial
Serial.print(voltValue);
Serial.print(",");
Serial.println(UVIndex);
delay(200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment