pictographer
Well-known member
I'm recording the level of light in one of my skylights using a Teensy 3.1 and a phototransistor with the aim of making a system to alert me if my photovoltaic power generation system declines in performance.
The readings are somewhat noisy and don't span the full range of the ADC. I was wondering if it would be possible to reduce the noise by using ADC_1 connected to nothing to cancel the noise generated within the Teensy itself from the readings of ADC_0 connected to the phototransistor.
The current noise level is probably "good enough" for what I'm trying to accomplish since the sunlight changes slowly so I can massively oversampling and applying a median filter, but I'm curious if the noise canceling idea makes any sense. I'd also like to get a more practical understanding of how to prioritize various approaches to reducing sensor noise.
The wires from the phototransistor to the Teensy are about a couple of meters long from an old two-wire phone cable. Not shielded. I don't know the gauge.
How would you prioritize the following ways of understanding/reducing noise?
The readings are somewhat noisy and don't span the full range of the ADC. I was wondering if it would be possible to reduce the noise by using ADC_1 connected to nothing to cancel the noise generated within the Teensy itself from the readings of ADC_0 connected to the phototransistor.
The current noise level is probably "good enough" for what I'm trying to accomplish since the sunlight changes slowly so I can massively oversampling and applying a median filter, but I'm curious if the noise canceling idea makes any sense. I'd also like to get a more practical understanding of how to prioritize various approaches to reducing sensor noise.
The wires from the phototransistor to the Teensy are about a couple of meters long from an old two-wire phone cable. Not shielded. I don't know the gauge.
How would you prioritize the following ways of understanding/reducing noise?
- Calculate the Fourier transform of the noise to see if there are obvious periodic elements like "mains' hum" and understand how aggressive a low-pass filter to use.
- Add a small capacitor 0.1uF or 0.01uF between the ADC input and ground.
- Add a simple low-pass filter made from a resistor and capacitor.
- Try a shorter cable.
- Try a shielded cable.
- Try a cable with twisted pairs of wires.
- Try different parameters for the ADC library.
- Use a median filter in software.
- Boost the signal to the ADC by wiring the phototransistor to the base of another transistor.
- Try to find the datasheet for the phototransistor.
- Try using ADC_1 to cancel noise in ADC_0 readings.
- Try running the project from a battery rather than the USB port of a pocket router.
- Other ideas?
Code:
// Photodiode from 19 to 18.
#include "ADC.h"
ADC *adc = new ADC(); // adc object
void setup() {
Serial.begin(9600);
pinMode(18, INPUT);
// Pull down pin 18.
//*portConfigRegister(18) = PORT_PCR_MUX(1) | PORT_PCR_PE;
*portConfigRegister(18) |= PORT_PCR_PE; //pull enable
*portConfigRegister(18) &= ~PORT_PCR_PS; //pull down
pinMode(19, OUTPUT);
digitalWriteFast(19, 1);
analogReference(INTERNAL); // Untested.
adc->setAveraging(1); // set number of averages
adc->setResolution(16); // set bits of resolution
adc->setConversionSpeed(ADC_VERY_LOW_SPEED );
adc->setSamplingSpeed(ADC_VERY_LOW_SPEED);
// with 16 averages, 12 bits resolution and ADC_HIGH_SPEED conversion and sampling
// it takes about 32.5 us for a conversion
// adc->enablePGA(64, ADC_0);
}
const long avg = 1; // 2048
const char* dstr = "****************************************************************";
unsigned long i = 0;
void loop() {
Serial.print(i++);
Serial.print('\t');
long lux = adc->analogRead(18, ADC_0);
for (long k = 0; k < avg - 1; ++k) {
lux += adc->analogRead(18, ADC_0);
}
lux /= avg;
Serial.print(lux);
long dots = log(4 * lux);
Serial.print('\t');
Serial.print(analogRead(26));
Serial.print('\t');
Serial.println(dstr + (64 - dots));
delay(10);
}
// Values range from 1 to about 250.
// Under 25, the values look like noise compared to the Enphase PV data.
// Clearly, depending on the phase of the samples, we see different peaks.
// The Enphase PV data has 12 samples per hour or one sample every five minutes.
// A median filter on a five minute window results in significantly smoother graphs than Enphase.