Analog Reading for Temperature sensor Cumulative value

Hello, everybody,
I am trying to read temperature using A0
It gives me only the first reading(after switch on), a correct value, after that the value still increasing with non-fixed step.
I tried to connect pull-down resistor, and also I tried to connect a capacitor, unfortunately, the increment is still
can anybody advise me?

Please post your schematic and code using code tags when you post the code

1 Like


unsigned int ADC_Value = analogRead(sensorPin);

Hi,
what type, (model, link, ....), is this your sensor?

RV mineirin

1 Like

And the rest of your sketch ?

What type of sensor are you using ?

1 Like

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x3F, 16 column and 2 rows

int trigPin = 9;    // TRIG pin
int echoPin = 8;    // ECHO pin
int Wait_LED = 10;  // Waiting Visitor LED
int well_LED = 11;  // Well LED
int ill_LED = 12;  // Well LED
const int buzzer = 6; //buzzer to arduino pin 6
const int buzzer_active = 7; //buzzer to arduino pin 7
const int sensorPin = A1; // T01
float duration_us, distance_cm;

void setup() {
  lcd.init();               // initialize the lcd
  lcd.backlight();          // open the backlight
  pinMode(trigPin, OUTPUT); // config trigger pin to output mode
  pinMode(echoPin, INPUT);  // config echo pin to input mode pin to output mode
  pinMode(Wait_LED, OUTPUT);// config Waiting Visitor LED
  pinMode(well_LED, OUTPUT);// config well  LED
  pinMode(ill_LED, OUTPUT);// config ill  LED
  pinMode(buzzer, OUTPUT); // Set buzzer - pin 6 as an output
  pinMode(buzzer_active, OUTPUT); // Set buzzer - pin 7 as an output


}

void loop() {

  digitalWrite(buzzer_active, LOW);
  // generate 10-microsecond pulse to TRIG pin
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // measure duration of pulse from ECHO pin
  duration_us = pulseIn(echoPin, HIGH);

  // calculate the distance
  distance_cm = 0.017 * duration_us;

  if (distance_cm > 75)
  {
    lcd.clear();
    lcd.setCursor(0, 0); // start to print at the first row
    lcd.print("Pls Be Closer");
    lcd.setCursor(0, 1);
    lcd.print("Let Chk Ur Temp");
    digitalWrite(Wait_LED, HIGH);
    digitalWrite(well_LED, LOW);
    digitalWrite(ill_LED, LOW);


    delay(1000);
  }

  else {
    digitalWrite(Wait_LED, LOW);
    digitalWrite(well_LED, LOW);
    digitalWrite(ill_LED, LOW);
    lcd.clear();
    delay(500);
    lcd.setCursor(0, 0);
    lcd.print("Your Temp is:");
    delay(500);
    lcd.setCursor(2, 1);
    lcd.print("."); delay(500);
    lcd.print("."); delay(500);
    lcd.print("."); delay(500);
    lcd.print("."); delay(500);
    lcd.print("."); delay(500);
    lcd.print("."); delay(500);
    lcd.print("."); delay(500);
    lcd.print("."); delay(500);
    lcd.print(".");
    delay(3000);

    unsigned int ADC_Value = analogRead(sensorPin) - 123;
    //float i=((double)ADC_Value*285/1023-70);

    float i = ((((double)ADC_Value - 202.6) / 810.4) * 450) - 70;
    // float j=(i-4)/16*450-70;
    lcd.setCursor(0, 0);
    lcd.print("                      ");
    lcd.setCursor(2, 1);
    lcd.print("                      ");
    lcd.setCursor(0, 0);
    lcd.print(ADC_Value);
    delay(1000);
    lcd.setCursor(1, 1);
    lcd.print(i);
    ADC_Value = 0;
    i = 0;
    delay(10000);


    if (i < 37.7)
    {

      lcd.setCursor(2, 1);
      lcd.print("                      ");
      lcd.setCursor(3, 1);
      lcd.print(i);
      ADC_Value = 0;
      i = 0;
      lcd.setCursor(8, 1);
      lcd.print("C");
      digitalWrite(well_LED, HIGH);
      digitalWrite(Wait_LED, LOW);
      digitalWrite(ill_LED, LOW);
      delay(3000);

      lcd.setCursor(0, 0);
      lcd.print("                      ");
      lcd.setCursor(2, 1);
      lcd.print("                      ");
      lcd.setCursor(0, 0);
      lcd.print("You are welcome");
      delay(1000);
      lcd.setCursor(1, 1);
      lcd.print("Door is Open");
      delay(2000);
    }
    else {


      lcd.setCursor(2, 1);
      lcd.print("                      ");
      lcd.setCursor(3, 1);
      lcd.print(i);
      i = 0;
      lcd.setCursor(8, 1);
      lcd.print("C");
      digitalWrite(ill_LED, HIGH);
      digitalWrite(well_LED, LOW);
      digitalWrite(Wait_LED, LOW);
      digitalWrite(buzzer_active, HIGH);
      tone(buzzer, 1000); // Send 1KHz sound signal...
      delay(1000);        // ...for 1 sec
      noTone(buzzer);     // Stop sound...
      delay(1000);        // ...for 1sec
      tone(buzzer, 1000); // Send 1KHz sound signal...
      delay(1000);        // ...for 1 sec
      noTone(buzzer);     // Stop sound...
      tone(buzzer, 1000); // Send 1KHz sound signal...
      delay(1000);        // ...for 1 sec
      noTone(buzzer);     // Stop sound...
      tone(buzzer, 1000); // Send 1KHz sound signal...
      delay(1000);        // ...for 1 sec
      noTone(buzzer);     // Stop sound...
      delay(1000);        // ...for 1sec
      tone(buzzer, 1000); // Send 1KHz sound signal...
      delay(1000);        // ...for 1 sec
      noTone(buzzer);     // Stop sound...
      tone(buzzer, 1000); // Send 1KHz sound signal...
      delay(1000);        // ...for 1 sec
      noTone(buzzer);     // Stop sound..
      digitalWrite(buzzer_active, LOW);

      delay(2000);

      lcd.setCursor(0, 0);
      lcd.print("                      ");
      lcd.setCursor(2, 1);
      lcd.print("                      ");
      lcd.setCursor(0, 0);
      lcd.print("You are Sick");
      delay(2000);
      lcd.setCursor(0, 1);
      lcd.print("Pls Go Hospital");
      digitalWrite(buzzer_active, HIGH);
      tone(buzzer, 1000); // Send 1KHz sound signal...
      delay(1000);        // ...for 1 sec
      noTone(buzzer);     // Stop sound...
      delay(1000);        // ...for 1sec
      tone(buzzer, 1000); // Send 1KHz sound signal...
      delay(1000);        // ...for 1 sec
      noTone(buzzer);     // Stop sound...
      tone(buzzer, 1000); // Send 1KHz sound signal...
      delay(1000);        // ...for 1 sec
      noTone(buzzer);     // Stop sound...
      digitalWrite(buzzer_active, LOW);

      delay(2000);
    }
  }
}

