Relay 2 channel cannot function

need help…why my relay cannot function…

void sensoil()
{
  Serial.println (Sensorvalue);
  Sensorvalue = analogRead (A0);
  Sensorvalue = map(Sensorvalue, 0,1023,1023,0);
  SensorValuePercent = (Sensorvalue / 1023) * 100; // In percent

  Blynk.virtualWrite(A0, Sensorvalue);
}

void relay ()
{
     if (param.asInt())
    {       
        digitalWrite(Sensorvalue, HIGH);
    } else 
    {
        digitalWrite(Sensorvalue, LOW);
    }
    Serial.print(Sensorvalue>700);
    Serial.println(param asStr());
}

We don’t know… can you give us more hints :wink:

i use wemos D1, but dont know how to code the programming when connect to relay…help me

Try this example for using both a physical Button and a Widget button to control a GPIO pin… in this example an LED, but you can simply plug in your relay trigger pin instead.

Break it down to learn how the various Blynk commands and functions work.

https://examples.blynk.cc/?board=WeMos%20D1&shield=ESP8266%20WiFi&example=More%2FSync%2FSyncPhysicalButton

More examples and information in the Docs, Help Center and Sketch Builder links… all at the top right of this page.

any simulator can i play with?

@kmrol85 why do you need a simulator if you have a WeMos?

i dont know how to connect or coding? im still new with this stuff… but, i really want to make my iot watering system… dht11 sensor can function well, but my waterpump cannot function…need help

Do you have a link to the relay you are using?

In isolation your code snippet looks to have several errors.

Many relays are active (ON) LOW but if you test with an LED and a 470R then the snippet would be OK.

Your Serial.print() looks wrong.

If possible post your full sketch.

here is my full sketch…

#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define BLYNK_PRINT Serial
#define BLYNK_PRINT DebugSerial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include "DHT.h"
#define DHTPIN D6     
#define DHTTYPE DHT11 
#define CH1 
#define CH2 
 

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

char auth[] = "f3ac3074f763494c852d57ef25c88129";
char ssid[] = "VIRUS detected!!!";
char pass[] = "xxxxxxxx";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000, sendDHT);
  Blynk.run();
}

void sendDHT()
{
  float h = dht.readHumidity();    // reading Humidity 
  float t = dht.readTemperature(); // read Temperature as Celsius (the default)
  // check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t)) {    
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Serial.print(t, 2);    //print the temperature
  Serial.println(h, 2);  //print the humidity

  Blynk.virtualWrite(V4, h);
  Blynk.virtualWrite(V5, t);
}

int Sensorvalue=0;
int sensorPin=A0;
int SensorValuePercent=0;

void sensoil()
{
  Serial.println (Sensorvalue);
  Sensorvalue = analogRead (A0);
  Sensorvalue = map(Sensorvalue, 0,1023,1023,0);
  SensorValuePercent = (Sensorvalue / 1023) * 100; // In percent

  Blynk.virtualWrite(A0, Sensorvalue);
}

int RELAY1 = A0;
int RELAY2 = D7;
int delayValue = 1000;

void senrelay (){
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  
  digitalWrite(RELAY1, HIGH);
  digitalWrite(RELAY2, HIGH);

  digitalWrite(RELAY1, LOW);
  digitalWrite(RELAY2, LOW);
  
}

void senwater()

{

  float liquid_level;
  int liquid_percentage;
  int top_level = 500;//Maximum water level
  int bottom_level = 0;//Minimum water level
  int Senvalue=0;
 

  liquid_level = analogRead(Senvalue);
  liquid_percentage = ((liquid_level-bottom_level)/top_level)*100;//Percentage of water in the container 
  Serial.println(liquid_level); 
  Serial.println(liquid_percentage);
  Blynk.virtualWrite(V0, liquid_level);
  Blynk.virtualWrite(V1, liquid_percentage);

  
}

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

your relay module must have optocoupler to work correctly

OK, we are not here to be code mechanics… but this all needs medical attention stat!! :stuck_out_tongue:

I am new to the ESP8266, but this looks wrong on a few points:

A) why not just use the IDE serial monitor to watch the debug info? NO need for SofwareSerial

B) your order and repetitive defines are wrong… Should be only these two lines and in this order…

#define BLYNK_PRINT Serial  // This sends all normal Blynk feedback info to the programming UART port
#define BLYNK_DEBUG  // very first line in your sketch, and only for debug purposes as it will slow everything down

.
.
.

Not critical, but these lines look lost here… move them back up before the setup void.
.
.
.

Thes void functions are just sitting there… there is no timer calls to run them, so they are doing nothing that I can see.
.
.
.

More lost little souls… move them with their brethren, up before the setup void :wink: (easier to keep track of).
.
.
.

Don’t… just don’t use delays in the voids… that is what the timers are for.