How to make Arduino sense DC motor polarity change


I'm making a 8 mm film projector (for digital conversion) with the Arduino and a L298N module for PWM and PID speed regulation.

My problem is, that originally the variable speed DC motor changed its direction via a polarity reversing switch that also mechanically selected the correct reel to be spun. That's why I have to keep using the original switch to change the direction of the film projection.

But the plarity change is a problem for the L298N module so I have to use a bridge rectifier to power the module.

Although I can tell the module to rotate the motor in any direction, I have to do that at the same time as the mechanical switch is being rotated. Thus I need a way for the arduino to read if there's a voltage on switch contacts and if yes, what polarity it's set to.

So I have to sense these three states from the switch (while the arduino is still on):

- the projector is off (no voltage from the switch) - the projector is in forward mode (contact 1 has from +10 to to +25 V DC and contact 2 is ground) - the projector is in reverse mode (contact 1 is ground and contact 2 has from +10 to +25 V DC)

At first it seemed like a simple task but now I'm stuck. I'll be very thankfull for any advice.

Thank you in advance With regards Daniel Krnac

Consider using two voltage dividers (for example, 47K & 12K resistors) and two analog input pins to safely sense the states of contacts 1 and 2.

Don't forget to define a suitable ground connection on the projector, and connect the Arduino ground to it.

That's exactly what I did (with extra diode before the dividers for extra protection). I'm ashamed to admit I forgot to find a grounding point. I'll try that, thanks a lot.

So I found out that there's no real ground on the output of the switch but, it has -3V DC on it measured against the real ground of the projector. The other contact has +10 to +25V against the other contact and around -3 V less against the real ground (+7 V to +22 V).

Would it be ok to measure both contacts with arduino against the real ground of the projector? I am using a 1 Mohm and 200 kohm resistor as the voltage divider and a diode on both inputs so they won't get negative voltage.

Thanks again D.K.

I don't completely understand your description of the situation, but with a 1M resistor between the projector and the Arduino, exposure to negative voltages won't damage the input.

There is an effective diode between ground and the input that will act to limit the input voltage to about -0.7V, and the current flow through the 1M resistor will be too small to damage the diode or the input.

Thanks, so I’ve tried it and it measures the voltage nicely - analogRead gives a value of around 700 at one input and about 10 at the other which is just about what I was aiming for.

However, there’s a another problem - when I stop the projector, the arduino just freezes, probably from a sudden voltage drop or something like that. Even though it’s powered by the computer. Any ideas?

What do you mean by "stop the projector"?

It can be very dangerous to have two different household AC-line powered devices connected together, especially if they are powered from different circuit breakers.

Make sure that the projector has a proper three wire earth ground connection, and then look up "ground loops in power systems".

The projector is powered by normal 220V oulet while the arduino is powered by a laptop, which is running on battery, not connected to the outlet to prevent the grounding loops. I always try to power the devices connected together from the same outlet for this reason or use other means (1:1 power transformer, optocouplers etc.). Don't get me started on grounding loops with pro audio equipment...

By stopping I mean turning the switch into stop position. That cuts off the voltage to the motor (not to the motor armature though). This does freeze the arduino.

What also freezes the arduino is turning the projector off via the outlet switch.

Since I don't have a oscilloscope, it's hard to record what exactly is going on. I just guess it's a voltage spike, most probably an inductive voltage spike from the motor. Can I address that somehow? With a capacitor maybe? Flyback diode? Should I Maybe use a optocoupler?

Thanks again, I appreciate all the help Wiith regards D.K.