Skip to content

Commit

Permalink
Add TMP36 example sketch.
Browse files Browse the repository at this point in the history
  • Loading branch information
JChristensen committed Mar 30, 2018
1 parent ac0b0a3 commit af4de20
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/mcp9800/mcp9800.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ void loop()
Serial.print(c16 / 16.0); // print the individual reading
Serial.print("C ");
Serial.print(avg / 16.0); // print the moving average
Serial.print("C \n");
Serial.print("C\n");
delay(1000);
}
2 changes: 1 addition & 1 deletion examples/mcp9808/mcp9808.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ void loop()
Serial.print(c16 / 16.0); // print the individual reading
Serial.print("C ");
Serial.print(avg / 16.0); // print the moving average
Serial.print("C \n");
Serial.print("C\n");
delay(1000);
}
38 changes: 38 additions & 0 deletions examples/tmp36/tmp36.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Arduino Moving Average Library
// https://github.com/JChristensen/movingAvg
// Copyright (C) 2018 by Jack Christensen and licensed under
// GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
//
// Example sketch to smooth the readings from a TMP36 analog temperature sensor.
// Connect the sensor to the A0 pin.

#include <movingAvg.h> // https://github.com/JChristensen/movingAvg

const uint8_t SENSOR_PIN(A0); // connect sensor to A0 pin
movingAvg avgTemp(10); // define the moving average object

void setup()
{
Serial.begin(115200);
avgTemp.begin();
}

void loop()
{
int tC100 = readTMP36(SENSOR_PIN); // read the sensor
int avg = avgTemp.reading(tC100); // calculate the moving average
Serial.print(tC100 / 100.0); // print the individual reading
Serial.print("C ");
Serial.print(avg / 100.0); // print the moving average
Serial.print("C\n");
delay(1000);
}

// read TMP36 temperature sensor, return °C * 100
// TMP36 output is 10mV/C with a 500mV offset
long readTMP36(int muxChannel)
{
long uV = (analogRead(muxChannel) * 5000000L + 512) / 1024; //microvolts from the TMP36 sensor
return (uV - 500000 + 50) / 100;
}

3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
movingAvg KEYWORD1
begin KEYWORD2
reading KEYWORD2
getAvg KEYWORD2
getAvg KEYWORD2

0 comments on commit af4de20

Please sign in to comment.