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. I am ready to help in prototyping IoT, Smart Home, and other products.

Contact

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

Amazon Echo – Read Temperature and Humidity from Sensor
Intermediate
  • 233
  • 12

Full instructions

I am going to show how to use Amazon Echo to read temperature and humidity from sensor.

Do You Know How Your Plants Are Feeling? [Particle+Ubidots]
Intermediate
  • 145
  • 3

Full instructions

Build and deploy a soil moisture and temperature sensor for commercial greenhouses or private garden monitoring and treatment.

Build a People Counter for $30 Using NodeMCU
Intermediate
  • 2,057
  • 15

Full instructions

This project educates administrators and decision makers to the amount of people passing through a particular space and how they operate.

Blynk App with Linkit7688 Duo and Webcam
Intermediate
  • 285
  • 3

Full instructions

How to make a functional application with Blynk and the Linkit Smart 7688 Duo board, with utility for home automation.

Christmas Gift Box
Intermediate
  • 3,559
  • 595

Full instructions

Christmas Gift Box plays music and sends an email when it is opened.

Never4Get
Intermediate
  • 52
  • 2

Work in progress

Never4Get is a program/device that notifies you when you need a book. You will receive a message when you forgot a book in your locker.

Never4Get

Team Never4Get

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback