Sensor acts weird on 9V supply

Hello, I bought myself an arduino to play with since last week :). So I'm new to the world of Arduino.

I'm making a starter project in which you can see the temprature on an LCD. The sensor I'm using is an LM35.
The problem however is that with my USB everything is as its expected to be, but when I replace the USB supply with my 9V supply my sensor
reads 10° more then normal and de characters on my LCD are almost unreadble. I don't know what is causing this, so I hope someone can help me out :slight_smile:

Code:

#include <LiquidCrystal.h>
//Analog Input
int SensorPin = A0;
//Digital Outputs
char TempLow = 18;
char TempHigh = 23;


LiquidCrystal lcd(13, 12, 4, 5, 6, 7);
float TempC;

void setup()
{
  lcd.begin(16, 2);
}
void loop()
{
  TempC = analogRead(SensorPin);
  TempC = (TempC * (5.0 / 1024.0)) * 100;
  
  lcd.setCursor(1,0);
  lcd.print(TempC);
  
    if(TempC < TempLow)
  { //COLD
    
  }
  if(TempC > TempLow && TempC <  TempHigh)
  { //GOOD
  
  }
  if(TempC > TempHigh)
  {  //HOT
  
  }
  
  delay(5000);
}

You need to tell us how you wired it up.
Is the 9V going to the power jack?
Is the sensor wired up to the Vin pin or the +5V pin?

Did you find that sketch somewhere ? Please copy a link to it in your text.

You write a floating point variable to the lcd.
Is that allowed ?

You write a floating point variable to the lcd.
Is that allowed ?

Yes

Thanks for the replies.

You need to tell us how you wired it up.
Is the 9V going to the power jack?
Is the sensor wired up to the Vin pin or the +5V pin?

The 9V adapter is connected to the power supply.
As for the sensor, if you take the flat side of the LM35 my connections are:

  • Left: +5v Pin
  • Middle: A0 Pin
  • Right: GND Pin

Did you find that sketch somewhere ? Please copy a link to it in your text.

You write a floating point variable to the lcd.
Is that allowed ?
LiquidCrystal - Arduino Reference

I Don't think its the LCD since it works when connected to USB but not when connected trough 9V adapter.

Edit:
Here's a scheme

We need to know more, and you need to test more.

Do you have a multimeter ?
Is the 9V adapter really 9V, or perhaps 14V ? Some adapters are very bad. Is it a DC adapter ?
I use a switching adapter of 7.5V for my Arduinos.
If you use the USB to power the Arduino, what voltage is the 5V pin ? The LM35 works with different voltages, but the voltage read at the analog input of the Arduino depends on the 5V.

Can you open a serial communication with the serial monitor of the Arduino IDE ?
Use Serial.begin(9600); to initialize and in write the temperature also to the serial monitor with Serial.println(TempC);
Is that also unreadable ?

Do you use a Arduino Uno ?

What you describe is correct, however I suspect what you do is not. We have to spot the difference so can you post a photo of the 9V powered setup.

What you describe is correct, however I suspect what you do is not. We have to spot the difference so can you post a photo of the 9V powered setup.

This is the 9V supply I use:

I've also posted a scheme of my project in my previous post.

Do you have a multimeter ?
Is the 9V adapter really 9V, or perhaps 14V ? Some adapters are very bad. Is it a DC adapter ?
I use a switching adapter of 7.5V for my Arduinos.
If you use the USB to power the Arduino, what voltage is the 5V pin ? The LM35 works with different voltages, but the voltage read at the analog input of the Arduino depends on the 5V.

Can you open a serial communication with the serial monitor of the Arduino IDE ?
Use Serial.begin(9600); to initialize and in write the temperature also to the serial monitor with Serial.println(TempC);
Is that also unreadable ?.

I don't have a multimeter at home atm. I've already tried with serial monitor but the problem is once hooked up with usb everyting is normal, also I should clarify that the characters of the LCD fade and thats why it so unreadable (you can see the characters if you look close).

Also I noticed even when it connected trough USB , if I gently touch the LM35 the temprature jumps 20° higher en then back to lower.

It is weird. You need a multimeter to measure all the voltages.
Do you use the backlight without resistor ?
I would advise a resistor. Some LCD display schematics use 47 ohm to 5V, other use 330 Ohm.

It seems to me, the problem isn't the temperature sensor, it's the LCD.

You are saying, the temperature measurement works when you power the setup using the USB ?

Get a multimeter and check the voltages.

I am also wondering if it is wise to use pin 13 when connecting to the LCD. Is there a LED
connected to that pin on your arduino board ?

Are the batteries fresh? A volt meter would tell you if the voltage from them is dropping when it is under load.

if I gently touch the LM35 the temprature jumps 20° higher en then back to lower.

That is because you are getting a poor connection with your bread board, that is why they are a bad idea. I never use then and I never recommend anybody does.

A couple of things. First, taking only one sample is going to result in a noisy reading, try averaging a bunch of samples, like dozens of them. They don't take long at all. Secondly, on the odd chance that the onboard regulator is current limiting, take one or two batteries out of your pack and see what happens. Just jumper across the missing battery location. This will reduce the power dissipation of the voltage regulator (heat output) but still allowing plenty of head room on the input voltage to output 5V. If you have 6 brand new "copper tops" in your pack, the supply voltage is above 10V; 7.5V is likely more than enough.