Programming Servo to Arduino with Bluetooth

Hey guys

I am a huge noob and beginner at using the Arduino. I wanted to try to control a servo with bluetooth, and I wanted to write my own sketch. So, I wrote this:

#include <Servo.h>

Servo myservo;
int pos = 0;
void setup ()
{
myservo.attach(9);
Serial.begin(9600);
}
void loop()
{
if (Serial.available()>0)
{
int bluetooth = Serial.read();
Serial.println(bluetooth);
myservo.write(bluetooth);
}
}

It doesn't work. I can't control the servo. I am not really familiar with C/C++. Could someone please help me?

Thanks,

I am a huge noob and beginner at using the Arduino

, so much so, I thought the rules about NOT CROSS-POSTING and USING CODE TAGS don't apply to me.

They do.
Duplicates deleted.

Sorry. Now I know. Nonetheless, could someone please help me?

Hey guys

I am trying to connect my bluetooth module to a servo. I decided to try to write my own sketch. However, the program doesn't work. Also, the circuitry is all right.

#include <Servo.h>

Servo myservo; 
int pos = 0; 
void setup () 
{ 
  myservo.attach(9); 
  Serial.begin(9600);
} 
void loop() 
{ 
  if (Serial.available()>0)
  { 
    int bluetooth = Serial.read();
    Serial.println(bluetooth); 
    myservo.write(bluetooth); 
  } 
}

Thanks

The whole "DO NOT CROSS-POST, CROSS-POSTING WASTES TIME" thing seems to be hard for you to comprehend.

Do you think a two day time-out might help you concentrate?

Develop your servo control code first using the serial monitor, then move to the blue tooth setup. Below is some simple servo test code.

//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String 
    int n = readString.toInt();  //convert readString into a number
    Serial.println(n); //so you can see the integer
    myservo.write(n);
    readString="";
  } 
}

Hey guys

I made this code for the servo to send data using the serial monitor:

#include <Servo.h>
String readString; 
Servo myservo; 

void setup() 
{ 
  Serial.begin(9600); 
  myservo.attach(9); 
  myservo.write(90); 
  Serial.println("Ready"); 
} 
void loop(){ 
  while (Serial.available()) { 
    char a = Serial.read(); 
    readString += a; 
    delay (2); 
  } 
  if (readString.length() > 0) { 
    Serial.println(readString); 
    int x = readString.toInt(); 
    if (x >= 0)
    Serial.print("the angle is: ");
    Serial.println(x); 
    myservo.write(x); 
  } 
  readString=""; 
}

Now, I want to add bluetooth functionality. As in, I can control the servo using bluetooth. I would like to know how I would do this. It's kind of hard to find something online.

Thanks for your help!

SIEVEPRIMESAXON:
It's kind of hard to find something online.

So this is your problem.

Below are the links I found googling:
https://www.arduino.cc/en/Main/ArduinoBoardBT?from=Main.ArduinoBoardBluetooth
http://playground.arduino.cc/Learning/Tutorial01

And another 2,589,997 results.

I did look through those. What I was trying to ask was, I want to control the servo with bluetooth. However, I also read that softwareserial doesn't work so well with the Servo library. So, what should I do? I can't find many resources for that.

Okay. Let me clarify. I'm using a Bluetooth module, Hc-06, and I have a Wifi shield on top. Also, for some reason, I can't upload anything. This error pops up:
"Arduino: 1.6.3 (Windows 8.1), Board: "Arduino BT, ATmega328"

Build options changed, rebuilding all

Sketch uses 6,044 bytes (21%) of program storage space. Maximum is 28,672 bytes.

Global variables use 265 bytes (12%) of dynamic memory, leaving 1,783 bytes for local variables. Maximum is 2,048 bytes.

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x9e

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x9e

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x9e

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x9e

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x9e

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x9e

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x9e

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x9e

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x9e

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x9e

Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

I'm using an Arduino Uno. The board is on "Arduino Uno" and the port is correct.

SIEVEPRIMESAXON:
I'm using an Arduino Uno. The board is on "Arduino Uno" and the port is correct.

It looks like the board is set to "Arduino BT".

Okay. I made it to Arduino Uno. So, I uploaded the sketch, and now it works! I'm using this app to try to control the servo. https://play.google.com/store/apps/details?id=arduino.bluetooth.servo

"Arduino Bluetooth Servo"

However, what's weird is that, although I can see the serial data monitor, it only produces "1", which is weird. When I input a value from the serial monitor, it works.