Hi
I am a beginner in arduino. I am doing a project with servo, arduino and a bluetooth module. when signal is given to arduino from bluetooth module arduino must rotate the servo and again when signal is given it must rotate in opposite direction. This is what I need. But when the below given program is uploaded to arduino servo rotates and turns back to its original position immediately. Help me make correct code so that the servo rotates 80°and stops and when next signal is given it must rotate 80° in reverse direction.
#include <Servo.h>
String reads;
Servo myservo;
void setup() {
Serial.begin(9600);
myservo.attach(9);
// attaches the servo on pin 9 to the servo object
}
void loop() {
while(Serial.available()==0);
reads=Serial.readStringUntil('\n');
if (reads=="adrfjhlnm")
{
myservo.write(0);
// waits for the servo to get there
}
if (reads=="wrong")
{
myservo.write(79);
}
}