Hello everyone so the time has finally come to ask my first question...So my problem is that I have a LM335Z temperature sensor (here's the datasheet) and I have connected the one of the pins pin directly to ground and the other to analog input and also 2k ohm resistor to vcc(5v, according to Arduino documentation). The problem occurs when I connect a bunch of other sensors, LEDs and an LCD, as it seems there is a voltage drop and when this happens the sensor gives wrong data, so how to fix it? I tried powering the Arduino with a 9v DC adapter(the sensor was again working correctly) but the linear voltage regulator on the board kind of doesn't like it(it gets hot). So is there any way to calibrate it with the Arduino by measuring the current voltage on the 5v pin and calculating the real temperature using USB power. Here's the code I am using:
Bad idea to use default Aref with this sensor.
Small variations in Aref (the 5volt supply) will show up in the temp.
1.1volt Aref (stable) can be used with an LM35 or TMP36, but it's not so easy with an LM335.
Here is how the sensor circuit is connected. The whole circuit doesn't draw much about 60-100mA(if not counting the digital pins) I was powering it with 9V AC/DC power adapter which can provide 0,6A output, may be the voltage is kind of high? I thought it might be better if I drop the 9V to 6V using this adapter
about the range of the temperature, nothing special just want to monitor room temperature which varies min 18C to max 35-40C if the sensor is exposed to sunlight.
6volt is borderline on Vin, and too low for the DC jack.
The DC jack needs 7.3volt minimum for the onboard fet to switch to from USB supply to external supply.
7.5volt is ideal if you are going to connect "heavy loads" to the 5volt pin.
9volt is good. 12volt is still ok for a few LEDs and an LCD.
Is your 9volt adapter regulated?
I think this setup, and your simple code, could jump 1degreeC.
Maybe more if you switch from USB to external.
You could change to a TMP35 or TMP36 if you want to stay analogue.
Then it becomes easier to use the more stable internal bandgap reference of the Arduino, because those sensors output <1volt at room temp.
Leo..
Thanks for the fast reply I was about going out to buy it LOL! OK, so I have one TMP36 from the Arduino starter kit and I connected it as it's shown in the book and also get the code from the book:
and when the Mega is powered by the USB the sensor shows a 6 degree error(much less than the LM335, which had about 10-15 degrees error) but when powered with the 9V(not 100% sure if it's regulated because the adapter is from a router) the sensor has about 0,5 - 1 degree error which is great. The voltage regulator on the board is warm on touch(when I hold my finger for about 6 sec it get slightly hot, which is normal) hope I will be able to run it for a long time.
Wrote this some time ago.
It uses the internal 1.1volt Aref, and smoothing.
I already adapted it for a Mega, but do read the comments.
Connect the sensor to A1, and change the serial monitor to the baud rate in the code.
Line 17 is for calibration.
Leo..
// Thermometer in Celcius and Fahrenheit
// displays on serial monitor and/or LCD
// TMP35 or TMP36 temp sensor connected to Analogue input A1, 3.3volt and ground
// or LM35 temp sensor connected to A1, 5volt and ground
// TMP35 and LM35 temp range ~+2C to ~+105C
// TMP36 temp range ~-40C to ~+55C
// see line 46 for TMP35/LM35/TMP36 code selection
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // your LCD pins could be different
byte ledPin = 10; // backlight pin
const byte numReadings = 32; // number of readings for smoothing (max 64)
int readings[numReadings]; // readings from the analogue input
byte index = 0; // index of the current reading
unsigned int total = 0; // running total
int inputPin = A1; // the pin that the sensor is connected to
float Aref = 1.0759; // temp calibration | change in small 0.000x steps to the actual Aref voltage of ---YOUR--- Arduino for accurate temp readings
float tempC; // Celcius
float tempF; // Fahrenheit
void setup() {
//analogWrite(ledPin, 200); // optional dimming
analogReference(INTERNAL1V1); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
Serial.begin(115200); // ---set the serial monitor to this value---
lcd.begin(16, 2); // shield with 2x16 characters
lcd.print("Thermometer"); // info text
lcd.setCursor(0, 1); // second row
lcd.print("0-100 Celcius");
for (index = 0; index < numReadings; index++) { // fill the array for faster startup
readings[index] = analogRead(inputPin);
total = total + readings[index];
}
index = 0; // reset
delay(2000); // info display time
}
void loop() {
total = total - readings[index]; // subtract the last reading
readings[index] = analogRead(inputPin); // one unused reading to clear ghost charge
readings[index] = analogRead(inputPin); // read from the sensor
total = total + readings[index]; // add the reading to the total
index = index + 1; // advance to the next position in the array
if (index >= numReadings) // if we're at the end of the array
index = 0; // wrap around to the beginning
// convert value to temp | leave only one of these two lines uncommented
//tempC = total * Aref * 0.1 / numReadings; // value to celcius conversion for TMP35 or LM35
tempC = total * Aref * 0.1 / numReadings - 50.0; // value to celcius conversion for TMP36
// Celcius to Fahrenheit conversion
tempF = tempC * 1.8 + 32;
// print to LCD
if (total == 1023 * numReadings) { // if overflow
lcd.clear();
lcd.print("---TOO HOT---");
}
else {
lcd.clear();
lcd.print(tempC, 2); // two decimal places
lcd.setCursor(6, 0); // position 6, first row
lcd.print("Celcius");
lcd.setCursor(0, 1); // second row
lcd.print(tempF, 1); // one decimal place
lcd.setCursor(6, 1); // position 6, second row
lcd.print("Fahrenheit");
}
// print to serial monitor
Serial.print("Raw average = ");
Serial.print(total / numReadings);
if (total == 1023 * numReadings) {
Serial.println(" ----too hot----");
}
else {
Serial.print(" The temperature is ");
Serial.print(tempC, 2);
Serial.print(" Celcius ");
Serial.print(tempF, 1);
Serial.println(" Fahrenheit");
}
delay(500); // use a non-blocking delay when combined with other code
}