Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
greg
Published © GPL3+

Sensing the temperature (S1.1)

In this hands on lab you will build a simple circuit to calculate the temperature.

BeginnerFull instructions provided491
Sensing the temperature (S1.1)

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
Breadboard (generic)
Breadboard (generic)
×1
Temperature Sensor
Temperature Sensor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit

Code

Base Code

Arduino
// Temperature Sensor
int sensorPin = A0;   // Sets A0 as the input pin for the sensor
int sensorValue = 0;  // initialise a variable to store the value coming from the sensor
int Dres = 1024;      // set max 10-bit digital value
int VCC = 3300;       // set VCC voltage milliVolts
int offset = 500;        // set tolerance of 500 milliVolts
int scaling = 100;         // set the voltage scaling at 10mM / deg C
float temperature = 0.0; // set the initial temperature as 0
float voltage = 0.0;     // set the initial voltage to 0

void setup() {
  Serial.begin(9600);
  // Set 10bit read resolution
  analogReadResolution(10);
}

void loop() {

  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  Serial.print("sensorValue = ");
  Serial.print(sensorValue);

  // Calculate the voltage
  voltage = sensorValue * (VCC/Dres); // milliVolts
  Serial.print(" voltage = ");
  Serial.print(voltage);
  Serial.print(" VCC = ");
  Serial.print(VCC);

  // Calculate the temperature
  temperature = (voltage - offset ) / scaling;
  Serial.print(" temperature(C) = ");
  Serial.println(temperature);

  delay(1000);
}

Credits

greg
0 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.