ESP32 CAM car issues

Hey everybody, I am making a remote controlled car from scratch with an ESP32 cam. I would like to control the car using either the builtin WIFI or bluetooth. Unfortunately, whiile making the code I come across an error that says "Compilation Error:a function definition is not allowed here before '{' token."

Here is my code:

// Define pins
const int echoPin = 12;
const int trigPin = 13;

// Start the sensor
DistanceSensor sensor(trigPin, echoPin);

// Motor A connections
//int enA = 9;
int in1 = 2;
int in2 = 14;

// Motor B connections
//int enB = 3;
int in3 = 15;
int in4 = 13;

void setup() {
	
  
  // Start serial port
  Serial.begin(115200);


 
  // Set all the motor control pins to outputs
	//pinMode(enA, OUTPUT);
	//pinMode(enB, OUTPUT);
	pinMode(in1, OUTPUT);
	pinMode(in2, OUTPUT);
	pinMode(in3, OUTPUT);
	pinMode(in4, OUTPUT);
	
void forward() {
  digitalWrite(in1, HIGH);
	digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
	digitalWrite(in4, LOW);

void back() {
	digitalWrite(in1, LOW);
	digitalWrite(in2, HIGH);
	digitalWrite(in3, LOW);
	digitalWrite(in4, HIGH);

void left() {
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);

void right() {
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH); 

void stop() {
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);

}



void loop() {
  
  
  server.handleClient();
    
      command = server.arg("State");
      if (command == "W") forward();
      else if (command == "S") back();
      else if (command == "A") left();
      else if (command == "D") right();
      else if (command == "E") stop();

Please help :cold_sweat:

missing ending brackets "}" on setup and loop..

good luck.. ~q

I have tried putting the end brackets, yet it still gives me an error

probably complaining about "command" and "server" both being undefined in your loop..
where's the rest of the code??

sorry.. ~q

So far this all the code that I have. I was hoping to verify and upload the code successfully.

There are a large number of errors.

A lot of missing closing braces, }, on functions.

Using a variable that has not been declared.

Using external functions that appear to need an external library, but no library included.

The code is a really a very long way from being able to remotley control a car over WiFi and the idea is a very ambitious project if you have not coded before.

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