I am building an optical rotation encoder for my "autonomous robot" (a LED pointing to a photodiode that gets interrupted as the axis rotates).
My issue is that at the voltage that I am using the motors (~9v) they generate too much electromagnetic interference so the microcontroller (arduino) triggers a "falling" without any physical move (it makes a ~5v value oscillate below ~2.2v)
I believe that's what is happening. See my image for my testing setting.
I have my circuit connected to the computer and I have a completely independent dc motor connected to isolated batteries. When I turn the motor ON, the microcontroller starts triggering like crazy (even 50 times per second, at about 20cm of distance).
I think that the only possible cause is electromagnetic interference. I realize my circuit is exposed (I am using LEDs, resistors, etc., without covering).
So, as a test I covered my "rotation encoder" (the red protoboard in the image) in aluminium foil. It helped a lot (but it didn't fix the issue completely in the static testing setting - the issue is even worse if the axis is actually moving). I also covered the DC motor in aluminium foil with no improvement (I believe that it actually made it worse).
I didn't cover the resistences and LEDs with plastic isolation (thermoshrinkable) because this is the prototype in the protoboard (want to avoid investing all the time it takes because I am breaking it apart the minute it works to mount it in the real robot). I can do that if I find indications it would help.
So the question is: for a DIY/hobby level project, what approach should I take to isolate the circuit from the interference that seems to be coming from the DC motor?.
Thanks.
Note: per request added encoder circuit.