jakob MonteyneBenjamin Decoene
Published © GPL3+

The composting friend

Our goal is to make composting easier to use and to maintain.

IntermediateFull instructions provided4 hours1,375

Things used in this project

Hardware components

IOTOPIA Rapid Development kit
AllThingsTalk IOTOPIA Rapid Development kit
×1
SparkFun ProtoShield Kit
SparkFun ProtoShield Kit
×1
Adafruit 4.7k ohm resistor
×1
soil mosture sensor
×1
temperature sensor
×1
powerbank
×1

Software apps and online services

AllThingsTalk Maker
AllThingsTalk Maker
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

waterproof case moisture sensor

part1

waterproof case moisture sensor

part2

waterproof case moisture sensor

assembly

Schematics

breadboard schematic

Temperatuursensor tekening bb ezpnvbchqy

elektrical schematic

Temperatuursensor tekening schem mofg184prz

Code

Main Program

Arduino
#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

jakob Monteyne

jakob Monteyne

1 project • 0 followers
Benjamin Decoene

Benjamin Decoene

1 project • 0 followers

Comments