I have 5 capacitive humidity sensors hooked on A0 … A4 but I can’t read anything due to extreme levels of noise (I have and antenna and a switching power supply in my circuit).
What is the recommendation in this case? Small capacitor to the ground?
@felipe1,
When the Sensor isn’t connected, you will get random ADC values.
I’ve used those capacitive sensors for soil moisture monitoring in the past.
I calibrated my Code with (2) const int values, one for Air, and one for Water (actual ADC readings for both media). Then map your future readings between these (2) const int’s.
The following were my actual calibrations for a 10-bit ADC, but this shows that without knowing the endpoints, the ADC readings from these sensors aren’t very useful:
const int AirValue = 593 ; // replace this value with Value_1
const int WaterValue = 278 ; // replace this value with Value_2
You might be way past this in your project, if so I apologize.
Unfortunately that is not my case, if I connect the sensor straight to the photon I have stable reading. The problem is when I connect the sensor using a 2 meter cable.
I’ve just added an RC filter to it (8pF and 1k) but it didnt do much. It’s not a real time application so I’m thinking of collecting 100 readings and taking the average to see if I can get rid of the noise.
It could be an option. What I don’t understand is that I’ve used the same cable but with an arduino and it worked. I switched to particle so I could expose the variables to the cloud.
I’m getting completely random readings (note that I did not map the values):
Does your cable have a bare wire in it (no insulation) if so, use that as a drain, connect it to ground on the photon side, and leave it disconnected on the other end.
What Arduino?
Most "legacy" Arduinos use 5V as Vref and only 10bit resolution so any noise would be less prominent and AVRs also use a different kind of ADC and have higher input impedance (IIRC).
@ScruffR Uno I guess I got used to the noise forgiveness of arduino’s ADC and tried to do the same. What do you think about adding a voltage follower to each AI?
@Rftop and @Mjones Thanks guys, I’ve changed the cable for a shielded one and it drastically improved the reading stability
@felipe1, that analog moisture sensor uses a frequency to voltage circuit using a 555 timer as the frequency generator and a basic RC integrator to produce the voltage. This frequency to voltage approach will yield some ripple on the voltage values. Your code should perhaps take several measurements and calculate an average to reduce the effect of noise. You could even apply a digital low-pass filter (lots of libraries available) to target noise more specifically.
The RC has a 1M resistor coupled with a 1uF capacitor which creates a relatively high impedance circuit while the Analog inputs on the STM32 are lower impedance. Using a voltage follower would remove the impedance issue but may be overkill for your application.