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 program so that the servo rotates 80°and stops and when next signal is given it must rotate 80° in reverse direction.
There is an typing error in your program. It is much better to copy and paste the code rather than re-type it. For all I know there are other differences from the code in your Arduino.
Add a Serial,print() statement so you can check what is actually being received.
...R Serial Input Basics - simple reliable non-blocking ways to receive data.
[#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(179);
}
}
/code]
@gunabala, it is about 10 days since you first posted your program. Please tell us what changes you have made during that period and what the revised program actually does and what you want it to do that is different.