Things used in this project

Schematics

Project connection diagram
Temperature%20humidity%20logger

Code

LinkIt ONE CODEArduino
DHT Library can be downloaded from:
https://github.com/Seeed-Studio/Grove_Starter_Kit_For_LinkIt/tree/master/libraries/Humidity_Temperature_Sensor
#include <LBattery.h>
#include <LGPRS.h>
#include <LGPRSClient.h>
#include "DHT.h"

#define URL    "things.ubidots.com"
#define TOKEN ""  // replace with your Ubidots token generated in your profile tab
#define VARID1 ""    //Temperature variable id           
#define VARID2 ""    //Humidity variable id
#define VARID3 ""    //Battery Level variable id 


// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)  
#define DHTPIN 2     // Digital pin 2 where DHT 22 is connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);

char buff[256];  //Info about battery level and charging

//Temperature and Humidity sensor readings from DHT 22
float t = 0.0;
float h = 0.0;

//Location where this logger is placed!! 
String loclat="19.21833";
String loclng="72.978088";
String Location;

//Initializing gprs
LGPRSClient client;  //GPRS Client

void setup()
{
  Serial.begin(9600);
  Serial.println("Temperature Humidity Logger by Er.Amol");
  dht.begin();

// Creating a string containing latitude and longitude information of the Logger's location
  Location="{\"lat\":";
  Location=Location+loclat;
  Location += " ,\"lng\":";
  Location=Location+loclng+ "}";
  
  Serial.println("Attach to GPRS network by APN setting");
  //Note add Access point name, username and password according to your sim card manufacturer/service provide
   while (!LGPRS.attachGPRS("APN","Username","Password"))
  {
    delay(500);
   }

  LGPRSClient globalclient ;
  client = globalclient;

  delay(2000);
}

void loop()
{
  Serial.println("Smart Trash Can Project by Er.Amol");
  if(dht.readHT(&t, &h)) //Reading Temperature and humidity from DHT 22
 {
  delay(2000);
  dht.readHT(&t, &h);
  Serial.println("------------------------------");
  Serial.print("Temperature: ");
  Serial.println(t);

  Serial.print("Humidity: ");
  Serial.println(h);  

  sprintf(buff,"Battery level = %d", LBattery.level() );
  Serial.println(buff);
 
 String payload = "[{\"variable\":\"" VARID1 "\",\"value\":"+ String(t)+",\"context\":"+Location+"},{\"variable\":\"" VARID2 "\",\"value\":" + String(h) + "},{\"variable\":\"" VARID3 "\",\"value\":" + String(LBattery.level()) + "}]";
 
 String le = String(payload.length());
  
  // if you get a connection, report back via serial:
  Serial.print("Connect to ");
  Serial.println(URL);
  if (client.connect(URL, 80))
  {
    // Build HTTP POST request
    Serial.println("connected");    
    client.print(F("POST /api/v1.6/collections/values/?token="));
    client.print(TOKEN);
    client.println(F(" HTTP/1.1"));
    client.println(F("Content-Type: application/json"));
    client.print(F("Content-Length: "));
    client.println(le);
    client.print(F("Host: "));
    client.println(URL);
    client.println(); 
    client.println(payload);  
  }
  else
  {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  delay(100);
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected())
  {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  //Delay of about 1 minute or 60 seconds
   for (int minutes = 0; minutes < 7; minutes++) 
   {
     delay(10000);  //10 seconds delay or 10 thousand milli-seconds
   }
   
  }
}

Credits

Selfie emcil20q6d
Amol Disale

I am passionate about the idea of open-source hardware and software. My area of interests are IoT, Smart Home, Open Source Hardware.

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

PET TRACKER (ENSORINSTITUUT)
Intermediate
  • 75
  • 3

Full instructions

The Pet Tracker will find your pet anywhere at any time.

PET TRACKER (ENSORINSTITUUT)

Team The Pet Trackers

SORT4U
Intermediate
  • 42
  • 2

Full instructions

It's the sorting machine that you've been waiting for. Just throw all your junk in it and let it sort for you.

SORT4U

Team The Avengers

ELECTRACKER (Ensorinstituut)
Intermediate
  • 42
  • 2

Full instructions

Measure the usage of your home's apparatus and send it to the cloud.

DIY Smart Lamp - controlled by toggle switch and Alexa
Intermediate
  • 342
  • 6

Full instructions

Build a smart lamp that can be controlled by flipping a switch and Alexa, for only $35.

Developing a Low-Cost Microcentrifuge Using E-Waste
Intermediate
  • 270
  • 4

Work in progress

Quality microcentrifuges are generally too expensive for most people to afford. This project aims to provide a low-cost alternative.

Garden sensors dashboard
Intermediate
  • 21
  • 1

Full instructions

Monitor your greenhouse or personal garden environmental variables at a glance with a Linkit enabled sensor Hub.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback