Editorial Solution

We will need The LM35 temperature sensor.

From the datasheet by Texas Instruments:

  • Range : -55 °C to 150 °C
  • Linear +10 mV/°C Scale Factor (the LM35 sensor changes its output by 10 mV, for every 1°C)
  • The voltage range by LM35’s OUT pin is -0.55 V to 1.5 V

If the temperature is -10 °C and the voltage on the GND pin of LM35 is 0 Volts, then the voltage produced on the Out pin of LM35 is -100 millivolts. 

But let us consider, that the voltage provided on the GND pin of LM35 is 1 Volt, then the voltage produced on the OUT pin of LM35 is 900 millivolts.

This means that the voltage at the Out pin is shifted up by 1 Volt.

Now, the shifted positive values can be easily detected by Arduino’s ADC. 

 

Connection 

  • The voltage at the GND pin is 1.241 Volts, which will shift the negative voltage on the Vout pin to positive voltages by 1.241 Volts.

 

Let’s write code.:

  • Read voltage on both Analog pins.
  • Subtract the offset voltage (LM35 reference) 1.241 Volts
  • Convert voltage to temperature
  • Print the temperature on the Serial Monitor. We can also connect an LCD & display temperature on it. For this task, we will use the Serial monitor.
     

Code

const int lm35_pin = A0;   /* LM35 O/P pin */
const int offset_pin = A1; /* LM35 GND pin */
float offset_voltage = 0;  /* offset voltage stored in milli-volts */

float temp_val;

void setup() {
  Serial.begin(9600);
}

void loop() {
  offset_voltage = analogRead(offset_pin) * (5000 / 1024); /* read offset voltage on A1 pin and convert it to milli-volts */

  temp_val = analogRead(lm35_pin) * (5000 / 1024); /* Convert adc value to equivalent voltage (milli-volts) */
  temp_val = temp_val - offset_voltage;    /* remove the offset voltage */
  temp_val = (temp_val / 10);              /* LM35 gives output of 10mv/°C */

  Serial.print("Temperature = "); /* Print the temprature*/
  Serial.print(temp_val);
  Serial.println(" Degree Celsius");
  delay(1000);
}

 

Code explanation

  • float temp_val = adcValue * (5000 / 1024) : converts ADC_value to voltage (milli volts). 
  • temp_val = temp_val - offset_voltage: removes the offset voltage, that is given to the GND pin.
  • temp_val = (temp_val/10) : converts into degree Celsius (1 degree Celsius = 10mV).
     

Output

 

Output video

  • As we can see in the video, the temperature change is successfully detected and printed on the Serial monitor.

 

Negative temperature detection

  • Measuring negative temperature would require liquid nitrogen but it is -196 °C. So, it will damage our sensor.
  • Unfortunately, we will skip measuring negative temperature!

 

 

 

 

Submit Your Solution