Let's Workshop: Keyestudio LM35 Temperature Sensor


Here is a quick introduction to using the Keyestudio LM35 temperature sensor module. Hopefully it will provide you with the confidence to intergrate a small and simple analog temperature monitor into your project.

This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of temperatures.

Components

  • 1pcs Arduino UNO or Compatible - LCAA100005
  • 1pcs Keyestudio LM35 Temperature Sensor Module - BDAA100017
  • 3pcs Male to Female Jumper Cables - GBAA100002

Wiring

Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers.

Coding

The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. The variable is then sent through a small calculation to convert a voltage to temperature in celcius. The calculated value then overwrites the original value held in the variable. Following that we send it to the serial monitor so that the value can be read on the screen.

Load the code below into the Arduino IDE and upload it to your board.

/*
  A simple program designed to setup and demonstrate the Keyestudio 
  LM35 temperature sensor module. - BDAA100017
 
  The program monitors an analog pins and outputs the value to the
  serial monitor.
  
  modified 9th October 2019
  by Sebastian Karam - Flux Workshop
*/
int analogApin = 0; // define OTA/S signal pin
int analogA; // define variable to store value read from pin
  
void setup() {
  pinMode(analogApin, INPUT); // set the OTA/S signal pin as an input
  Serial.begin(9600); // launch the serial monitor
  Serial.println("Flux Workshop Example");
}
 
void loop() {
  analogA = analogRead(analogApin);  // read the voltage level on the A0
  analogA = (analogA * 500) / 1024; // convert the voltage level to a temperature
  Serial.println((String)"Temperature: " + analogA + " degC"); // send the result to the serial monitor
  delay(200); // pause for a moment before repeating
}

Running

With the board loaded with the program and all the connections made the serial monitor will produce an output like the one seen below. In this case the sensor is on the table and a cup full of boiling water is placed on top of it. It would keep going up if I kept recording, but I am sure you have better things to do with your day.

What to try next?

  • Use the output to monitor room temperature at set times.
  • The calculation in the code reads Celcius, some tweaking will get it to farenheit, and dare I suggest Kelvin.
Previous article Let's Workshop: Keyestudio Ambient Light Sensor Module
Next article Let's Workshop: Keyes 801S Vibration Sensor Module

Leave a comment

* Required fields