Hello forum, I have a problem with noise on my analog lines and I was wondering if anyone had any quick and dirty ideas I could play with. Here is a quick description of what I 'm trying to do.
I have a DC-SS009 3-axis accelerometer which spits out an analog signal which can be read through the Arduino's ADC. I thought I 'd mount it on a platform that is allowed to rotate along one axis and stick two motors with propellers on either end to balance it at a given angle. The whole setup can be seen below.
Now, some more detail. The motors suck around 400 mA when going strong so I power them through an L293 H-Bridge. Now, here is the problem. Motors on the power line do absolutely disgusting things to the voltage level. When powering both my Arduino and the motors from the same source, I have had the Arduino resetting repeatedly.
To counter this, I have kept the Arduino and motor power supplies separate, the motors are powered by a battery (some 10.5 Volts give or take) and the Arduino by the PC through the USB cable. To keep things even cleaner, the logic level voltage needed by L293 is given by a 5V voltage regulator and not by the Arduino 5V pin. This way, the only interaction between the Arduino and the L293 is through two of the Arduino's digital out PWM pins which connect to the corresponding input pins of the L293. To dampen any nastiness in the motor power lines I have added a capacitor on each, connecting it to ground. Battery, voltage regulator, motors and Arduino share a common ground. All this is shown in the diagram below.
If I 'm using my multimeter properly, the capacitors I 'm using seem to be around 3.5 nF. Here they are.
This circuit is the best I could come up with the get rid of noise but unfortunately, it doesn't cut it. Here's why.
The picture below shows the final angle readings I get after processing the ADC voltages. This is the range of motion I have physically allowed the platform and the resolution is not that bad within it. These readings have been taken with the motors off and me moving the platform with my hand. It is sketched in a silly little Processing sketch I have written to act as a crude scope.
The next one shows the same thing (me moving the platform around within its limits of motion) but with the motors on. The noise is beyond terrible.
This one shows the transition to quiet as I turn the motors off. The difference is obvious.
Now, the big question is, where does the noise come from? If it's kicked back down the motors' power supply line and somehow manages to travel through the L293 and up the Arduino's digital output pins there's not much more I can think of doing other than stuffing ever bigger capacitors on the motor power supply line. However, I thought I could be picking up electromagnetic noise through the unshielded lines going to the ADC acting as aerials. I 'm sure the motors must be spitting out some pretty disgusting EM fields around them as they go about their business and the ADC line is just begging to pick it up.
To test this, I disconnected the digital output pins from the L293, completely isolating the Arduino from the motor power supply lines (they still share a ground). I then connected the motors directly to the battery and turned them on and off. The results are shown below. I was quite astonished at what a tremendous amount of noise my unshielded line is picking up (I am also astonished that the platform actually manages to kind of balance, although in a very drunk manner).
So, my big question. Is there anything I can try to get better measurements? The obvious answers I can think of are:
a) get an accelerometer with digital output (I 've got my eye on this one Triple Axis Accelerometer Breakout - BMA180 - SEN-09723 - SparkFun Electronics). Expensive but the best solution I guess.
b) get shorter ADC lines. My cables are certainly longer than they need to be but what happens if for whatever reason I need them to be long?
c) shield them. If I wrap the cables in tin foil and then connect it to ground, will I get any worthwhile effect or would I be wasting my time?
Am I missing something obvious?