About lm35 and buzzer

I want code the temperature sensor and buzzer. The sensor is inserted on a tooth brush. So the buzzer should make the sound for every half minute. It should remind for every half minute. How can we code this and the temperature should also be displayed

Tell about Your electronical and programming experience.

I am not much pro in programming

I can program for specific temperature greater or lesser than like that but i am not able to program like this

You answered half the question.

I donot have much experience in electronical but i can manage

Thanks. Helping You is beyond what I feel I want to do.
Let's hope other helpers step in.

Sounds like a school project, so we should only help you if you run into problems.
Start with providing your plans, your schematic diagram and your code.

//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
int buzzer = 5;

  • setup() - this function runs once when you turn your Arduino on
  • We initialize the serial connection with the computer
    void setup()
    Serial.begin(9600); //Start the serial connection with the computer
    //to view the result open the serial monitor

void loop() // run over and over again
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);

// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;

// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");

// Sounds the buzzer at the frequency relative to the note C in Hz
// Waits some time to turn off
//Turns the buzzer off
// Sounds the buzzer at the frequency relative to the note D in Hz
// Sounds the buzzer at the frequency relative to the note E in Hz
delay(1000); //waiting a second

if i use this i cannot get temperature values for every second. That is my problem

delay() stops the processor for the delay time.

Study the BlinkWithoutDelay example in the examples of the IDE.
Then remove all the delay() calls and replace it with millis() timing.

Hi @vamsi721 ,

use millis () instead of delay ().

RV mineirin

I have now solved the problem thank you guys

i have one more question. I will measure the temperature for like 2 minutes. But i want to get the only max temperature from it . But i am getting some spikes in the values from lm35 sensor. So i want to calculate mode. Is there any way to do this

The TMP36 part of your code is potentially not very stable, because you use default Aref (5volt supply). You could get better results if you use the internal/stable 1.1volt Aref.
You also take a detour by converting to voltage before converting to temp.
Just convert directly from A/D value to temp, and subtract 50C from that temp (the TMP36 offset).
You also don't get a higher resolution than 0.1C with a TMP36 and 10-bit A/D.
Example code attached. Read the comments.
If that doesn't fully cure the problem, then try adding smoothing code.

An if() statement could compare a new reading with a previous reading, and if the new one is higher, then replace the previous reading.

const byte tempPin = A0; // connect TPM36 to 3.3volt A0 and (not-shared) ground
float calibration = 0.1039; // calibrate temp by changing the last digit(s) of "0.1039"
float tempC;

void setup() {
  analogReference(INTERNAL); // use internal 1.1volt Aref

void loop() {
  tempC = (analogRead(tempPin) * calibration) - 50.0;
  Serial.print("Temperature:  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" C");
  delay(1000); // use a non-blocking delay when combined with other code

float prev_value = 0;
float cur_value = temperature;
if (cur_value > Prev_value);{
prev_value = cur_value

I have given in the code like this but i am getting error saying prev value not declared in this scope

  1. Semicolon in the wrong place.
  2. "prev_value" is not the same as "Prev_value"

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.