Issues with my Wiring and diagram

Hello Folks I got so good help from people here,
I made up following code>

//Leads for soil moistures 2 per soil moisture.

//divided in per module:
const byte sensor0 = A0;
#define LED_0_ON HIGH
#define LED_0_OFF LOW
#define pump_0_ON LOW
#define pump_0_OFF HIGH
const byte heartbeat_0_LED = 7;
const byte RELAY_0 = 3;
int SOIL_MOISTURE_0;


#define LEDon HIGH
#define LEDoff LOW
#define pumpON LOW
#define pumpOFF HIGH



//timing stuff
unsigned long heartbeatTime;
unsigned long machineTime;

unsigned long commonTime;
unsigned long commonInterval;
//const unsigned long pumpOnTime       = 3000ul;                //3 seconds
//const unsigned long pumpRestartTime  = 24ul * 60 * 60 * 1000; //24 hours

//for testing
const unsigned long pumpOnTime = 8000ul;      //8 seconds
const unsigned long pumpRestartTime = 10000;  //10 seconds
enum MachineStates { Startup,State0,State1,State2 };
MachineStates mState = Startup;


void setup() {
  Serial.begin(9600);  //starts up the serial monitor.

  digitalWrite(heartbeat_0_LED, LEDoff);
  pinMode(heartbeat_0_LED, OUTPUT);

  digitalWrite(RELAY_0, HIGH);
  pinMode(RELAY_0, OUTPUT);
}
void loop() {

  //is it time to toggle the heartbeatLED ?
  if (millis() - heartbeatTime > 500) {
    //restart this TIMER
    heartbeatTime = millis();
    //toggle LED
    digitalWrite(heartbeat_0_LED, digitalRead(heartbeat_0_LED) == HIGH ? LOW : HIGH);
  }

  //**********************************************                m a c h i n e   T I M E R
  //is it time to service the State Machine ?
  if (millis() - machineTime > 1000ul) {
    //restart this TIMER
    machineTime = millis();
    Plant_0();
  }

}  //END of   loop()


void Plant_0() {

  switch (mState) {
    //******************
    case Startup:
      {
        //next state
        mState = State0;
      }
      break;

    //******************
    case State0:
      {
        SOIL_MOISTURE_0 = analogRead(sensor0);
        Serial.print("Soil Moisture = ");
        Serial.println(SOIL_MOISTURE_0);

        //is the soil dry ?
        if (SOIL_MOISTURE_0 > 500) {
          digitalWrite(RELAY_0, pumpON);
          Serial.println("\nTurning ON the pump");
          Serial.println("Waiting for 3 sec");

          //set the wait time
          commonInterval = pumpOnTime;

          //restart the common TIMER
          commonTime = millis();

          //next state
          mState = State1;
        }
      }
      break;

    //******************
    case State1:
      {
        //has the common TIMER expired ?
        if (millis() - commonTime >= commonInterval) {
          digitalWrite(RELAY_0, pumpOFF);
          Serial.println("\nTurning OFF the pump");
          Serial.println("Waiting for 24 hours\n");

          //set the wait time
          commonInterval = pumpRestartTime;

          //restart the common TIMER
          commonTime = millis();

          //next state
          mState = State2;
        }
      }
      break;

    //******************
    case State2:
      {
        //has the common TIMER expired ?
        if (millis() - commonTime >= commonInterval) {
          //we will now restart the cycle

          //next state
          mState = State0;
        }
        break;
      }

  }  //END of   switch()

}  //END of   checkMachine()

This is my wiring diagram

The code itself is working I believe.
but I think somewhere in the wiring part its connected wrong somewhere.
Because the relay is not turning on the water pump.

Many thanks in advance

Who knows.

You have not said what the problem is ...........................

Somewhere in the wiring part I believe something is wrong because the relay is not triggered.
neither the led is lighting.

One thing is certain and that is you should have a current limiting resistor in series with the LED. Quite apart from that, are you sure that the LED is wired the right way round ?

Have you tested the LED using the Blink example in the IDE ?

The thing its a good thought you have previously.
I made it work flawless unfortunately I had to rewire everything.
The project was on ice for 1 month before that everything was working fine.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.