Hello. I need your help on my project
I am using Robojax_L298N_DC_motor library on my blynk project in order to run my moters with L298N motor driver it is not working.
#define BLYNK_TEMPLATE_ID ---
#define BLYNK_DEVICE_NAME ---
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD
#include "BlynkEdgent.h"
#include <Robojax_L298N_DC_motor.h>
#include <ESP32Servo.h>
#include <HCSR04.h>
#define CHA 0
#define ENA 13
#define IN1 12
#define IN2 14
// motor 2 settings
#define IN3 15
#define IN4 2
#define ENB 4
#define CHB 1
const int CCW = 2; // do not change
const int CW = 1; // do not change
#define motor1 1 // do not change
#define motor2 2 // do not change
Robojax_L298N_DC_motor robot(IN1, IN2, ENA, CHA, IN3, IN4, ENB, CHB);
const byte triggerPin = 18;
const byte echoPin = 19;
UltraSonicDistanceSensor distanceSensor(triggerPin, echoPin);
Servo servo;
int led1 = 32;
int led2 = 33;
int led3 = 25;
int led4 = 23;
int myServo = 5;
float distance;
int pinValue;
BLYNK_WRITE(V0) {
pinValue = param.asInt();
digitalWrite(led1, pinValue);
if (pinValue == 1) {
Serial.println("DEVICE ON");
}
else {
Serial.println("DEVICE OFF");
}
}
void hcsr04() {
// int pinValue=BLYNK_WRITE(V0); //START IF DEVICE is ON, GET VALUE FROM V0
if (pinValue == 1) {
float distance = distanceSensor.measureDistanceCm();
//Serial.println(distance);
Blynk.virtualWrite(V2, distance);
if (distance < 200) {
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
else {
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led2, LOW);
}
}
else {
Blynk.virtualWrite(V2, 0.00);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
}
BLYNK_WRITE(V3) {
int forward = param.asInt();
if (forward ==1) {
robot.rotate(motor1, 80, CW);//run motor1 at 60% speed in CW direction
robot.rotate(motor2, 80, CCW);//run motor1 at 60% speed in CW direction
}
else {
robot.brake(1);
robot.brake(2);
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
}
void setup()
{
Serial.begin(115200);
delay(100);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
robot.begin();
servo.attach(myServo);
BlynkEdgent.begin();
timer.setInterval(500L, hcsr04);
}
void loop() {
BlynkEdgent.run();
timer.run();
}
If I use library examle on my esp32 it is working.
/*
* Library Example for L298N Module to control DC motors
*
* This code is to control single motor. For two motor control, please open L298N_DC_2_Motors
* this code is ready for ESP32
* Watch video instructions for this code: https://youtu.be/2JTMqURJTwg
*
* Written by Ahmad Shamshiri on Dec 24, 2019
* in Ajax, Ontario, Canada. www.robojax.com
*
Need wiring diagram from this code: Purchase My course on Udemy.com http://robojax.com/L/?id=62
*
*
* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on Udemy.com http://robojax.com/L/?id=62
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can support me on Patreon http://robojax.com/L/?id=63
or make donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Robojax_L298N_DC_motor.h>
// motor 1 settings
#define CHA 0
#define ENA 13 // this pin must be PWM enabled pin if Arduino board is used
#define IN1 12
#define IN2 14
// motor 2 settings
#define IN3 15
#define IN4 2
#define ENB 4// this pin must be PWM enabled pin if Arduino board is used
#define CHB 1
const int CCW = 2; // do not change
const int CW = 1; // do not change
#define motor1 1 // do not change
#define motor2 2 // do not change
// for single motor
//Robojax_L298N_DC_motor robot(IN1, IN2, ENA, CHA, true);
// for two motors without debug information // Watch video instruciton for this line: https://youtu.be/2JTMqURJTwg
Robojax_L298N_DC_motor robot(IN1, IN2, ENA, CHA, IN3, IN4, ENB, CHB);
// fore two motors with debut information
//Robojax_L298N_DC_motor robot(IN1, IN2, ENA, CHA, IN3, IN4, ENB, CHB, true);
void setup() {
Serial.begin(115200);
robot.begin();
//L298N DC Motor by Robojax.com
}
void loop() {
// robot.demo(1);
robot.rotate(motor1, 80, CW);//run motor1 at 60% speed in CW direction
robot.rotate(motor2, 80, CCW);//run motor1 at 60% speed in CW direction
// Robojax L298N Library. Watch video instruciton https://youtu.be/2JTMqURJTwg
}
I cannot undestand what is the problem. Please help!