Hello guys I am currently working on my school project where we are supposed to make a soil moisture
sensor. After taking the moisture reading you must be able to like… toggle a switch to open or close an irrigation system. I decided to use my Arduino Yun( previously I was using a Raspberry pi, and Arduino together, but they broke(due to high voltage) so I bought a Yun) I succeeded in making the soil moisture sensing part, which I based on the TemperatureWebPanel sketch I found on the IDE. Find my sketch, and html web interface below, I didn’t edit the Javascript code I left it as is.I also left the time printing code, I thought it was cool. So now I have two buttons on my web interface, and when I press them I want to be able to open, and close a pin on the arduino while the moisture sensing sketch is running. I tried combining the Bridge Sketch with this sketch (with a lil bit of edits) and it didn’t work. Please Help!!! I am quite new to programming, and this is how I learn it (through doing stuff).
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
// Listen on default port 5555, the webserver on the Yún
// will forward there all the HTTP requests for us.
YunServer server;
String startString;
long hits = 0;
const int val_probe = 0;
const int red_Led = 8;
const int blue_Led = 6;
const int green_Led = 7;
const int warning = 4;
void setup() {
Serial.begin(9600);
// Bridge startup
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Bridge.begin();
digitalWrite(13, HIGH);
pinMode(A0, INPUT);
// Listen for incoming connection only from localhost
// (no one from the external network could connect)
server.listenOnLocalhost();
server.begin();
}
void loop() {
// Get clients coming from server
YunClient client = server.accept();
// There is a new client?
if (client) {
// read the command
String command = client.readString();
command.trim(); //kill whitespace
Serial.println(command);
if (command == “moisture”) {
// get the time from the server:
Process time;
time.runShellCommand(“date”);
String timeString = “”;
while (time.available()) {
char c = time.read();
timeString += c;
}
Serial.println(timeString);
float moisture = analogRead(val_probe);
float mois_level = moisture / 1023;
float soil_percentage = mois_level * 100;
client.print("Current time on the Yún: ");
client.println(timeString);
client.print("
Moisture Level in soil: ");
if(soil_percentage > 50.00 && soil_percentage < 95.00) {
digitalWrite(blue_Led, HIGH);
Serial.println("
(WET!)");
client.println("
(WET!)");
delay(100);
digitalWrite(blue_Led, LOW);
}
else if(soil_percentage > 95.00 && soil_percentage < 99.00) {
digitalWrite(green_Led, HIGH);
Serial.println("
(MEDIUM)");
client.println("
(MEDIUM)");
delay(100);
digitalWrite(green_Led, LOW);
}
else if(soil_percentage > 99.01) {
digitalWrite(red_Led, HIGH);
Serial.println("
(DRY)");
client.println("
(DRY)");
delay(100);
digitalWrite(red_Led, LOW);
}
else if (soil_percentage < 50.00 && soil_percentage > -1.00 ) {
digitalWrite(red_Led, HIGH);
delay(100);
digitalWrite(red_Led, LOW);
delay(100);
digitalWrite(blue_Led, HIGH);
delay(100);
digitalWrite(blue_Led, LOW);
delay(100);
digitalWrite(green_Led, HIGH);
delay(100);
digitalWrite(green_Led, LOW);
Serial.print("
(DROWNING)");
client.println("
(DROWNING)");
}
else {
digitalWrite(warning, HIGH);
delay(100);
digitalWrite(warning, LOW);
Serial.println("
ERROR: If error persists, check the following: “);
client.println(”
ERROR: If error persists, check the following: “);
Serial.println(”
Power Supply “);
client.println(”
Power Supply “);
Serial.println(”
If error still persists, read guide @ www.tswelo.com/mois-sens-guide.pdf");
client.println("
If error still persists, read guide @ www.tswelo.com/mois-sens-guide.pdf");
delay(1000);
Serial.println(“Please wait while I try to reconnect you…”);
client.println(“Please wait while I try to reconnect you…”);
delay(1000);
}
client.print(soil_percentage);
client.print(" % “);
client.print(”
readings taken so far: ");
client.print(hits);
}
// Close connection and free resources.
client.stop();
hits++;
}
delay(50); // Poll every 50ms
}
HELLO TSWELOPELE
PLEASE WAIT WHILE WE CONNECT YOU WITH YOUR SOIL... :)TO READ THE GUIDE ON HOW TO USE THIS SYSTEM TO IT’S FULL POTENTIAL,
CLICK HERE