I am using a JIC 139 UV Sensor (datasheet) with an Arduino Mega 2560 and should be reading smooth curves as I bring a UV source to towards the sensor. Instead, my curves are increasing and oscillating. How can I remove the oscillations and what is the cause of these oscillations?
Code:
float mapfloat(long x, long in_min, long in_max, long out_min, long out_max)
{
return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min;
}
int averageAnalogRead(int pinToRead)
{
byte numberOfReadings = 8;
unsigned int runningValue = 0;
for(int x = 0 ; x < numberOfReadings ; x++)
runningValue += analogRead(pinToRead);
runningValue /= numberOfReadings;
delay(100);
return(runningValue);
}
void setup() {
Serial.begin(9600);
}
void loop() {
float pinRead0 = averageAnalogRead(0);
float pVolt0 = pinRead0 / 1024.0 * 5.0;
// In mW/m^2
Serial.println(pVolt0);
// Serial.println(mapfloat(pVolt0, 0.0, 5.0, 0.0, 15.0));
delay(100);
}
`
Here is a sample screenshot from the Serial Plotter at 3 different distances from the UV Source:
Would post cicuit but don't have enough reputation. Will post as response. edit: I added a very large capacitor(3300 uf) between the output pin and ground which seemed to smooth the values a little bit but the noise still exists
edit: The x-axis is number of readings and the y-axis is voltage(0-5v) calculated from analogRead()