Sending analog signals through Bluetooth serial

Hey guys,
I’m trying to use a Bluetooth serial connection to send analog input from one microcontroller to a receiving microcontroller (both Teensy 3.1), and having the receiver analogWrite the result. However, I’m having a hard time trying to keep the data intact as I send it.

My analog input has a resolution of 12, and it is saved to an int that can range from 0 to 4096. I’ve tried sending this data by simply using Serial1.write(), but that only sends a byte with a max value of 255 (so an analog read value of 256 would be written received as 0). I’ve looked at a few examples that talk about seperating the integers into two bytes, sending them, and reassembling the integer, but I’m not sure if it applies to numbers as big a 4000.

Any ideas on how I would go about this? I just want to send a number (say, 3000) through Bluetooth serial, receive it, and use that number to AnalogWrite (The teensy is capable of true analog output).

The Bluetooth modules I’m using are the Bluesmirf silvers from Sparkfun.

Try serial.print().

Thanks for the reply. I've tried serial.print, but it just gives me each digit one at a time. I need the entire integer intact.

tanml: Thanks for the reply. I've tried serial.print, but it just gives me each digit one at a time. I need the entire integer intact.

Then you probably need to capture the digits being sent into a String or c-string, then convert the captured character string into a number.

zoomkat: Then you probably need to capture the digits being sent into a String or c-string, then convert the captured character string into a number.

I've read a few answers that say to do this. I'm pretty new to programming, so do you think you can give me some pointers on how to go about this?

I’ve read a few answers that say to do this. I’m pretty new to programming, so do you think you can give me some pointers on how to go about this?

The below code is for servos, but a similar setup might work for your situation. A string of incoming characters is captured from the serial port as readString until a comma , is encountered (used as an end of data packet delimiter). readString is then converted to an integer and is used as a control value for the servo.

//zoomkat 3-5-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port

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

void setup() {

  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-delomit-test-22-dual-input"); // so I can keep track of what is loaded

void loop() {

  //expect a string like 700, or 1500, or 2000,
  //or like 30, or 90, or 180,

  if (Serial.available())  {
    char c =;  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >0) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
          Serial.print("writing Microseconds: ");
          Serial.print("writing Angle: ");

        //do stuff with the captured readString 
        readString=""; //clears variable for new input
    else {     
      readString += c; //makes the string readString

Hey I'm trying to do the same thing (output the sensor value via Bluetooth). What's the best way to do this? I know I have to wire the FSR to the A0 pin. But what's a sketch I can use to send the FSR values via Bluetooth to the Arduino serial monitor on my PC?

You cannot send data to serial monitor via bluetooth, use a proper terminal programme instead, like RealTerm. You can then send the data in exactly the same way as you would send it to the monitor via cable. I assume you know how to do that, if not, get that sorted first.

Thanks Nick! I will try RealTerm.

Hooking up with the USB I have done successfully. I use a really basic sketch like this:

//From the bildr article

int flexiForcePin = A0; //analog pin 0

void setup(){ Serial.begin(9600); }

void loop(){ int flexiForceReading = analogRead(flexiForcePin);

Serial.println(flexiForceReading); delay(250); //just here to slow down the output for easier reading }

The values show up in the serial monitor just fine.

The thing I've had trouble doing is finding a good way to send the values by Bluetooth.

My TX and RX pins are connected and I've tried to add this to the sketch:

Serial myPort; // The serial port

{ // List all the available serial ports println(Serial.list()[5],9600);

String portName = Serial.list()[5]; myPort = new Serial(this, portName, 9600); }

Maybe I'm wrong but this highlighted "5"s are just the COM port number for the incoming signal from the Bluetooth.

I'm totally lost lol

nayefisaac: The values show up in the serial monitor just fine.

If the code is kosher for the serial monitor, that is all you need. Just ensure the serial monitor is disconnected when you use bluetooth. And bluetooth is disconnected when you upload the code.

It's Kosher. Works great. Currently the code is uploaded to the Arduino UNO, the Bluetooth is hooked up to the UNO and paired with my laptop.

I also just downloaded RealTerm.

I'm trying to adjust the settings in RealTerm now, to see if any FSR data will show up.

So far the port and baud rate is set. Baud rate matches the one from the code. Port is the incoming port. I also clicked the RX pin.

Nothing yet

Omnia Vinces Perseverando.......

Have been persevering on this for almost 2 years now. Never been able to get it to work. I just tried CoolTerm and it connects to the COM port just fine, but no data is coming in. I really have no idea what the issue is. Thanks for the help

nayefisaac: I just tried CoolTerm and it connects to the COM port just fine,

What COM port? If you are using the same as you used for serial monitor, it probably explains everything. I don't know how common it is but my Dell laptop had bluetooth on COM 40. You might check the bluetooth manager or windows control panel.

Yeah I see it in the device manager in windows. On my Gateway the USB shows up on COM 4. But that's not an issue, because I always have it un-plugged when I'm attempting to transmit on Bluetooth. The COM ports for the Bluetooth module are COM3 (Outgoing) and COM5 (Incoming)

Everything is connected properly (FSR to UNO and UNO to Bluetooth module via TX and RX lines).

Code works over a UART (USB) connection.

Bluetooth module connects and pairs to the laptop.

The COM ports are working properly and connect in RealTerm and CoolTerm. I even tried in BlueTerm on my tablet. Everything pairs and connects but no data is coming in.

Could it be that I don't have my settings in the terminal application right? If the code works over USB connection and it's supposed to work the same way over a Bluetooth connection, how would it Receive in the terminal app?

I was a bit fast and loose there. By "same way" I meant same code. The terminal settings are reasonably straightforward. You just match the port and baud 9600 and settings n,8,1,none, and display as one or the other of the Ascii buttons. The statuses on the right side should flash in an entertaining manner.

CHECK that the setup is confirmed in the bottom right corner, if not, press the green tick change box.

I'm beginning to doubt your wiring.

You might find the following background notes useful

I did read those 2 links from a different thread. That’s why I initially thought maybe I have to alter and merge the FSR code with some sort of 2-way communication code.

The settings on the terminal are all set and it shows up in the bottom right corner. What doesn’t show is the statuses. Yesterday the TX status button was solid yellow. Today it’s nothing.

I’ve attached a pic of my setup.

When I spoke to the manufacturer for the RN-52 Bluetooth, as well as Sparkfun (where I bought it), they both said that TX and RX should do the job. They also mentioned that CTS and RTS aren’t needed, I could tie them together or leave them alone. I tried both ways, but it doesn’t seem to do or affect anything.

I have TX from the Arduino going to RX on the Bluetooth and vice versa. I’m also powering the Bluetooth off of the UNO, and both with a LI battery. The FSR is plugged up using a voltage driver circuit which is essentially just a resistor spliced to the AI0 pin and to GND.

Everything works fine when I plug up using a USB, but that had me doubting my wiring to the Bluetooth because nothing happens.

Bluetooth powers up, and pairs fine, but there is a missing link somewhere in transmitting the data through the TX and RX lines.


I just tried doing the same thing with another device all together. This time I tried it with the Feather MO which integrates the MCU and the Bluetooth together. It also uses Arduino. So that there's no need to jump wire the UNO to the Bluetooth module. Here it is:

So what I did was install all the drivers, plugged it up by USB, attached the FSR to the Feather, uploaded the FSR code and tested it on the serial monitor via USB. It works just fine.

But when I unplugged the USB, and paired the device via Bluetooth and opened up the Terminal window using the Bluetooth's incoming COM port, it still doesn't send the data.

So that's 2 devices not sending the data, the UNO and the Feather. So it can't be the wiring....

Here it is:

Well, I guess that should put any disquiet about the wiring to bed.

It is time to publish your code.

A successful pair or connection indicates only the, it does not mean the arduino to bluetooth connection is kosher - or the code. I don’t know anything about the RN42, but it should work like any other bluetooth.

I think it has to be the code, I'm just using the basic code I posted. Any idea how I would have to alter it?