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.
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?
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
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.
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..