my code as following:
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() {
sensorValue_Light = analogRead(sensorPin_Light);
sensorValue_Temp = analogRead(sensorPin_Temp);
//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.