Skip to content

Instantly share code, notes, and snippets.

@kenwalger
Created June 13, 2017 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenwalger/f94dc82a2e797da372dcbae46fe78ddc to your computer and use it in GitHub Desktop.
Save kenwalger/f94dc82a2e797da372dcbae46fe78ddc to your computer and use it in GitHub Desktop.
MicroPython Temperature Sensor for the NodeMCU ESP8266.
from machine import ADC
adc = ADC(0) # assign to the analog to digital 0 pin
adc.read() # returns TMP 36 value
def temp(value):
return value/10
def fahrenheit(celsius):
return (celsius * (9/5)) + 32
reading = adc.read()
celsius_temp = temp(reading)
fahrenheit_temp = fahrenheit(celsius_temp)
print("TMP36 reading {}\nDegrees Celsius{}\nDegrees Fahrenheit {}".format(
reading, celsius_temp, fahrenheit_temp))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment