Solenoid pushing/pulling platform

Hi,

my overall goal is to make a platform controlled by 2 solenoids (product: https://www.adafruit.com/products/412) on a timer (one pushes, holds for 5min pulls back, and then another pushes and holds, comes back) all controlled by one button when turned on. My solenoid uses a 12V DC external wall converter plugged into the barrel jack.

However, im having an issue with the large 12V solenoid I am using. Im using this schematic i’ve drawn up and attached here. It works completely fine when i use a USB cable for 5V on a tiny 5V solenoid (product: Mini Push-Pull Solenoid - 5V : ID 2776 : $4.95 : Adafruit Industries, Unique & fun DIY electronics and kits). the solenoid pushes out when i hit the button, and comes back when i hit the button again. works like a charm. But when i try using my big 12V solenoid with the external power supply, its like the button doesnt fully function. I press it, the solenoid goes out sometimes, or it doesnt come back, or it flickers in and out. its not functioning the right way. Any ideas? my guess is that im using wrong resistors or something but im not sure whats going on.

DISCLAIMER: my schematic is not drawn perfectly. Im using a TIP120 transistor, 1N004 diode, 10k resistor for the button, 1k resistor for the solenoid, and NO 9V BATTERY. either USB or 12V DC depending on the size solenoid. THis works good for the 5V small one, not the 12V big one.

// constants won’t change. They’re used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int solenoidPin = 13; // the number of the LED pin

// Variables will change:
int solenoidState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin

// the following variables are long’s because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 20; // the debounce time; increase if the output flickers

void setup() {
pinMode(buttonPin, INPUT);
pinMode(solenoidPin, OUTPUT);

// set initial LED state
digitalWrite(solenoidPin, solenoidState);
}

void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);

// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you’ve waited
// long enough since the last press to ignore any noise:

// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it’s been there for longer
// than the debounce delay, so take it as the actual current state:

// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;

// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
solenoidState = !solenoidState;
}
}
}

// set the LED:
digitalWrite(solenoidPin, solenoidState);

// save the reading. Next time through the loop,
// it’ll be the lastButtonState:
lastButtonState = reading;
}

But when i try using my big 12V solenoid

Which draws how much current exactly? And how much current can your 12V supply give?

We like schematics here not physical layout diagrams mainly because of this sort of rubbish:-

Im using a TIP120 transistor, 1N004 diode, 10k resistor for the button, 1k resistor for the solenoid, and NO 9V BATTERY. either USB or 12V DC depending on the size solenoid.

So what anyone has to do is to turn that layout into a schematic in their head and apply all the corrections that you couldn't bother to do.

Much much better is a pen and paper schematic photographed and posted.

Did you know powering stuff from the Vin pin is a bad idea because it has to go through a diode first with a 1A rating.

Chances are very high that the big solenoid is heavily overloading the power supply you are using for it.

As for "schematics" what you have shown is a wiring diagram and it is suitable only for showing someone unskilled in the art which wire goes where, not for figuring out how it works .
You will find life much simpler if you lay out your "elementary diagram" or "schematic" (the name depends on your pedigree) without regard to the physical location of components nor wires. Just organize it so the flow is from left to right and lines connect points which go to-gether. And name the points (Ard 4 for Arduino pin 4, PB for pushbutton, etc.)

Making comprehensible elementaries or schematics is a bit of an art but the ultimate objective is to carry usable information to the reader. I hope I haven't discouraged you.

rather than to the arduino, correct?

Yes correct. BUT you still haven't said how much current the big solenoid takes. This is vital. It could be that it is too much for the transistor with a 1K base or too much for the bread board connections.

Hi,
From the adafruit site,

You will need a fairly good power supply to drive a solenoid, as a lot of current will rush into the solenoid to charge up the electro-magnet, about 100mA, so don't try to power it with a 9V battery!

Very disappointed with adafruit, they tell you everything except coil resistance and actual current.
Sorry hidden 100 Ohms.
I'm not sure what sort of performance you are looking for in a 24V coil, at a reduced voltage.

As requested, a proper schematic is the only way we can tell how your project is assembled, a picture of your project so we can see you layout would be helpful too.

Thanks... Tom... :slight_smile:

I was unable to get the current reading through the solenoid. To my knowledge, you need to break the circuit in order to get the current reading, which i did but wasnt able to come up with anything so any guidance on that will be extremely appreciated.

I uploaded the schematic i have in this comment. And to Tom, I uploaded a diagram of my circuitry to show its layout was uploaded in my original post. Thanks for all the help

