ESP8266, Uno and solar to control solenoid

Greetings all, First, I'm of course, new. While I've been playing a lot with the Arduino (and rPi and others), I really don't have a lot (read: any) experience. I've spent a great deal of time trying to learn and have just about every book. So here's my project: I'd like to take a ESP8266 module (I really would like to keep this wifi), an Uno (if need be, I understand the 8266 might be able to handle it all), and a solar panel/li-po battery combo to control a simple hose bib solenoid. Where I live in NorCal, you get fined for overwatering and I simply keep forgetting to shut off the water to my veggie boxes. I've got the modules, the Uno, the solenoid (12v), and I'm getting (if I'm pointed that way) the SparkFun Sunny Buddy and one of their large solar panels. I've also got a couple 2000ma batteries. What I DON'T have is any clue how this all goes together. Trust me, I've read what I can but so much of what is out there makes assumptions about the readers level of knowledge. Even the Sunny Buddy hook up tutorial glosses over how to hook up "the load" and whether the battery will power 'the load' when there's no sun. (This last part seems obvious to me, yes, it would. But the device is listed as a battery charger, so there's some question. Several commenters to the site have asked the same question, with no answers for months!) My questions (right now) aren't around the programming, I think I can get through that. How to hook it all up. I'm imagining the Sunny Buddy (SB from now on) is going to have the solar panel coming in, the battery going out and the "load" being the Uno. I've seen the wiring there, so I think I can do that. (Never soldered, either. I learn fast.) But what about the solenoid? A motor controller board? How does that get powered? If my suggestions for the power controller (the SB) is incorrect, I'm open to all suggestions.

Like I said, I'd really like to keep three aspects of the project - wifi cause I have other ideas I'd like to do with 8266, uno (or the wifi module itself, I'm not picky) and solar. BTW, I know there's simpler solutions - like a sprinkler controller, but I'll not learn anything there.

Thanks so much in advance.

MadProphet: I understand the 8266 might be able to handle it all

Indeed, it can easily do that. Actually, it is a SOC (System On a Chip) with a faster processor and more memory than a regular Arduino, it can even run a web server, host a web page and images etc. You can program it like a normal Arduino if you use Ivan Grokhotkov's ESP8266 Arduino core. You can control its I/O using the familiar digitalRead/Write functions, for example.

As for power, I'd go with a 12V SLA (Sealed Lead Acid) battery (like a car battery). Why? 1. You've got your 12V for the solenoid, 2. They are much easier to charge from a solar panel than Li-Ion batteries. Then just use a step-down converter to get 3.3V for the ESP8266.

How you drive the solenoid, depends on its current draw: if it's under 0.5A, you might get away with a simple NPN (power)transistor. If it's higher, I'd go for a MOSFET, you'll then probably also need 2 extra transistor, to drive the MOSFET with 12V (the 3.3V from the ESP8266 won't be enough to turn on the FET completely, unless you use a low gate voltage, logic level MOSFET). You could also use a relay. Make sure however, that you use a flyback diode, since the solenoid is an inductive load, and will produce high voltages when suddenly turned off, that may damage your transistor, or cause sparks in the relay.

Most MOSFET drivers you'll find online are badly designed, they're just simple emitter followers, that keep the voltage the same as the input, which is not what you want. Other designs invert the signal, meaning that they turn on when nothing is connected, and turn off when you apply 3.3V. This is absolutely not what you want, you want your valve closed if your ESP8266 crashes! Take a look at my article on driving loads with Arduino.

Good luck! Pieter

Thanks for the quick - and complete - reply. I've been doing a lot of reading today and that's the best solution I've read.

I've seen plenty of 12v solar controllers, so I should be able to use one of those for the panel to battery connection, then go with the step down for the ESP8266.

The solenoid I'm using is from Sparkfun and is one of the 'normally closed' models. I've already left the water on twice this year in excess of a full day. $51 fine each time. So this is going to save me money!!

Thanks again for the suggestion.

OK, Pieter, I've bought a 10w solar panel, a MooHoo solar controller - it has both 5v and 12v simultaneous outputs, so I believe I have separate power that way to each device (solenoid and ESP8266). I also bought a Huzzah Feather instead of just the 8266 module I have. Looks like programming will be simpler and since power can be supplied through the USB (which is how the solar controller outputs 5v), seems like the power on that side is covered.

So, I'm seeing it as huzzah, breadboard, the MOSFET's, the solenoid. My one question (till the parts are all in hand) is do I wire the 12v output from the controller where ground goes to the breadboard and positive to the solenoid? Nothing needed between those parts?

I think I've got or can find, the setup on the board once I understand this. I'm not just asking for solutions without doing a LOT of research, but finding an answer that's both simple enough for me to understand and specific enough to my situation to feel good about it I've not found.

Thanks again for any suggestions.

My one question (till the parts are all in hand) is do I wire the 12v output from the controller where ground goes to the breadboard and positive to the solenoid? Nothing needed between those parts?

  • Ground from the charge controller goes to ground of the breadboard, and ground of the ESP.
  • 12V of the charge controller goes to one side of the solenoid.
  • The second terminal of the solenoid goes to the drain of the N-Channel MOSFET (see schematic below)
  • The source of the MOSFET goes to ground.
  • The 5V output of the charge controller goes to a 3.3V (LDO) voltage regulator.
  • The ground of the voltage regulator goes to the ground of the breadboard and the charge controller (all grounds go together)
  • The 3.3V output of the voltage regulator goes to Vcc of the ESP.

If you’re using a 3.3V logic level MOSFET:

(power supply is the 12V output of the charge controller, in this case)

If you’re using a ‘normal’ MOSFET:

For more info, read the article I linked in my previous post.

Edit: the second diagram shows a resistive load, if you use a solenoid (inductive), you need a flyback diode as well (just like in the first one).