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!

I made one

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

Give feedback

Comments

Similar projects you might like

Controlling IR Appliances by Schedule
Intermediate
  • 227
  • 9

This project helps you control your IR appliances by setting schedule.

 Controlling IR-Controlled Appliances Through Internet
Intermediate
  • 348
  • 10

Turning your AC on before arriving at the office, changing your room temperature before coming back home by imitating IR signal.

Build a Tank Volume Reader in Under $30 using ESP32
Intermediate
  • 767
  • 8

Full instructions

Build a DIY Level Sensor - tank monitor for volume, temperature, and humidity. Prototype for under $30.

Christmas Gift Box
Intermediate
  • 3,604
  • 595

Full instructions

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

Linkit One: Blowing an LED
Intermediate
  • 954
  • 27

Full instructions

In this tutorial I Will show you how to turn on an led with your mouth. The Led will turn on when start to blow the sound sensor.

Pet Feeder
Intermediate
  • 7,792
  • 196

Have you even forgotten to feed yout pet? Things can happen... But not anymore! From now on PetFeeder will buzz, blink and message you!

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login