Stackable bluetooth shield + servo

Hello,

I'm new to Arduinos and have an Arduino UNO, a stackable bluetooth shield and a servo.

What I would like to do is control the servo with my phone using bluetooth. I have tried looking for tutorials online on how to do this but none of them explain how to do this using a stackable shield, or my understanding of it isn't very good and I can't get it to work.

Could someone please help me with some links or tutorials to follow on stackable bluetooth shields? I'm really lost.

Edit: My apologies. I may have posted this in the wrong section and just realized.

Thank you!

Hello,

I'm new to Arduinos and have an Arduino UNO, a stackable bluetooth shield and a servo.

What I would like to do is control the servo with my phone using bluetooth. I have tried looking for tutorials online on how to do this but none of them explain how to do this using a stackable shield, or my understanding of it isn't very good and I can't get it to work.

Could someone please help me with some links or tutorials to follow on stackable bluetooth shields? I'm really lost.

Thank you!

I've asked that your post be moved. You don't really have a programming question (yet).

You did not supply enough details for us to help you. Which bluetooth shield do you have?

Using a shield does not mean using all the pins on the Arduino. Most are simply passed through. Connecting a servo control wire to one of the unused pins is easy.

Getting data from the bluetooth shield, which gets it from the phone, may, or may not, be easy. Making sense of the data may, or may not, be easy. Using the data, when you have understandable data, to control a servo is trivial.

If you have some code, feel free to share that. "It doesn't work" is too lame for help. "It does xxx, while I expected it to do yyy" is much more likely to get useful help.

In normal operation, the bluetooth will only use four pins - power, ground, Tx, Rx and the device works the same as one not on a shield - hence the dearth of specific information. A shield is likely to offer a choice of different pins for Rx, Tx. The other pins on the shield are available for either use for other stuff you may add to the shield, like a clock or a sensor, or pass-through to the next shield, or both. Now you had better give some indication of the shield you have.

I will add a picture of the shield I have because I borrowed this one from school and haven’t been able to find the exact one.

I do have some code which I’ve been trying out and asked for help because I couldn’t get any of it to work. I’ll try and explain what I have so far then and also attach a picture of the bluetooth shield I have.

I tried to start easy and turn on an LED with the bluetooth shield. I used an app called Bluetooth SPP (for the sending of characters) and found some code which I modified to how I would like it to work with the LED:

#include <SoftwareSerial.h> //Software Serial Port

#define RxD 7 // This is the pin that the Bluetooth (BT_TX) will transmit to the Arduino (RxD)
#define TxD 6 // This is the pin that the Bluetooth (BT_RX) will receive from the Arduino (TxD)

#define DEBUG_ENABLED 1

SoftwareSerial blueToothSerial(RxD,TxD);

/----------------------SETUP----------------------------/
void setup() {
Serial.begin(9600); // Allow Serial communication via USB cable to computer (if required)
pinMode(RxD, INPUT); // Setup the Arduino to receive INPUT from the bluetooth shield on Digital Pin 6
pinMode(TxD, OUTPUT); // Setup the Arduino to send data (OUTPUT) to the bluetooth shield on Digital Pin 7
pinMode(13,OUTPUT); // Use onboard LED if required.
setupBlueToothConnection(); //Used to initialise the Bluetooth shield

//pinMode(Datapin, OUTPUT); // Setup the RGB LED Data Pin
//pinMode(Clkpin, OUTPUT); // Setup the RGB LED Clock pin

}

/----------------------LOOP----------------------------/
void loop() {
digitalWrite(13,LOW); //Turn off the onboard Arduino LED
char recvChar;
while(1){
if(blueToothSerial.available()){//check if there’s any data sent from the remote bluetooth shield
recvChar = blueToothSerial.read();
Serial.print(recvChar); // Print the character received to the Serial Monitor (if required)

//If the character received = ‘r’ , then change the RGB led to display a RED colour
if(recvChar==‘r’){
digitalWrite(9,HIGH);
}

//You can use the following code to deal with any information coming from the Computer (serial monitor)
if(Serial.available()){
recvChar = Serial.read();

//This will send value obtained (recvChar) to the phone. The value will be displayed on the phone.
blueToothSerial.print(recvChar);
}
}
}
}

//The following code is necessary to setup the bluetooth shield ------copy and paste----------------
void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=CHIBB\r\n"); //set the bluetooth name as “SeeedBTSlave”
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println(“The slave bluetooth is inquirable!”);
delay(2000); // This delay is required.
blueToothSerial.flush();
}

I'm not sure why you think that code will work with your shield. The comments in the code indicate that it is setting up a a bluetooth device in XBee form factor, which is not what you have.

On the off chance that the setup stuff is ignored by the bluetooth device you do have, it's difficult to see from the picture what the jumpers are for. If they do control which pins the device is connected to to send and receive data, you should be printing to the Serial instance/Serial Monitor application what, if anything, you receive from the bluetooth device.

The infinite loop in the infinite loop() is stupid. Get rid of it.

I am using the following shield. I wish I could provide more details about it but I haven’t been able to find much.

http://www.geeetech.com/stackable-bluetooth-shield-for-iduinoarduino-p-618.html

I also tried this out using the following code which I modified to turn the LED on when it receives a character “r”. This character gets sent from my phone using the Bluetooth SPP application (Although I have come to understand from someone else that the example I found won’t work with the shield I have at all):

#include <SoftwareSerial.h> //Software Serial Port

#define RxD 7 // This is the pin that the Bluetooth (BT_TX) will transmit to the Arduino (RxD)
#define TxD 6 // This is the pin that the Bluetooth (BT_RX) will receive from the Arduino (TxD)

#define DEBUG_ENABLED 1

SoftwareSerial blueToothSerial(RxD,TxD);

/----------------------SETUP----------------------------/
void setup() {
Serial.begin(9600); // Allow Serial communication via USB cable to computer (if required)
pinMode(RxD, INPUT); // Setup the Arduino to receive INPUT from the bluetooth shield on Digital Pin 6
pinMode(TxD, OUTPUT); // Setup the Arduino to send data (OUTPUT) to the bluetooth shield on Digital Pin 7
pinMode(13,OUTPUT); // Use onboard LED if required.
setupBlueToothConnection(); //Used to initialise the Bluetooth shield

//pinMode(Datapin, OUTPUT); // Setup the RGB LED Data Pin
//pinMode(Clkpin, OUTPUT); // Setup the RGB LED Clock pin

}

/----------------------LOOP----------------------------/
void loop() {
digitalWrite(13,LOW); //Turn off the onboard Arduino LED
char recvChar;
while(1){
if(blueToothSerial.available()){//check if there’s any data sent from the remote bluetooth shield
recvChar = blueToothSerial.read();
Serial.print(recvChar); // Print the character received to the Serial Monitor (if required)

//If the character received = ‘r’ , then change the RGB led to display a RED colour
if(recvChar==‘r’){
digitalWrite(9,HIGH);
}

//You can use the following code to deal with any information coming from the Computer (serial monitor)
if(Serial.available()){
recvChar = Serial.read();

//This will send value obtained (recvChar) to the phone. The value will be displayed on the phone.
blueToothSerial.print(recvChar);
}
}
}
}

//The following code is necessary to setup the bluetooth shield ------copy and paste----------------
void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=CHIBB\r\n"); //set the bluetooth name as “SeeedBTSlave”
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println(“The slave bluetooth is inquirable!”);
delay(2000); // This delay is required.
blueToothSerial.flush();
}

Would you happen to have an example that would work with the shield I have?

I mentioned in my first post that I would like links on how to work with this shield because I could not find any examples to work with. I also mentioned that I am new to the subject. You asked me what shield I am using and I provided you with a picture and also told me that you rather I post code and whatnot so that you can be helpful.

The example I found and tried out was using a bluetooth shield and arduino, I factored in the LED. I understand if I did that wrong.

Would you happen to know where I could find an example that would work with this shield? Since according to you I started off completely wrong.

Would you happen to know where I could find an example that would work with this shield?

I doubt that the shield came from the discount bluetooth shield bin at KMart. Surely there is a manufacturer's name somewhere on the board. Possibly on the bottom.

A top view of the board would have been better than an isometric view, but pictures alone won't be much help. We need to know how the shield communicates with the bluetooth device and how it communicates with the Arduino.

The bluetooth shield I have looks a bit like yours but doesn't use code that looks anything like your code.

It does have a website from which you can order it. But I can't find any examples using this specific shield and that's why I posted here asking for help. And the wiki page I found on there doesn't help me much.

http://www.geeetech.com/stackable-bluetooth-shield-for-iduinoarduino-p-618.html

