I am doing a project making a 3D printed programmable trainset. I am using an L298N to drive two TT-motors (The common yellow ones used in many projects). Everything seemed to work fine and I could control the speed and direction of the motors. But now I need to add some micro switches that can read code-blocks in the tracks. I have attached the microswitches so they connect to ground, when activated and I have attached interrupt routines using the FALLING setting. I started out using the build-in pullup resistors and everything works, as long as the motors are not running. As soon as the motors start running I get a lot of false calls of my interrupt routines even though the microswitches are not activated. I have measured with an oscilloscope and there seems to be a lot of noise in the system that causes the false reads. I have tried external 5.1K ohm pullup resistors and added 100 pF capacitors to the motors, but nothing seems to help. Does anyone have similar experiences and maybe a solution. Right now I am out of options and this is completely stalling the project. Best regards Tobias.

