Monday, 26 June 2017

Temperature and Humidity data send to google spreadsheet using Arduino with Ethernet shield:

Temperature and Humidity data send to google spreadsheet using Arduino with Ethernet shield:


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

byte mac[] = { 0xDA, 0xDA, 0xEA, 0xFA, 0xAE, 0xEA }; //Setting MAC Address
char server[] = "api.pushingbox.com"; //pushingbox API server
IPAddress ip(192,168,0,56); //Arduino with Ethernet Shield IP address.
EthernetClient client; //define 'client' as object
String data; //GET query with data
float tempt;
boolean value= false;

void setup() {

  Serial.begin(9600);

  if (Ethernet.begin(mac) == 0) {
  Serial.println("Failed to configure");
  Ethernet.begin(mac, ip);
  }

  delay(1000);
}

void loop(){
  int baca_ADC = analogRead(A0); //read analog input on pin A7
   tempt = baca_ADC ; // ADC to celcius conversion
   getData(); //packing GET query with data
   Serial.println("connecting");
   if (client.connect(server, 80)) {
     sendData();
     value  = true; //connected = true
   }
   else{
     Serial.println("connection failed");
   }

  while(value){
    if (client.available()) {
    char c = client.read(); //save http header to c
    Serial.print(c); //print http header to serial monitor
    }
    if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
          Serial.print("Temperature Sent :");
          Serial.println(tempt); //print sent value to serial monitor
    client.stop();
          value = false;
          data = ""; //data reset
    }
  }
  delay(5000); // interval
}

void getData(){
  data+="";
  data+="GET /pushingbox?devid=<ENTER YOUR DEVICE ID>&tempData=";
  data+=tempt;
  data+=" HTTP/1.1";
}
void sendData(){
  Serial.println("connected");
  client.println(data);
  client.println("Host: api.pushingbox.com");
  client.println("Connection: close");
  client.println();
}


Circuit Diagram:




0 comments:

Post a Comment

if you have any doubt please let me know