I'm driving a relay through a transistor , which is driving a small 5v solenoid (Solenoid - 5V (Small) - ROB-11015 - SparkFun Electronics). I'm powering the solenoid with a 4.5v battery separately from the arduino, which is powered by a USB cable. Do I need a diode for the solenoid? And if I need one , is the 1N4001 good for this purpose? Finally, how will I connect the diode?
A 1N4001 will be fine. Connect it across the motor leads with the Cathode to the +5V supply (backwards). I would suggest using an n-channel MOSFET such as this N-Channel MOSFET 60V 30A - COM-10213 - SparkFun Electronics if the solenoid draws alot of current. Here's an example of a simple driver. Maybe some capacitor filtering across the supply as well.
Thank you very much!
I found a 5v 2A psp power supply, and I managed to control the solenoid using that instead of the battery. Also, why do I need filtering with a cap ?
Arduinoisawesome:
And what can these spikes do to the arduino ?
Well a big inductive spike vaporises parts of every chip on the board I'd guess.... Depends on the size of the coil and how much magnetic energy is has when you try and switch it off. So yes you always need protection when switching current to solenoids or non-trivial inductors.
Thank you pwillard and MarkT, very informative posts.
I have one more question. So, is the 1N4001 diode (without a capacitor) enough to protect my arduino from the inductive spikes that the small 5 volt solenoid creates? Also, what capacitor value would be ok for filtering the noise?
A power rectifier like the 1N4001 is fine, if not a bit of overkill for a small 5V relay. Technically, you could get by with a small signal diode like a 1N4148 and be just fine.
As for Capacitors: it's all spelled out in the link already provided. De-coupling
Technically, you could get by with a small signal diode like a 1N4148 and be just fine.
A 1N4148 will be under-rated. According to the datasheet, and part #, the solenoid has a DC resistance of 4.5 ohms. With 5 volts, it will draw 1.1 amps. A 1N4148 is only rated for 200mA continuous with a 450mA surge rating. I would stick with the 1N4001.
A 1N4148 is only rated for 200mA continuous with a 450mA surge rating.
Yes but the diode does not have to take the continuous forward current of the relay it just has to cope with the back EMF when the voltage is removed. This will cause only a small spike which is likely to be within the current surge rating of the diode, especially considering the duty cycle involved. There are duty cycle considerations in that 450mA rating.