# Pro Micro - 32u4 onboard Temperature reading

**URL:** <https://community.sparkfun.com/t/pro-micro-32u4-onboard-temperature-reading/24128>\
**Category:** Arduino\
**Created:** [May 7, 2012, 11:59pm UTC](https://community.sparkfun.com/t/pro-micro-32u4-onboard-temperature-reading/24128 "2012-05-07T23:59:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephanie](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@Stephanie](https://community.sparkfun.com/u/Stephanie)\
**Post date:** [May 7, 2012, 11:59pm UTC](https://community.sparkfun.com/t/pro-micro-32u4-onboard-temperature-reading/24128/1 "2012-05-07T23:59:15Z")

</div>

I’m using the Pro Micro (3.3v 8MHz) in a project and as I was reading the 32u4 documentation and discovered it has an on-board temperature sensor.

Is there any way to access that via the Arduino IDE? I know it probably wouldn’t be as simple as “analogRead(12)” (though that would be lovely). Is there some code I can add or modify though, to access it? The datasheet gives the MUX address for the temperature sensor as 0b100111 but I’m not sure what to do with that.

I did look in the Pro Micro add-on bundle, particularily the wiring\_analog.cpp file, and while I could see the steps taken to perform an analog read, I couldn’t figure out how exactly it went from something like “analogRead(0)” to having the ADC registers correctly addressed.

Thanks!

---

<div class="post-metadata">

**Author:** ![TCWORLD](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@TCWORLD](https://community.sparkfun.com/u/TCWORLD)\
**Post date:** [May 8, 2012, 9:25am UTC](https://community.sparkfun.com/t/pro-micro-32u4-onboard-temperature-reading/24128/2 "2012-05-08T09:25:06Z")

</div>

I have put this together based on the wiring\_analog.h file in the arduino core, and based on the Atmel datasheet.

Note that this is untested. If it doesn’t work, let me know and i will try to figure out why.

All you do is call readTempSensor(); and it will return the value (0 to 1023) from the temperature sensor.

```auto
int readTempSensor(){
    //Enable the Temp sensor. 0bxx0yyyyy sets mode.
    // xx is the reference, set to internal 2.56v as per datasheet
    // yyyyy is the lower 5 bits of the mux value so 00111 as per what you found
    ADMUX = 0b11000111; 
    ADCSRB |= (1 << MUX5); //MUX5 is the 6th bit of the mux value, so 1 as per what you found
    
    //Convert TWICE as first reading is a dud (according to datasheet)
    sbi(ADCSRA, ADSC); // start the conversion
    while (bit_is_set(ADCSRA, ADSC)); // ADSC is cleared when the conversion finishes
    //Second conversion
    sbi(ADCSRA, ADSC); // start the conversion
    while (bit_is_set(ADCSRA, ADSC)); // ADSC is cleared when the conversion finishes

    byte low = ADCL;
    byte high = ADCH;

    return (high << 8) | low;
}

```

---

<div class="post-metadata">

**Author:** ![Stephanie](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@Stephanie](https://community.sparkfun.com/u/Stephanie)\
**Post date:** [May 8, 2012, 11:20am UTC](https://community.sparkfun.com/t/pro-micro-32u4-onboard-temperature-reading/24128/3 "2012-05-08T11:20:09Z")

</div>

Wow that’s exactly what I was looking for!

Thank you very much TCWORLD!

---

<div class="post-metadata">

**Author:** ![lilgenie\_malamide](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@lilgenie\_malamide](https://community.sparkfun.com/u/lilgenie_malamide)\
**Post date:** [June 10, 2015, 11:46pm UTC](https://community.sparkfun.com/t/pro-micro-32u4-onboard-temperature-reading/24128/4 "2015-06-10T23:46:08Z")

</div>

Hi - I am trying the exact same thing but on a Pro-micro 5V.

I am a beginner.

When I copied the same code as above into the IDE ver 1.6 : it gave an error saying ‘sbi’ was not declared in this scope.

In the void loop() - I called for the readTempSensor() and I pasted the readTempSensor code outside of the {} of the void loop()

Any comments please?

Thanks

---

<div class="post-metadata">

**Author:** ![uChip](https://avatars.discourse-cdn.com/v4/letter/u/ee7513/32.png) [@uChip](https://community.sparkfun.com/u/uChip)\
**Post date:** [June 11, 2015, 3:25pm UTC](https://community.sparkfun.com/t/pro-micro-32u4-onboard-temperature-reading/24128/5 "2015-06-11T15:25:13Z")

</div>

It looks like Arduino took away sbi() (or maybe there is an #include needed) in the new IDE. I have not tested it other than to see that it compiles, but you might try bitSet(ADCSRA, ADSC); instead. Alternatively, sbi() is a macro that in this case translates to: ADCSRA |= 1\<\<ADSC; so you could try that as well.

- Chip

---

<div class="post-metadata">

**Author:** ![lyndon](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lyndon](https://community.sparkfun.com/u/lyndon)\
**Post date:** [June 11, 2015, 6:21pm UTC](https://community.sparkfun.com/t/pro-micro-32u4-onboard-temperature-reading/24128/6 "2015-06-11T18:21:04Z")

</div>

I don’t use the Arduino IDE much, but i believe sbi() & cbi() have been deprecated from g++ for some time. The preferred approach is to use the bit value operators.

---

<div class="post-metadata">

**Author:** ![lilgenie\_malamide](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@lilgenie\_malamide](https://community.sparkfun.com/u/lilgenie_malamide)\
**Post date:** [January 2, 2016, 5:48am UTC](https://community.sparkfun.com/t/pro-micro-32u4-onboard-temperature-reading/24128/7 "2016-01-02T05:48:58Z")

</div>

Thank you guys. Let me try that.
