Using serial to produce multi-digits

I am interested in sending servo data ranges (0-179) from using serial communication one arduino to another arduino that has the servo on it. The problem is I keep getting numbers like "179" in single digit increments of "1" "7" "9", which of course means the servo barely moves. I read that I can use Messenger to tailor how the data is received, but I haven't had any success with it. Can someone recommend the basic code using Messenger (or another recommended solution) so I can receive integers larger than 9 on the arduino board using Serial communication?

Instead of using Messenger, use

** Serial.print(servoControlByte, BYTE);**

where servoControlByte is the variable you want to send.

The BYTE parameter will send it as a single character, probably unprintable in many cases, but the receiving Arduino will not care about that.

As long as the value you send is less than 256, you’ll be Ok. Your range of (0-179) fits this requirement.

So I tried what you recommended and I get garbled information in the Monitor window. Is this normal? Here is the code I am trying out:

int analogValue0, val0;

void setup() {
// Serial port enable

void loop() {
// read analog pin 0
analogValue0 = analogRead(0);

// remap values from the analogValue5 variable to 0 / 179
val0 = map(analogValue0, 0, 1023, 0, 179);

// send the value to the serial port
Serial.println(val0, BYTE);


Same issue, but wrong code. Here is the code I’m using:

 /* FSR simple testing sketch. 

Connect one end of FSR to power, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground 

For more information see */

int fsrPin = 0;     // the FSR and 10K pulldown are connected to a0
int fsrReading;     // the analog reading from the FSR resistor divider

void setup(void) {
  // We'll send debugging information via the Serial monitor

void loop(void) {
  fsrReading = analogRead(0); 
   fsrReading = map(fsrReading, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)  
  Serial.println(fsrReading);     // the raw analog reading

OK, I got it working. The byte statement did the trick. The issue was receiving the same byte on the other end. And yes, the byte data looks garbled, but it was communicated fine on the other arduino. Thanks for the help.

I have a follow up question. The following syntax worked perfectly:

Serial.println(servoControlByte, BYTE);

If I wanted to send multiple analog inputs and receive them for specific servos (let's say two of them), is it possible to label the sending info as?:

Serial.println(servoControlByte1, BYTE); Serial.println(servoControlByte2, BYTE);

And how would I receive that information so that it goes to the correct servo on the other arduino board? I currently work with one servo and all I have to do is listen to the data streaming in. With two servos I need to separate which analog input it should listen to. I rad about Handshake, but I'm not sure I want a constant receive request going on in the background. Any examples of getting this to work is appreciated.

If you want to control multiple servos, you will need to send more data. That data stream will need interpretation. Where the data stream starts and ends will need to be defined, too.

You should be able to send 4 bytes - ‘<’, ServoNumber, ServoValue, ‘>’.

Use whatever delimiters you like, but don’t try to do without them. Read the serial data , throwing away junk until you find a ‘<’ (or whatever start delimiter you like). Read a byte, servoNumber. Read another byte, servoValue. Read another byte. If the last byte is NOT ‘>’ (or whatever ending delimiter you like), the data that you have collected is suspect, and should not be used. If the last bytes IS the ending delimiter, the data that you have collected is good, and you can control the appropriate servo (in servoNumber), sending it to the appropriate location (in servoValue).

Thanks PaulS. I got it.