Internal pull-up gone away for one port

Hello

My internal pull-up for digital port 4 seems to be killed. I can properly read LOW or HIGH from that port shorting it with ground or 5V. But i can’t read HIGH from internal pull-up. All other ports work as expected.

This pin was connected to a reversed diode (1N4007) that was connected to one leg of a 6V DC motor (powered with ~7V). It was supposed to tell the direction the motor was running. When given leg was grounded, pin would read LOW. When it was VCC diode would open and pin would read HIGH from pull-up.

Any chance this setup killed the pull-up ?

Yes

larryd:
Yes

Can you elaborate please ?

Motors generate very large voltage spikes, and should never be connected to ANY microprocessor pins.

That includes the 5V pin, which is not intended, and should never be used, to power any motor or servo.

You are lucky that only the pullup seems to be destroyed, but I would not trust that processor any more.

jremington:
Motors generate very large voltage spikes, and should never be connected to ANY microprocessor pins.

That includes the 5V pin, which is not intended, and should never be used, to power any motor or servo.

You are lucky that only the pullup seems to be destroyed, but I would not trust that processor any more.

Unless I misinterpreted the data sheet, that diode is rated to handle 1000V when reverse polarized. I still don’t see the point.

The spikes coming from the motor can forward bias the diode, Arduino goes poof !

Very good advice:

You are lucky that only the pullup seems to be destroyed, but I would not trust that processor any more.

BTW, always show a schematic how you are hooking up your circuit.

I still don't see the point.

The motor generates large negative spikes, as well as positive ones.

Common rectifier diodes (1N4007) also have a significant reverse recovery time.
The diode could still be conducting some time (both ways) after the first spike has gone.
Leo..

Ok thanks a lot for all the clarification. Makes sense now.

I’m using a 6 terminal rocker switch to pick motor direction. Perhaps I can look for a 9 terminal one and use the third track for arduino alone. Any other suggestion?

Current diagram is attached.

4CB34D6B-BC54-49C4-AA06-161E0965B911.png

The rocker switch is another source of potential trouble, leading to even larger voltage spikes. I suggest to use an appropriate motor driver (Pololu has a great selection). Tutorial on motor electrical noise reduction techniques.

With a motor driver, you KNOW which direction the motor should be turning, and some will tell you how much current it is drawing, which also informs you if the motor is stalled.

jremington:
The rocker switch is another source of potential trouble, leading to even larger voltage spikes. I suggest to use an appropriate motor driver (Pololu has a great selection).

With a motor driver, you KNOW what direction the motor should be turning, and some will tell you how much current it is drawing, which also informs you if the motor is stalled.

Yes I considered that option before but to be honest I was trying to avoid it. It’s a kids electric bike that I’m tinkering with, I’m trying to keep the powertrain as close to original as possible. If anyone is interested, for a full description of this project please take a look at

Thanks again for the help

4CB34D6B-BC54-49C4-AA06-161E0965B911.png

Use a DPDT switch.
It can isolate the Arduino completely from the motor.

Also, a capacitor across the motor would be a good idea, 1μf non polarized.

larryd:
Use a DPDT switch.
It can isolate the Arduino completely from the motor.

That’s what I’m using. But one track for each motor terminal. I need a third one for arduino.

larryd:
Also, a capacitor across the motor would be a good idea, 1μf non polarized.

Will do. Was reading the link someone posted before it was recommended to use 3 capacitors of 0.1uf. 1 for each pin and housing and one across both pins.

Should have said 3PDT

Motor drivers contain clamping diodes, usually as body diodes inside the mosfets, to keep spikes within the limits of battery voltage.

Could do the same by adding a bridge rectifier to that motor,

  • and - to battery + and -, and the two AC terminals to the two motor terminals.

An opto coupler (or two) could be a safer way to detect motor direction.
Opto LED with a (1k) current limiting resistor across the motor, and opto transistor between input pin and ground. With internal pull up enabled on the pin.
If you only use one opto, then add a small diode (1N4148) across the opto LED, to protect against reverse voltage. If you use two optos, use the LEDs back to back.
Let us know if you need a diagram.
Leo..

Wawa:
An opto coupler (or two) could be a safer way to detect motor direction.

did I get it right ?

Almost.
Opto transistor emitter goes to ground, and collector to Arduino input.

Wise to also add that small signal diode across the opto LED.
See this image.

Leo..

Wawa:
Almost.
Opto transistor emitter goes to ground, and collector to Arduino input

Yes of course slap on the face

Will order the parts and update my project. Will include the signal diode as well.

Thanks a lot for your help buddy.