hi, singaporean student here. Doing a project for school but can't seem to get this right. using an LM35 temperature sensor to detect air temp, microcontroller is Arduino Uno. 5v power source is usb from my Macbook air to the uno, pins from left to right are 5v, analog pin A1, and ground. switched between 3 lm35s but all seem to have the same issue. there are various components connected but specifically used the code for only temp sensor. the deadline is soon so someone please help me solve this issue
code is below here
int raw = 0;
float temp = 0;
void setup() {
Serial.begin(9600);
pinMode( A1, INPUT );
}
void loop() {
raw = analogRead(A1);
temp = (raw/1023.0 )*5.0*1000/10;
Serial.println(temp);
delay(1000);
}
ill check when im back at the lab on Monday, but I've used several different codes from different sources and all of them give me similar outputs, such as a 8-10 good values then drops to 0
yes its connected to 5v. However, I read that I should power the circuit with a more stable power source like a dc power supply and not rely on the usb from the computers power. is this true? or the computer is good enough
all good, finally got it to work! output shows constant temperature and increases and decreases as I hold on to the sensor and let go! thx for all your help!
I was also about to give up thinking I got a cheap fake knock off part, but it wasn't.
I got it to work in the end after an hour or so.
I disconnected everything except the LM35 sensor, then noticed in the Serial Monitor that the sensor reading values were now stable, and no longer fluctuating randomly up or down.
In my case the culprit was the LCD.
I had a single ground to the bread board, and both the LM35 and LCD was connected to it.
I disconnected the ground of the LCD from the bread board, then connected directly to another GND in the Adruino.
Boom, LCD was now displaying the correct temperature stably.
I have posted the requirement to give an LM35 it's own ground maybe 100 times on this forum over the last years. If you had done a search, you would have found it.
You would also have found that code with analogReference(INTERNAL); in setup() gives you a supply voltage independent readout and a 5 times higher temp resolution. Only with that you can have a stable one decimal place readout.
Basic example attached.
Leo..