# Driving a Bi-Stable solenoid

#### pavanbabut

##### Member
Hello all,

My first project trying to use a bi-stable solenoid. The solenoid itself is not that high torque device so no high power requirements here.

Solenoid specs:
Operating voltage: 5VDC
Coil resistance: 30Ω ~ 0.166mA
CW/CCW pulse timing: 50ms/100ms (min/max)

The device this is going to work along with has a dedicated TTL (high) input to turn it ON and is powered ON as long as the TTL is high, would like to use this same TTL to activate this solenoid either CW/CCW and then do the reverse when the TTL is low. A 5VDC 0.2A power supply is available to drive the solenoid from this device.

Have been looking at some threads discussing H-Bridges to work with latching solenoids, is this still the way to go these days and/or is there a better way in this situaiton?

Any suggestions?

thanks

#### Pommie

##### Well-Known Member
Do you have a link to this solenoid?

Mike.

#### pavanbabut

##### Member
I hope its OK to post it here as it says 'proprietary document'. As for the pulse timing requirement, they mentioned it in an email.

#### Attachments

• 111.3 KB Views: 10

#### Pommie

##### Well-Known Member
Looks like you'll need a H-bridge but not a high power one. Something like the mp6513. The TTL input being high makes no sense. Only outputs can be high/low. What is the actual TTL device?

Mike.

#### pavanbabut

##### Member
Maybe I should rephrase it, lets say it is a +5VDC signal coming out of an Arduino board digital pins going through a buffer. I use this to power On a device which turns On when it receives a high input and stays On as long as this input is high on one of its controlling pins. Would like to use this same signal to control the solenoid as well as they both are in the same path in the physical device.

Last edited:

#### Pommie

##### Well-Known Member
Do you have two spare pins on the Arduino and the source code?

Mike.

#### KeepItSimpleStupid

##### Well-Known Member
Most of the h-bridges need a NOT enable and a Direction signal. Not enable was used because TTL typically floats high and that woul turn the driver off. Your H-bridge would have to be MOSFET based becase of the lower voltage drop.

Bi-stable is good because all it needs is a pulse. With some solenoids you have to reduce the power when in hold mode/

There are some drivers that have 3 inputs to allow coast and brake.

#### pavanbabut

##### Member
I have spare 8pins on my arduino. At the end I need to control 4 of these solenoids independently.

#### Pommie

##### Well-Known Member
I suggest two L298 dual H-bridge driver modules. Each module can drive 2 solenoids using 4 inputs. Are you able to change the source code to accommodate these?

Mike.

#### pavanbabut

##### Member
I can update the arduino source code to our needs, so not a problem there and I still have more than enough space left to add more code on Mega board. If you can show me a sample on how to drive one, I can probably adapt it to multiple ones. If it makes things easy, I can even decouple driving solenoid from coupling it to the power On TTL of other device. I can implement driving solenoids completely independent.

#### Pommie

##### Well-Known Member
Here's some (untested) code that I think should work.
Code:
/* The pin numbers that the
*  driver boards are connected
*/
uint8_t pins[8] = {1,2,3,4,5,6,7,8};
uint32_t tick[4];

void turnOn(uint8_t num,uint8_t dir){
tick[num]=millis();                       //store time switched on
digitalWrite(pins[num*2],LOW);             //ensure both outputs are low
digitalWrite(pins[num*2+1],LOW);
if(dir==1){
digitalWrite(pins[num*2],HIGH);        //move CW
}else{
digitalWrite(pins[num*2+1],HIGH);      //move CCW
}
}

void turnOff(){
for(uint8_t i=0;i<4;i++){
if(tick[i]>0){                       //is this output on?
if((millis()-tick)>=75){         //has it been on for 75mS?
digitalWrite(pins[i*2],LOW);  //turn it off
digitalWrite(pins[i*2+1],LOW);
tick[i]=0;                   //clear time
}
}
}
}
You will need to set pinMode for the 8 pins and fill in the correct values in the pin array and clear the tick array in setup.
Just continually call the turnOff code from the loop and to move a solenoid call turnOn with num=the number of the solenoid and dir to +1 or 255 (-1) for the direction.

HTH

Mike.
Edit corrected typo in code.

Last edited:

#### pavanbabut

##### Member
Great thanks will give this a try when I get my hands on couple of those boards. BTW, when you say " continually call the turnOff code from the loop", does it really need to be run all the time on Arduino program loop even when the solenoid if in "OFF" state?