PushPull Solenoid with Arduino Nano

I’ll start with the link as that seems to be the first question:
https://www.circuito.io/static/reply/index.html?solutionId=5eb0918bd47e800030295740&solutionPath=storage.circuito.io

First of all I just found this site and it is wonderful! I’m not entirely new, but I stopped for a few years and now I’m back to learning this stuff. I just love it, but my old brain has trouble figuring out the code. This is great to help know what components are needed to make stuff happen and code to get it going.

I built this with circuito.io and I need modify the code slightly to work more simply. I got it to work, after much frustration, until I figured out I had to input the number 1 in the serial monitor to make it run the test. But what I what to do now is get rid of the serial input and just plug it in or turn it on and the solenoid will activate every 4 mins. I know how to change the time in miliseconds, I just don’t know how to eliminate the test part of this code and get it to work. Also, is this a bit of over kill with the components? I just simply need the solenoid to activate every 4 mins or so. And, can I power it up with just the USB or Battery, do I need Both? I would prefer just the USB. I do have a 3.0 volt solenoid that I think is strong enough to do what I want if that helps.

Thanks in advance for your help. I saw a similar post but it was using a Raspberry Pi or something. I couldn’t translate.
Mark

1 Like

Hi Mark

I’m not sure what time zone you’re in but didn’t want you to think this was being ignored. I’ll have a look after work today, explain the code and what you need to change to do what you want.

No worries, I’m in the eastern time zone in the USA. Thanks!

I think this is the circuit you created: https://www.circuito.io/app?components=10218,11015,11022

Disclaimer: I’m a beginner when it comes to electronics.

It looks to me like circuito is protecting your Arduino by providing a separate power source for the solenoid and controlling the power to the solenoid via the MOSFET. The maximum current draw of the Arduino is 200mA and the datasheet of the solenoid indicates it can draw 1.1A. That 1.1A could also exceed the USB power supply (depending on the USB you use):

0.5 A ( USB 2.0) 0.9 A ( USB 3.0) 1.5 A ( BC 1.2) 3 A ( USB -C) Up to 5 A ( PD )

To be safe, I would use what they’re suggesting. My next post will cover the code.

Great to see you’ve managed to download the code and upload it to your Arduino. Forgive me if I explain the obvious, just gloss over what you already know.

The setup method will be invoked once, when the Arduino gets powered up. If you’re not going to use the serial input or output, you can remove these lines:

    // Use the Serial Monitor to view printed messages
    Serial.begin(9600);
    while (!Serial) ; // wait for serial port to connect. Needed for native USB
    Serial.println("start");

You’ve said you don’t want a menu, so you can remove this line from the setup method as well:
menuOption = menu();

The loop method runs again and again as quickly as the Arduino is able to. You didn’t say how long the solenoid should activate for but the loop method can be replaced with this if you want it to activate for 1 second every 4 minutes:

void loop()
{
  digitalWrite(PULLPUSHSOLENOID_PIN_SIG, HIGH); //Turn Solenoid on.
  delay(1000);  //waits 1000 milliseconds (1 sec). change the value in the brackets (1000) for a longer or shorter delay in milliseconds.
  digitalWrite(PULLPUSHSOLENOID_PIN_SIG, LOW); //Turn Solenoid off.
  delay(1000 * 60 * 4); // waits 4 minutes
}

In summary, your entire program could be this simple:

#include "Arduino.h"

#define PULLPUSHSOLENOID_PIN_SIG	2

void setup()
{
  pinMode(PULLPUSHSOLENOID_PIN_SIG, OUTPUT);
}

void loop()
{
  digitalWrite(PULLPUSHSOLENOID_PIN_SIG, HIGH); //Turn Solenoid on.
  delay(1000);  //waits 1000 milliseconds (1 sec). change the value in the brackets (1000) for a longer or shorter delay in milliseconds.
  digitalWrite(PULLPUSHSOLENOID_PIN_SIG, LOW); //Turn Solenoid off.
  delay(1000 * 60 * 4); // waits 4 minutes
}

Great, I’ll try this when I get home. So from what I understand, I should leave the components as designed. I’ll need to keep both the usb and the battery. And I’ll reduce the code to your recommendation. Thanks for you help. I’ll let you know later how it works out!
Mark

Bernhard, Thanks a million!! This worked great. It did not like the formula (1000604) very well, so I just changed the value to 240000 and it uploaded to my Nano. It didn’t work at first, but I found my 9volt battery was low. New battery and it works just like it is supposed to. Thanks again for your timely help!
Mark

Brilliant news. So glad I could help. :smiley:

Bernhard, I have a small twist to this design and I want to make sure I don’t fry my Nano. I have discovered that the 5V solenoid is not strong enough to push the key that I need it to push. If I up-size the solenoid to a 12V or 24V solenoid, do I need to add anything to the design so that I don’t fry the board? I need to power the 24V with at least 2- 9V batteries. I don’t have a 12V solenoid but can order one if need be. I currently have it working with the 24V solenoid but I’m using a Power FET Switch Electronic Brick (NFET) to connect it, using it as a relay. But I need to power the NANO but I’m afraid to test it by connecting the 18volts to the bread board. Is the MOSFET protecting the board? Any additional help is appreciated. I’ve been searching for an answer online but can’t find anything that addresses my particular question. Thanks!!!

Hi Mark

Apologies for the delay, work is intense at the moment and after 10 hours at the screen I tend to want to get away from it at the end of the day.

The MOSFET is not protecting your Arduino from the power supply. The higher voltage should be driving the solenoid (in your case, but often a motor). The Arduino should have it’s own separate power supply which could be from the same source or stepped down to within the range of the Arduino. For a nano that’s between 7-12V.

So you should be okay using a 12v power supply for both, or use a step down power supply of you get a 24v solenoid.

Hope that helps and was not too late to save your nano.

No worries and no hurry. It’s the step-down from the same power supply that I don’t quite understand how to do. That is what I want to do and not add another battery to the project.

I just found the schematics for the Nano Board and it states that VIN 6-20 V input to the board. So I can safely power both the board and the solenoid with 18 volts. I actually simplified the design and am using the “Blink” sketch. I’m only using the Power FET Switch Electronic Brick (NFET) and using pin D13 to send the signal. If I work on it long enough, Sometimes I can figure it out on my own. But I bet there is a power regulator I can use to step-down the volts, for future reference. I probably need to figure that one out as I may need to apply more volts to the 24V solenoid to give it more strength, if this is still not enough.

I started replying earlier but work events took over.

This (link below) is an example of a voltage step down component. Each one has different characteristics and voltage ranges so it’s best to search about for what you need.

https://www.ti.com/product/TPS53119

Hope that helps

Great! Thanks. I was just looking at “Buck transformers” but was not sure if that was what I needed. I’ll look into these and see if I can make sense of it. Thanks again, for all your help.

It’s even more simple than that. I just used a L7805CV Positive voltage regulator IC, to separate 5.0 volts to go to the Nano and I even added another 9V battery for a total of 27V incoming (22V actual) to power the 24V solenoid. Now I can use just two batteries in series to power the solenoid and split off 5V for the controller. If the solenoid needs more power to push the button, I can safely add another battery. If I can use a smaller 12V solenoid I don’t have to use the voltage regulator. I’ve learned something new today, with your help!! Thanks!