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

WalabotEye - Object Tracker with Haptic Feedback
Intermediate
  • 1,027
  • 9

Full instructions

For the hard of sight, use this to have a better understanding of the world around you.

Automatic Fear 1.0
Intermediate
  • 324
  • 5

Full instructions

A device capable of frightening my sister and with compatibility with other members of the family

Theremino Adapter for CNC.
Intermediate
  • 302
  • 8

Full instructions

Attention: This adapter is used to replace the parallel port with the USB, and not to operate Mach3 CNC or Linux.

Theremino Logger
Intermediate
  • 173
  • 5

Datalogger is simple to use but with great performance. The base, concise and intuitive.

Smart Sump Pump Monitor
Intermediate
  • 845
  • 10

Full instructions

Sump pump monitor has live dashboard for usage statistics, and data logging. Email notifications through Particle Cloud or IFTTT.

Robotic Arm Control Using Bluetooth, Arduino and Android App
Intermediate
  • 795
  • 9

Full instructions

Control a robotic arm using a Bluetooth HC-05 module and Arduino via an Android app.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback