Bistable Solenoid Valve

I'm making a project about a gardening system with the help of bistable solenoid valve and a microcontroller. I have use regular solenoid valve before with the help of a relay module but I now I want to try it with a bistable/latching solenoid because they don't use current while the valve is open so I can have a low power consumption setup at the garden with batteries for a long time.

My setup is a ATTiny13a MCU, 1N4007 Diode, 4xAA Alkaline batteries, MX1058 or MX1616 motor controller and a bistable solenoid valve. My setup diagram is included.


I'm using the diode to reduce voltage input of the MCU so ATTiny13a can run under 5.5V.
The solenoid valve specification is 3.6 to 6V, 9 ohm coil resistance and a pulse width of 30ms.

My code is

 // Arduino Code for ATTiny13a || 
 // Bistable Solenoid Valve || 30ms impulse || 9 ohms coil resistance || 3.6 to 6 Volts 
 // Motor Controller MX1508/MX1616 Module H-Bridge

const int SolenoidA1 = 1; // Set Digital Pin 0 on Solenoid pin
const int SolenoidA2 = 2; // Set Digital Pin 1 on Solenoid pin

void setup()
{
  pinMode(SolenoidA1,OUTPUT);    // Set the Digital Pin 0 as an output 
  pinMode(SolenoidA2,OUTPUT);    // Set the Digital Pin 1 as an output  
  digitalWrite(SolenoidA1, LOW); // SolenoidA1 (Open Valve) - initially off
  digitalWrite(SolenoidA2,HIGH); // Close the solenoid valve
  delay(30);                     // Impulse delay for the bistable solenoid valve
  digitalWrite(SolenoidA2,LOW);  // When project is starting
}
void loop()
{
  digitalWrite(SolenoidA1,HIGH); // Set HIGH for pin A1 to open the valve
  delay(30);                     // Impulse delay for the bistable solenoid valve
  digitalWrite(SolenoidA1,LOW);  // Set LOW for pin A1 to maintain the valve
  delay(10000);                  // Wait for 10 seconds and keep the valve open
  digitalWrite(SolenoidA2,HIGH); // Set HIGH for pin A2 to close the valve
  delay(30);                     // Impulse delay for the bistable solenoid valve
  digitalWrite(SolenoidA2,LOW);  // Set LOW for pin A2 to maintain the valve
  delay(20000);                  // Wait for 20 seconds and keep the valve closed
}

Is my hardware wiring setup and my code is correct or not? The code is just a demo and if you guys think is correct then I can modify the code with millis and include sleep. Main thing is the pulse width time, should I really have that 30ms between the valve state? or change the impulse delay to shorter or longer?. I have never used a bistable solenoid so I really don't know how to run it. So I did not experiment too much and afraid that it might burn the solenoid. Also I'm using a diode to drop voltage for the MCU, is using a voltage regulator like AMS1117 is better?

If the solenoid specs give 30ms, go with that or slightly more, like 35ms.
Your wiring looks ok to me, but for the battery life, I would try with 3AA without burning energy with diode. Solenoid specs give minimum voltage of 3.6V and your motor driver shouldn't have huge voltage drop, so it might work well.

Alright, I'll change it 35ms. All I'm concerned is that will it burn if I give it too much time interval.

For battery, I think 3xAA is good or maybe use a 18650 3.7V battery.

You don't burn it because of few ms more. But be careful with your code and wiring while testing. If you place that delay(20000) on wrong line, some damage might occur...

3AA is easier, with 18650 you absolutely need over discharge protection.

You're right, AA is easier and cheaper. If you're okay with my code then I'll start testing it.

1 Like

My concern is I see nothing in your code to determine the actual position of your bi-stable valve after recovering from a power failure. Is that ok with your project?

Actually I did, inside void setup() the valve will close after a power failure or a reset.

Are you sure about the pin wiring? Shouldn’t you be using physical pins 5 and 6, not 6 and 7? Easy to test with leds.

Wait, circuit shows 6 & 7 means MCU pins 1 & 2. Isn't it correct?

I tried the setup and so far so good, everything works like expected. Just hope it stays that way.

Running temporarily with 18650 and solenoid works properly.

Good.
Be aware what I said about protection. Also, when 18650 is on the lower side of charge level <3.7V, the voltage might be too low for solenoid.
If you need rechargeable battery option, use 4AA NiMh

I understand, I used 18650 temporarily to just test the setup if it works or not.

I tested power consumption at idle with 9.6MHz internal clock, 3xAA Zinc Carbon is 4.55V and 3.6mA. I'll have to use low power mode or sleep to get under 100µA or maybe use a tiny solar panel with rechargeable NiMH.

Try with low power/sleep approach.

OK, if it works then you’re good. I don’t have the Tiny13 but on my Tiny 45 used pins 5 and 6.