NEED HELP arduino project

Still the wrong name here

Hey I am making this project where I take data from capacitive soil 1.2 sensor, I need help when it falls below a certain value I want it to trigger a relay which while run for a specific time. Can some one help me. Thanks.
This is what I have have so far, it will not trigger the relay.

#include <BlynkSimpleStream.h>
#include <SoftwareSerial.h>
BlynkTimer timer;

int relayPin = 8;
volatile byte relayState = HIGH;
const int AirValue = 650;
const int WaterValue =390;
int intervals = (AirValue - WaterValue)/3;
int soilMoistureValue =0;
// You could use a spare Hardware Serial on boards that have it (like Mega)
SoftwareSerial DebugSerial(2, 3); // RX, TX


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

void setup()
{
  pinMode(8,OUTPUT);
  pinMode(A0,INPUT);

  // Debug console
  DebugSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

  timer.setInterval(1000L, relay);
}

void loop()
{
  Blynk.run();
  timer.run();
}

void relay(){
 if (soilMoistureValue < AirValue && soilMoistureValue > (AirValue - intervals))
 {
    digitalWrite (relayPin, HIGH);
  }
  else {
    digitalWrite (relayPin, LOW); 
  }
  
}

You already had a topic about this… Please do not make redundant topics.

I merged them both into this original.

2 Likes

Hey for some reason the the relay is not working properly can you help me.

Do you know what could be wrong in the sketch?

Hey can you see my sketch below the relay does not trigger for some reason.

@smity We are not here as code troubleshooters at your beck and call :stuck_out_tongue: Please post ONE request, then wait for someone willing and able to respond on their own timing.

Personally I have no idea, but then I am busy on my own stuff so not really working on your code :wink:

1 Like

ok, I am sorry.

ok, but what is going on ?
and where is the code to get AirValue and soilMoistureValue values ?
if I were you, I’ll add 2 sliders to simulate values and test relays
:thinking:

20-026711

when I add a virtual switch to the pin the rely is on, it works, but not when I want it to in the sketch, when the value drops below a certain point.