Hi,
You can remove the 10K between the switch and gnd, just connect the switch to gnd and the digital input, and in setup turn on PULL_UP resistors.
Your 10K does not do anything special.
In your circuit you are switching LOW when you close the switch.

If you want to switch HIGH when closing the switch.

  • Connect the switch from 5V to digital input.
  • Connect the 10K from digital input to GND

Tom... :slight_smile:

What's the amp and voltage of your external power supply? I drive 12v Solenoid via Arduino but I am using a relay module to control the solenoid.

Hi,
OPs last circuit diagram.
1985b0106a52db32ac3776dc651058f13a935e8e.jpg

Tom… :slight_smile:

thanks! ill try it out and let you know how it goes. By the way, would you recommend me using relays for my overall project if i have to use 2 solenoids connected with one button?

sarouje:
What's the amp and voltage of your external power supply? I drive 12v Solenoid via Arduino but I am using a relay module to control the solenoid.

Another thing is that you should replace the diode 1N4004 for 1N4007 that's HV (1000V) to prevent the flyback efect that may cause some interference on your arduino!
As sarouje said, I also recommend you to use a relay to control your selonoid with a separated power supply from your arduino to the selonoid!

rmartins:
Another thing is that you should replace the diode 1N4004 for 1N4007 that’s HV (1000V) to prevent the flyback efect that may cause some interference on your arduino!
As sarouje said, I also recommend you to use a relay to control your selonoid with a separated power supply from your arduino to the selonoid!

my power supply voltage is 12V and 2A. Would using a relay module help my solenoid push out? I used what Tom said with a pull up resistor input but the solenoid does not push with full force enough to move a very lightweight platform back and forth. Would the relay and separate power supply to the breadboard help push out with full force?

armandave:
my power supply voltage is 12V and 2A. Would using a relay module help my solenoid push out? I used what Tom said with a pull up resistor input but the solenoid does not push with full force enough to move a very lightweight platform back and forth. Would the relay and separate power supply to the breadboard help push out with full force?

I'm sure that's will work (if you selonoid spec is 12V / 2A not grater than your power supply can provide), a relay will handle it without problem! I recommend you to use the relays board that comes with optocoupler IC like this:

I see absolutely no need to go and use a relay. And lots of reasons to avoid them.

Grumpy_Mike:
I see absolutely no need to go and use a relay. And lots of reasons to avoid them.

What would you suggest then Grumpy_Mike? Ive seen sources using relays, and sources not using relays that both work. I'd prefer not to use one, too. I've uploaded the schematics like you've asked. If you do believe that the current is too much for the transistor with 1k base, what do you recommend swapping it out for?

First I would try with a 220R resistor. Then I would use a logic level FET. There seems to be no reason why it should not work at that power. Does it work correctly if you connect it directly to the power supply?

@Mike I really dont want to drag away from the topic, can you please elaborate why we should not use relays in this scenario. I am using one now to drive a solenoid.

In my new version I am thinking of not to use relay to drive solenoid and moving to ULN2083A, I have to drive several 12v motors, 2 peristaltic pumps and solenoid.

The same ULN2803A will be driving a relay too but to on/off some AC devices.

Your explanation will be helpful to decide and correct if I made a mistake here.

Grumpy_Mike:
First I would try with a 220R resistor. Then I would use a logic level FET. There seems to be no reason why it should not work at that power. Does it work correctly if you connect it directly to the power supply?

I tried it out and still no good. I used the 220 ohm and P30N06LE MOSFET transistor. Here is what happens: the solenoid pushes out when plugged in with the power source (i have initial state of solenoid as HIGH). However, the pressing the button does not pull back the solenoid. it just stays out until i turn off the arduino. Also, it does not work correctly if i power my arduino directly from the barrel jack and wires to the board.

I cant even say my parts are faulty either because they just came in the mail.
any other suggestions will be extremely appreciated it for this project, thanks

update, so it seems like i required a 24v source. a sticker on the solenoid said use that along with 96ohm resistor. I did. the solenoid worked perfectly fine with a blink example code. then i moved over to the debouncing button switch code i have to make the solenoid go out wiht one push of button, and come back with another push. it did it once, and then it seemed like the arduino fried and unusable now. i thought the diode was supposed to protect the arduino from the pull back of the solenoid?

Grumpy_Mike:
I see absolutely no need to go and use a relay. And lots of reasons to avoid them.

I completely agree, but it's depend of what you are dealing with ! Some cases, we have no choice!
Some cases that the "mechanical" relay should not be used, but you can't deal with, you may use a "Solid-State" relay!