I have a bunch of houseplants all on a table that take awhile to water, so I combined some components of Adabox 003 (namely the feather esp8266) with a Darlington transister, solenoid valve and some irrigation supplies to make an automatic watering system that can be turned on by Adafruit IO!
This is the solenoid valve in question. I couldn't use the Adafruit one because it needs at least 6 psi to function, I believe, and I was just using a gravity fed system that provides less than that:
I whipped up my first ever proto board design using a Darlington transister as a switch. The esp8266 was hooked to the transistor's base pin, and when activated it switches the transistor on/off, either allowing or interrupting AC current provided by a barrel jack to flow from collector through the emitter of the transistor into ground. This switches on/off the solenoid valve, which is also wired into the AC portion of the transistor:
Everything was small enough to fit into an Altoids tin, which I suspect was purposefully design by adafruit when making the perma proto board. The long wires hook up to the solenoid:
I can switch the transistor on and off through adafruit IO. This is just a modified version of the Digital Output example for Adafruit IO. You'll need to make your own config file:
Code: Select all
#include "config.h"
/************************ Example Starts Here *******************************/
// define digital pin 4
#define SOLENOID_PIN 4
// set up the 'digital' feed
AdafruitIO_Feed *digital = io.feed("solenoid-trigger");
void setup() {
// set solenoid pin as a digital output
pinMode(SOLENOID_PIN, OUTPUT);
// start the serial connection
Serial.begin(115200);
// wait for serial monitor to open
while(! Serial);
// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();
// set up a message handler for the 'digital' feed.
// the handleMessage function (defined below)
// will be called whenever a message is
// received from adafruit io.
digital->onMessage(handleMessage);
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
}
void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
}
// this function is called whenever a 'digital' feed message
// is received from Adafruit IO. it was attached to
// the 'digital' feed in the setup() function above.
// it is meant to show on the serial monitor if a message is received,
// then send that message (High or Low) to the solenoid pin.
void handleMessage(AdafruitIO_Data *data) {
Serial.print("received <- ");
if(data->toPinLevel() == HIGH)
Serial.println("HIGH");
else
Serial.println("LOW");
// write the current state to the solenoid
digitalWrite(SOLENOID_PIN, data->toPinLevel());
}
So far its working great! But I have one question. The esp8266 is currently battery powered with a small 500 mAh battery, so I have to charge it whenever I want to use this system. This isn't great because I have to be there whenever I want to use it, which sorta defeats the purpose. I can charge the feather battery and function the esp8266 simultaneously when I plug the usb cable into my computer, but the esp8266 won't function if I plug the usb into something like a portable battery I use to charge my phone. Is there any way to get around this? How can I power the esp8266 continuously without constantly connecting it to my computer? My suspicion is I would I need a 'powered' usb port, as oppose to the portable cell phone charging battery, which is 'unpowered' but I'm not sure because I'm not very familiar with what a powered usb port is and how it differs from an unpowered usb source.
Hope y'all like my project and can help me out!