Temperature/pH Sensor affected by RGB BackLight LCD

I am using a Arduino Uno Wifi with a Grove Kit base shield for my School Final Year project. i have not touch IOT before so i am sorry for sounding abit stupid..

Problem: When i connect either pH or Temperature sensor, the temperature is something like the 2nd picture. But when i turn on the the switch as you can see from the first picture(Top Right of the board), The temperature jumps up high as u can see from the 3rd picture. Why is this so? I am unsure which is the supposing accurate result as the difference is way too big. I am think maybe it is because of the voltage after i turn on the switch? Need some expert's help!

No info to go on. Try asking your local medium, maybe her crystal ball can tell you more. Mine is defective.

wvmarle:
No info to go on. Try asking your local medium, maybe her crystal ball can tell you more. Mine is defective.

I do not need sarcasm replies.

Still no code, no schematics, no part numbers. You seriously expect a serious answer? Did you even read the "how to" sticky?

Hello!
I have a similar unexplained behavior of my temperature sensor, mounted on UNO:

A. Code:

Here is how I get the temperature:

/// MODULE 1: Read and show sensor's values
SensVal = analogRead (sensorPin); //declare SensVal as the varaible to which the sensor sends the values
delay(5000); // read only at 5000 ms
Serial.print ("Senzor value: "); //communicate the name of the received values variables
Serial.println (SensVal); // show the value of the sensor
Voltage=(SensVal/1024.0*5.); // convert the values of the sensor to voltage
Serial.print ("Voltage: "); // communicate th variable name
Serial.println (Voltage); // communicate the voltage
Temp=(Voltage-0.5)*100.; //calculate the temperature from voltage
Serial.print ("Temperature is: "); //communicate the name of the varaible temperature
Serial.println (Temp); //communicate the value of the temperature
/// END MODULE 1

Here is how I display the temperature:

/// MODULE 3: Display the temperature on LCD
{
led.clear();
led.setCursor (0,0);
led.print ("temperature:");
led.setCursor (0,1);
led.print (Temp);
led.print (" Deg Celsius");
}
/// END MODULE 3

==========

B. PARTS:

  • UNO
  • LCD 1602 2x16 QUAPSS Display on I2C backpack based on PCF8574 - jumper on, backlight on (non-dimmable)
  • temperature sensor: analogic SEN-VRM-05 (looks like a no-name one)
  • a group of 2 LEDs that blinks under and bellow a certain value that I have to provide via serial dialogue (code not provided above, because it is very long and I used it both with and without display- so I suppose it could not influence the situation).

=====

C. Behavior

When the LCD is wired , the temperature is some 5 degree Celsius above the one I get without Display. Same as on serial check.

Checked also by touching: the temperature increases by some 4 degrees Celsius: with the Display mounted, the read temperature is 39-40 degree Celsius (and I feel OK :-)) .

======

Question:

I have two hypothesis:
a) There is a drop voltage somewhere when I connect the LCD (?)- which looks very likely, because when I set backlight off the temperature decreases by 1-2 degrees
b) The calibration -the function Voltage - temperature shall be non-linear (?)

Of course I can re-write the formula temperature - voltage, but this would be a non-scientific way to proceed :slight_smile:

There is also my concern the display can influence the data reading, thus jeopardizing my future project GPS data logging and displying. Far more difficult to control.

Question is:

  • why this happens?
  • how can I prevent this to happen (hardware/software)?

Advise highly appreciated!

falexandru:
Question is:

  • why this happens?
  • how can I prevent this to happen (hardware/software)?
  1. Because you measure with default Aref, and assume it is 5.000volt, and stays 5.000volt under load.
    Any dip in the supply will lower Aref, and so raise the temp result of the maths line.
    In other words, if the ruler that you measure something with shrinks, you measure a higher value.

  2. Measure the TMP36 with the more stable internal 1.1volt Aref.

Attached is TMP36 test code that uses 1.1volt Aref and averaging.
You need to calibrate if you want accurate temps. Read the comments.
Leo..

// TMP36 temp sensor output connected to analogue input A0, 3.3volt and ground

unsigned int total; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt Aref | change to (INTERNAL1V1) for a Mega
  Serial.begin(9600);
}

void loop() {
  total = 0; // reset total
  for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
    total += analogRead(A0); // add each value
  }
  tempC = total * 0.001632 - 50.0; // Calibrate temp by changing the last digit(s) of 0.001632
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit

  Serial.print("The temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 1); // one decimal place
  Serial.println(" Fahrenheit");

  delay(1000); // use a non-blocking delay when combined with other code
}

Based on your code, 4°C difference is a 0.04V difference. That's tiny, and a fairly normal aberration for standard voltage regulators when placed under load. So assuming your LCD (which draws a lot of power, for microprocessor measures) is powered from the Arduino, it will affect the actual value of the internal 5V supply.
Also indeed it is never exactly 5V, so with 0.01V being 1° difference you'll have to calibrate for that. For most applications this doesn't matter much, but you're so much pushing the edges that you will see a difference.

There's also this -0.5 factor: you deduct 0.5V from the reading. Is that really exact? Is the 0°C reading exactly -0.5V or a little bit off? Another problem factor. Finally the issue of linearity over the full range, and it really being 100°C = 1.000V difference.

Finally you may try connecting it through an external ADC, such as the ADS1115. This chip should give you more stable readings, and higher (16-bit vs. 10-bit) resolution.

@Wava - >Thank you! Really conclusive! And I can build further on your answer because it is grounded.

Does this code accept being modified for my sensor on 5V? [/code]

Wawa:
2) Measure the TMP36 with the more stable internal 1.1volt Aref.

Leo..

// TMP36 temp sensor output connected to analogue input A0, 3.3volt and ground

@vwmarle

Thank you! Clear and easy to understand!

I have on my desk a YwRobot Breadboard Power Supply (based on AMS1117 voltage regulator manufactured by Advanced Monolithic Systems). I guess this is the way you reccomanded - separate source from the UNO's?

Not yet mounted, as I miss the cable to the barrel (btw, I do not know the type of the connector to look for).

wvmarle:
Also indeed it is never exactly 5V, so with 0.01V being 1° difference you'll have to calibrate for that.

You can, if current draw would be constant, and voltage stays the same over time.
On USB supply, or if you blink/PWM a LED, 5volt will hop up/down.

"// TMP36 temp sensor output connected to analogue input A0, 3.3volt and ground"
The TMP36 can be powered from the potentially 'cleaner' 3.3volt pin, so why not.
Won't affect anything else.
Also wise to give the TMP36 it's own ground wire (not shared).
Leo..

/START

// Display on I2C - initialize
#include <Wire.h>;
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 led(0x3F); // set the LCD address to 0x3F for a 16 chars and 2 line display

//Variables section
//a) Senzor Variables
int sensorPin; // declare int the PIN to which the sensor is conected
int SensVal; //declare int the variable to store the values from senzor
float Voltage; // declare float the voltage between the sensor sends
float tempC; //declare float the temperature

// TMP36 temp sensor output connected to analogue input A0, 3.3volt and ground

unsigned int total; // A/D readings

void setup()
{
//Initialize LCD display

Wire.begin();
led.begin(16, 2); // initialize the lcd
led.clear();
led.setBacklight(1); //apparentely, my display can be only on for >0 or of =0
led.setCursor(0,0);
led.print("Start measuruing");

delay (5000);
//End LCD display initialization
//Start serial
Serial.begin(9600); // open the serial communication
//End serial
//Set sensors
sensorPin=A0; //state the PIN to which the sensor is connected
analogReference(INTERNAL); // use the internal ~1.1volt Aref | change to (INTERNAL1V1) for a Mega
//End set sensor
}

void loop(){
/// MODULE 1: Read and serial monitor sensor's values
total = 0; // reset total
for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
total += analogRead(A0); // add each value
}
tempC = total * 0.0013600 - 50.0; // Calibrate temp by changing the last digit(s) of 0.001632
Serial.print("The temperature is ");
Serial.print(tempC, 1); // one decimal place
Serial.print(" Celsius ");
delay(1000); // use a non-blocking delay when combined with other code
/// END MODULE 1: Read and serial monitor sensor's value

/// MODULE 3: Display the temperature on LCD
{
led.clear();
led.setCursor (0,0);
led.print ("temperature:");
led.setCursor (0,1);
led.print (tempC);
led.print (" Deg Celsius");

}
/// END MODULE 3
}
//END

====

This code returned a non-movable 56.8 value when sensor is connected to 3.3 V and a highly variable value (some 4 Degrees+-, which also decrease in a matter of minutes) when connected to 5 V. When I removed the jumper of the LCD thus putting backlight off, the temperature decreased by some 2 degrees - as the serial told me.

When I put my finger on the sensor, the temperature rises by some 3-4 degrees.

Eventually, after some 5 minutes and repeated modifications, the temperature value got stability and the reading appears to be correct. But, a big "but" when I pick the display in my hand the temperature rises by 3 degrees. I took the jumper off and the temperature decreases suddenly by 5 degrees.

The board is connected to 5 V USB from a PC desktop.

===

Question:

Did I mistakenly modify something in the code?

Or perhaps a conventional ground is needed (e.g. to the third wire of the network or to earth)?

I may also think that it just impossible to really measure the temperature by this type of sensor.

Thank you!

Did you try the code from post#5 without LCD connected.
You should have a very stable readout in the serial monitor, with a temp error of a few degrees max.
If not, show your wiring.
Leo..

Cleaned up the code.
LCD part is untested.
Leo..

// TMP36 temp sensor | connected to analogue input A0, 3.3volt and ground
#include <Wire.h>;
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 led(0x3F);
unsigned int total;
float tempC;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  led.begin(16, 2);
  led.setBacklight(1);
  led.print("Start measuring");
  delay (3000);
  led.clear();
  led.print ("Temperature:"); // stays the same, so why not print it once in setup
  analogReference(INTERNAL); // use the internal ~1.1volt Aref | change to (INTERNAL1V1) for a Mega
}

void loop() {
  total = 0; // reset total
  for (int x = 0; x < 64; x++) total += analogRead(A0); // 64(max) analogue readings
  tempC = total * 0.001632 - 50.0; // calibrate temp by changing the last digit(s) of 0.001632
  Serial.print("The temperature is  ");
  Serial.print(tempC, 1);
  Serial.println(" Celsius");
  {
    led.clear();
    led.setCursor (0, 1); // second row
    led.print (tempC, 1); // one decimal place
    led.print ("° Celsius");
  }
  delay(1000); // loop every second
}

Code looks sound to me; can't find anything odd in it. How's the result? Stable now?

Wawa:
Cleaned up the code.
LCD part is untested.
Leo..

Thank you for warning!

The LCD is on I2C soldered backpack. I am going to thoroughly revise and optimize the code for better control.

Which I found particularly difficult: usual libraries do not work on this display + backpack I2C. Not even Malpartida's library. My guess it that it has a very particular internal wiring (?). I had to use the seller's own library, which does misteriousely work.

I found the library that you use, and the code from post#12 compiles with it.
Couldn't test it ofcourse.

Post a link to the LCD/backpack.

You shouldn't assume that the backlight LED has a current limiting resistor.
If not, then that could explain things.

As said, try to get stable/accurate readings first without the LCD.
Leo..

Wawa:
You shouldn't assume that the backlight LED has a current limiting resistor.
If not, then that could explain things.

Depends on how it is wired - my LCD with i2c backpack has the backlight controlled from software, so that would make it safe to assume it does have a resistor built in. Could very well be the backpack, not the LCD itself, though.

Wawa:
As said, try to get stable/accurate readings first without the LCD.
Leo..

I removed the section of the code related to printing on LCD (from your second version), while keeping it wired. The (serial) reading is much more stable (within 1 degree) and is not influenced by handling the LCD.

LCD link is:

There is a jumper on the backpack - when on, it forces the backlight on. I cant control the dimming by software. When I take it out, the temperature decreases by some 2 degrees.

I talk in Celsius (metric-only country here).

Wiring:

LCD (BP):

GND ->common GND (breadboard)
VCC -> common 5 V (breadboard)
SDA -> A4 UNO
SCL -> A5 UNO

Senzor:
GND -> common GND (breadboard)
VCC -> common 5 V (breadboard)
OUT -> A0

also wired (not included in this code) - microSD

Source: 5 V PC Desktop
Breadboard - 175X67 mm Nikel Project Board manufactured by CandD Educational
Wires: dedicated Breadboard jumpers

falexandru:
I removed the section of the code related to printing on LCD (from your second version), while keeping it wired. The (serial) reading is much more stable (within 1 degree) and is not influenced by handling the LCD.

An Uno, without a shield, powered from USB, with TMP36 powered from the 3.3volt pin of the Uno, the TMP36 using it's own Arduino ground pin, with that sketch, should be stable within 0.1 degree C.

Just read post#8 again, about the breadboard supply.
Maybe we need to see the full picture of the setup.

There seems to be a 100ohm resistor in series with the backlight LED.
Leo..