5V Electromagnet 25KG Holding F (3875 Adafruit Industries LLC)
2N3904-AP Transistor
1N4148 Diode
22KΩ Resistor
Attached are images of the circuit diagram and my breadboard setup. The red wire is connected to 5V, the black wire is connected to GND, and the green wire is connected to digital pin 2. The blue wires connect to the electromagnet.
Here is my code:
int elecMag=2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(elecMag, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(elecMag, HIGH);
}
The only potential issue that I see is my electromagnet connection. This electromagnet has loose wires at the end, which I just stuck directly into the breadboard. I am not sure if this is the proper way to connect wires that don't have the little black clamps at the end, so please let me know if there is a better way to connect the electromagnet to the breadboard.
Other than the loose wire connection of my electromagnet, I cannot spot any issues. What I am doing wrong?
according to the datasheet for the electromagnet, it draws a current of 0.6 Amps at 5V. With some research, I found that powering the Arduino from a USB limits your total power consumption to 500mA, so I may need to connect an external power supply to get this to work.
I tried using a 220Ω resistor, but it still did not function.
so I may need to connect an external power supply to get this to work.
Definitely.
The 2N3904 transistor can handle only 200 mA. It may have burned out internally with that electromagnet. Also, breadboards are for low power logic circuitry, and the tracks tend to burn with high currents used by motors, servos and electromagnets.
Use a logic level MOSFET instead, for example this one and for permanent installations, use a PCB, not a breadboard.
Did you forget to connect the grounds together. Lets try a simple experiment, remove the connection from the microcontroller and connect it to 5V. If the electromagnet works you have a software/microcontroller problem, if not you blew the transistor. Also the diode you are using appears to be too small, it must be able to handle the full current of the electromagnet for the flyback pulse. If it is blown you will constantly blow transistors. If you cycled it with the diode disconnected for any reason by-by transistor. If you can get a logic level avalanche protected MOSFET and substitute it for the transistor B-G, E-S, B-G. If you use an avalanche rated MOSFET you will not need the diode. When it works change the resistor to something in the 25-50 ohm range. NOTE: 600mA is 3X 200mA why would that transistor work in the first place.
Do you have a DMM?
As has been noted in earlier posts, make sure the gnd of the UNO is connected to the Emitter of the transistor and the gnd of the 5V solenoid supply.
Although it has been mentioned already, the 2N3904 will be destroyed when you try to pass 600mA, it is max rated for 200mA only. Either use the suggested MOSfet or a power Darlington transistor.