Hardware components | ||||||
![]() |
| × | 1 | |||
| × | 1 | ||||
Software apps and online services | ||||||
![]() |
|
This Farming Robot purpose is to be able to accomplish the following:
Aerate, seed, water, feed, weed, monitor soil, data collection feedback, micro-feed selected plants based on their desired plants GPS location.
The goal is to grow without pesticides, by utilizing horticulture principles.
Testing and tracking individual plant level soil nutrient depletion, creating live soil depletion data and hopefully data predictions, to monitor nutrient uptake on a per plant basis.
If you have read this far get involved, we need your help!
Just getting started, not a pro dont judge
Arduinonow with data logger for each entry onto cvs file GPS is also recorded
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SPI.h> /// sd card reader
#include <SD.h> /// sd card reader
#include <SPI.h> /// wifi script
#include <WiFiNINA.h> /// wifi script
#define wifiConnect 8 /// wifi script
char ssid[] = "wifiname"; /// wifi script case sensitive
char pass[] = "wifi passw"; /// wifi script case sensitive
int keyIndex = 0; /// wifi script
int status = WL_IDLE_STATUS; /// wifi script
WiFiServer server(80); /// wifi script
String command; ///part of beeing able to send commands from terminal line to drive
static const int RXPin = 0 , TXPin = 1;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object of Josef McInturff
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
const int l1=2,l2=3,r1=5,r2=6; /// motor driving pins connected to relay
/// pin 4 is required to be used by my SD card shield
// ** MOSI - pin 11
// ** MISO - pin 12
// ** CLK - pin 13
// ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
const int chipSelect = 4;
void setup(){
pinMode(wifiConnect, OUTPUT); /// wifi script
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card..."); //// SD Card script
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
/// setup for driving the robot below
pinMode(r1,OUTPUT); // R1 right motors forward
pinMode(r2,OUTPUT); // R2 right motors reverse
pinMode(l1,OUTPUT); // L1 left motors forward
pinMode(l2,OUTPUT); // L2 left motors reverse
digitalWrite (r1,HIGH); //low activates relays i use set all to high
digitalWrite (r2,HIGH);
digitalWrite (l1,HIGH);
digitalWrite (l2,HIGH);
Serial.begin(9600);
ss.begin(GPSBaud);
while (status != WL_CONNECTED) { /// wifi script
Serial.print("Attempting to connect to Network named: "); /// wifi script
Serial.println(ssid); /// wifi script
status = WiFi.begin(ssid, pass); /// wifi script
delay(10000); /// wifi script
} /// wifi script
server.begin(); /// wifi script
digitalWrite(wifiConnect, HIGH); /// wifi script
// Serial.print("SSID: "); /// wifi script
// Serial.println(WiFi.SSID()); /// wifi script
IPAddress ip = WiFi.localIP(); /// wifi script
Serial.print("IP Address: "); /// wifi script
Serial.println(ip); /// wifi script
}
void loop(){
String dataString = ""; // sd card script
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
Serial.print("SSID: "); /// wifi script
Serial.println(WiFi.SSID()); /// wifi script
IPAddress ip = WiFi.localIP(); /// wifi script
Serial.print("IP Address: "); /// wifi script
Serial.println(ip); /// wifi script
Serial.println(dataString); // print sensor to the serial port too:
}
}
//Serial.print("Type Command ( STOP, FORWARD, BACK, LEFT, RIGHT )"); /// sending commands via terminal
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) { // sd card script takes value from input 0 analog on first go thru loop
int sensor = analogRead(analogPin); // sd card script
dataString += String(sensor); // sd card script
if (analogPin < 2) { // sd card script
dataString += ",";} // sd card script
if (analogPin >= 2) {
dataString += ",";
dataString += "Latitude";
dataString += ",";
dataString += String (gps.location.lat(), 6); /// dataString += (gps.location.lat(), 6);
dataString += ",";
dataString += "Longitude";
dataString += ",";
dataString += String (gps.location.lng(), 6);
dataString += ",";
}
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt Replace SD card reboot");
}
// put your main code here, to run repeatedly:
// LOW signal of arduino aktivates relay:
// driving instructions below
if(Serial.available()){
}
if (Serial.available()) {
command = Serial.readStringUntil('\n');
command.trim();
if (command.equals("STOP")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(l1, HIGH);
digitalWrite(l2, HIGH);
delay(1000);
}
else if (command.equals("FORWARD")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(5000);
}
else if (command.equals("BACK")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, LOW);
digitalWrite(l1, HIGH);
digitalWrite(l2, LOW);
delay(5000);
}
else if (command.equals("LEFT")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, HIGH);
digitalWrite(l2, LOW);
delay(2000);
}
else if (command.equals("RIGHT")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, LOW);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(2000);
}
else if (command.equals("ROW ")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(500);
}
else {
Serial.println("bad command");
}
Serial.print("Command: ");
Serial.println(command);
}
}
////credits to : tutorials from
///https://www.elithecomputerguy.com/author/admin/
///Paul McWhorter his youtube video shows step-by-step instructions
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
created by josef mcinturff Common Creative CC
#include <SPI.h> /// wifi script
#include <WiFiNINA.h> /// wifi script
#define wifiConnect 8 /// wifi script
char ssid[] = "YOUR WIFI NAME"; /// wifi script
char pass[] = "Your PASSWORD"; /// wifi script
int keyIndex = 0; /// wifi script
int status = WL_IDLE_STATUS; /// wifi script
WiFiServer server(80); /// wifi script
static const int RXPin = 3 , TXPin = 4;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object of Josef McInturff
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
char t; // TESTING VARIBLE TO DRIVE ROBOT s stop L left R right B Backwards
const int l1=10,l2=11,r1=12,r2=13; /// motor driving pins connected to relay
void setup(){
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
/// setup for driving the robot below
pinMode(r1,OUTPUT); // R1 right motors forward
pinMode(r2,OUTPUT); // R2 right motors reverse
pinMode(l1,OUTPUT); // L1 left motors forward
pinMode(l2,OUTPUT); // L2 left motors reverse
digitalWrite (r1,HIGH); //low activates relays i use set all to high
digitalWrite (r2,HIGH);
digitalWrite (l1,HIGH);
digitalWrite (l2,HIGH);
Serial.begin(9600);
ss.begin(GPSBaud);
}
void loop(){
// put your main code here, to run repeatedly:
// LOW signal of arduino aktivates relay:
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
}
}
// driving instructions below
// char t = 'F'; // TESTING VARIBLE TO DRIVE ROBOT s stop L left R right B Backwards
if(Serial.available()){
t = Serial.read();
}
// R1 right motors forward
// R2 right motors reverse
// L1 left motors forward
// L2 left motors reverse
if(t == 'F'){ //move forward(all motors rotate in forward direction)
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(l1,LOW);
digitalWrite(l2,HIGH);
delay(1000);
t = 'S';
}
else if(t == 'B'){ //move reverse (all motors rotate in reverse direction)
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(l1,HIGH);
digitalWrite(l2,LOW);
delay(1000);
t = 'S';
}
else if(t == 'L'){ //turn right (left side motors rotate in forward direction, right side motors rotate in reverse direction for 100ms & stop)
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(l1,HIGH);
digitalWrite(l2,LOW);
delay(1000);
t = 'S';
}
else if(t == 'R'){ //turn left (right side motors rotate in forward direction, left side motors rotate in reverse direction for 100ms & stop)
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(l1,LOW);
digitalWrite(l2,HIGH);
delay(1000);
t = 'S';
}
else if(t == 'S'){ //STOP (all motors stop)
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(l1,HIGH);
digitalWrite(l2,HIGH);
}
delay(100);
}
FUNCTIONING SERIAL READ OUT
ArduinoWORKING CODE
SERIAL READ OUT OF
ip
WIFI NETWORK
gps LOCATION
RECIVES DRIVING DRIRECTION FROM COMMAND LINE
SERIAL READ OUT OF
ip
WIFI NETWORK
gps LOCATION
RECIVES DRIVING DRIRECTION FROM COMMAND LINE
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SPI.h> /// wifi script
#include <WiFiNINA.h> /// wifi script
#define wifiConnect 8 /// wifi script
char ssid[] = "wifi network name"; /// wifi script
char pass[] = "wifi NETWORK PASSWORD"; /// wifi script
int keyIndex = 0; /// wifi script
int status = WL_IDLE_STATUS; /// wifi script
WiFiServer server(80); /// wifi script
String command; ///part of beeing able to send commands from terminal line to drive
static const int RXPin = 3 , TXPin = 4;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object of Josef McInturff
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
char t; // TESTING VARIBLE TO DRIVE ROBOT s stop L left R right B Backwards
const int l1=10,l2=11,r1=12,r2=13; /// motor driving pins connected to relay
void setup(){
pinMode(wifiConnect, OUTPUT); /// wifi script
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
/// setup for driving the robot below
pinMode(r1,OUTPUT); // R1 right motors forward
pinMode(r2,OUTPUT); // R2 right motors reverse
pinMode(l1,OUTPUT); // L1 left motors forward
pinMode(l2,OUTPUT); // L2 left motors reverse
digitalWrite (r1,HIGH); //low activates relays i use set all to high
digitalWrite (r2,HIGH);
digitalWrite (l1,HIGH);
digitalWrite (l2,HIGH);
Serial.begin(9600);
ss.begin(GPSBaud);
while (status != WL_CONNECTED) { /// wifi script
Serial.print("Attempting to connect to Network named: "); /// wifi script
Serial.println(ssid); /// wifi script
status = WiFi.begin(ssid, pass); /// wifi script
delay(10000); /// wifi script
} /// wifi script
server.begin(); /// wifi script
digitalWrite(wifiConnect, HIGH); /// wifi script
Serial.print("SSID: "); /// wifi script
Serial.println(WiFi.SSID()); /// wifi script
IPAddress ip = WiFi.localIP(); /// wifi script
Serial.print("IP Address: "); /// wifi script
Serial.println(ip); /// wifi script
}
void loop(){
// put your main code here, to run repeatedly:
// LOW signal of arduino aktivates relay:
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
Serial.print("SSID: "); /// wifi script
Serial.println(WiFi.SSID()); /// wifi script
IPAddress ip = WiFi.localIP(); /// wifi script
Serial.print("IP Address: "); /// wifi script
Serial.println(ip); /// wifi script
}
}
// driving instructions below
// char t = 'F'; // TESTING VARIBLE TO DRIVE ROBOT s stop L left R right B Backwards
if(Serial.available()){
t = Serial.read();
}
// R1 right motors forward
// R2 right motors reverse
// L1 left motors forward
// L2 left motors reverse
if(t == 'F'){ //move forward(all motors rotate in forward direction)
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(l1,LOW);
digitalWrite(l2,HIGH);
delay(1000);
t = 'S';
}
else if(t == 'B'){ //move reverse (all motors rotate in reverse direction)
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(l1,HIGH);
digitalWrite(l2,LOW);
delay(1000);
t = 'S';
}
else if(t == 'L'){ //turn right (left side motors rotate in forward direction, right side motors rotate in reverse direction for 100ms & stop)
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(l1,HIGH);
digitalWrite(l2,LOW);
delay(1000);
t = 'S';
}
else if(t == 'R'){ //turn left (right side motors rotate in forward direction, left side motors rotate in reverse direction for 100ms & stop)
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(l1,LOW);
digitalWrite(l2,HIGH);
delay(1000);
t = 'S';
}
else if(t == 'S'){ //STOP (all motors stop)
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(l1,HIGH);
digitalWrite(l2,HIGH);
}
delay(100);
Serial.println("Type Command ( STOP, FORWARD, BACK, LEFT, RIGHT )"); /// sending commands via terminal
delay(1000);
if (Serial.available()) {
command = Serial.readStringUntil('\n');
command.trim();
if (command.equals("STOP")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(l1, HIGH);
digitalWrite(l2, HIGH);
delay(1000);
}
else if (command.equals("FORWARD")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(5000);
}
else if (command.equals("BACK")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, LOW);
digitalWrite(l1, HIGH);
digitalWrite(l2, LOW);
delay(5000);
}
else if (command.equals("LEFT")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, HIGH);
digitalWrite(l2, LOW);
delay(2000);
}
else if (command.equals("RIGHT")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, LOW);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(2000);
}
else if (command.equals("ROW ")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(500);
}
else {
Serial.println("bad command");
}
Serial.print("Command: ");
Serial.println(command);
}
}
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SPI.h> /// sd card reader
#include <SD.h> /// sd card reader
#include <SPI.h> /// wifi script
#include <WiFiNINA.h> /// wifi script
#define wifiConnect 8 /// wifi script
char ssid[] = "WIFI NETWORK NAME"; /// wifi script
char pass[] = "WIFI PASSWORD"; /// wifi script
int keyIndex = 0; /// wifi script
int status = WL_IDLE_STATUS; /// wifi script
WiFiServer server(80); /// wifi script
String command; ///part of beeing able to send commands from terminal line to drive
static const int RXPin = 0 , TXPin = 1;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object of Josef McInturff
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
const int l1=2,l2=3,r1=5,r2=6; /// motor driving pins connected to relay
/// pin 4 is required to be used by my SD card shield
// ** MOSI - pin 11
// ** MISO - pin 12
// ** CLK - pin 13
// ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
const int chipSelect = 4;
void setup(){
pinMode(wifiConnect, OUTPUT); /// wifi script
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card..."); //// SD Card script
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
/// setup for driving the robot below
pinMode(r1,OUTPUT); // R1 right motors forward
pinMode(r2,OUTPUT); // R2 right motors reverse
pinMode(l1,OUTPUT); // L1 left motors forward
pinMode(l2,OUTPUT); // L2 left motors reverse
digitalWrite (r1,HIGH); //low activates relays i use set all to high
digitalWrite (r2,HIGH);
digitalWrite (l1,HIGH);
digitalWrite (l2,HIGH);
Serial.begin(9600);
ss.begin(GPSBaud);
while (status != WL_CONNECTED) { /// wifi script
Serial.print("Attempting to connect to Network named: "); /// wifi script
Serial.println(ssid); /// wifi script
status = WiFi.begin(ssid, pass); /// wifi script
delay(10000); /// wifi script
} /// wifi script
server.begin(); /// wifi script
digitalWrite(wifiConnect, HIGH); /// wifi script
// Serial.print("SSID: "); /// wifi script
// Serial.println(WiFi.SSID()); /// wifi script
IPAddress ip = WiFi.localIP(); /// wifi script
Serial.print("IP Address: "); /// wifi script
Serial.println(ip); /// wifi script
}
void loop(){
//Serial.print("Type Command ( STOP, FORWARD, BACK, LEFT, RIGHT )"); /// sending commands via terminal
// sd card script
// put your main code here, to run repeatedly:
// LOW signal of arduino aktivates relay:
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
Serial.print("SSID: "); /// wifi script
Serial.println(WiFi.SSID()); /// wifi script
IPAddress ip = WiFi.localIP(); /// wifi script
Serial.print("IP Address: "); /// wifi script
Serial.println(ip); /// wifi script
// print sensor to the serial port too:
}
String dataString = ""; // sd card script
// read three sensors and append to the string:
for (int analogPin = 0;
analogPin < 3;
analogPin++) { // sd card script
int sensor = analogRead(analogPin); // sd card script
dataString += String(sensor); // sd card script
if (analogPin < 2) { // sd card script
dataString += ",";}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt Replace SD card reboot");
}
}
// driving instructions below
if(Serial.available()){
}
if (Serial.available()) {
command = Serial.readStringUntil('\n');
command.trim();
if (command.equals("STOP")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(l1, HIGH);
digitalWrite(l2, HIGH);
delay(1000);
}
else if (command.equals("FORWARD")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(5000);
}
else if (command.equals("BACK")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, LOW);
digitalWrite(l1, HIGH);
digitalWrite(l2, LOW);
delay(5000);
}
else if (command.equals("LEFT")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, HIGH);
digitalWrite(l2, LOW);
delay(2000);
}
else if (command.equals("RIGHT")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, LOW);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(2000);
}
else if (command.equals("ROW ")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(500);
}
else {
Serial.println("bad command");
}
Serial.print("Command: ");
Serial.println(command);
}
}
}
int toggleState;
int buttonStatus = 0;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(9, OUTPUT); // turn water relay on "needs water"
pinMode(10, OUTPUT); // turn water relay on "needs nutrients"
// this sketch also uses Analog pin 1 water sensing sensor value over 1000 under 900
// this sketch also uses Analog pin 2 nutrients sensing
pinMode(8, INPUT_PULLUP); // enable internal pull-up pin 8 will be used as trigger by the {gps target plant reached} pin Later pullup may need to bemoved later
// pin 8 is currently a push botton but may later be set by "target arrived" function of my gps i also want to use this pin to take instant reading where the head unit is currently
Serial.begin(9600);
Serial.println("please push botton to trigger sensor reading");
}
// the loop routine runs over and over again forever:
void loop() {
// Set LED colour to their Digital Ouputs. Read the input on analog pin 0:
int water = 9; //feeding pin to run pump for water
int nutrients = 10; // feeding pin for nutrients
int sensorValueWater = analogRead(A1);
int sensorValueNutrients = analogRead(A2);
int pinValue = digitalRead(8); ///Pushbotton code
delay(10); // quick and dirty debounce filter
if (buttonStatus != pinValue) { ///Pushbotton code
buttonStatus = pinValue; ///Pushbotton code
Serial.println(buttonStatus); ///Pushbotton code
}
// Set the initial state of the LEDs to OFF
digitalWrite(9, HIGH); //feeding pin to run pump for water Low activates relay
digitalWrite(10, HIGH); // feeding pin for nutrients low activated relay
if(buttonStatus > 0) { //// in this loop we take readings and set relay to water and nutrients dispensary
// Logic Loop that sets the required LED to ON
if (sensorValueWater >= 1000) (digitalWrite(water, LOW)); ////watering code
else if ((sensorValueWater <= 999) && (sensorValueWater >=901)) (digitalWrite(water, HIGH)); ////watering code
else if (sensorValueWater <= 900) (digitalWrite(water, HIGH)); ////watering code
else ;
// Prints the condition of soil. Dry, Wet or Perfect
if (sensorValueWater >= 1000) (Serial.print("SOIL IS TOO DRY!!!!! watering now ")); ////watering code
else if ((sensorValueWater<= 999) && (sensorValueWater >=901)) (Serial.print("SOIL IS PERFECT!!!!! ")); ////watering code
else if (sensorValueWater <= 900) (Serial.print("SOIL IS TOO WET!!!!! ")); ////watering code
else;
// print out the value you read:
Serial.print("Soil Humidity: ");
Serial.println(sensorValueWater);
delay(1500); // delay in between reads for stability and keep water and nutrients on for this delay
digitalWrite(9, HIGH); //feeding pin to run pump for water
// Logic Loop that sets the required LED to ON
if (sensorValueNutrients >= 1000) (digitalWrite(nutrients, LOW)); ////nutirents code
else if ((sensorValueNutrients <= 999) && (sensorValueNutrients >=901)) (digitalWrite(nutrients, HIGH)); ////nutrients code
else if (sensorValueNutrients <= 900) (digitalWrite(nutrients, HIGH)); ////nutrients code
else ;
// Prints the condition of soil. Dry, Wet or Perfect
if (sensorValueNutrients >= 1000) (Serial.print("nutrients are LOW dispensing now ")); ////watering code
else if ((sensorValueNutrients<= 999) && (sensorValueNutrients >=901)) (Serial.print("SOIL IS PERFECT!!!!! ")); ////watering code
else if (sensorValueNutrients <= 900) (Serial.print("SOIL IS TOO HOT IN NUTRIENTS!!! ")); ////watering code
else;
// print out the value you read:
Serial.print("Nutrients: ");
Serial.println(sensorValueNutrients);
delay(1500); // delay in between reads for stability and keep water and nutrients on for this delay
digitalWrite(10, HIGH); // feeding pin for nutrients
}
while(buttonStatus >= 1) { // this code makes sure we are only running samples once after pushing putton nat as long as button is pushed manually (gps location arrived i dnt want to run this sketch non stop)
toggleState=! toggleState;
digitalWrite(8, toggleState);
delay(200) ;
buttonStatus = digitalRead (8);
}
toggleState =! toggleState;
digitalWrite (8, toggleState);
delay(200);
}
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <Math.h>
char t; // TESTING VARIBLE TO DRIVE ROBOT s stop L left R right B Backwards
const int l1=10,l2=11,r1=12,r2=13; /// motor driving pins connected to relay
// written by Josef McInturff
//long lat,lon; // create variable for latitude and longitude object
float lat = 28.54,lon = 77.17; // create variable for latitude and longitude object
SoftwareSerial gpsSerial(4,3); //rx,tx
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5); ///LCD PINS LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
TinyGPS gps; // create gps object
void setup() {
Serial.begin(9600);
//Serial.println("The GPS Received Signal:");
gpsSerial.begin(9600); // connect gps sensor
lcd.begin(16,2);
/// setup for driving the robot below
pinMode(r1,OUTPUT); //right motors forward
pinMode(r2,OUTPUT); //right motors reverse
pinMode(l1,OUTPUT); //left motors forward
pinMode(l2,OUTPUT); //left motors reverse
digitalWrite (r1,HIGH); //low activates relays i use set all to high
digitalWrite (r2,HIGH);
digitalWrite (l1,HIGH);
digitalWrite (l2,HIGH);
}
void loop() {
///setting up GPS On LCD display
while(gpsSerial.available()){ // check for gps data
if(gps.encode(gpsSerial.read()))// encode gps data
gps.f_get_position(&lat,&lon); // get latitude and longitude
// display position
lcd.clear();
lcd.setCursor(1,0);
lcd.print("GPS Signal");
//Serial.print("Position: ");
//Serial.print("Latitude:");
//Serial.print(lat,6);
//Serial.print(";");
//Serial.print("Longitude:");
//Serial.println(lon,6);
lcd.setCursor(1,0);
lcd.print("LAT:");
lcd.setCursor(5,0);
lcd.print(lat);
//Serial.print(lat);
//Serial.print(" ");
lcd.setCursor(0,1);
lcd.print(",LON:");
lcd.setCursor(5,1);
lcd.print(lon);
}
String latitude = String(lat,6);
String longitude = String(lon,6);
Serial.println(latitude+";"+longitude);
delay(1000);
// driving instructions below
char t = 'R'; // TESTING VARIBLE TO DRIVE ROBOT s stop L left R right B Backwards
if(Serial.available()){
t = Serial.read();
}
if(t == 'F'){ //move forward(all motors rotate in forward direction)
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(l1,LOW);
digitalWrite(l2,HIGH);
delay(1000);
t = 'S';
}
else if(t == 'B'){ //move reverse (all motors rotate in reverse direction)
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(l1,HIGH);
digitalWrite(l2,LOW);
delay(1000);
t = 'S';
}
else if(t == 'L'){ //turn right (left side motors rotate in forward direction, right side motors rotate in reverse direction for 100ms & stop)
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(l1,HIGH);
digitalWrite(l2,LOW);
delay(1000);
t = 'S';
}
else if(t == 'R'){ //turn left (right side motors rotate in forward direction, left side motors rotate in reverse direction for 100ms & stop)
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(l1,LOW);
digitalWrite(l2,HIGH);
delay(1000);
t = 'S';
}
else if(t == 'S'){ //STOP (all motors stop)
digitalWrite(r1,HIGH);
digitalWrite(r2,HIGH);
digitalWrite(l1,HIGH);
digitalWrite(l2,HIGH);
}
delay(100);
}
Drivable robot on command line storing sampler data on SD card with GPS coordinates
Arduinodrive robot to desired location push button then record sensor readings and GPS data store to SD card
//// pin layout digital side 0 RX GPS
// 1 tx GPS
// 2 driving left motor forward
// 3 driving Left motor reverse (make sure they are mechanically interlocked so both dont com on at once) Blinking on relay during startup or data x fer can short out load circuit motor drives
// 4 ** SD card shield madatory pin
// 5 driving Right side Forward
// 6 driving Right side Backwards (same note as left motor protect reverse polarity shorts)
// 7
// 8
// 9 dispense water pin on
// 10 dispense nutrients pin
// 11 **** MOSI - pin 11
// 12 ** MISO - pin 12
// 13 ** CLK - pin 13
/// pin 4 is required to be used by my SD card shield
// ** MOSI - pin 11
// ** MISO - pin 12
// ** CLK - pin 13
// analog side 0
// 1
// 2
// 3
// 4
// 5
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SPI.h> /// sd card reader
#include <SD.h> /// sd card reader
#include <SPI.h> /// wifi script
#include <WiFiNINA.h> /// wifi script
#define wifiConnect 8 /// wifi script
char ssid[] = "wifi name"; /// wifi script
char pass[] = "Password wifi"; /// wifi script
int keyIndex = 0; /// wifi script
int status = WL_IDLE_STATUS; /// wifi script
WiFiServer server(80); /// wifi script
int toggleState; ///soil sampler code
int buttonStatus = 1; ///soil sampler code
String command; ///part of beeing able to send commands from terminal line to drive
static const int RXPin = 0 , TXPin = 1;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object of Josef McInturff
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
const int l1=2,l2=3,r1=5,r2=6;// boomleft=7, boomright=8; /// motor driving pins connected to relay
/// pin 4 is required to be used by my SD card shield
// ** MOSI - pin 11
// ** MISO - pin 12
// ** CLK - pin 13
// ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
const int chipSelect = 4;
void setup(){
pinMode(wifiConnect, OUTPUT); /// wifi script
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card..."); //// SD Card script
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present! may need to be rebooted");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(9, OUTPUT); // turn water relay on "needs water" ///soil sampler code
pinMode(10, OUTPUT); // turn water relay on "needs nutrients" ///soil sampler code
// this sketch also uses Analog pin 1 water sensing sensor value over 1000 under 900 ///soil sampler code
// this sketch also uses Analog pin 2 nutrients sensing ///soil sampler code
pinMode(8, INPUT_PULLUP); // enable internal pull-up pin 8 will be used as trigger by the {gps target plant reached} pin Later pullup may need to bemoved later ///soil sampler code
// pin 8 is currently a push botton but may later be set by "target arrived" function of my gps i also want to use this pin to take instant reading where the head unit is currently ///soil sampler code
Serial.begin(9600);
Serial.println("please push botton to trigger sensor reading"); ///soil sampler code
///soil sampler code
/// setup for driving the robot below
pinMode(r1,OUTPUT); // R1 right motors forward
pinMode(r2,OUTPUT); // R2 right motors reverse
pinMode(l1,OUTPUT); // L1 left motors forward
pinMode(l2,OUTPUT); // L2 left motors reverse
digitalWrite (r1,HIGH); //low activates relays i use set all to high
digitalWrite (r2,HIGH);
digitalWrite (l1,HIGH);
digitalWrite (l2,HIGH);
Serial.begin(9600);
ss.begin(GPSBaud);
while (status != WL_CONNECTED) { /// wifi script
Serial.print("Attempting to connect to Network named: "); /// wifi script
Serial.println(ssid); /// wifi script
status = WiFi.begin(ssid, pass); /// wifi script
delay(10000); /// wifi script
} /// wifi script
server.begin(); /// wifi script
digitalWrite(wifiConnect, HIGH); /// wifi script
// Serial.print("SSID: "); /// wifi script
// Serial.println(WiFi.SSID()); /// wifi script
IPAddress ip = WiFi.localIP(); /// wifi script
Serial.print("IP Address: "); /// wifi script
Serial.println(ip); /// wifi script
}
void loop(){
String dataString = ""; // sd card script
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
Serial.print("SSID: "); /// wifi script
Serial.println(WiFi.SSID()); /// wifi script
IPAddress ip = WiFi.localIP(); /// wifi script
Serial.print("IP Address: "); /// wifi script
Serial.println(ip); /// wifi script
Serial.println(dataString); // print sensor to the serial port too:
}
}
// Set LED colour to their Digital Ouputs. Read the input on analog pin 0: ///soil sampler code
int water = 9; //feeding pin to run pump for water ///soil sampler code
int nutrients = 10; // feeding pin for nutrients ///soil sampler code
int sensorValueWater = analogRead(A4); ///soil sampler code
int sensorValueNutrients = analogRead(A5); ///soil sampler code
int pinValue = digitalRead(8); ///Pushbotton code ///soil sampler code
delay(10); // quick and dirty debounce filter ///soil sampler code
if (buttonStatus != pinValue) { ///Pushbotton code ///soil sampler code
buttonStatus = pinValue; ///Pushbotton code ///soil sampler code
Serial.println(buttonStatus); ///Pushbotton code ///soil sampler code
} ///soil sampler code
// Set the initial state of the LEDs to OFF ///soil sampler code
digitalWrite(9, HIGH); //feeding pin to run pump for water Low activates relay ///soil sampler code
digitalWrite(10, HIGH); // feeding pin for nutrients low activated relay ///soil sampler code
if(buttonStatus > 0) { //// in this loop we take readings and set relay to water and nutrients dispensary ///soil sampler code
///soil sampler code
// Logic Loop that sets the required LED to ON
if (sensorValueWater >= 1000) (digitalWrite(water, LOW)); ////watering code
else if ((sensorValueWater <= 999) && (sensorValueWater >=901)) (digitalWrite(water, HIGH)); ////watering code
else if (sensorValueWater <= 900) (digitalWrite(water, HIGH)); ////watering code
else ;
// Prints the condition of soil. Dry, Wet or Perfect
if (sensorValueWater >= 1000) (Serial.print("SOIL IS TOO DRY!!!!! watering now ")); ////watering code
else if ((sensorValueWater<= 999) && (sensorValueWater >=901)) (Serial.print("SOIL IS PERFECT!!!!! ")); ////watering code
else if (sensorValueWater <= 900) (Serial.print("SOIL IS TOO WET!!!!! ")); ////watering code
else;
// print out the value you read:
Serial.print("Soil Humidity: ");
Serial.println(sensorValueWater);
delay(1500); // delay in between reads for stability and keep water and nutrients on for this delay
digitalWrite(9, HIGH); //feeding pin to run pump for water
// Logic Loop that sets the required LED to ON
if (sensorValueNutrients >= 1000) (digitalWrite(nutrients, LOW)); ////nutirents code
else if ((sensorValueNutrients <= 999) && (sensorValueNutrients >=901)) (digitalWrite(nutrients, HIGH)); ////nutrients code
else if (sensorValueNutrients <= 900) (digitalWrite(nutrients, HIGH)); ////nutrients code
else ;
// Prints the condition of soil. Dry, Wet or Perfect
if (sensorValueNutrients >= 1000) (Serial.print("nutrients are LOW dispensing now ")); ////watering code
else if ((sensorValueNutrients<= 999) && (sensorValueNutrients >=901)) (Serial.print("SOIL IS PERFECT!!!!! ")); ////watering code
else if (sensorValueNutrients <= 900) (Serial.print("SOIL IS TOO HOT IN NUTRIENTS!!! ")); ////watering code
else;
// print out the value you read:
Serial.print("Nutrients: ");
Serial.println(sensorValueNutrients);
delay(1500); // delay in between reads for stability and keep water and nutrients on for this delay
digitalWrite(10, HIGH); // feeding pin for nutrients
// read GPS location and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) { // sd card script takes value from input 0 analog on first go thru loop
int sensor = analogRead(analogPin); // sd card script
dataString += String(sensor); // sd card script
if (analogPin < 2) { // sd card script
dataString += ",";} // sd card script
if (analogPin >= 2) {
dataString += ",";
dataString += "Latitude";
dataString += ",";
dataString += String (gps.location.lat(), 6); /// dataString += (gps.location.lat(), 6);
dataString += ",";
dataString += "Longitude";
dataString += ",";
dataString += String (gps.location.lng(), 6);
dataString += ",";
dataString += "Watersensor";
dataString += ",";
dataString += String (sensorValueWater);
dataString += ",";
dataString += "Nutrientsensor";
dataString += ",";
dataString += String (sensorValueNutrients);
dataString += ",";
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt Replace SD card reboot");
}
}
delay(200);
}
}
while(buttonStatus >= 1) { // this code makes sure we are only running samples once after pushing putton nat as long as button is pushed manually (gps location arrived i dnt want to run this sketch non stop)
toggleState=! toggleState;
digitalWrite(8, toggleState);
delay(200) ;
buttonStatus = digitalRead (8);
}
toggleState =! toggleState;
digitalWrite (8, toggleState);
delay(200);
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
// File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
// if (dataFile) {
// dataFile.println(dataString);
// dataFile.close();
// }
// if the file isn't open, pop up an error:
// else {
// Serial.println("error opening datalog.txt Replace SD card reboot");
// }
// put your main code here, to run repeatedly:
// LOW signal of arduino aktivates relay:
// driving instructions below
if(Serial.available()){
}
if (Serial.available()) {
command = Serial.readStringUntil('\n');
command.trim();
if (command.equals("STOP")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(l1, HIGH);
digitalWrite(l2, HIGH);
delay(1000);
}
else if (command.equals("FORWARD")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(5000);
}
else if (command.equals("BACK")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, LOW);
digitalWrite(l1, HIGH);
digitalWrite(l2, LOW);
delay(5000);
}
else if (command.equals("LEFT")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, HIGH);
digitalWrite(l2, LOW);
delay(2000);
}
else if (command.equals("RIGHT")) {
digitalWrite(r1, HIGH);
digitalWrite(r2, LOW);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(2000);
}
else if (command.equals("ROW ")) {
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(l1, LOW);
digitalWrite(l2, HIGH);
delay(500);
}
else {
Serial.println("bad command");
}
Serial.print("Command: ");
Serial.println(command);
}
}
////credits to : tutorials from
///https://www.elithecomputerguy.com/author/admin/
///Paul McWhorter his youtube video shows step-by-step instructions
Comments
Please log in or sign up to comment.