Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Temperature Printing Program
- * By Orwell Kowalyshyn @ themakery.space
- *
- * This program reads a temperature sensor and calculates four different values of
- * temperature in Celcius, Farenheit, and Kelvin
- *
- * The program also converts the signal into its equivalent in volts.
- *
- * Program assumes standard 500mv offset from thermistor. Consult
- * your own sensor's datasheet for exact range and relationships.
- *
- * Lilypad thermistor is type MCP9700
- * https://www.sparkfun.com/datasheets/DevTools/LilyPad/MCP9700.pdf
- * standard form linear relationship V = (1/100)T + 0.5 for MCP9700
- * standard form linear relationship V = (1.9/100)T + 0.4 for MCP9701
- *
- */
- //define arduino ports as constants
- #define sensorPin A0
- #define outputPin 13
- #define offsetT 0.5 //MCP9700
- #define inverseSlopeT 100.0/1.0 //MCP9700
- void setup() {
- Serial.begin(9600);
- //set up serial port
- pinMode(outputPin, OUTPUT);
- //define LED output
- digitalWrite(outputPin, LOW);
- //start by turning LED off
- }
- void loop() {
- int sensorRead = analogRead(sensorPin);
- //read the raw sensor value between 0-1023, 10-bit ADC
- float sensorVoltage = (sensorRead*5.0)/1024.0;
- //convert the sensor value to Volts (5.0V per 1024 steps)
- float sensorTempC = (sensorVoltage-offsetT)*inverseSlopeT;
- //convert the voltage into degrees Celcius as per datasheet
- float sensorTempF = (sensorTempC*1.8)+32.0;
- //convert degrees Celcius to degrees Farenheit
- float sensorTempK = sensorTempC + 273.15;
- //convert degrees Celcius to Kelvin
- if (sensorTempC > 22) { //turn on LED when warm
- digitalWrite(outputPin, HIGH);
- }
- else if (sensorTempC <= 22) { //turn off LED when cold
- digitalWrite(outputPin, LOW);
- }
- //Debug display values
- Serial.println(" Voltage: "+String(sensorVoltage)+" Celcius: "+String(sensorTempC)+" Farenheit: "+String(sensorTempF)+" Kelvin: "+String(sensorTempK));
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement