The end goal is to control this 12V, 10W solenoid valve via bluetooth, activating it for a few seconds max. (Solenoid catalog page screenshot at bottom).
Hardware:
Arduino Uno
Aforementioned solenoid valve, 12VDC version (6100-1B00A-AAA2B)
Resistors:
** 1 kΩ between UNO output and MOSFET gate
** 10 kΩ from MOSFET gate to ground (which is to keep the MOSFET from activating unexpectedly, though I don't understand why)
** 10 kΩ from UNO output to ground (can't remember why though...)
** 1 kΩ and 2kΩ to create voltage divider between UNO TX and Bluetooth RX (as explained here)
Very basic code for prototype testing is below. If there are any errors there, I'm all ears. Mainly, I'm looking for feedback on the hardware and wiring. Will this setup work? All of this is going to be rigged up on a testing apparatus, where the valve releases pressurized gas through a nozzle. Ultimately, there will be two solenoids, each connected to two nozzles, to control the spin of the apparatus. I hope everything is clear.
Many thanks for any help!
Milan
char val; //variable to receive data from Serial port
int valve = 2; //Output pin 2
void setup() {
pinMode(valve = 2, OUTPUT);
digitalWrite(valve, LOW);
Serial.begin(38400); //I've also seen 9600
}
void loop() {
if ( Serial.available() ) //Looking for signal from Bluetooth HC-05
{
;
}
val = Serial.read();
if ( val == 'a' )
{
digitalWrite(valve = 2, HIGH); //send 5V to MOSFET, activate-open solenoid valve
delay(500);
digitalWrite(ledpin, LOW); //send 0V to MOSFET, deactive-close solenoid valve
}
}
You need only the 10K from Uno pin to ground. You should remove the other 10K.
Without either of the 10K, while starting up, the Uno pin will float and so will the MOSFET gate. This can cause the MOSFET to switch partially on and conduct current. Because it is only partially switched on, it's resistance will be higher than it should be. This can result in a high heat dissipation, making the MOSFET get hot and potentially damaging it. Also the solenoid might partially activate.
The 10K on the Uno pin will ensure the MOSFET stays off while the Uno starts up.
Putting the 10K on the MOSFET gate is the wrong place to have it. It would still prevent the gate floating, but when the MOSFET is activated, the 1K and 10K would form a voltage divider, resulting in a lower voltage on the gate. This lower voltage could increase the mosfet's resistance, and, again, create some unwanted heat.
Thank you. I see 1000V max peak reverse voltage instead of 100V and higher I_FSM current ratings. I imagine those are the most important differences.
Thanks. Logic level means specifically designed to work with 5V signal, right?
Appreciated. I think I was looking at different diagrams showing the same thing in different ways. I also didn't have a great sense of what "floating" means, but found this good explanation. Your description also makes good sense.
I see, thank you. It's only before void setup that we set the value of the pin. Thereafter, we only need to refer to it by name. This tutorial really led me astray.
Was braindead and copied from that same tutorial. A quick compile also showed my error.
Instead it should be:
void loop() {
if ( Serial.available() )
{
val = Serial.read();
}
I made the corrections to the wiring and code, and also realized that using the more compact buck converter (LM2576 datasheet) would be easier for prototyping. So the first diagram shows that. Pretty confident I got it right.
I made another layout with the 2nd solenoid (and MOSFET, diode, resistors...). If anything looks off with that or the code, let me know.
Random questions: do people ever prefer an SVG over a JPG, so you can zoom in? And this Cirkit Designer seems pretty intuitive. Anyone else tried it out, or have other recommendations?
char val; //variable to receive data from Serial port
int valve = 2; //Output pin 2
int valve2 = 4; //Output to 2nd solenoid valve from pin 4
void setup() {
pinMode(valve, OUTPUT);
pinMode(valve2, OUTPUT);
digitalWrite(valve, LOW);
digitalWrite(valve2, LOW);
Serial.begin(38400);
}
void loop() {
if ( Serial.available() > 0) //Looking for signal from Bluetooth HC-05
{
val = Serial.read();
}
if ( val == 'a' ) //If we sent 'a' from our phone controller
{
digitalWrite(valve, HIGH); //send 5V to MOSFET, activate-open solenoid valve
delay(500);
digitalWrite(valve, LOW); //send 0V to MOSFET, deactive-close solenoid valve
}
if ( val == 'b' ) //If we sent 'b' from our phone controller
{
digitalWrite(valve2, HIGH); //send 5V to 2nd MOSFET, activate-open 2nd solenoid valve
delay(500);
digitalWrite(valve2, LOW); //send 0V to 2nd MOSFET, deactive-close 2nd solenoid valve
}
}