In this project, I'll show you how you we built a very cool and cheap aquaponic system from recycled materials. This aquaponic system will contain a planter for growing fresh food without fertilizers, a fish tank to grow healthy fish.
How It WorksFish would eat food then fish waste would be transferred using water pump to fertilize plants in the planter. After that, the water will be filtered and cleaned, then return again to the fish tank. This cycle would save water and grow fish and plants with no costs.
Step 1: Building the Body - "Recycling Old Pallet Wood"Building bell syphon to drain water.
Connect the pump (plant watering system).
Building the Feeder
For the feeder, I used a DC motor and fixed a screw on its shaft so when it rotates it rotate the screw and make fish food fall in the fish tank.
Test the rock to check if it can be used as media or not.
GitHub Repository : https://github.com/FadyT/Smart_aquaponic.git
the maxfthr board should send sensor readings ( temperature , humidity , sun light brigtness ....) through serial communication to the sparkfun thingdev board then the sparkfun thing dev board should take these sensor readings and save it's values on firebase database , after that it get the actuator values (led strip colors , feeder , heater and pump) from the firebase database then send these values to maxfthr board to switch realys on or off and wait for certain time then switch them off and set their values to 0 and send the colors to change led strip color
the application is connected to firebase so we can monitor sensors readings and change actuator values from it .
Ultrasonic sensor code : i followed tutorial by Dejan Nedelkovski as ultrasonic library isn't supported for maxfthr board
/*
* Ultrasonic Sensor HC-SR04 and Arduino Tutorial
*
* by Dejan Nedelkovski,
* www.HowToMechatronics.com
*
*/
// defines pins numbers
const int trigPin = 26;
const int echoPin = 29;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
Analogue sensor reading code
soil moisture and water temperature sensor are connected to pin 0 and 1 as they can read voltage up to 5 v while ldr is powered from pwm pin having output voltage of 150 so that sensor voltage doesn't increase more than 1.2 v as if it has been connected to 5 v power it will always read 255 which is max value .
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
//soil moisture 800 out of water , 300 inside water
// read the input on analog pin 0:
int sensorValue1 = analogRead(A0);
// read the analog in value:
int sensorValue = analogRead(A2);
// map it to the range of the analog out:
int outputValue = 150;
// change the analog out value:
analogWrite(47, outputValue);
// print out the value you read:
Serial.print("soil moisture : ");
Serial.print(sensorValue1);
Serial.print(",");
int sensorValue2 = analogRead(A1);
// print out the value you read:
Serial.print("temprature : ");
float mv = ( sensorValue2 / 1024.0) * 5000;
waterTemp = mv / 10;
Serial.print(waterTemp);
Serial.print(",");
// print the results to the Serial Monitor:
Serial.print("light sensor = ");
Serial.print(sensorValue);
Serial.print("\t input voltage = ");
Serial.println(outputValue);
delay(5000);
}
LED strip testing code:
Simple test to make sure the LED strip is working fine by passing 3 values (0 , 100 , 254 ) to output pwm pins . 0 will make it turn off , 100 make it light with low brightness , 254 will make led strip light with maximum brightness
int Red = 40;
int Green = 41;
int Blue = 42;// the PWM pin the LED is attached to
// the setup routine runs once when you press reset:
void setup() {
// declare pins to be an output:
pinMode(Red, OUTPUT);
pinMode(Green, OUTPUT);
pinMode(Blue, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(Red, 0);
analogWrite(Green, 0);
analogWrite(Blue, 0);
analogWrite(20, 0);
delay(5000);
analogWrite(Red, 100);
analogWrite(Green, 100);
analogWrite(Blue, 100);
analogWrite(20, 100);
delay(5000);
analogWrite(Red, 254);
analogWrite(Green, 254);
analogWrite(Blue, 254);
analogWrite(20, 254);
delay(5000);
}
DHT11 sensor code:
int DHpin = 28;
byte dat [5];
byte read_data () {
byte data;
for (int i = 0; i < 8; i ++) {
if (digitalRead (DHpin) == LOW) {
while (digitalRead (DHpin) == LOW); // wait for 50us
delayMicroseconds (30); // determine the duration of the high level to determine the data is '0 'or '1'
if (digitalRead (DHpin) == HIGH)
data |= (1 << (7-i)); // high front and low in the post
while (digitalRead (DHpin) == HIGH); // data '1 ', wait for the next one receiver
}
}
return data;
}
void start_test () {
digitalWrite (DHpin, LOW); // bus down, send start signal
delay (30); // delay greater than 18ms, so DHT11 start signal can be detected
digitalWrite (DHpin, HIGH);
delayMicroseconds (40); // Wait for DHT11 response
pinMode (DHpin, INPUT);
while (digitalRead (DHpin) == HIGH);
delayMicroseconds (80); // DHT11 response, pulled the bus 80us
if (digitalRead (DHpin) == LOW);
delayMicroseconds (80); // DHT11 80us after the bus pulled to start sending data
for (int i = 0; i < 4; i ++) // receive temperature and humidity data, the parity bit is not considered
dat[i] = read_data ();
pinMode (DHpin, OUTPUT);
digitalWrite (DHpin, HIGH); // send data once after releasing the bus, wait for the host to open the next Start signal
}
void setup () {
Serial.begin (9600);
pinMode (DHpin, OUTPUT);
}
void loop () {
start_test ();
Serial.print ("Current humdity =");
Serial.print (dat [0], DEC); // display the humidity-bit integer;
Serial.print ('.');
Serial.print (dat [1], DEC); // display the humidity decimal places;
Serial.println ('%');
Serial.print ("Current temperature =");
Serial.print (dat [2], DEC); // display the temperature of integer bits;
Serial.print ('.');
Serial.print (dat [3], DEC); // display the temperature of decimal places;
Serial.println ('C');
delay (700);
}
Relays Test code :
void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(27, OUTPUT); pinMode(43, OUTPUT); pinMode(44, OUTPUT);}// the loop function runs over and over again forevervoid loop() { digitalWrite(27, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(43, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(44, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(27, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second digitalWrite(43, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second digitalWrite(44, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second}
test code sending constant values from max board to thing dev board
void setup() {
//==================================//
// Serial Communication //
//==================================//
Serial.begin (9600);
Serial2.begin(9600);
}
void loop() {
//==================================//
// Serial Communication //
//==================================//
// send data //
//==================================//
Serial2.println("218,72,132,0.00,0.00,0.00,20,25,2"); //Write the serial data
delay (1000);
//==================================//
//---------Read Serial--------------//
//==================================//
if (Serial2.available()) {
String data = String(Serial2.readStringUntil('\n')); // sends ascii code
Serial.print("READING DATA FROM SERIAL 2 : ");
Serial.println(data); //Print data on Serial Monitor
char *str;
char sz[50] ;
data.toCharArray(sz, 50);
char *p = sz;
String words[25] = "";
int i = 0 ;
while (str = strtok (p, ","))
{
words[i] = str;
//Serial.println(str);
p = NULL;
i = i + 1 ;
}
Serial.print("Red : ");
Serial.print(words[0]);
Serial.print("Green : ");
Serial.print(words[1]);
Serial.print("Blue : ");
Serial.print(words[2]);
Serial.print("Heater : ");
Serial.print(words[3]);
Serial.print("Pump : ");
Serial.print(words[4]);
Serial.print("Feeder : ");
Serial.print(words[5]);
Serial.println("");
delay(1500);
}
else
{
Serial.print("serial 2 not available ");
delay(5000); //Wait for the serial
}
}
test code for sending data from thing dev board to maxfthr board
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
// Set these to run example
//#define FIREBASE_HOST "FIREBASE DATABASE LINK " // Formated like that without http or / (aquaponicsystem-9e0ec.firebaseio.com")
//#define FIREBASE_AUTH "FIREBASE DATABASE AUTH "
//#define WIFI_SSID "WIFI NAME"
//#define WIFI_PASSWORD "WIFI PASSWORD"
String actuator = "";
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
String data = "";
//-------- get sensor reeading from maxfthr board ---------//
if (Serial.available()) {
data = String(Serial.readStringUntil('\n')); // sends ascii code
delay (1000);
char *str;
char sz[50] ;
// String testData = "18,72,132,0.00,218,72,132,0.00,0.00,0.00";
data.toCharArray(sz, 50);
char *p = sz;
String words[25] ;
int i = 0 ;
while (str = strtok (p, ","))
{
words[i] = str;
p = NULL;
i = i + 1 ;
}
// set value
delay(1000);
if (words[0] != 0 && words[1] != 0 && words[2] != 0 && words[3] != 0 && words[4] != 0 && words[5] != 0 )
{
Firebase.setString("airhumidity", words[0]);
Firebase.setString("airtemp", words[1]);
Firebase.setString("light", words[2]);
Firebase.setString("watertemp", words[3]);
Firebase.setString("soilmoisture", words[4]);
Firebase.setString("waterlevel", words[5]);
delay(5000); //Wait for the serial port.
}
}
else
{
Serial.print("serial1 not available ");
// Firebase.setString("recieveddata", "error");
delay(1500); //Wait for the serial
}
Firebase.setString("recieveddata", data);
//------ get actuators state from firebase-------//
String red = "" , green = "" , blue = "" ;
float feeder = 0.00 , heater = 0.00 , pump = 0.00 ;
red = Firebase.getString("red");
delay(100);
green = Firebase.getString("green");
delay(100);
blue = Firebase.getString("blue");
delay(100);
feeder = Firebase.getFloat("feederstate");
delay(100);
heater = Firebase.getFloat("heaterstate");
delay(1000);
pump = Firebase.getFloat("pumpstate");
delay(100);
//------------- send values to maxfthr board -------------//
actuator = "" ;
actuator.concat(red);
actuator.concat(",");
actuator.concat(green);
actuator.concat(",");
actuator.concat(blue);
actuator.concat(",");
actuator.concat(feeder);
actuator.concat(",");
actuator.concat(heater);
actuator.concat(",");
actuator.concat(pump);
actuator.concat(",");
Firebase.setString("actuator", actuator);
if (feeder == 1.00 || heater == 1.00 || pump == 1.00)
{
//if state of any of heater , feeder , pump is on set it's value as 1 and send this value to max fthr
//and wait 1 minuite or any time u want and then turn it off again by setting value to zero
Serial.println(actuator);
delay (5000);
Firebase.setFloat("feederstate", 0.00);
Firebase.setFloat("heaterstate", 0.00);
Firebase.setFloat("pumpstate", 0.00);
}
Serial.println(actuator);
actuator = "";
delay (5000);
}
Example code for splitting string
//Then is a sample code to how to split string in arduino
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
char *str;
char sz[] = "this , is , the , text , we , want , to ,split";
char *p = sz;
String words[15] = "";
int i = 0 ;
while (str = strtok (p, ","))
{
words[i] = str;
//Serial.println(str);
p = NULL;
i = i + 1 ;
}
Serial.print(words[0]);
Serial.print("*");
Serial.print(words[1]);
Serial.print("*");
Serial.print(words[2]);
Serial.print("*");
Serial.print(words[3]);
Serial.print("*");
Serial.print(words[4]);
Serial.print("*");
Serial.print(words[5]);
Serial.print("*");
Serial.print(words[6]);
Serial.print("*");
Serial.print(words[7]);
Serial.println("*");
delay(1000);
}
Final full MAX32620FTHR code that will send sensor data to SparkFun Thing Dev and receive actuator values.
//==================================//
// DHT //
//==================================//
int DHpin = 28;
byte dat [5];
//====================================//
// DHT Functions //
//====================================//
byte read_data () {
byte data;
for (int i = 0; i < 8; i ++) {
if (digitalRead (DHpin) == LOW) {
while (digitalRead (DHpin) == LOW); // wait for 50us
delayMicroseconds (30); // determine the duration of the high level to determine the data is '0 'or '1'
if (digitalRead (DHpin) == HIGH)
data |= (1 << (7 - i)); // high front and low in the post
while (digitalRead (DHpin) == HIGH); // data '1 ', wait for the next one receiver
}
}
return data;
}
void start_test () {
digitalWrite (DHpin, LOW); // bus down, send start signal
delay (30); // delay greater than 18ms, so DHT11 start signal can be detected
digitalWrite (DHpin, HIGH);
delayMicroseconds (40); // Wait for DHT11 response
pinMode (DHpin, INPUT);
while (digitalRead (DHpin) == HIGH);
delayMicroseconds (80); // DHT11 response, pulled the bus 80us
if (digitalRead (DHpin) == LOW);
delayMicroseconds (80); // DHT11 80us after the bus pulled to start sending data
for (int i = 0; i < 4; i ++) // receive temperature and humidity data, the parity bit is not considered
dat[i] = read_data ();
pinMode (DHpin, OUTPUT);
digitalWrite (DHpin, HIGH); // send data once after releasing the bus, wait for the host to open the next Start signal
}
//==================================//
// Led Strip //
//==================================//
int Red = 40;
int Green = 41;
int Blue = 42;
int RedBrightness = 0;
int GreenBrightness = 0;
int BlueBrightness = 0;
//==================================//
// Ultrasonic //
//==================================//
const int trigPin = 26;
const int echoPin = 29;
long duration;
int distance;
//==================================//
// Lm35dz //
//==================================//
int Lm35 = A1;
float waterTemp = 0;
//==================================//
// Ldr //
//==================================//
int Ldr = A2;
int Brightness = 0 ;
//==================================//
// Soil Moisture //
//==================================//
//about 800 out of water 300 inside water
int sensor_pin = A0;
int output_value ;
//==================================//
// Relays //
//==================================//
int HeaterRelay = 27 ;
int PumpRelay = 43 ;
int FeederRelay = 44 ;
int HeaterState = 0 ;
int PumpState = 0 ;
int FeederState = 0 ;
void setup() {
// put your setup code here, to run once:
//==================================//
// Serial Communication //
//==================================//
Serial.begin (9600);
Serial1.begin(9600);
Serial2.begin(9600);
//==================================//
// Led Strip //
//==================================//
pinMode(Red, OUTPUT);
pinMode(Green, OUTPUT);
pinMode(Blue, OUTPUT);
//==================================//
// Ultrasonic //
//==================================//
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
//==================================//
// DHT //
//==================================//
pinMode (DHpin, OUTPUT);
//==================================//
// Relays //
//==================================//
pinMode (HeaterRelay, OUTPUT);
pinMode (PumpRelay, OUTPUT);
pinMode (FeederRelay, OUTPUT);
}
void loop() {
// main code that will run repeatedly:
//==================================//
// Led Strip //
//==================================//
analogWrite(Red, RedBrightness);
analogWrite(Green, GreenBrightness);
analogWrite(Blue, BlueBrightness);
//==================================//
// Ultrasonic //
//==================================//
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
//==================================//
// Lm35dz //
//==================================//
float val = analogRead(Lm35);
float mv = ( val / 1024.0) * 5000;
waterTemp = mv / 10;
//Serial.print("TEMPRATURE = ");
//Serial.print(waterTemp);
//Serial.print("*C");
//==================================//
// Ldr //
//==================================//
output_value = analogRead(Ldr);
//==================================//
// Soil Moisture //
//==================================//
output_value = analogRead(sensor_pin);
output_value = map(output_value, 550, 0, 0, 100);
delay(50);
//==================================//
// DHT //
//==================================//
start_test();
//==================================//
// Relays //
//==================================//
digitalWrite(HeaterRelay, HeaterState);
digitalWrite(PumpRelay, PumpState);
digitalWrite(FeederRelay, FeederState);
//==================================//
// Serial Communication //
//==================================//
//---------send data----------------//
// Dht //
String myString = String(dat [0], DEC);
myString.concat(".");
myString.concat(String(dat [1], DEC));
myString.concat(", ");
myString.concat(String(dat [2], DEC));
myString.concat(".");
myString.concat(String(dat [3], DEC));
myString.concat(", ");
// Ldr //
myString.concat(Brightness);
myString.concat(", ");
// Lm35 //
myString.concat(waterTemp);
myString.concat(", ");
// soil //
myString.concat(output_value);
myString.concat(", ");
// Ultrasonic //
myString.concat(distance);
// Print all //
Serial.println(myString); //Write the serial data
Serial2.println(myString); //Write the serial data
delay (1000);
//---------Read Serial--------------//
if (Serial1.available()) {
String data = String(Serial1.readStringUntil('\n')); // sends ascii code
Serial1.print("READING DATA : ");
Serial1.println(data); //Print data on Serial Monitor
char *str;
char sz[50] ;
data.toCharArray(sz, 50);
char *p = sz;
String words[25] = "";
int i = 0 ;
while (str = strtok (p, ","))
{
words[i] = str;
//Serial.println(str);
p = NULL;
i = i + 1 ;
}
// set value
RedBrightness = words[0].toInt() ;
GreenBrightness = words[1].toInt();
BlueBrightness = words[2].toInt();
analogWrite(Red, RedBrightness);
analogWrite(Green, GreenBrightness);
analogWrite(Blue, BlueBrightness);
int FeederState = words[3].toInt() ;
int HeaterState = words[4].toInt() ;
int PumpState = words[5].toInt() ;
if (HeaterState == 1 )
{
digitalWrite(HeaterRelay, HeaterState);
}else {
digitalWrite(HeaterRelay, 0);
}
if (PumpState == 1 )
{
digitalWrite(PumpRelay, PumpState);
}else {
digitalWrite(PumpRelay, 0);
}
if (FeederState == 1)
{
digitalWrite(FeederRelay, FeederState);
}else {
digitalWrite(FeederRelay, 0);
}
Serial.print("Red : ");
Serial.print(words[0]);
Serial.print("Green : ");
Serial.print(words[1]);
Serial.print("Blue : ");
Serial.print(words[2]);
Serial.print("Heater : ");
Serial.print(words[3]);
Serial.print("Pump : ");
Serial.print(words[4]);
Serial.print("Feeder : ");
Serial.print(words[5]);
Serial.println("");
delay(1500);
} else
{
// // test code written in same format sent from spark fun thing dev board
// String testCode = "117,255,102,1.00,1.00,1.00";
// char *str;
// char sz[50] ;
// testCode.toCharArray(sz, 50);
// char *p = sz;
// String words[25] = "";
// int i = 0 ;
// while (str = strtok (p, ","))
// {
// words[i] = str;
// //Serial.println(str);
// p = NULL;
// i = i + 1 ;
// }
// // set value
// RedBrightness = words[0].toInt() ;
// GreenBrightness = words[1].toInt();
// BlueBrightness = words[2].toInt();
// analogWrite(Red, RedBrightness);
// analogWrite(Green, GreenBrightness);
// analogWrite(Blue, BlueBrightness);
//int FeederState = words[3].toInt() ;
//int HeaterState = words[4].toInt() ;
//int PumpState = words[5].toInt() ;
//if (HeaterState == 1 )
//{
//digitalWrite(HeaterRelay, HeaterState);
//}else {
//digitalWrite(HeaterRelay, 0);
//}
//if (PumpState == 1 )
//{
//digitalWrite(PumpRelay, PumpState);
//}else {
//digitalWrite(PumpRelay, 0);
//}
//if (FeederState == 1)
//{
//digitalWrite(FeederRelay, FeederState);
//}else {
//digitalWrite(FeederRelay, 0);
//}
// Serial.print("Red : ");
// Serial.print(words[0]);
// Serial.print("Green : ");
// Serial.print(words[1]);
// Serial.print("Blue : ");
// Serial.print(words[2]);
// Serial.print("Heater : ");
// Serial.print(words[3]);
// Serial.print("Pump : ");
// Serial.print(words[4]);
// Serial.print("Feeder : ");
// Serial.print(words[5]);
// Serial.println("");
// delay(1500);
// ////////////////////////////////////////////////////////////////////////
Serial.print("serial not available ");
delay(1500); //Wait for the serial
}
}
Final full SparkFun Thing Dev Code that reads sensor data, sends it to Firebase, gets actuator data, and sends it to the MAX32620FTHR board.
//
// Copyright 2015 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// FirebaseDemo_ESP8266 is a sample that demo the different functions
// of the FirebaseArduino API.
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <SoftwareSerial.h>
// Set these to run example
//
#define FIREBASE_HOST "FIREBASE DATABASE LINK " // Formated like that without http or / (aquaponicsystem-9e0ec.firebaseio.com")
#define FIREBASE_AUTH "FIREBASE DATABASE AUTH "
#define WIFI_SSID "WIFI NAME"
#define WIFI_PASSWORD "WIFI PASSWORD"
const byte recieveRxPin = 15;
const byte recieveTxPin = 14;
const byte sendRxPin = 13;
const byte sendTxPin = 12;
SoftwareSerial mySerial (recieveRxPin, recieveTxPin);
SoftwareSerial mySerial2 (sendRxPin, sendTxPin);
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
mySerial.begin(9600);
mySerial2.begin(9600);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
//-------- get sensor reeading from maxfthr board ---------//
if (mySerial.available()) {
String data = String(mySerial.readStringUntil('\n')); // sends ascii code
Serial.print("READING DATA : ");
Serial.println(data); //Print data on Serial Monitor
char *str;
char sz[50] ;
data.toCharArray(sz, 50);
char *p = sz;
String words[25] = "";
int i = 0 ;
while (str = strtok (p, ","))
{
words[i] = str;
//Serial.println(str);
p = NULL;
i = i + 1 ;
}
// set value
Serial.print(words[0]);
Serial.print("Air Humidity ");
Serial.print(words[1]);
Serial.print("Air Temp");
Serial.print(words[2]);
Serial.print("Ldr");
Serial.print(words[3]);
Serial.print("waterTemp");
Serial.print(words[4]);
Serial.print("Soil Moisture");
Serial.print(words[5]);
Serial.print("Ultrasonic");
delay(1000);
if (words[0] != ""){
Firebase.setString("recieveddata", data);
Firebase.setString("airhumidity", words[0]);
Firebase.setString("airtemp", words[1]);
Firebase.setString("light", words[2]);
Firebase.setString("watertemp", words[3]);
Firebase.setString("soilmoisture", words[4]);
Firebase.setString("waterlevel", words[5]);
}
delay(1000); //Wait for the serial port.
}
else
{
//test code using similar format as sent from maxfthr board
String testData = "15.0 , 29 , 435 , 28 , 99 , 15 ";
char *str;
char sz[50] ;
testData.toCharArray(sz, 50);
char *p = sz;
String words[25] = "";
int i = 0 ;
while (str = strtok (p, ","))
{
words[i] = str;
//Serial.println(str);
p = NULL;
i = i + 1 ;
}
// set value
Serial.print(words[0]);
Serial.print("Air Humidity ");
Serial.print(words[1]);
Serial.print("Air Temp");
Serial.print(words[2]);
Serial.print("Ldr");
Serial.print(words[3]);
Serial.print("waterTemp");
Serial.print(words[4]);
Serial.print("Soil Moisture");
Serial.print(words[5]);
Serial.print("Ultrasonic");
delay(1000);
Firebase.setString("recieveddata", testData);
Firebase.setString("airhumidity", words[0]);
Firebase.setString("airtemp", words[1]);
Firebase.setString("light", words[2]);
Firebase.setString("watertemp", words[3]);
Firebase.setString("soilmoisture", words[4]);
Firebase.setString("waterlevel", words[5]);
delay(500); //Wait for the serial port.
/////////////////////////////////////////////////////
Serial.print("serial not available ");
// Firebase.setString("recieveddata", "error");
delay(1500); //Wait for the serial
}
//------ get actuators state from firebase-------//
String red , green , blue , feeder , heater , pump ;
red = Firebase.getString("red");
delay(100);
green = Firebase.getString("green");
delay(100);
blue = Firebase.getString("blue");
delay(100);
feeder = Firebase.getFloat("feederstate");
delay(100);
Serial.println(Firebase.getString("heaterstate"));
heater = Firebase.getFloat("heaterstate");
delay(1000);
pump = Firebase.getFloat("pumpstate");
delay(100);
//------------- send values to maxfthr board -------------//
String actuator = "";
actuator.concat(red);
actuator.concat(",");
actuator.concat(green);
actuator.concat(",");
actuator.concat(blue);
actuator.concat(",");
actuator.concat(feeder);
actuator.concat(",");
actuator.concat(heater);
actuator.concat(",");
actuator.concat(pump);
if (feeder.toInt() == 1 || heater.toInt() == 1 || pump.toInt() == 1)
{
Serial.println(actuator);
mySerial2.println (actuator);
//if state of any of heater , feeder , pump is on set it's value as 1 and send this value to max fthr
//and wait 1 minuite or any time u want and then turn it off again by setting value to zero
delay (60000);
Firebase.setString("feederstate", "0");
Firebase.setString("heaterstate", "0");
Firebase.setString("pumpstate", "0");
}
Serial.println(actuator);
mySerial2.println (actuator);
}
Running Firebase on ArduinoFirst part:
Second part:
Step 5: Unity App Developmenthttps://forum.easyar.com/portal.php?mod=view&aid=11
Simply follow this link to learn how to setup AR mode.
NOTE: Package name on EasyAR cloud should be same as package name on Unity app and Firebase package name, or it will show invalid key error.
Step 7: Find Full Unity Project HereZIP folder containing full Unity project + image target for AR:
https://drive.google.com/open?id=1-i5zR6BjpS2PxWVLspfQ4aYxVdNYoEZ3
APK application connected to my Firebase account:
https://drive.google.com/open?id=1x5eVqVIayUtiL03tw0zdbLhaxm1C3IDl
Demo VideosTesting the aquaponic system:
Testing the feeder mechanism:
Project link:
https://drive.google.com/open?id=1E3XeX4SR3aDyuK38vtq1H_UxAGOaWlkK
Comments