Quantcast
Channel: ThingSpeak IoT Community - Forum: Arduino
Viewing all articles
Browse latest Browse all 172

dtecres on Arduino Uno R3+W5100+LM35, Temperature not display in Thingspeak...

$
0
0

Dear All,

I'm trying to use the W5100 Ethernet Shield with Arduino Uno R3 to send the temperature read from LM35 to Thingspeak. 

Unfortunately, nothing happened after an hour (interval is 5 minutes). I can't find any wrong in the code and I don't know what went wrong. Frown 

I'm attaching the code as below:

#include <SPI.h>
#include <Ethernet.h>
#include "ThingSpeak.h"

// W5100 Network Setup
byte W5100_MacAddress[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

//Thingspeak Setup
unsigned long Channel_Number = 302633; // Channel ID
const char * Write_API_Key = "VAMPTX0YTHJ17WJ5"; // Write API Key
int Channel_Field = 1; // Field where Temperature data upload to

// LM35 sensor input to analog
#define LM35_Temp_Sensor A0

EthernetClient client;

float LM35_Temp_Value = 0; // Initial Temperature value
int Interval = 300; // Interval read the temperature every 5 mins

void setup()
{
// Serial connection
Serial.begin(9600);

// Disable SD Card SPI
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);

// Connect to local network and internet
Ethernet.begin(W5100_MacAddress);
Serial.println();
Serial.print("W5100 IP Address: ");
Serial.println(Ethernet.localIP());
Serial.print("W5100 Subnet Mask: ");
Serial.println(Ethernet.subnetMask());
Serial.print("W5100 Gateway: ");
Serial.println(Ethernet.gatewayIP());
Serial.println();

// Connect to Thingspeak server
if (ThingSpeak.begin(client))
{
Serial.println();
Serial.println("Connect to Thingspeak Server...");
Serial.println();
}
else
{
Serial.println();
Serial.println("Failed to connect to Thingspeak Server!!!");
Serial.println();
}

}

void loop()
{
LM35_Temp_Value = analogRead(LM35_Temp_Sensor)* 0.0048828125 * 100;
Serial.print("Current temperature: ");
Serial.print(LM35_Temp_Value);
Serial.println("°C");
delay(100);

// Write the temperature to Thingspeak Server
if(ThingSpeak.writeField(Channel_Number, Channel_Field, LM35_Temp_Value, Write_API_Key))
{
Serial.println();
Serial.println("Uploading data to Thingspeak Server...");
Serial.println();
}
else
{
Serial.println();
Serial.println("Failed to upload data to Thingspeak Server!!!");
Serial.println();
}

// The temperature will read every 5 mins
for (int i=0; i <= Interval; i++)
{
delay(1000); // 1 second delay
}

}


Viewing all articles
Browse latest Browse all 172

Trending Articles