I am using an Arduino Uno in a sketch that reads the values of photodiodes, and the Arduino is plugged into my laptop. The analog inputs for the photodiodes are grounded via resistors.
In the early days of my project, I had noticed that the program was running in a much more reliable way when the power cord was disconnected.
Recently as the code got more complex, it became pretty much impossible to get it to work.
On the following screenshots, I am simply plotting the values of 2 of the photodiodes. These values should be nearly constant.
Case n°1 : The power cord is far away from the laptop
Case n°2 : I am touching the power cord and the laptop at the same time
Case n°3 : The power cord is plugged into the laptop (I also plotted 2 constant values to get a stable display of the curves)
So it seems that I am having an issue with grounding. I tried with another laptop whose power cord was grounded, but I got the same issue. Replacing the Uno by another Uno first, and then by a Mega, didn't help either.
I bought a USB cable with ferrite at both ends, hoping that it could calm down the noise, but no.
Now here comes the fun part : when I plug the Arduino in a PC instead of my laptop, it works flawlessly. And if I switch right away back to my laptop, it keeps on working for a while, until I have to go back to the PC to solve it.
I am about to order a kit of ceramic capacitors, because from what I understand, it's often the way to solve that kind of issue.
The thing is that I need to measure the voltages from these sensors at a very fast pace. How would you suggest that I use these capacitors with that constraint? (If that's the right idea, and if ceramic are better suited than electrolytics)
IMO, ceramics because you have what appears to be an AC interference. Start with the smallest value cap you can unless you know the joule rate you need.
Are you using shielded cables and cables of the same material? Take the two sensor wires and twist them, then wrap them in aluminum foil and ground the foil in one location at the Arduino.
Photodiodes can't reliably be directly connected to an Arduino input, as they are high impedance. You need a photodiode amplifier (a transimpedance amplifier) and shielded inputs.
I just measured the noise frequency and it looks very close to 50Hz, as voltage supply is supposed to be in Europe, that's interesting!
Sorry I haven't drawn the schematics, but there are simply a couple of diodes plugged on PWM outputs, 2 photodiodes linked to +5V and Analog Inputs (reverse biais), and 2 resistors in between Analog Inputs and ground.
I will try without photodiode amplifier, because I have already successfully run the sketch for hours in a row (and when it works, it works perfectly), and because it would make the project more complicated. I am not using shielded cables, but I will keep that in mind.
Now I have a better idea about where the noise comes from, so I can work on that.
Thanks for your answers!
Unshielded inputs and wires, connected to high impedance sources, are good antennas for receiving the electrical signals from overhead lighting and household wiring.
Also, the Arduino ADC is specified for 10K source impedance, maximum.