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

Smart and Safe Outdoor Plant Watering System
Intermediate
  • 2,543
  • 18

Monitors soil moisture and weather forecasts to give plants just the water they need. Safe garden hose hookup for season long watering.

Eco-Thing #1  "Eco-Smart-Container V1.0"
Intermediate
  • 2,217
  • 16

Full instructions

An IoT device that could help keep the Sandy River Delta clean, as garbage is a very common problem.

Christmas Gift Box
Intermediate
  • 3,684
  • 595

Full instructions

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

Smart Garbage Monitoring System Using Arduino 101
Intermediate
  • 968
  • 5

Full instructions

A method in which waste management is automated. An innovative system that will help keep the city clean and healthy

SensorBoat
Intermediate
  • 186
  • 2

Full instructions

An Arduino controlled boat that takes temperature, accelerometer, and light data from any body of water.

Control the Injection of a Liquid
Intermediate
  • 321
  • 2

Protip

Control the injection of a liquid with GOBLIN 2 from anywhere via Ubidots platform.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog