i wanted to control my servo with bluetooth modue. I gave certain values for rotating it. but when i press those values the servo rotates but then retains it's original position and pc pc also make the sound of arduino board disconnecting because i powered the board with my pc(tried with powerbank also)
this is my code
#include <Servo.h>
Servo myservo;
int pos = 0;
char data = 0;
void setup() {
myservo.attach(9);
Serial.begin(9600);}
void loop(){
if(Serial.available() > 0){
data = Serial.read();
if(data == 'F'){
// for (pos = 0; pos <= 180; pos += 1) even this line dosent work
myservo.write(180);
delay(1);
}}
else if(data == 'B'){
// for (pos = 180; pos >= 0; pos -= 1) even this line dosent work
myservo.write(0);
delay(1);
}}
connections servo red wire -- 5v (not working in 3.3 v) orange wire -- pin9 brown wire -- gnd
bluetooth (hc05) 5v -- 5v gnd -- gnd rx -- tx tx -- rx