Problem with analog inputs when multiple sensors are connected

Hello. Im working with arduino Uno. Trying to interface 3 sensors at a time i.e., humidity sensor to a digital pin, soil moisture sensor to an analog pin and LM35 to another analog pin. But the LM35 is giving weird readings. When its connected alone, then its perfectly fine. Could anyone figure out the problem and suggest a solution? The code is correct as far as i know..

Attaching the code will be a big help.

#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
Serial.begin(9600);
dht.begin();
Serial.println("Weather Sensor");
}

void temparature()
{
float temp=analogRead(5);
temp=temp5100/1024;
Serial.print("temparature:");
Serial.print(temp);
Serial.println("^C");
delay(2000);

}

void moisture()
{

float moist=analogRead(1);
Serial.print("soil moisture:");
Serial.print(moist);
Serial.println(".");

delay(2000);
}

void humidity()
{

float humid=dht.readHumidity();
float t=dht.readTemperature();
Serial.print("humidity:");
Serial.print(humid);
Serial.println("%");

delay(5000);
}

void loop()
{
temparature();
moisture();
humidity();
}
This is the code.

Try this code which is working perfect for me .

float temp=analogRead(5);
float millivolts = (temp / 1024.0) * 5000;
float celsius = millivolts / 10;
Serial.print("temparature:");
Serial.print(celsius);
Serial.println("^C");
delay(2000);

Thank you :slight_smile:

Your code is working fine. I had made a mistake in type conversions(1024.0 instead of 1024)

You are welcome wish u the best