And again, I used code of a random example I found online, because I could not find anything that helped me. So I understand when you tell me it's wrong and it won't work.

And the wiki page I found on there doesn't help me much.

Well, at least it confirms that the jumpers ARE for selecting the software serial pins and that SoftwareSerial will be used to communicate with the bluetooth device.

What kind of phone do you have? Does your phone confirm that the bluetooth device is present and working?

I have a Samsung Galaxy S5. Yes, I can connect to the bluetooth shield using the app I mentioned earlier (Bluetooth SPP).

I just have no clue how to proceed with the LED and then with the servo.

Thanks for your patience by the way, I really appreciate it.

I just have no clue how to proceed with the LED

Modify the code you posted earlier. Get rid of the setupBlueToothConnection() function and the call to it in setup().

In loop(), just read the data from the software serial instance, and send it to the hardware serial instance:

void loop()
{
   if(blueToothSerial.available())
   {
       char c = blueToothSerial.read();
       Serial.print("I got a ");
       Serial.println(c);
   }
}

Now, that won't do anything to turn the LED on or off, but it WILL confirm that the phone and bluetooth device are communicating and the the bluetooth device and the Arduino are communicating, or it will confirm that there is a failure to communicate. But, that is the necessary first step.

I think the code is utter junk, and overly verbose as well.

You might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

Note that some bluetooth modules come set to a different baud rate. This means you need to alter the command Serial.begin(9600) accordingly Same goes for the setting in the bottom right corner on the serial monitor

I'm not familiar with the shield. I assume there is nothing wrong with it, but the vital module is a plain vanilla HC-05 and this means it will not work with an iPhone, and maybe that is what the someone else meant.

A clearer picture would help but the 3x8 pinrows are probably selectors for software serial. The lettering around them is unreadable. If the rightmost two are labelled D0,D1, they are for hardware serial and I suggest you select them. If they are not labelled thus, selecting HW on S2 should do the trick as I imagine it over-rides all those pins.

So if I understood you correctly:

I only have this as my code now:

#include <SoftwareSerial.h> //Software Serial Port

#define RxD 6 // This is the pin that the Bluetooth (BT_TX) will transmit to the Arduino (RxD)
#define TxD 7 // This is the pin that the Bluetooth (BT_RX) will receive from the Arduino (TxD)

#define DEBUG_ENABLED 1

SoftwareSerial blueToothSerial(RxD,TxD);

/----------------------SETUP----------------------------/
void setup() {
Serial.begin(9600); // Allow Serial communication via USB cable to computer (if required)
pinMode(RxD, INPUT); // Setup the Arduino to receive INPUT from the bluetooth shield on Digital Pin 6
pinMode(TxD, OUTPUT); // Setup the Arduino to send data (OUTPUT) to the bluetooth shield on Digital Pin 7
pinMode(13,OUTPUT); // Use onboard LED if required.
setupBlueToothConnection(); //Used to initialise the Bluetooth shield

}

/----------------------LOOP----------------------------/
void loop()
{
if(blueToothSerial.available())
{
char c = blueToothSerial.read();
Serial.print("I got a ");
Serial.println(c);
}
}

After this, I do see in the app that it received about 9B, but it doesn’t show me anything in the Serial monitor.

Also I forgot to mention, with my previous code, using the app I could click on a button that sends an “r” and every time I clicked it random characters would show up on my serial monitor. Here’s a screenshot of it so you can see what I mean. This is why I thought I might have had it half right when I posted it:

I only have this as my code now:

If that IS all of your code, it won't even compile, so it is useless to talk of it working or not.

It does not look like the bluetooth module's baud rate is the same as the Arduino thinks that is it.

Your setup() function needs to call blueToothSerial.begin() with the correct baud rate.

The garbled received characters may indicate a mismatch on the baud rates. If you want to do very basic trouble shooting, then you can load the below non serial dummy program on the arduino. This allows the arduino to be used as a basic TTL serial interface with what is connected to the arduino hardware tx/rx pins. Once this done, set the bluetooth shield to use the arduino hardware tx/rx pins. Open the serial monitor and what is received by the bluetooth shield will be sent directly to the serial monitor for viewing. If what is received is garbled, then try different baud settings in the serial monitor. Note that devices attached to the arduino hardware pins during code upload may cause problems.

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Thank you so much for the help! I completely missed the different baud rates! I can see the characters I send now and control the LED.

Have a nice day!