Wifi controlled solenoid valve

Hi

Files are here (fritzing breadboard sketch and code also below)

I’m a relative newby, and have embarked on a project for my dad to use on his Farm. I have no doubt I haven’t done things perfectly (and possibly even some things wrong) so I thought I’d share my project and see if anyone has any improvements.

Background: we’ve just installed a bore pump which has a pressure switch to turn itself off once the tank it pumps into is full and the inlet float valve closes. As our tank overflows into a dam he doesn’t want to install the float valve.

Instead, taking advantage of the pipe running straight past the house I decided to put a Solenoid valve controlled via a nodemcu. Although just within the wifi signal of the house, we didn’t want to run power out to the valve and hence has been designed to run off solar/battery. Because of this we changed out the usual 24vac solenoid with a 12vdc latching solenoid (pulse required to open valve and reverse polarity pulse required to close. I.e no constant power required to keep valve open).

Specifics:
Solar Panel
6ah SLA battery
Solar controller
12v adjustable buck step down (to 5V)

5V 2 channel relay board with selectable low/high activate. I’ve gone with LOW to activate relay. The two relays are wired to reverse the polarity for open/close commands.

Nodemcu
Logic Level converter (to interface from 3.3v nodemcu to the 5V relay board)
https://www.jaycar.com.au/arduino-compatible-logic-level-converter-module/p/XC4486

Additionally I added the following for local control and monitoring:

  • 2 x momentary switches to open/close valve if wifi is down (by grounding the signal line to LLC and hence relay board)
  • LCD Voltmeter connected through a centre off momentary dpdt switch to either side of the step down voltage regulator. (to check voltages both sides of the step down, but only when at the panel to avoid unnecessary current draw. I believe I could just used a spdt switch and used a common ground for this but i had the dpdt lying around.l)

Fairly simple Blynk setup. Two virtual pins (V10, V11) attached to the Open and closed button pins on Nodemcu. Also chucked in a wifi signal setproperty as the install will be right on edge of the wifi range.

A couple of specific questions.

  1. For setup and testing I’ve been using a constant 12.4V supply from wall wart. When I deploy and connect to Solar/battery obviously the input voltage will range based on how sunny it is and how much we’ve drained from battery. Will this effect the 5V output of the step down, and hence cause issues for the Nodemcu and relay board both powered off the 5V?

  2. The physical buttons are just a direct connections between signal circuit to ground. So when physical button is pressed although the Nodemcu is default HIGH the physical button grounds the signal line to LLC and then relay board. Although functionally this is working I’d like some feedback on whether this is good/best practice.

  3. I havent quite got my head around pull-up/pull-down resistors. Being good practice I have pulled up the D1 Output pin to 5V. Do I need to, or is this done on the board itself?

Any questions/comments would be greatly appreciated as this project has given me a good feel for what is possible.

//To Control Irrigation Solenoid valuve at Farm

//Open button (V10) and close button (V11) to trigger relays forcing solednoid valve to open/close

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "xxxx";
char ssid[] = "xxxx";
char pass[] = "xxxx";

BlynkTimer timer;

int value;
int relaypin1 = 4;  // digital pin for relay 1
int relaypin2 = 5;  // digital pin for relay 2
String displaywifi;
int wifisignal;

void setup()
{
  // Debug console
  Serial.begin(115200);
  digitalWrite(relaypin1, HIGH);
  digitalWrite(relaypin2,HIGH);
  pinMode(relaypin1,OUTPUT);
  pinMode(relaypin2,OUTPUT);

  Blynk.begin(auth, ssid, pass);
  
  timer.setInterval(1000000L, sendwifi);
    
}

BLYNK_WRITE(V10)
{
  value = param.asInt(); // Get State of Virtual Button
  
  Serial.print("V10 button value is: ");
  Serial.println(value);
  
  if (value ==1){
    digitalWrite(relaypin1,LOW);
  }
  else{
    digitalWrite(relaypin1, HIGH);
  }
}

BLYNK_WRITE(V11)
{
  value = param.asInt(); // Get State of Virtual Button
  
  Serial.print("V10 button value is: ");
  Serial.println(value);
  
  if (value ==1){
    digitalWrite(relaypin2, LOW);
  }
  else{
    digitalWrite(relaypin2,HIGH);
  }
}

void loop()
{
  Blynk.run();
  timer.run();
}
void sendwifi()
{
  wifisignal = map(WiFi.RSSI(), -105, -40, 0, 100);
  displaywifi = String("           Wifi: ") + wifisignal +String("%");
    
  Blynk.setProperty(V10, "label", displaywifi);
  Blynk.setProperty(V11, "label", displaywifi);
  
}

BLYNK_APP_CONNECTED(){
  Blynk.syncAll();
  
}

It shouldn’t do. Most buck converters can handle a wide range of input voltages whilst still giving the desired output voltage. But, do some tests and if you have a problem then swap it for another one.

That’s fine as far as I can see, although you don’t need the logic level converters as most relay modules for this type are quite happy working with a 3.3v signal.

What you dont want is to have pins that are floating at a level that’s not LOW or HIGH, but somewhere in between. The idea of pull-up is to pull a floating signal HIGH, and pull-downs pull a floating signal LOW.
Most of the time they aren’t really needed, but better safe than sorry. The board has internal pullups that can be used when doing the pinMode declaration, or you can use physical 10k resistors between the pin and 3.3v to pull the pin HIGH and between the pin and GND to pull the pin LOW.

What’s your logic in including this piece of code?..

Also, does your solar charge controller have a data socket on it that looks like a, RJ45 Ethernet connector?

Pete.

1 Like

Appreciate the response Pete

I’ll give the relay board a try without the LLC. I seem to recall I had some issues getting it to work on 3.3v. Think the board was still seeing 3.3v as LOW.

As for the last bit of sync code…it’s a leftover I could probably get rid off. It went when during an attempt to get the wifi signal back into the app using the setproperty. I had quite a few issues getting it to work and this was one attempt to get it to work. Fairly sure the fix ended up being quite embarrassing I’d forgot the timer run command in the loop function.

As for solar controller, the one in the fritzing sketch doesn’t quite match what I used. This is the one I used. Only a USB port in front
https://www.jaycar.com.au/12-24v-10a-solar-charge-controller-with-usb/p/MP3750 ed

Also meant to attach a few photos of the install!

)

image|666x500

1 Like

Looks like you could use the USB output to power your project.

Pete.

I did think about that, but I figured I needed the 12v for the relays and then 5V for relay board (after giving up trying to power on 3.3v so I figured I may as well just wire in the 5V from the regulator to the Vin on Nodemcu