Doug Schaefer
Published © GPL3+

DIYSprinkler Controller

Make your own sprinkler controller and I have the software to control it. Must have an existing sprinkler system or you could make your own

IntermediateFull instructions provided2 hours1,700
DIYSprinkler Controller

Things used in this project

Hardware components

Photon
Particle Photon
×1
JBtek 8 Channel DC 5V Relay Module for Arduino Raspberry Pi DSP AVR PIC ARM
×1
LM2596 DC to DC Buck Converter 3.0-40V to 1.5-35V Power Supply Step Down Module
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
24V Power Supply
×1
Existing Sprinkler System
×1
Particle I2C interface adapter
ControlEverything.com Particle I2C interface adapter
Update - Took out bread board and put this in its place.
×1

Software apps and online services

DIYSprinkler
It is all free I just wanted to create a website to hold the software.
DIY Sprinkler Login
This is where you go to create a new account.

Story

Read more

Schematics

MainBuild

Photon with a 8 relay board

Code

Firmware

C/C++
This is the current Firmware that you will need to use.
int relay1 = D1;      // variable to store the Relay Pin Out
int relay2 = D2;
int relay3 = D3;
int relay4 = D4;
int relay5 = D5;
int relay6 = D6;
int relay7 = D7;
int relay8 = D0;

int relay9 = A1;      // variable to store the Relay Pin Out
int relay10 = A2;
int relay11 = A3;
int relay12 = A4;

int pos_relay1 = 0;    // variable to store the Relay position
int pos_relay2 = 0;
int pos_relay3 = 0;
int pos_relay4 = 0;
int pos_relay5 = 0;
int pos_relay6 = 0;
int pos_relay7 = 0;
int pos_relay8 = 0;

int pos_relay9 = 0;
int pos_relay10 = 0;
int pos_relay11 = 0;
int pos_relay12 = 0;

int relayToggle1(String command);
int relayToggle2(String command);
int relayToggle3(String command);
int relayToggle4(String command);
int relayToggle5(String command);
int relayToggle6(String command);
int relayToggle7(String command);
int relayToggle8(String command);

unsigned long lastTime = 0UL;
char publishString[40];

void setup() {
  // initialize the Relay pin as an output:
    pinMode(relay1, OUTPUT);
    pinMode(relay2, OUTPUT);
    pinMode(relay3, OUTPUT);
    pinMode(relay4, OUTPUT);
    pinMode(relay5, OUTPUT);
    pinMode(relay6, OUTPUT);
    pinMode(relay7, OUTPUT);
    pinMode(relay8, OUTPUT);
    
    pinMode(relay9, OUTPUT);
    pinMode(relay10, OUTPUT);
    pinMode(relay11, OUTPUT);
    pinMode(relay12, OUTPUT);
 
 // We are also going to declare a Particle.function so that we can turn the Relay on and off from the cloud.
   //Particle.function("led",ledToggle);
   Particle.function("relay1",relayToggle1);
   Particle.function("relay2",relayToggle2);
   Particle.function("relay3",relayToggle3);
   Particle.function("relay4",relayToggle4);
   Particle.function("relay5",relayToggle5);
   Particle.function("relay6",relayToggle6);
   Particle.function("relay7",relayToggle7);
   Particle.function("relay8",relayToggle8);
   
   Particle.function("relay9",relayToggle8);
   Particle.function("relay10",relayToggle8);
   Particle.function("relay11",relayToggle8);
   Particle.function("relay12",relayToggle8);

   //declare aParticle.variable so that we can store the value of the relay, and get it from the cloud.
   Particle.variable("pos_relay1", pos_relay1);
   Particle.variable("pos_relay2", pos_relay2);
   Particle.variable("pos_relay3", pos_relay3);
   Particle.variable("pos_relay4", pos_relay4);
   Particle.variable("pos_relay5", pos_relay5);
   Particle.variable("pos_relay6", pos_relay6);
   Particle.variable("pos_relay7", pos_relay7);
   Particle.variable("pos_relay8", pos_relay8);
   
   Particle.variable("pos_relay9", pos_relay9);
   Particle.variable("pos_relay10", pos_relay10);
   Particle.variable("pos_relay11", pos_relay11);
   Particle.variable("pos_relay12", pos_relay12);

   // For good measure, let's also make sure all Relays are off when we start:
   digitalWrite(relay1, HIGH);
   digitalWrite(relay2, HIGH);
   digitalWrite(relay3, HIGH);
   digitalWrite(relay4, HIGH);
   digitalWrite(relay5, HIGH);
   digitalWrite(relay6, HIGH);
   digitalWrite(relay7, HIGH);
   digitalWrite(relay8, HIGH);
   
   digitalWrite(relay9, HIGH);
   digitalWrite(relay10, HIGH);
   digitalWrite(relay11, HIGH);
   digitalWrite(relay12, HIGH);

}

