Go Down

Topic: Bluetooth controlled car with Ultrasonic sensor and MIT app inventor (Read 71 times) previous topic - next topic

HizonPastor

Hi everyone,

I am recently making a project, a bluetooth controlled car that can receive and send data or ascii files with one bluetooth module and one arduino (with L293D motor shield)
I'm trying to use MIT app inventor as the remote control
I get a problem when I try to compile my code, and the error is: expected `}' at end of input.
I've checked the parts that I recently added/changed, tried to fix them, but nothing.
Here is my code:




#include <AFMotor.h>
#include <Servo.h>

const int trigPin = 3; const int echoPin = 2; long duration, cm;

AF_DCMotor left1Motor(1, MOTOR12_1KHZ);
AF_DCMotor left2Motor(2, MOTOR12_1KHZ);
AF_DCMotor right1Motor(3, MOTOR34_1KHZ);
AF_DCMotor right2Motor(4, MOTOR34_1KHZ);

Servo servo1;
Servo servo2;

#define right1Speed 200
#define right2Speed 200
#define left1Speed 200
#define left2Speed 200

String readString;

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

  servo1.attach(10);
  servo2.attach(9);

  servo1.write(0);
  servo2.write(0);

Serial.begin(9600);  pinMode(trigPin, OUTPUT);  pinMode(echoPin, INPUT);

  right1Motor.setSpeed(right1Speed);
  right2Motor.setSpeed(right2Speed);
  left1Motor.setSpeed(left1Speed);
  left2Motor.setSpeed(left2Speed);
}

void loop() {
  while (Serial.available()) {
    delay(50);
    char c = Serial.read();
    readString += c;
  }
  if (readString.length() > 0) {
    Serial.println(readString);

   
    if (readString == "FORWARD") {
      right1Motor.run (FORWARD);
      right2Motor.run (FORWARD);
      left1Motor.run (FORWARD);
      left2Motor.run (FORWARD);
    }

    if (readString == "BACK") {
      right1Motor.run (BACKWARD);
      right2Motor.run (BACKWARD);
      left1Motor.run (BACKWARD);
      left2Motor.run (BACKWARD);
    }

    if (readString == "COUNTER") {  //Left
      right1Motor.run (FORWARD);
      right2Motor.run (FORWARD);
      left1Motor.run (BACKWARD);
      left2Motor.run (BACKWARD);
    }

    if (readString == "CLOCKWISE") {  //Right
      right1Motor.run (BACKWARD);
      right2Motor.run (BACKWARD);
      left1Motor.run (FORWARD);
      left2Motor.run (FORWARD);
    }

    if (readString == "STOP") {
      right1Motor.run (RELEASE);
      right2Motor.run (RELEASE);
      left1Motor.run (RELEASE);
      left2Motor.run (RELEASE);
    }

    if (readString == "TAPON") {
      servo1.write(90);
      delay(1000);
    }
    servo1.write(0);
    delay(1000);

    if (readString == "KUHAIN") {
      servo2.write(90);
      delay(1000);
    }
    servo2.write(0);
    delay(1000);

    readString = "";
 
 
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2); 
  digitalWrite(trigPin, HIGH); 
  delayMicroseconds(10); 
  digitalWrite(trigPin, LOW);
 
  duration = pulseIn(echoPin, HIGH);
 
  cm = (duration/2)/29.1;
  if(cm < 20)
  {
    Serial.print("d"); delay(400);
  }
  else
  {
    Serial.print("n"); delay(400);
  } 
}

slipstick

And what do you get when you put the extra } at the end as it suggests?

Steve

Go Up