Printing Char from DEC in serial

Hello all, I’m betting this is an easy one but there’s something I’m not grasping. 1st off, I’m sending data over XBee in the form of a variable. Data is coming from a DS18B20 Temperature sensor to an Arduino. I’m using the Dallas Temperature sensor library. I named the device grabbing temperature in direct sunlight ‘suntemp’, I will later incorporate another temp sensor in the shade to grab ‘shade temp’…first things first though. Here’s the code grabbing the variable ‘suntemp’:

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:

DeviceAddress shadeTemp = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };
DeviceAddress sunTemp = { 0x28, 0x9D, 0x56, 0xEB, 0x03, 0x00, 0x00, 0xD5 };

void setup(void)
  // start serial port
  // Start up the library
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(sunTemp, 10);
  sensors.setResolution(shadeTemp, 10);

void printTemperature(DeviceAddress deviceAddress)
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {

void loop(void)
  //Serial.println("SunTemp: ");

So far on the send side in the serial monitor, the temp is reading and printing correctly and it’s 75.20
Here’s the code on the receiver side:

void setup() {
        Serial.print("testing Xbees");

                             // opens serial port, sets data rate to 9600 bps

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) 
                //val =;                 
                Serial.println("is this correct?   ");

Serial gives me 55,53,46,50,48,13,10
which is 75.20 in ASCII, but I want to display this to an LCD as Characters. I’m not sure of how to alter the code so it prints the data in Character form.
Can someone help. Thanks much.

ASCII is the correct form to send to an LCD so there is nothing to do, just send these values to the LCD as an LCD.write()

One million apologies. I am wrong in my description of what's happening.

Correction. I am getting the values back in DEC in the 'receiver' sides serial monitor that I would like to display as normal Characters.

'Send' sides serial monitor is displaying the characters. 75.20

So I guess the real question is how to print a variable as Char over serial. I apologize if I'm missing something very elementary here, I'm a bit new to programming in Arduino.

You are using


To print your characters right? The issue is that returns an int (I'm betting). The overload for println reads the int, and assumes you're doing something like


In this situation you would obviously want to print the number 1337, not a character.

So to make sure println understands what you're trying to give it try this


Then a character should be printed correctly. The (char) is called a typecast and forces the integer to become a character.

I'd test this but I don't have an Arduino on hand unfortunately.

The issue is that returns an int (I'm betting).

You loose your bet, it returns the byte that was sent, normally an ASCII value but it depends what was sent.


The issue is that returns an int (I'm betting).

You loose your bet, it returns the byte that was sent, normally an ASCII value but it depends what was sent.

No, he wouldn't. The return type for is an int. In general, the data is in the low order byte. The error code, if any, is in the high order byte.

The Serial.print() overload for int does not know that only the low order byte contains data of interest, as a char, so it doesn't print the value that way.

You can do several things. One is to store the low order byte only in a char variable, then print the char variable. Another is to cast the output as a char, when printing.

To: wd40bomber7, that was it! Thanks for teaching me something. That forced the 'receiver' side to print out the data in the correct CHAR format. Thanks a ton, I can think of many other ways to use this casting now.

Thanks a ton.