Site Navigation

Your Account

Choose Language

Anything programming related to the Hexbright

34 Questions View all

Converting temperature sensor output to degrees Celsius

Hello HexBright Forum,

Does anyone know how to convert the temperature sensor output to degrees celsius? Using the conversion described in the MCP9700 TT datasheet (Vout = Tc1 x TA + V0c, with Tc1 = 10 mV/C and V0c = 500 mV) after converting the APIN_TEMP analog read to mV (4.9 mV/unit) is producing seemingly erroneous data (unless the Hexbright PCB really does run at ~55 degrees C when plugged into a USB and the light off, does it?). I'm hoping to program the HexBright to 'blink-out' the ambient temperature in degrees celsius (in whole integers) following some sort of button/accelerometer input (for example, 25 degrees would 'blink-out' as, two blinks, pause, five blinks). Any help that anyone can provide would be greatly appreciated. Thanks!

Answered! View the answer I have this problem too

Is this a good question?

Score 1
Add a comment

4 Answers

Chosen Solution

I think you have the equation correct however your mV/unit is incorrect (should be 3300/1024, not 5000/1024). Just to spell it out for everyone -


the temp sensor is listed as MCP9700. Looking at the datasheet (, (page 3) one can see a 500mV zero offset (mV output at 0 degree C) and a 10mV/C temp coefficient (mV change per degree C). Therefore the equation becomes: mV = (10mV/C)*(T)+500mV

Example: 20 degrees C

(10mV)*(20C)+500 = 700mv (sensor output)

Example: 50 degrees C

(10mV)*(50C)+500 = 1000mv (sensor output)

Look at figure 2-16 on page 7.

Assuming a 3.3v (3300mV) reference and a 10 bit (1024 steps) analog to digital converter, solving for C, the equation for temp (deg C) in the Arduino code is -

double temp_c = ((temperature*(3300.0/1024.0))-500)/10;

Of course temp_c must be defined etc.

My Hexbright just lying there is reading -

Temp: 690 mV, 214, 19 C (The converted mV value, digital number and converted temp in Celsius.

Seems like ambient temp to me.

Was this answer helpful?

Score 1


Thanks! Now two great solutions!


Add a comment
Most Helpful Answer

Take a look at this library.

Like you I first tried converting the sensor to degrees based on the data sheet, and had some difficulty. Part of the problem is that the steps of analogRead vary based on the the operating voltage. The documentation specifies values for arduino, which runs at 5 volts, but I believe the hexbright runs at 3.3 volts.

Even once I accounted for that, my readings were off by several degrees, so I wrote a calibration program.

Also, take a look at the library methods.

Of particular interest to you would be 'get_fahrenheit', 'get_celsius', 'get_thermal_sensor', 'print_number', and 'printing_number'.

Was this answer helpful?

Score 1


Thank you so much for your help. Your library is awesome, but a little bit over my neophyte head. I really like your use of the green/red LEDs as the output for the temperature and will be copying it. Thanks again!


I'd be happy to help with any issues you have with the library.

I'm trying to make it as easy to use as possible, so I'd love to hear more details about your experience, good or bad!

If you want to get real-time help, jump on the irc channel (#hexbright).


Don't misunderstand me, the library is great and pretty easy to use. I'm probably being a little bit obtuse, being relatively new to programing I'm not very comfortable using other peoples executable functions when I don't know exactly what they are doing and figuring out what they are doing in a library is a lot of work. For this reason, starting out at least, I find it easier to work through examples of relatively simple programs (similar to the HexBright demos) to build my own omnibus program (which usually ends up being inefficiently executed and not very polished) before using others' polished work. Thanks again, working through your library is proving to be extremely educational!


If you're worried about the value of Vcc, the ATmegas have an internal bandgap reference that can be read by the ADC to find its value.

JCW shows some simple code to do this:

The reference may not be very accurate though :/


Add a comment

how can read k thermocouple with arduino? any coding or give me suggestion about this .

plz help

Was this answer helpful?

Score 0
Add a comment

Here you have to follow below steps

step1: First we have to read adc count(this is the raw data of adc)

step2: then we have to find how many millivolts to 1 degree centigrade.

this step is done through sensor data sheet

step3: step1/step2

step4:result is in millivolts

step5:we have to convert millivolts to degree centigrade.

this step is done through adc in microcontroller data sheet

Was this answer helpful?

Score 0
Add a comment

Add your answer

Andy Slupe will be eternally grateful.