Pages: [1]   Go Down
 Author Topic: Temp Sensor does not get reasonable result  (Read 442 times) 0 Members and 1 Guest are viewing this topic.
Offline
Newbie
Karma: 0
Posts: 4
 « on: June 21, 2011, 05:48:07 am » Bigger Smaller Reset

Hi All,

I am totally new to arduino, even hardware, could someone help me out with below problem:

I have an arduino UNO and DFROBOT ethernet shield which connected with each other. Then, I connect a temperature sensor (lm 35 dz) to the ethernet shield, 5 v power supply. Additionally, I use a 9 volts AC power supply for the entire unit. I use following formula to calculate centigrade from pin output: signal*voltage*100/1023, voltage here is 4.98 volts measured manually.

However, result is near 40 degree while real temperature is only 24 degree. Also I measure the voltage between power supply and GND of this temp sensor, it is about 0.25 volts which multiple by 100 is close to real temperature.

I do not know what's wrong? Could anyone give me some idea or clues about it?

Regards,
Jie
 Logged

Netherlands
Online
Tesla Member
Karma: 90
Posts: 9428
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #1 on: June 21, 2011, 05:59:00 am » Bigger Smaller Reset

Can you post your sketch (use the #button for appropiate tagging) and a drawing how you connected the LM35?

 Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline
Newbie
Karma: 0
Posts: 4
 « Reply #2 on: June 21, 2011, 11:04:33 am » Bigger Smaller Reset

my code as following:
Code:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10,10,102,160 };
unsigned int localPort = 8012;

int sensorPin_Light = A0;
int sensorValue_Light = 0;

int sensorPin_Temp = A1;
int sensorValue_Temp = 0;
char sensorValue_Temp_Char[2] ;

byte remoteIP[] = { 10,10,102,133 };
int remotePort = 58121; // the destination port

void setup() {
Ethernet.begin(mac,ip);
Udp.begin(localPort);

Serial.begin(9600);
}

void loop() {

//udp packet can have max 160 bits for data.
char udp_content[20] ;
//four char is used for every integer's digital whose max value is 1024, and end with ','
char sensorValue_Light_Char[5] ;
itoa (sensorValue_Light, sensorValue_Light_Char, 10);

char sensorValue_Temp_Char[5] ;
itoa (sensorValue_Temp, sensorValue_Temp_Char, 10);

strcpy (udp_content,sensorValue_Light_Char);
strcat (udp_content,",");
strcat (udp_content,sensorValue_Temp_Char);
strcat (udp_content,",");

Serial.println(udp_content);

Udp.sendPacket(udp_content, remoteIP, remotePort );
delay(2000);
}

how i connect the lm35:
5v for power, GND line connect with GND pin and analog in 1 for temperature.
PS. meanwhile, I also use a light intensity sensor with A0.

 « Last Edit: June 22, 2011, 03:44:58 am by fruit112358 » Logged

New Jersey
Offline
Edison Member
Karma: 24
Posts: 2354
 « Reply #3 on: June 21, 2011, 11:49:40 am » Bigger Smaller Reset

This:
Code:

may be problematic. The analog pins share a single A2D converter. If you try to read from multiple pins in rapid succession, the later results tend to be inaccurate. Recent posts have suggested a couple of remedies: use a small delay between readings or take two readings for each input and ignore the first. In your case, just commenting out the analogRead for the light should show you if that is the issue.
 Logged

Netherlands
Online
Tesla Member
Karma: 90
Posts: 9428
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #4 on: June 21, 2011, 11:50:14 am » Bigger Smaller Reset

Please modify your post, select the code and use the # button , thank you
 Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Netherlands
Online
Tesla Member
Karma: 90
Posts: 9428
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #5 on: June 21, 2011, 12:01:46 pm » Bigger Smaller Reset

Q:

Udp.sendPacket(udp_content, remoteIP, remotePort ); ?? How does sendPacket know the length of the packet to be send?
 Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline
Newbie
Karma: 0
Posts: 4
 « Reply #6 on: June 22, 2011, 04:41:58 am » Bigger Smaller Reset

Q:

Udp.sendPacket(udp_content, remoteIP, remotePort ); ?? How does sendPacket know the length of the packet to be send?

According to my understanding, for every UDP packet in IP v4, the size of data in one packet is always 160 bits. In other words, no matter how real size of data is, the method always send 160 bits data every time.
 Logged

Offline
Newbie
Karma: 0
Posts: 4
 « Reply #7 on: June 22, 2011, 05:38:47 am » Bigger Smaller Reset

This:
Code:

may be problematic. The analog pins share a single A2D converter. If you try to read from multiple pins in rapid succession, the later results tend to be inaccurate. Recent posts have suggested a couple of remedies: use a small delay between readings or take two readings for each input and ignore the first. In your case, just commenting out the analogRead for the light should show you if that is the issue.

I have tried both ways: only read temperature and read twice when there is light sensor. fortunately, both of them works well for me. Thank you very much.
 Logged

Netherlands
Online
Tesla Member
Karma: 90
Posts: 9428
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #8 on: June 22, 2011, 06:45:03 am » Bigger Smaller Reset

Quote
According to my understanding, for every UDP packet in IP v4, the size of data in one packet is always 160 bits. In other words, no matter how real size of data is, the method always send 160 bits data every time.

Dived into the library myself, and the function is overloaded. for a byte string you need to supply the length and for a char array it sends until it meets a '\0' char.

Code:
/* Send packet contained in buf of length len to peer at specified ip, and port */
/* Use this function to transmit binary data that might contain 0x00 bytes*/
/* This function returns sent data size for success else -1. */
uint16_t UdpClass::sendPacket(uint8_t * buf, uint16_t len,  uint8_t * ip, uint16_t port){
return sendto(_sock,(const uint8_t *)buf,len,ip,port);
}

/* Send  zero-terminated string str as packet to peer at specified ip, and port */
/* This function returns sent data size for success else -1. */
uint16_t UdpClass::sendPacket(const char str[], uint8_t * ip, uint16_t port){
// compute strlen
const char *s;
for(s = str; *s; ++s);
uint16_t len = (s-str);
// send packet
return sendto(_sock,(const uint8_t *)str,len,ip,port);
}
 Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline
Newbie
Karma: 0
Posts: 37
 « Reply #9 on: June 23, 2011, 08:37:05 am » Bigger Smaller Reset

You might also consider using a resistor
 Logged

 Pages: [1]   Go Up