Hi, I am working on a car for school project(due April 7) that uses Servo for Steering and Motor (with L298N Motor Driver) for Acceleration/Deceleration.
I made an App on Android and I was successful on interfacing Android with Arduino, I can send in data from Android, and Arduino is able to read those values.
I wanted to know how should i setup so that when I tilt my screen left or right(Accelerator) my Servo will steer left/right and if I use SeekBar, then my motor will accelerate/decelerate. What kind of values should i send it from Android and how should I use the value received in Arduino. An example would be very helpful.
Here is how i send the servo data using the method
writeData(data + "\n");
Here is how i receive the data in Arduino
void loop()
{
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
motor = Serial.parseInt();
// do it again:
pos = Serial.parseInt();
// look for the newline. That's the end of your sentence:
if (Serial.read() == '\n') {
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}
Is there any efficient way to send/receive the data?