BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

No me funciona leer una entrada virtual

hola necesito ayuda con mi proyecto. Tengo una placa Wemos D1 y quiero pulsar un boton en mi aplicacion Blynk y que encienda un motor, y que este motor frene cuando aprieto un pulsador(un final de carrera) conectado a mi placa Wemos D1
Screenshot_2

El final de carrera esta definido como FCA y tiene conectado una resistencia a vcc (pull-up)

The BLYNK_WRITE(V7) function is not a repeating loop, it just runs once when the value of the V7 widget changes.
So, you cannot use this function to monitor the status of the fca pin and stop the motor when the limit switch is activated.

Instead, the BLYNK_WRITE(V7) callback function should simply start the motor (assuming that the limit switch isn’t activated) and stop it manually in mid travel.

You need either a second function that is called by a timer and which monitors the state of the fca pin and stops the motor when the limit switch is reached, or a interrupt attached to the fca pin which calls a function that stops the motor.

BTW, posting a screenshot of a small part of your code isn’t the best way to get help with this issue.

Pete.

1 Like

Please don’t post screenshots of your code.
Copy and paste the code and pit triple backticks at the beginning and end of your code.
Triple backticks look like this:
```

Pete.

#define BLYNK_PRINT Serial
 
#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>


// You should get Auth Token in the Blynk App.

// Go to the Project Settings (nut icon).

char auth[] = "xxxxxxxxxxxxxxxxxxxxx";
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "************";
char pass[] = "******";

int LeftPin = D1; // Pines de salida Puente H (motor)
int RightPin = D2; // Pines de salida Puente H (motor)
int b;
int MOTOR;
int FCA = D7;

void setup()
{
 Serial.begin(115200);
 pinMode(LeftPin, OUTPUT);
 pinMode(RightPin, OUTPUT);
 pinMode(FCA, INPUT);
 
  Blynk.begin(auth, ssid, pass);
  Serial.begin(9600);
}

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

BLYNK_WRITE(V7) {
b = digitalRead(FCA); 
int pinValue = param.asInt();

if(pinValue == 1) 
  { 
    MOTOR=1;
    Serial.println("motor1");
  } 
if(b == LOW) 
  { 
    MOTOR=0;
    Serial.println("motor0");
  } 

if(MOTOR == 1)
{
  digitalWrite(LeftPin, LOW);
  digitalWrite(RightPin, HIGH); 
  Serial.println("on");
}

if(MOTOR != 1)
{
  //digitalWrite(LeftPin, LOW);
  digitalWrite(RightPin, LOW); 
  Serial.println("off");
}
}

Disculpa, soy nuevo en esto

I fixed your code formatting attempt…

Blynk - FTFC

1 Like

Muchas gracias !

#define BLYNK_PRINT Serial
 
#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>


// You should get Auth Token in the Blynk App.

// Go to the Project Settings (nut icon).

char auth[] = "sN-m6mERgFkzdb-W4RLtj5VIwfPJaOzW";
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "WiFi-Arnet-4663";
char pass[] = "4166793BE3";

//int pul1 = 6; //derecha
int pul2 = 7;
//int pul3 = 4; //izquierdita
int pul4 = 5;
int LeftPin = 8; //motor
int RightPin = 9; //motor
int a;
int b;
int MOTOR;
int c;
int d;
int sw1;
int sw2;
BlynkTimer timer;

void setup() {
//pinMode(pul1, INPUT); 
pinMode(pul2, INPUT);
//pinMode(pul3, INPUT); 
pinMode(pul4, INPUT);
pinMode(LeftPin, OUTPUT);
pinMode(RightPin, OUTPUT);

Blynk.begin(auth, ssid, pass);
timer.setInterval(10L, motorDC);
Serial.begin(9600);
MOTOR=0;
sw1=0;
sw2=0;
}

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

void motorDC() {
//a = digitalRead(pul1); 
b = digitalRead(pul2);

if(a == LOW && sw1 == 0) 
  { 
    //digitalWrite(b, LOW);
    sw1=1;
    if(MOTOR == 0 && b==HIGH)
    {
      digitalWrite(LeftPin, LOW);
      digitalWrite(RightPin, HIGH); 
      MOTOR=1;
      Serial.println("on");
    }
    else
    {
      digitalWrite(RightPin, LOW);
      digitalWrite(LeftPin, LOW);
      MOTOR=0;
    }
  }
else if(a == HIGH && sw1 == 1)
{
  sw1 = 0;
}

if(MOTOR == 1 && b==LOW)
{
  digitalWrite(RightPin, LOW);
  MOTOR=0;
}

//c = digitalRead(pul3); 
d = digitalRead(pul4);

if(c == LOW && sw2 == 0) 
  { 
    sw2=1;
    if(MOTOR == 0 && d==HIGH)
    {
      digitalWrite(LeftPin, HIGH);
      digitalWrite(RightPin, LOW); 
      MOTOR=1;
      Serial.println("on");
    }
    else
    {
      digitalWrite(RightPin, LOW);
      digitalWrite(LeftPin, LOW);
      MOTOR=0;
    }
  }
else if(c == HIGH && sw2 == 1)
{
  sw2 = 0;
}

if(MOTOR == 1 && d==LOW)
{
  digitalWrite(LeftPin, LOW);
  MOTOR=0;
}

}

BLYNK_WRITE(V7) 
{
a = param.asInt();
}


BLYNK_WRITE(V8) 
{
c = param.asInt();
}

Necesito ayuda para que los pulsadores virtuales V7 Y V8 sean leídos dentro de la función motorDC() y hagan lo que hacían pul1 y pul3 (eran pulsadores físicos)
Quiero que ‘a’ lea el pulsador V7 y cumpla su función dentro de la función motorDC()
Quiero que ‘c’ lea el pulsador V8 y cumpla su función dentro de la función motorDC()

Please don’t duplicate your topics… I merged them both here.