Yes that looks fine. Any diode should do typically a rectifier diode 1N4001 is used here.
R1 I would put at 3K3 rather than 1K but it is not critical. Some people would recommend a 10K from the base to ground as well.
Finally I would put a large capacitor across the 12V supply, something in excess of 220uF just to take out some of the current surge.
You say mosfets but you have drawn transistors?
They are not logic level FETs but at 5V gate voltage they are in the 1R8 to 5R3 turn on range so while they are on they are not hard on. Look for a FET that says 'Logic level FTE' for the best results but these will do for what you want them for.
A final note: if you do use the 2N7000 instead of a transistor (not a bad idea) then the 10k resistor from gate to source is highly recommended else the gate will float when the Arduino is unpowered or in reset. That is undesirable.
--
The Quick Shield: breakout all 28 pins to quick-connect terminals
Ok, 3.3K resistors instead of 1K, a 10K resistor from base to ground.
I'm not entirely sure of the difference between a regular transistor, a field effect transistor and a MOSFET, do they have different symbols? I Can't find a "logic level" FET on RS that isn't a MOSFET, but you say the MOSFET I've found previously should be ok?
When you say I need a 220uF or greater capacitor across the 12V supply, does that mean the capacitor going from the 12V to the ground, something like this?
Also, what voltage should the capacitor have? I've found one that has a spec of 16V, would that be OK?
does that mean the capacitor going from the 12V to the ground,
Yes just like you drew.
Also, what voltage should the capacitor have
The voltage rating of the capacitor should be greater than the voltage you are going to use it at. As a rule 80% is a good rating so for use at 12V then 16V or greater rating is what you want.
If you are using a FET then 1K is fine but put an additional resistor from the gate to ground just to keep things turned off when the 12V is connected but the arduino power is not.
A mosfet is a particular kind of fet. Instead of flowing current from base to emitter to turn it on (like a bipolar transistor, which is what you have drawn), you apply a voltage between the gate and the source (which is connected to ground for an n-channel mosfet in the circuit you've drawn). You really, really want to make sure that you apply enough voltage to the mosfet to turn it all the way on; otherwise, it behaves like a voltage controlled resistor and gets really hot. The pull-down resistor on the gate will turn it solidly off when unpowered. A 16V cap is a little lower voltage than I'd use, but will probably work well enough.
Eep! Ok, I see, well, the application is to bring up "shapes" made out of a combination of the solenoids poking up through a surface. It shouldn't be more than 1 operation per second, but i guess while the solenoids are energized they form the display, so the MOSFET would be allowing current through all the time while the display was being shown (instead of in quick striking pulses like the glokenspiel) if this is a problem, should I use a different FET instead of the 2N7000?
The MOSFET will not be dissipating 1.2W. It is the solenoid dissipating 1.2W. This means at 12V the solenoid is allowing about 100mA of current to flow (12V * 0.1A --> 1.2W).
At 100mA the on-resistance of the 2N7000 (about 5ohms worst case) means the 2N7000 should dissipate 0.10.15=50mW.
Hi everyone, I have a quick question, I've set up the circuit as described for just one solenoid using a 12V 1.25A power supply. It seems to work in principle, except when I set the pin high the amount the solenoid moves is so tiny that it can't be seen, just felt as a light pressure. Does anyone know whet i might be doing wrong? I'm sure it's something really simple I'm missing...
Here's my code
/*
for solenoids
moves a solenoid and lights an led when a button is pressed
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* see pdf cirrcuit for solenoids, attached to pin 8 in this example
*/
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int solPin1 = 8; // the number of the solenoid pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output
pinMode(solPin1, OUTPUT); // initialize the solenoid pin as an output
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input:
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); //turn on LED
digitalWrite(solPin1, HIGH); //tell solenoid to turn on
Serial.println("button pressed down");
}
else {
digitalWrite(ledPin, LOW); // turn LED off
digitalWrite(solPin1, LOW); //tell solenoid to turn off
Serial.println("button NOT pressed down");
}
}
Ok, when the wire that was going to pin 8 of the arduino is connected to the 12V power supply instead it causes the solenoid to become pulled in fully, fixed in place, instead of being free to move. Is that what should happen? What I want is for the solenoid to push up and stay there while the button is pressed.
Ok I'm sorry, i attached the lead that was in pin 8 to 5V and nothing happened at all. All the grounds are attached together. I thought 5V wasn't enough to drive the solenoid?
Ah! I'm sorry, I'm an idiot, I'd not turned on the 12V supply, connecting the lead that was in pin 8 to 5V does cause the solenoid to pull in, i'm mistaken. When the button is pressed in the original configuration the solenoid is pulled in also.
I thought this meant that it would "push" upwards like a pointing finger when powered. Looks like it just pulls the bar all the way inside. Or am i just not understanding?
...perhaps if i turn it upside down and use the skinny end...
Ok, i'm officially overcoming a serious case of noob-itis. Apologies for my stupid questions, It all seems to be working, I'd just never used solenoids before!
Thank you so much for your help! I hadn't realized how the solenoids worked. Now I need to get the whole thing soldered up and into a rig. I was amazed the solenoid actually worked with my circuit first time, even though i thought it didn't!