Skip to content

Instantly share code, notes, and snippets.

@futureshocked
Last active July 30, 2019 00:51
Show Gist options
  • Save futureshocked/79960bb8bebaa0ff5b1a4c7534a805e1 to your computer and use it in GitHub Desktop.
Save futureshocked/79960bb8bebaa0ff5b1a4c7534a805e1 to your computer and use it in GitHub Desktop.
This sketch read the voltage of a Grove temperature sensor and calculates the temperature in degrees C.
/* 04.010 - Grove temperature sensor (Temperature Sensor V1.1/1.2)
*
This sketch read the voltage of a Grove temperature sensor and
calculates the temperature in degrees C.
The temperature sensor is an analog sensor.
Components
----------
- Grove Base Shield
- An Arduino Uno compatible board (such as Arduino/Genuino Uno or Seeeduino)
- Grove Temperature Sensor V1.1/1.2
- One Grove cable
IDE
---
Arduino IDE
Libraries
---------
- Math
Connections
-----------
Use a Grove cable to connect the temperature module to Base Shield connector A0.
Other information
-----------------
- Use this sketch along side the video lecture 04.010 of Grove For Busy People
- Original sketch location: http://wiki.seeedstudio.com/Grove-Temperature_Sensor_V1.2/ by Loovee @ 2015-8-26
- Grove component: https://txplo.re/4hc
- Thermistor datasheet: http://www.mwftr.com/emblab/Temp%20Sensor%20-NCP18WF104F03RC.pdf
- Thermistor model: NCP18WF104F03RC (NTC- Negative Temperature Coefficient)
- Learn about temperature coefficient: https://en.wikipedia.org/wiki/Temperature_coefficient
Github Gist
-----------
<script src="https://gist.github.com/futureshocked/79960bb8bebaa0ff5b1a4c7534a805e1.js"></script>
https://gist.github.com/futureshocked/79960bb8bebaa0ff5b1a4c7534a805e1
For course information, please go to https://techexplorations.com/product/grove-for-busy-people/
Created on July 5 2019 by Peter Dalmaris
*/
#include <math.h>
const int B = 4275; // B value of the thermistor
const int R0 = 100000; // R0 = 100k
const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A0
void setup()
{
Serial.begin(9600);
}
void loop()
{
int a = analogRead(pinTempSensor);
float R = 1023.0/a-1.0;
R = R0*R;
float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet
Serial.print("temperature = ");
Serial.println(temperature);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment