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

Controlling a dc motor using nodemcu, L298N and blynk

#1

Hello, i’m very new to arduino and still learning (no programming background). Please be gentle to me. Btw, i’m helping my daughter to do this project. She really likes electronic especially arduino.

I’m making a simple IOT system on how to open/close a curtain by using NodeMCU + L298N + Blynk

What i expect : 1. when i press V0 = The curtain is opening for 5 seconds then stop

                   2. when i press V1 = The curtain is closing for 5 seconds then stop

*note that V1 and V2 are the switch button. Not push button. So, when V1-ON, V2 should OFF. Vice versa.

What happen : Nothing works.

*When i tried just by using NodeMCU, by giving the the pins HIGH or LOW. it works. So, it means that the wiring of the components and its pins are true.

It really confusing me. Sorry for my bad english.

I read the post by nick before posting the problem/topic, but i dont know how to post the code they others did (have a box for codes). Thanks so much

regards, HAMDAN


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "c5342bebfbce468db903e859d769ea62";
char ssid[] = " ";
char pass[] = " ";

int Positive = 15; 
int Negative = 13; 

long int stop1;

void setup() 
  {
    Serial.begin(9600);
    Blynk.begin(auth, ssid, pass);

    stop1=millis()+5000;  // 5 seconds timer
 
    pinMode(Positive, OUTPUT); 
    pinMode(Negative, OUTPUT); 
  }

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

BLYNK_WRITE(V0)
  {
   if (millis()<stop1)
      {
        digitalWrite(Positive, LOW);  // open curtain
        digitalWrite(Negative, HIGH);
      } 
 
    else 
      {
        digitalWrite(Positive, LOW);  // stop the operation after 5 seconds
        digitalWrite(Negative, LOW);
      }
  }

BLYNK_WRITE(V1)
  {
   if (millis()<stop1)
      {
        digitalWrite(Positive, HIGH);  // close curtain
        digitalWrite(Negative, LOW);
      } 
 
    else 
      {
        digitalWrite(Positive, LOW);  // stop the operation after 5 seconds
        digitalWrite(Negative, LOW);
      }
  }
0 Likes

#2

Firstly, you need to edit your post (using the pencil icon at the bottom) and insert three backticks at the top and bottom of your post so that it displays correctly. Three backticks looks like this:
```

Secondly, the stuff you’re trying to do with mills() just won’t work the way that you’re trying to do it.
What you should do is to use a timeout timer. If you search the forum for Blynk timer and Timer then you’ll find some examples.

Thirdly, it will be much simpler from a logic perspective if you use just one button to begin with. Change the labels on the button from off/on to open/closed and use that to indicate if the curtains are closed or opened.

Pete.

0 Likes