How to code in this adruino

Hii I'm creating a rc car for which I've used l28N motor driver and adruino. This adruino have wifi inbuilt. I don't know how to code in this cause everytime my code fail to work


If anyone know how to code in this so please say . Thanks

Welcome to the forum

As your topic does not relate directly to the installation or operation of the IDE it has been moved to the Programming category of the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post any error messages in code tags as it makes it easier to scroll through them and copy them for examination

1 Like

My first question is "what board is that?" and the answer appears to be an Uno + ESP8266 combo. I don't know if that was ever an official Arduino board but there are lots of clones about.

I don't really know much about that, but you may find this helpful ATmega328p + ESP8266 WIFI tutorial

Yes it's a combo of wifi+atmega. I see that post but code is not working like I'm trying to get wifi on through that but it's not happening. no ip address showing in serial monitor.

Ok, there are many things that can go wrong. Post a minimal example showing the problem and we can have a look.

Get either a real UNO, or better still a NANO.

Hi, @ravishankar_5046
What you have is;

What Arduino controller have you selected in the IDE?

Please post your code.
Please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Tom.... :smiley: :+1: :coffee: :australia:

Yah sure .
Wring :-
L298N Pin Connect to Arduino
IN1 =D5
IN2 =D6
IN3= D9
IN4= D10
ENA =D3 (PWM)
ENB= D11 (PWM)
GND= GND
VCC= External 12V Battery
5V =Output Arduino 5V

Code :-

#include <ESP8266WiFi.h>

// Motor Driver Pins
#define ENA 3 // Enable motor A (PWM)
#define ENB 11 // Enable motor B (PWM)
#define IN1 5 // Motor A direction
#define IN2 6
#define IN3 9 // Motor B direction
#define IN4 10

// WiFi Credentials
const char* ssid = "Your_WiFi_Name";
const char* password = "Your_WiFi_Password";

// Create a server on port 80
WiFiServer server(80);

void setup() {
Serial.begin(115200);

// Setup motor pins as OUTPUT
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

// Stop motors at start
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
analogWrite(ENA, 0);
analogWrite(ENB, 0);

// Connect to WiFi
Serial.print("Connecting to WiFi");
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nConnected to WiFi!");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());

server.begin(); // Start the server
}

void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("Client Connected");

while (client.available()) {
String command = client.readStringUntil('\r');
Serial.println("Command: " + command);
client.flush();

if (command == "FORWARD") {
  moveForward();
} 
else if (command == "BACKWARD") {
  moveBackward();
} 
else if (command == "LEFT") {
  turnLeft();
} 
else if (command == "RIGHT") {
  turnRight();
} 
else if (command == "STOP") {
  stopMotors();
}

}
}

// Motor Control Functions
void moveForward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
analogWrite(ENA, 255);
analogWrite(ENB, 255);
}

void moveBackward() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
analogWrite(ENA, 255);
analogWrite(ENB, 255);
}

void turnLeft() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
analogWrite(ENA, 200);
analogWrite(ENB, 200);
}

void turnRight() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
analogWrite(ENA, 200);
analogWrite(ENB, 200);
}

void stopMotors() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}

I’m guessing you missed the post on CODE TAGS.

Going more methodically at the beginning, will make your life easier as you get further along.

Did you deliberately not use code tags as requested ?

I don't know how to to use code tag that's why I didn't use sorry for that , any suggestions how to use

Then you have obviously not read post #2

Hi,

Lets use decent noticeable links.
This will tell you how to place code in your post.

Tom.... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.