void loop() {
    unsigned long now = millis();
    //Every 15 seconds publish uptime
    if (now-lastTime>5000UL) {
        lastTime = now;
        // now is in milliseconds
        unsigned nowSec = now/1000UL;
        unsigned sec = nowSec%60;
        unsigned min = (nowSec%3600)/60;
        unsigned hours = (nowSec%86400)/3600;
        sprintf(publishString,"%u:%u:%u",hours,min,sec);
        Particle.publish("Uptime",publishString);
    }
}

int relayToggle1(String command) {
    if (command=="on") {
        digitalWrite(relay1,LOW);
        pos_relay1 = 1;
        Particle.variable("pos_relay1", &pos_relay1, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay1,HIGH);
        pos_relay1 = 0;
        Particle.variable("pos_relay1", &pos_relay1, INT);
        return 0;
    }
    else {
        return -1;
    }
}
int relayToggle2(String command) {
    if (command=="on") {
        digitalWrite(relay2,LOW);
        Particle.variable("pos_relay2", &pos_relay2, INT);
        pos_relay2 = 1;
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay2,HIGH);
        pos_relay2 = 0;
        Particle.variable("pos_relay2", &pos_relay2, INT);
        return 0;
    }
    else {
        return -1;
    }
}
int relayToggle3(String command) {
    if (command=="on") {
        digitalWrite(relay3,LOW);
        pos_relay3 = 1;
        Particle.variable("pos_relay3", &pos_relay3, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay3,HIGH);
        pos_relay3 = 0;
        Particle.variable("pos_relay3", &pos_relay3, INT);
        return 0;
    }
    else {
        return -1;
    }
}
int relayToggle4(String command) {
    if (command=="on") {
        digitalWrite(relay4,LOW);
        pos_relay4 = 1;
        Particle.variable("pos_relay4", &pos_relay4, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay4,HIGH);
        pos_relay4 = 0;
        Particle.variable("pos_relay4", &pos_relay4, INT);
        return 0;
    }
    else {
        return -1;
    }
}
int relayToggle5(String command) {
    if (command=="on") {
        digitalWrite(relay5,LOW);
        pos_relay5 = 1;
        Particle.variable("pos_relay5", &pos_relay5, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay5,HIGH);
        pos_relay5 = 0;
        Particle.variable("pos_relay5", &pos_relay5, INT);
        return 0;
    }
    else {
        return -1;
    }
}
int relayToggle6(String command) {
    if (command=="on") {
        digitalWrite(relay6,LOW);
        pos_relay6 = 1;
        Particle.variable("pos_relay6", &pos_relay6, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay6,HIGH);
        pos_relay6 = 0;
        Particle.variable("pos_relay6", &pos_relay6, INT);
        return 0;
    }
    else {
        return -1;
    }
}
int relayToggle7(String command) {
    if (command=="on") {
        digitalWrite(relay7,LOW);
        pos_relay7 = 1;
        Particle.variable("pos_relay7", &pos_relay7, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay7,HIGH);
        pos_relay7 = 0;
        Particle.variable("pos_relay7", &pos_relay7, INT);
        return 0;
    }
    else {
        return -1;
    }
}
int relayToggle8(String command) {
    if (command=="on") {
        digitalWrite(relay8,LOW);
        pos_relay8 = 1;
        Particle.variable("pos_relay8", &pos_relay8, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay8,HIGH);
        pos_relay8 = 0;
        Particle.variable("pos_relay8", &pos_relay8, INT);
        return 0;
    }
    else {
        return -1;
    }
}

int relayToggle9(String command) {
    if (command=="on") {
        digitalWrite(relay9,LOW);
        pos_relay9 = 1;
        Particle.variable("pos_relay9", &pos_relay9, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay9,HIGH);
        pos_relay9 = 0;
        Particle.variable("pos_relay9", &pos_relay9, INT);
        return 0;
    }
    else {
        return -1;
    }
}

int relayToggle10(String command) {
    if (command=="on") {
        digitalWrite(relay10,LOW);
        pos_relay10 = 1;
        Particle.variable("pos_relay10", &pos_relay10, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay10,HIGH);
        pos_relay10 = 0;
        Particle.variable("pos_relay10", &pos_relay10, INT);
        return 0;
    }
    else {
        return -1;
    }
}

int relayToggle11(String command) {
    if (command=="on") {
        digitalWrite(relay11,LOW);
        pos_relay11 = 1;
        Particle.variable("pos_relay11", &pos_relay11, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay11,HIGH);
        pos_relay11 = 0;
        Particle.variable("pos_relay11", &pos_relay11, INT);
        return 0;
    }
    else {
        return -1;
    }
}

int relayToggle12(String command) {
    if (command=="on") {
        digitalWrite(relay12,LOW);
        pos_relay12 = 1;
        Particle.variable("pos_relay12", &pos_relay12, INT);
        return 1;
    }
    else if (command=="off") {
        digitalWrite(relay12,HIGH);
        pos_relay12 = 0;
        Particle.variable("pos_relay12", &pos_relay12, INT);
        return 0;
    }
    else {
        return -1;
    }
}

Credits

Doug Schaefer

Doug Schaefer

1 project • 1 follower

Comments