Created
June 13, 2017 05:11
-
-
Save kenwalger/f94dc82a2e797da372dcbae46fe78ddc to your computer and use it in GitHub Desktop.
MicroPython Temperature Sensor for the NodeMCU ESP8266.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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