Things used in this project

Hardware components:
Iotopia box rs
AllThingsTalk IOTOPIA Rapid Development kit
×1
07914 001
SparkFun ProtoShield Kit
×1
Adafruit 4.7k ohm resistor
×1
soil mosture sensor
×1
temperature sensor
×1
powerbank
×1
Software apps and online services:
Wzfnsjw4zdiosfhfhejx
AllThingsTalk Maker
Ide web
Arduino IDE
Hand tools and fabrication machines:
3drag
3D Printer (generic)

Custom parts and enclosures

waterproof case moisture sensor
part1
bescherming_onderkant_nN8ITfMPNU.par
waterproof case moisture sensor
part2
bovenpaneel_vochtsensor_NtUmjLRZIr.par
waterproof case moisture sensor
assembly
assembly_met_vochtsensor_EuceX3mftR.asm

Schematics

breadboard schematic
Temperatuursensor tekening bb ezpnvbchqy
elektrical schematic
Temperatuursensor tekening schem mofg184prz

Code

Main ProgramArduino
#include <SoftwareSerial.h>
#include "ATT_IOT_FONA.h"
#include "ATT_MQTT.h"

#include "ATT_IOT_GPRS.h"
#include <SPI.h>
#include <OneWire.h> 
#include <DallasTemperature.h>
#include <math.h>

#define deviceId "kJH6Py3Oatj33vRqxwO71jfx"
#define clientId "JakobM_cYGu2moo"
#define clientKey "zWLz4JvK"

#define FONA_APN       "web.pro.be"
#define FONA_USERNAME  ""
#define FONA_PASSWORD  ""

#define FONA_RX 3
#define FONA_TX 2
#define FONA_RST 5
#define ONE_WIRE_BUS 7
#define buttonNr 8 

SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);
 


ATTDevice Device(deviceId, clientId, clientKey);
#define httpServer "api.AllThingsTalk.io"
#define mqttServer httpServer

int HumidityAssetNr = 3;
int tempAssetNr = 1;
int WormAssetNr = 7;
int procentReadyAssetNr = 5;

int HumidityPin=5;
const int AnalogPinHumidity = A0;

unsigned long time;
unsigned int prevVal =0;

float Temperature=0.0;
int Humidity=0;
unsigned long numberOfHours = 0;
int procentReady = 0;

unsigned long StartNumberOfWorms = 20;
unsigned long NumberOfWorms = 0;

void callback(const char* topic, const char* payload, unsigned int length);


void setup()
{        
    fonaSS.begin(19200);
    Serial.begin(57600);
  
	while(!Serial && millis() < 2000);
  
    while (! Device.InitGPRS(fonaSS, FONA_RST, F(FONA_APN), F(FONA_USERNAME), F(FONA_PASSWORD))) {
        Serial.println("Retrying FONA");
    }
    Serial.println(F("Connected to Cellular!"));
    delay(2000);                                        		// wait a few seconds to stabilize connection
  
    while(!Device.Connect(httpServer))
        Serial.println("retrying");
    Device.AddAsset(tempAssetNr, "tempereturesensor", "tempereturesensor",false, "{\"type\": \"number\", \"unit\": °C }");
    Device.AddAsset(HumidityAssetNr, "moisturesensor", "moisturesensor",false, "{\"type\": \"integer\", \"unit\": % }");
    Device.AddAsset(procentReadyAssetNr, "compost timer", "almost finished!!!", true,"integer" );
    Device.AddAsset(WormAssetNr,"worm count", "worm count", false,"integer");
    while(!Device.Subscribe(callback, mqttServer, 1883))
        Serial.println("retrying"); 
    sensors.begin();
    pinMode(AnalogPinHumidity, INPUT);
    pinMode(buttonNr, INPUT);
    procentReady = numberOfHours/2928*100;
}


void loop()
{
unsigned long curTime = millis();
  if (curTime > (time + 3000))                          // publish readings every 3 seconds
  {
    Temperature = get_temp();
    Device.Send(String(Temperature),tempAssetNr);


int procentReady = analogRead(AnalogPinHumidity)*(-0.0977517107)+100;
    Device.Send(String(procentReady),HumidityAssetNr);
    time = curTime;
bool sensorVal = digitalRead(buttonNr);
if (sensorVal==HIGH){
  sensorVal = HIGH;
  delay(1000);
  numberOfHours = numberOfHours+1;
  Device.Send(String(procentReady),procentReadyAssetNr);
  Serial.println(procentReady + "% ready");
  }
else{
  Serial.println("compostingProces not started");
}
if (procentReady >99){
    Serial.println("proces complete, time to collect the compost!");
    sensorVal = LOW;
}
  NumberOfWorms = StartNumberOfWorms*pow(2,numberOfHours/720);
  Device.Send(String(NumberOfWorms + "wormen"),WormAssetNr);
  }
  Device.Process(); 
}


void callback(const char* topic, const char* payload, unsigned int length) 
{ 
	String msgString(payload);
	int* idOut = NULL;
  
	int pinNr = Device.GetPinNr(topic, strlen(topic));
    
	Serial.print("Payload: ");
    Serial.println(msgString);
    Serial.print("topic: ");
    Serial.println(topic);
    Serial.print("pin: ");
    Serial.println(pinNr);
    

  
	if(idOut != NULL)
		Device.Send(msgString, *idOut);    
}

//functie om de temperatuur op te vragen.
float get_temp()
{ 
 sensors.requestTemperatures(); // Send the command to get temperature readings 
 //Serial.print("Temperature is: "); 
float result;
result=sensors.getTempCByIndex(0);
//Serial.print(resultaat);
return result; 
}

Credits

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

Wifi Messenger
Intermediate
  • 40
  • 3

Protip

Calling my son from his room using 2 ESP8266 modules, instead of shouting.

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

Full instructions

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

Intel Curie TinyTILE Dress: Accelerometer + Optical Fibers
Intermediate
  • 297
  • 10

Full instructions

A dress using Intel Curie accelerometer on TinyTILE and its small form factor to control colors of the optical fibers with arm movements.

Smart Garden
Intermediate
  • 195
  • 4

Smart Garden is plant environmental monitoring system.

Control RGB LED by Dragging – Arduino 101 & App Inventor
Intermediate
  • 189
  • 4

Full instructions

This topic will teach you how to control a RGB LED on an Arduino 101 board with an Android device (MIT App Inventor).

Particle Photon Flip Dot Clock
Intermediate
  • 1,851
  • 30

Full instructions

The flip dot display uses an electromechanical dot matrix that spin from black to yellow to display text, numbers and more!

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback