Blynk car using nodemcu

I have made a car with nodmcu using blynk joystick … and i have added LDR sensor to it …but as per the code car should move on joystick movement …but it is moving only when in LDR detect light … … please help me with this

Seriously?
You really think that we can help you to solve this programming error without even seeing your code?

Pete.

2 Likes

//im sry sir …here is my code … i have merged ldr sensor code with wif car code
but the car is running only when ldr sensor is activated…

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

//Motor A
const int inputPin1  = 5;    // Pin 15 of L293D IC, D1 Pin of NodeMCU
const int inputPin2  = 16;    // Pin 10 of L293D IC, D0 Pin of NodeMCU
//Motor B
const int inputPin3  = 4;    // Pin  7 of L293D IC, D2 Pin of NodeMCU
const int inputPin4  = 0;    // Pin  2 of L293D IC, D3 Pin of NodeMCU
int EN1 = 12;                 // Pin 1 of L293D IC, D6 Pin of NodeMCU
int EN2 = 14;                 // Pin 9 of L293D IC, D5 Pin of NodeMCU
// Led Light Pin
const int Ledpin = 10;
const int ldrPin = A0;
//---------------

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
//char auth[] = "BwoQgjZstlMzCIUw7LztOUbBfght85wo"; // previous project Nodemcu token
char auth[] = "Zl-iSmOuIi6I3uTLjIac8spoLkqNEh45";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "abc";
char pass[] = "12345678";

BLYNK_WRITE(V1)
{
  int x = param[0].asInt();
  int y = param[1].asInt();

  // Do something with x and y
  Serial.print("X = ");
  Serial.print(x);
  Serial.print("; Y = ");
  Serial.println(y);

//  int speed =350;
//  analogWrite(EN1, speed);//sets the motors speed
//  analogWrite(EN2, speed);//sets the motors speed
// Joystick Movement
  if (y>350)
  {
    Serial.print("forward");
    forward();
  }

  if (y<170) 
    {
      Serial.print("backward");
      backward();
    }

   if (x<132)
    {
      Serial.print("left");
      left();
    }
 
  if (x>380) 
    {
      Serial.print("right");
      right();
    }

  if ((y==256) && (x==256))
    {
      Serial.print("stop");
      stop();
     }

}

//----------------------
BLYNK_WRITE(V2)
{
  int speed = param.asInt(); // assigning incoming value from pin V2 to a variable
    //speed =350;
    analogWrite(EN1, speed);//sets the motors speed
    analogWrite(EN2, speed);//sets the motors speed

}
//------------------------




void setup()
{
    pinMode(EN1, OUTPUT);   // where the motor is connected to
    pinMode(EN2, OUTPUT);   // where the motor is connected to
    pinMode(inputPin1, OUTPUT);
    pinMode(inputPin2, OUTPUT);
    pinMode(inputPin3, OUTPUT);
    pinMode(inputPin4, OUTPUT);  
    pinMode(Ledpin, OUTPUT);
    pinMode(ldrPin, INPUT);
  
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

void loop()
{
 Blynk.run();
   int ldrStatus = analogRead(A0);
  // put your main code here, to run repeatedly:
 if (ldrStatus >=20) {
  Blynk.notify("metal detected");
  }
  Blynk.run();
}

void left(void)
{
    digitalWrite(inputPin1, HIGH);
    digitalWrite(inputPin2, LOW);
    digitalWrite(inputPin3, HIGH);
    digitalWrite(inputPin4, LOW);  
}

void right(void)
{
    digitalWrite(inputPin1, LOW);
    digitalWrite(inputPin2, HIGH);
    digitalWrite(inputPin3, LOW);
    digitalWrite(inputPin4, HIGH); 
}

void stop(void)
{ 
    digitalWrite(inputPin1, LOW);
    digitalWrite(inputPin2, LOW);
    digitalWrite(inputPin3, LOW);
    digitalWrite(inputPin4, LOW); 
}

void backward(void)
{   
    digitalWrite(inputPin1, LOW);
    digitalWrite(inputPin2, HIGH);
    digitalWrite(inputPin3, HIGH);
    digitalWrite(inputPin4, LOW); 
}

void forward(void)
{ 
    digitalWrite(inputPin1, HIGH);
    digitalWrite(inputPin2, LOW);
    digitalWrite(inputPin3, LOW);
    digitalWrite(inputPin4, HIGH); 
}

@Kiran_Malganvi please edit your post, using the pencil icon at the bottom, and replace the characters you used at the beginning and end of your code with the correct characters, which are triple backticks.
Triple backticks look like this:
```

Pete.

sir im not getting where im wrong. but both code works good when they are separately …but when i merge them… the car will only move when sensor is high and get notification in blynk

Your first mistake is reading the LDR sensor on every repetition of the void loop, and breaking the number 1 rule of Blynk by having code which writes data to the Blynk server in the void loop - in this case a Blynk.notify command.

Read this:

Pete.

ok sir thank you…i will just try it now

I would handle the speed/turn on one. He is an excellent light weight way of doing it.

1 Like