TS01 temperature type IR ( TS01_IR_Thermal_Sensor_(4-20mA)_SKU_SEN0264-DFRobot )

and also I tried to measure the voltage input to A0 and it always fixed for the same object that means the sensor work correctly

I am sorry for post the code like this, but I don't know how to use code tag

@MSALA7Bibars how did I know that you would ignore the request to use code tags when posting your sketch ?

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

1 Like

Thanks for your help, I did the post using the code tag

Thank you

1 Like

@MSALA7Bibars
to use this temperature sensor do you need a special module.
It can't wired direct to arduino pins.

RV mineirin

1 Like

I used a resistor of 250 ohms as this link:

and as I mentioned before, I connect a voltmeter to A0 and GND and the voltage on the voltmeter is always correct and doesn't chang until the object change,

hee
where is pin 0???

Fony

So this can not work at the delays they wait 10 seconds and draw a point
All delay out and use millis

1 Like

Here is, I try to minimize the code only for the Temperature Sensor Reading: so I connected With A1 now


#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x3F, 16 column and 2 rows

const int sensorPin = A1; // T01

void setup() {
  lcd.init();               // initialize the lcd
  lcd.backlight();          // open the backlight
}

void loop() {

  lcd.clear();
  delay(500);
  lcd.setCursor(0, 0);
  lcd.print("Your Temp is:");
  delay(500);
  lcd.setCursor(2, 1);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print(".");
  delay(3000);

  unsigned int ADC_Value = analogRead(sensorPin) - 123;


  float i = ((((double)ADC_Value - 202.6) / 810.4) * 450) - 70;

  lcd.setCursor(0, 0);
  lcd.print("                      ");
  lcd.setCursor(2, 1);
  lcd.print("                      ");
  lcd.setCursor(0, 0);
  lcd.print("ADC Value:");
  lcd.setCursor(10, 0);
  lcd.print(ADC_Value);
  delay(1000);
  lcd.setCursor(1, 1);
  lcd.print("Temp:");
  lcd.setCursor(6, 1);
  lcd.print(i);
  ADC_Value = 0;
  i = 0;
  delay(10000);



}

and also you can watch the short video, you can see how the ADC value and Temperature reading are increasing and the voltmeter and amp meter are fixed.

Yes it can be good in the video but not with the sketch it is wrong
or copied wrong
and I have not seen the video

1 Like

Sory I am out

1 Like

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x3F, 16 column and 2 rows

const int sensorPin = A1; // T01

void setup() {
  lcd.init();               // initialize the lcd
  lcd.backlight();          // open the backlight
}

void loop() {

  lcd.clear();
  delay(500);
  lcd.setCursor(0, 0);
  lcd.print("Your Temp is:");
  delay(500);
  lcd.setCursor(2, 1);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print("."); delay(500);
  lcd.print(".");
  delay(3000);

  unsigned int ADC_Value = analogRead(sensorPin) - 123;


  float i = ((((double)ADC_Value - 202.6) / 810.4) * 450) - 70;

  lcd.setCursor(0, 0);
  lcd.print("                      ");
  lcd.setCursor(2, 1);
  lcd.print("                      ");
  lcd.setCursor(0, 0);
  lcd.print("ADC Value:");
  lcd.setCursor(10, 0);
  lcd.print(ADC_Value);
  delay(1000);
  lcd.setCursor(1, 1);
  lcd.print("Temp:");
  lcd.setCursor(6, 1);
  lcd.print(i);
  ADC_Value = 0;
  i = 0;
  delay(10000);



}

Please I need a support

Your code reflects using sensor pin A1 and you are saying you are using A0 so which is it? Next rather than a mountain of code start simple with just a few lines and measure the voltage. While this will be approximate you will at least get things working. Then slowly expand your code.

Ron

1 Like