Trouble with Digital-Write and current

Hello. This is not directly a XOD-related question, but I’m honestly not sure where to start looking for an answer to this problem and XOD is what I’m using to program.

I am using an Arduino Uno to control a circuit, and part of that circuit is an electromagnet tied to a button. The behavior I want from this circuit is as follows: When the button is not pushed, the Arduino keeps the magnet on. When the button is pushed down, the electromagnet should cut off. The electromagnet is on its own circuit with its own power source, and a single wire connected from the Arduino’s D13 pin to the base of a transistor turns that E/M circuit on and off. (I did this because the Arduino alone was not providing enough power).

The XOD node setup for this part is simple, just a button node connected to a digital-write. The button goes to the Arduino’s D12 pin, and the electromagnet is controlled by the D13. I do not think the problem is in the code. (Below is not the full code, just the part that is interacting with the E/M):

Screenshot (4)

The problem I am having is that instead of cutting off completely the electromagnet is only decreasing in power slightly when I hold the button down. I’m using it to hold a model car in place on a ramp, then when I press the button it will release and a timer starts. However, the weight of the car will be variable, so the decrease in the magnet’s strength is not always enough to release the car.

I believe this is happening because when the Arduino is writing a LOW state to the EMag, there is still marginal current passing through the wire, which is enough to open the transistor. I’ve fiddled with the resistance between the wire and the transistor, but I’ve ran into the problem of either making the magnet too weak to hold the heavier cars, or too strong enough to hold all the cars, but then it does not decrease in strength enough to release the lighter cars.

TL;DR: Is there a way to guarantee that an Arduino pin’s LOW state is as close to 0V as possible, either through XOD or through a hardware trick? Or do I just have to deal with some marginal current going through it at all times?

The full schematic is here, but the only relevant part is the button off of D12 and the E/M circuit off of D13:

if you understood correctly press once to activate, press again to deactivate, use flip-flop node.

D13 is usually connected to an LED, have you tried another pin?

I think part of the problem is that the button is wired incorrectly. The if the button connects the pin to V+, then to resistor should be between the pin and ground, not between the pin and button. This forces the pin to 0V when button is released instead of leaving it to float.

If you are doing a digital read, then XOD will be getting a zero or one; is cannot return a value in between, so button wiring cannot be the only problem. Could your choice of transistor be slowing some current through even when gate has no signal? If you move wire from D13 to ground, does the electro magnet turn off completely?

Thanks for catching the button problem; fixed it.

And yeah, when I physically disconnect the D13 wire the magnet turns off completely as expected. I think you’re right about my choice of transistor. I only have the one type of transistor on-hand, but that seems like the most promising lead at this point. It might just be that I need a better component.

Thanks for the input!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.