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

Raspberry Pi Motion Tracking Gun Turret
Intermediate
  • 267
  • 8

Full instructions

A motion tracking airsoft or Nerf gun turret with autonomous and manual operation modes, controlled by a Raspberry Pi.

Arduino Like Function on Kinetis K82 Freedom Stupid Board
Intermediate
  • 41
  • 3

Protip

1000 of K82 Freedom Boards are collecting dust because of the hobbyist unfriendly IDE, pump up the duds with easy Arduino-like functions.

Arduinomated Car Parking with Voice Assistance in Smartphone
Intermediate
  • 318
  • 9

Full instructions

Make an assistant which tells you about how much to drive backwards without any collision through your smartphone by Arduino and 1Sheeld.

Reducing Arduino Power Consumption
Intermediate
  • 132
  • 5

Full instructions

One the most important feature of portable electronics should be long battery life. We can reduce the current drawn by several ways.

Particle Photon Based Security System with Alerting
Intermediate
  • 1,335
  • 20

Full instructions

Be alerted to any door or window opening and closing in your house on your smart phone.

Sigfox Forest Fire Detector
Intermediate
  • 2,659
  • 16

Full instructions

How to prevent forest from burning? A small Sigfox signal can prevent natural disasters. We will use an Arduino MKRFOX + a flame detector.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog