I have bought a small 5V solenoid, which is supposed to work with the Arduino without requiring an external power source. The problem is that I do not get it to work. This is probably because I made some mistake, so I want to know what my mistake is.
To be honest, I know very little of solenoids, other than that they perform linear motions by means of electromagnetic force. I have tried treating the solenoid as if it were a simple motor, but performing a linear motion instead of a rotational motion. With the use of a NPN transistor, a diode, and a 2.2k ohm resistor, I get the motor to work... But not when I try to put the solenoid in its place.
I did notice something, though: when I connect the solenoid directly to the +5V power source and the ground of the Arduino, the solenoid moves "to the other end" in an instant. Then, when I remove the +5V power source, the solenoid withdraws. I can repeat this, but this is probably due to negative voltage spikes, which can potentially damage my Arduino, so I have tried to avoid repeating it.
This gave me an idea. The NPN transistor circuit, which is used to control a simple mini motor, can perhaps be used to control a solenoid by turning it on and off quickly enough to make it move rapidly. However, even then, the solenoid does nothing.
What am I doing wrong?
P.S. I am more or less new to Arduino and microcontrollers in general, but I am not new to programming.
The arduino digital I/O pins can provide 40mA max and to ensure that your arduino has a long life, it's recommended that you not exceed half of that. It sounds as though your solenoid needs more power - you'll need to use your transistor to switch the 5V supply directly rather than trying to run it off one of the pins.
It's possible too that you've already damaged the pin you were trying to use - might be worth testing it with an LED and suitable resistor.
wildbill:
The arduino digital I/O pins can provide 40mA max and to ensure that your arduino has a long life, it's recommended that you not exceed half of that.
I know. I will try to be careful with it.
It sounds as though your solenoid needs more power - you'll need to use your transistor to switch the 5V supply directly rather than trying to run it off one of the pins.
But this is what I am trying to do by using the transistor circuit. The pin (digital pin 9) simply controls the flow of electricity, since it is connected to the base of the NPN transistor (using a 2.2k ohm resistor).
It's possible too that you've already damaged the pin you were trying to use - might be worth testing it with an LED and suitable resistor.
I do not think so. It still works when I use the same pin for running a small motor.
I did notice something, though: when I connect the solenoid directly to the +5V power source and the ground of the Arduino, the solenoid moves "to the other end" in an instant.
I did notice something, though: when I connect the solenoid directly to the +5V power source and the ground of the Arduino, the solenoid moves "to the other end" in an instant.
That's expected behavior.
Thanks for the link. I have tried to implement it. It seems to "work better" [not sure whether you can really call it that way], since it actually does something in the transistor circuit now. However, it still only does something when turning the power on and off, i.e., plugging in and removing the USB cable; changing the signal to the base from HIGH to LOW, or vice versa, does nothing, though.
ArtificialUser:
However, it still only does something when turning the power on and off, i.e., plugging in and removing the USB cable; changing the signal to the base from HIGH to LOW, or vice versa, does nothing, though.
What does this mean?
It means you should post a schematic (or drawing) so we can see how you have things hooked up.
I have tried some more variations. I have also tried adding an external power supply with 4 AA 1.5V batteries. I am sure this should be enough for a small solenoid like this. But this did not work either. This is probably because the configuration itself is wrong. I still cannot figure out what is wrong with it, though.
It just does nothing. And I am sure the solenoid is not broken. My configuration must be wrong.