Created
August 25, 2014 22:20
-
-
Save JasonParmenter/85ffc334effbd84a0c81 to your computer and use it in GitHub Desktop.
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
/* | |
This is a simple example sketch that reads the analog output voltage from the MCP9700A temperature sensor. | |
Further information about the MCP9700A can be found here: | |
http://ww1.microchip.com/downloads/en/DeviceDoc/20001942F.pdf | |
Two methods used in this example: tempF(), tempC() utilizing conversion formula found in the | |
MCP9700A data sheet. | |
***************************************************************** | |
Wiring: | |
RED <--> 3.3V or 5.5V pin (power over I/O pins is OK). | |
BLACK <--> Any analog pin on the arduino (A0) in this example. | |
Bare <--> GND | |
***************************************************************** | |
created 21 Aug. 2014 | |
modified 9 Apr 2012 | |
by Jason Parmenter | |
*/ | |
// Any analog pin will do, but we will use analog pin 0. | |
const int sensorPin = A0; // BLACK wire from temp sensor (analog voltage) | |
float voltage = 3.62; // Typically 5V on Arduino (This is the reference voltage used by your boards A/D Converter). | |
float tmpC = 0; | |
float tmpF = 0; | |
void setup() { | |
// initialize serial communications at 9600 bps: | |
Serial.begin(9600); | |
pinMode(sensorPin,INPUT); | |
} | |
void loop() { | |
// read the analog in value: | |
tmpC = getTempC(); | |
tmpF = getTempF(); | |
// print the results to the serial monitor: | |
Serial.print("TempC = " ); | |
Serial.print(tmpC); | |
Serial.print(", "); | |
Serial.print("TempF = "); | |
Serial.println(tmpF); | |
delay(1000); | |
} | |
/********************************* | |
Method to get temperature (C) | |
**********************************/ | |
float getTempF() | |
{ | |
float tmp = analogRead(sensorPin); | |
tmp = tmp*voltage/1023; | |
return (tmp/0.01) - .5; | |
} | |
/********************************* | |
Method to get temperature (F) | |
**********************************/ | |
float getTempC() | |
{ | |
float tmp = getTempF(); | |
return (tmp - 32.0) * (5.0/9.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment