This page records our codes and our rocky path towards total control of our BLDC motors and water pumps using Arduino! 🙂

Tips: To view clearer images of our codes below, please click on the images and open them in another window.

 

Our significant milestones in coding

26 June 2019 (Wednesday)

  • Managed to control 2 water pumps (ON/OFF) independently from the Serial Monitor

 

27 June 2019 (Thursday)

  • Managed to control all 6 water pumps (ON/OFF) independently from the Serial Monitor

Image of code to be inserted:)

 

1 July 2019 (Monday)

  • Managed to control 2 motors independently from the Serial Monitor
    • Adjustable speed from input of 1000 (off) to 2000 (max speed)

  • After being able to control both motors and water pumps independently from the Serial Monitor, we finally tried out our Ethernet Shield and attempted to create our first web server in order to control our Arduino over Ethernet and make it more user friendly.

 

  • We first tried to control a single motor over Ethernet and it took us 4 days before we eventually succeeded!

 

4 July 2019 (Thursday)

  • After succeeding to control a single motor over Ethernet, we went on to test the code for multiple motors.
    • Each motor has three buttons – Low, Medium, High, to control its speed from 0 to the maximum speed.
    • Another change switching over to the web server was that we could no longer input a random value into the Serial Monitor to start the initializing of the electronic speed controller (ESCs). As such, we had to change the code a little such that the initializing of the ESCs occur automatically once the motor is powered.

Our code for controlling two motors over Ethernet:

A sneak peek of our web server
  • After a mini confidence boost from managing to control the motors independently over the internet, the next few days were dedicated to modifying the remaining of the code to include water pumps.

 

8 July 2019 (Monday) – The DAY!

  • Prior to testing out the codes which we wrote before, we first reconnected all the hardware to connect 4 motors and 6 water pumps onto one Arduino Mega board.
  • Due to a lack of ground on the board, we connected another mini breadboard to the whole circuit.

Since this is the first time the motors and the water pumps are connected on a single board, we first tried to control 1 motor and 1 pump over Ethernet:

  • This is how our web server looks like:

 

  • Below is the final code to control all 4 motors and 6 water pumps independently:
#include “math.h”
#include <Servo.h>
#include <SPI.h>
#include <Ethernet.h>
#define MAX_SIGNAL 2000
#define MIN_SIGNAL 1000
#define MOTOR_PIN1 6
#define MOTOR_PIN2 7
#define MOTOR_PIN3 8
#define MOTOR_PIN4 9
#define PUMP_PIN1 22
#define PUMP_PIN2 24
#define PUMP_PIN3 26
#define PUMP_PIN4 28
#define PUMP_PIN5 30
#define PUMP_PIN6 32
char DELAY1;
char DELAY2;
char DELAY3;
char DELAY4;
Servo motor1; //create servo object to control bldc motor
Servo motor2;
Servo motor3;
Servo motor4;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //physical mac address
byte ip[] = {192,168,0,158}; // ip in lan
byte gateway[] = {192,168,0,1}; // internet access via router
byte subnet[] = {255, 255, 255, 0}; // subnet mask
EthernetServer server(80);;//create a server at port 80
String readString, newString;
void setup() {
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet); // initialize Ethernet device
server.begin(); // start to listen for clients
//enable serial data print
Serial.begin(9600); //for diagnostics
Serial.print(“server is at”);
Serial.println(Ethernet.localIP());
Serial.println(“Welcome to SNEK!”);
pinMode(PUMP_PIN1,OUTPUT);//define control pin as output
pinMode(PUMP_PIN2,OUTPUT);//define control pin as output
pinMode(PUMP_PIN3,OUTPUT);//define control pin as output
pinMode(PUMP_PIN4,OUTPUT);//define control pin as output
pinMode(PUMP_PIN5,OUTPUT);//define control pin as output
pinMode(PUMP_PIN6,OUTPUT);//define control pin as output
Serial.println(“ESC calibration…”);
Serial.println(” “);
delay(1500);
Serial.println(“Program begin…”);
delay(1000);
Serial.println(“This program will start the ESC.”);
motor1.attach(MOTOR_PIN1);
motor2.attach(MOTOR_PIN2);
motor3.attach(MOTOR_PIN3);
motor4.attach(MOTOR_PIN4);
Serial.print(“Now writing maximum output: (“);Serial.print(MAX_SIGNAL);Serial.print(” us in this case)”);Serial.print(“\n”);
// Serial.println(“Turn on power source, then wait 2 seconds and press any key.”);
motor1.writeMicroseconds(MAX_SIGNAL);
motor2.writeMicroseconds(MAX_SIGNAL);
motor3.writeMicroseconds(MAX_SIGNAL);
motor4.writeMicroseconds(MAX_SIGNAL);
// Send min output
Serial.println(“\n”);
Serial.println(“\n”);
Serial.print(“Sending minimum output: (“);Serial.print(MIN_SIGNAL);Serial.print(” us in this case)”);Serial.print(“\n”);
motor1.writeMicroseconds(MIN_SIGNAL);
motor2.writeMicroseconds(MIN_SIGNAL);
motor3.writeMicroseconds(MIN_SIGNAL);
motor4.writeMicroseconds(MIN_SIGNAL);
Serial.println(“The ESC is calibrated”);
Serial.println(“—-“);
}
void loop() {
//create a client connection
EthernetClient client = server.available(); // try to get client
if (client){ //got client?
while(client.connected()){
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
Serial.print(c);
}
//if HTTP request has ended
if (c == ‘\n’) {
Serial.println(readString); //print to serial monitor and see what was captured for debuging
//now output HTML data header
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println();
client.println(“<HTML>”);
client.println(“<HEAD>”);
client.println(“<TITLE>Welcome to S.N.E.K. Control Centre</TITLE>”);
client.println(“<http-equiv=\”refresh\” content=\”1\”>”); //used to refresh the page in every 1 second
client.println(“</HEAD>”);
client.println(“<BODY>”);
client.println(“<H1>SNEK (Underwater ROV) Main Control Centre</H1>”);
client.println(“<hr />”);
client.println(“<br />”);
client.println(“<FORM ACTION=’/’ method=get>”); //uses IP/port of web page
client.println(“<br />”);
client.println(“Created by Jaslyn, Kiat Boon, Renee & Tiffany :)”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Click the following buttons below to control your desired motors or water pumps!”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Motor 1 (Pin 6)”);
client.println(“<a href =\”/?motor1veryhigh\”\”>Very High</a>”);
client.println(“<a href =\”/?motor1high\”\”>High</a>”);
client.println(“<a href =\”/?motor1med\”\”>Medium</a>”);
client.println(“<a href=\”/?motor1low\”\”>Low</a>”);
client.println(“<a href=\”/?motor1off\”\”>Off</a>”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Motor 2 (Pin 7)”);
client.println(“<a href =\”/?motor2veryhigh\”\”>Very High</a>”);
client.println(“<a href =\”/?motor2high\”\”>High</a>”);
client.println(“<a href =\”/?motor2med\”\”>Medium</a>”);
client.println(“<a href=\”/?motor2low\”\”>Low</a>”);
client.println(“<a href=\”/?motor2off\”\”>Off</a>”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Motor 3 (Pin 8)”);
client.println(“<a href =\”/?motor3veryhigh\”\”>Very High</a>”);
client.println(“<a href =\”/?motor3high\”\”>High</a>”);
client.println(“<a href =\”/?motor3med\”\”>Medium</a>”);
client.println(“<a href=\”/?motor3low\”\”>Low</a>”);
client.println(“<a href=\”/?motor3off\”\”>Off</a>”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Motor 4 (Pin 9)”);
client.println(“<a href =\”/?motor4veryhigh\”\”>Very High</a>”);
client.println(“<a href =\”/?motor4high\”\”>High</a>”);
client.println(“<a href =\”/?motor4med\”\”>Medium</a>”);
client.println(“<a href=\”/?motor4low\”\”>Low</a>”);
client.println(“<a href=\”/?motor4off\”\”>Off</a>”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Pump 1 (Pin 22)”);
client.println(“<a href =\”/?pump1on\”\”>On</a>”);
client.println(“<a href =\”/?pump1off\”\”>Off</a>”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Pump 2 (Pin 24)”);
client.println(“<a href =\”/?pump2on\”\”>On</a>”);
client.println(“<a href =\”/?pump2off\”\”>Off</a>”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Pump 3 (Pin 26)”);
client.println(“<a href =\”/?pump3on\”\”>On</a>”);
client.println(“<a href =\”/?pump3off\”\”>Off</a>”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Pump 4 (Pin 28)”);
client.println(“<a href =\”/?pump4on\”\”>On</a>”);
client.println(“<a href =\”/?pump4off\”\”>Off</a>”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Pump 5 (Pin 30)”);
client.println(“<a href =\”/?pump5on\”\”>On</a>”);
client.println(“<a href =\”/?pump5off\”\”>Off</a>”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“Pump 6 (Pin 32)”);
client.println(“<a href =\”/?pump6on\”\”>On</a>”);
client.println(“<a href =\”/?pump6off\”\”>Off</a>”);
client.println(“<br />”);
client.println(“<br />”);
// client.println(“Set motor position: <INPUT TYPE = TEXT NAME = ‘LED’ VALUE = ‘ ‘ SIZE = ’25’ MAXLENGTH = ’50’><BR>”);
// client.println(“<INPUT TYPE = SUBMIT NAME = ‘submit’ VALUE = ‘Submit now!’>”);
// client.println(“</FORM>”);
// client.println(“<BR>”);
// client.println(“</BODY>”);
// client.println(“</HTML>”);
delay(1);
//stopping client
client.stop();
//control motor 1
if (readString.indexOf(“?motor1veryhigh”) > 0){
int DELAY1 = 2000;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY1;
}
if (readString.indexOf(“?motor1high”) > 0){
int DELAY1 = 1750;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY1;
}
if (readString.indexOf(“?motor1med”) > 0){
int DELAY1 = 1500;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY1;
}
if (readString.indexOf(“?motor1low”) > 0){
int DELAY1 = 1250;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY1;
}
if (readString.indexOf(“?motor1off”) > 0){
int DELAY1 = 1000;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
readString = DELAY1;
}
//to control motor 2
if (readString.indexOf(“?motor2veryhigh”) > 0){
int DELAY2 = 2000;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY2;
}
if (readString.indexOf(“?motor2high”) > 0){
int DELAY2 = 1750;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY2;
}
if (readString.indexOf(“?motor2med”) > 0){
int DELAY2 = 1500;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY2;
}
if (readString.indexOf(“?motor2low”) > 0){
int DELAY2 = 1250;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY2;
}
if (readString.indexOf(“?motor2off”) > 0){
int DELAY2 = 1000;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
readString = DELAY2;
}
//to control motor 3
if (readString.indexOf(“?motor3veryhigh”) > 0){
int DELAY3 = 2000;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY3;
}
if (readString.indexOf(“?motor3high”) > 0){
int DELAY3 = 1750;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY3;
}
if (readString.indexOf(“?motor3med”) > 0){
int DELAY3 = 1500;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY3;
}
if (readString.indexOf(“?motor3low”) > 0){
int DELAY3 = 1250;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY3;
}
if (readString.indexOf(“?motor3off”) > 0){
int DELAY3 = 1000;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
readString = DELAY3;
}
//to control motor 4
if (readString.indexOf(“?motor4veryhigh”) > 0){
int DELAY4 = 2000;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY4;
}
if (readString.indexOf(“?motor4high”) > 0){
int DELAY4 = 1750;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY4;
}
if (readString.indexOf(“?motor4med”) > 0){
int DELAY4 = 1500;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY4;
}
if (readString.indexOf(“?motor4low”) > 0){
int DELAY4 = 1250;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
//clearing string for next read
readString = DELAY4;
}
if (readString.indexOf(“?motor4off”) > 0){
int DELAY4 = 1000;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
readString = DELAY4;
}
//control water pump 1
if (readString.indexOf(“?pump1on”) > 0){
digitalWrite(PUMP_PIN1, HIGH); //turn water pump 1 on
readString = “”;
}
if (readString.indexOf(“?pump1off”) > 0){
digitalWrite(PUMP_PIN1,LOW); //turn water pump 1 off
readString = “”;
}
//control water pump 2
if (readString.indexOf(“?pump2on”) > 0){
digitalWrite(PUMP_PIN2, HIGH); //turn water pump 2 on
readString = “”;
}
if (readString.indexOf(“?pump2off”) > 0){
digitalWrite(PUMP_PIN2,LOW); //turn water pump 2 off
readString = “”;
}
//control water pump 3
if (readString.indexOf(“?pump3on”) > 0){
digitalWrite(PUMP_PIN3, HIGH); //turn water pump 3 on
readString = “”;
}
if (readString.indexOf(“?pump3off”) > 0){
digitalWrite(PUMP_PIN3,LOW); //turn water pump 3 off
readString = “”;
}
//control water pump 4
if (readString.indexOf(“?pump4on”) > 0){
digitalWrite(PUMP_PIN4, HIGH); //turn water pump 4 on
readString = “”;
}
if (readString.indexOf(“?pump4off”) > 0){
digitalWrite(PUMP_PIN4,LOW); //turn water pump 4 off
readString = “”;
}
//control water pump 5
if (readString.indexOf(“?pump5on”) > 0){
digitalWrite(PUMP_PIN5, HIGH); //turn water pump 5 on
readString = “”;
}
if (readString.indexOf(“?pump5off”) > 0){
digitalWrite(PUMP_PIN5,LOW); //turn water pump 5 off
readString = “”;
}
//control water pump 6
if (readString.indexOf(“?pump6on”) > 0){
digitalWrite(PUMP_PIN6, HIGH); //turn water pump 6 on
readString = “”;
}
if (readString.indexOf(“?pump6off”) > 0){
digitalWrite(PUMP_PIN6,LOW); //turn water pump 6 off
readString = “”;
}
}}}}}

9 July 2019 (Tuesday) – Going forward

  • From now on, our aim is mainly to improve the user interface of our web server and hopefully be able to show the status of all the pumps and motors on the webserver.
  • We managed to change the switches (on and off) from hyperlink references to buttons yay!

 

Arduino code to change the switches from hyperlink references to buttons

 

 

 

 

 

 

Web server with buttons 🙂

 

10-11 July 2019 (Wednesday – Thursday)

  • Our battle to include the status of our motors and water pumps in our web server continues! We are still working hard on it!
  • Meanwhile, from what we have from Tuesday, we managed to control the water pump from our phone. This works as long as our phone is connected to the same WiFi as our main router and we access the IP address (192.168.0.158) from the web browser of our phone.

How our web server looks like on our phone

  • We really hope to get out the code that allows the showing the signal by the end of this week!

 

12 July 2019 (Friday)

  • We continued working on the Arduino code by attempting to show the signal of two pumps.

 

  • We managed to show the status of the water pumps as ‘0’ for Off and ‘1’ for On.
    • However, there is a lag that requires two clicks on the button or one click (another click to refresh the status). Example: one click on the button turns on the pumps and a second click on the button updates the water pump’s status correctly.
    • Moving forward, we hope to see if the lag can be resolved (such that only one click is required to turn on the pump and change the status) and use words (“on / off”) instead of numbers (0/1) to indicate the state clearly.

 

Arduino Code

 

Web Server with the Status Shown

Web Server with Both Pumps On

 

Web Server with Both Pumps Off

Web Server with One Pump On and One Pump Off

  • Initially, we were a little worried that refreshing the page and updating the status of one pump will affect the other pumps and motors (e.g. by resetting their status as off even though they may be on). However, our fears were unfounded as Arduino seems to store the status of each pump and motor independently and updating one won’t affect that of another. 🙂

 

  • Over the weekends, we will update incorporate the status part of this code with our previous code that controls all 4 motors and 6 propellers.

 

  • We finally incorporated the code for showing status as well as the code for replacing hyperlinks with buttons in our previously completed code. Can’t wait to load them up Arduino Mega Board and testing SNEK using the code in the waters the coming week!

 

15 July 2019 (Monday)

  • The status code works for both motors and pumps.
  • Meanwhile, we have started with waterproofing and below is the final code that we have uploaded to our arduino board.

#include “math.h”
#include <Servo.h>
#include <SPI.h>
#include <Ethernet.h>

#define MAX_SIGNAL 2000
#define MIN_SIGNAL 1000
#define MOTOR_PIN1 6
#define MOTOR_PIN2 7
#define MOTOR_PIN3 8
#define MOTOR_PIN4 9
#define PUMP_PIN1 22
#define PUMP_PIN2 24
#define PUMP_PIN3 26
#define PUMP_PIN4 28
#define PUMP_PIN5 30
#define PUMP_PIN6 32
char DELAY1;
char DELAY2;
char DELAY3;
char DELAY4;

Servo motor1; //create servo object to control bldc motor
Servo motor2;
Servo motor3;
Servo motor4;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //physical mac address
byte ip[] = {192,168,0,158}; // ip in lan
byte gateway[] = {192,168,0,1}; // internet access via router
byte subnet[] = {255, 255, 255, 0}; // subnet mask
EthernetServer server(80);;//create a server at port 80
String readString, newString;
char status1 = ‘0’;
char status2 = ‘0’;
char status3 = ‘0’;
char status4 = ‘0’;
char status5 = ‘0’;
char status6 = ‘0’;
char motorone = ‘0’;
char motortwo = ‘0’;
char motorthree = ‘0’;
char motorfour = ‘0’;

//for propellers, 0 status for off and 1 status for on
//for propellers, 0 (off), 1, 2, 3, 4 (highest speed)

void setup() {

//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet); // initialize Ethernet device
server.begin(); // start to listen for clients

//enable serial data print
Serial.begin(9600); //for diagnostics

Serial.print(“server is at”);
Serial.println(Ethernet.localIP());

Serial.println(“Welcome to SNEK!”);

pinMode(PUMP_PIN1,OUTPUT);//define control pin as output
pinMode(PUMP_PIN2,OUTPUT);//define control pin as output
pinMode(PUMP_PIN3,OUTPUT);//define control pin as output
pinMode(PUMP_PIN4,OUTPUT);//define control pin as output
pinMode(PUMP_PIN5,OUTPUT);//define control pin as output
pinMode(PUMP_PIN6,OUTPUT);//define control pin as output

Serial.println(“ESC calibration…”);
Serial.println(” “);
delay(1500);
Serial.println(“Program begin…”);
delay(1000);
Serial.println(“This program will start the ESC.”);

motor1.attach(MOTOR_PIN1);
motor2.attach(MOTOR_PIN2);
motor3.attach(MOTOR_PIN3);
motor4.attach(MOTOR_PIN4);

Serial.print(“Now writing maximum output: (“);Serial.print(MAX_SIGNAL);Serial.print(” us in this case)”);Serial.print(“\n”);
motor1.writeMicroseconds(MAX_SIGNAL);
motor2.writeMicroseconds(MAX_SIGNAL);
motor3.writeMicroseconds(MAX_SIGNAL);
motor4.writeMicroseconds(MAX_SIGNAL);

// Send min output
Serial.println(“\n”);
Serial.println(“\n”);
Serial.print(“Sending minimum output: (“);Serial.print(MIN_SIGNAL);Serial.print(” us in this case)”);Serial.print(“\n”);
motor1.writeMicroseconds(MIN_SIGNAL);
motor2.writeMicroseconds(MIN_SIGNAL);
motor3.writeMicroseconds(MIN_SIGNAL);
motor4.writeMicroseconds(MIN_SIGNAL);

Serial.println(“The ESC is calibrated”);
Serial.println(“—-“);

}

void loop() {
//create a client connection
EthernetClient client = server.available(); // try to get client

if (client){ //got client?
while(client.connected()){
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
Serial.print(c);
}

//if HTTP request has ended
if (c == ‘\n’) {
Serial.println(readString); //print to serial monitor and see what was captured for debuging

//now output HTML data header

client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println();

client.println(“<HTML>”);
client.println(“<HEAD>”);
client.println(“<TITLE>Welcome to SNEK (Underwater ROV) Control Centre</TITLE>”);
client.println(“<http-equiv=\”refresh\” content=\”1\”>”); //used to refresh the page in every 1 second

client.println(“</HEAD>”);
client.println(“<BODY>”);

client.println(“<H1>Welcome to SNEK (Underwater ROV) Control Centre (^_^)/ </H1>”);
client.println(“<hr />”);
client.println(“<br />”);

client.println(“<FORM ACTION=’/’ method=get>”); //uses IP/port of web page
client.println(“<br />”);

client.println(“Created by SNEK Team (^w^) consisting Jaslyn, Kiat Boon, Renee & Tiffany :)”);
client.println(“<br />”);
client.println(“<br />”);

client.println(“Click on the following buttons below to control your motors and water pumps!”);
client.println(“<br />”);
client.println(“<br />”);

client.println(“To check the status of motors: 0 – Off, 1 – Low, 2 – Medium, 3 – High, 4 – Very High”);
client.println(“<br />”);
client.println(“<br />”);

client.println(“To check the status of water pumps: 0 – Off, 1 – On”);
client.println(“<br />”);
client.println(“<br />”);

//controlling motors
client.println(“Motor 1 (Pin 6) Status = “) and client.print(motorone) and client.println(“<br/>”);
client.println(F(“<input type=button value=VERYHIGH onmousedown=location.href=’/?motor1veryhigh;’ target=inlineframe>”));
client.println(F(“<input type=button value=HIGH onmousedown=location.href=’/?motor1high;’ target=inlineframe>”));
client.println(F(“<input type=button value=MEDIUM onmousedown=location.href=’/?motor1med;’ target=inlineframe>”));
client.println(F(“<input type=button value=LOW onmousedown=location.href=’/?motor1low;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?motor1off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Motor 2 (Pin 7) Status = “) and client.print(motortwo) and client.println(“<br/>”);
client.println(F(“<input type=button value=VERYHIGH onmousedown=location.href=’/?motor2veryhigh;’ target=inlineframe>”));
client.println(F(“<input type=button value=HIGH onmousedown=location.href=’/?motor2high;’ target=inlineframe>”));
client.println(F(“<input type=button value=MEDIUM onmousedown=location.href=’/?motor2med;’ target=inlineframe>”));
client.println(F(“<input type=button value=LOW onmousedown=location.href=’/?motor2low;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?motor2off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Motor 3 (Pin 8) Status = “) and client.print(motorthree) and client.println(“<br/>”);
client.println(F(“<input type=button value=VERYHIGH onmousedown=location.href=’/?motor3veryhigh;’ target=inlineframe>”));
client.println(F(“<input type=button value=HIGH onmousedown=location.href=’/?motor3high;’ target=inlineframe>”));
client.println(F(“<input type=button value=MEDIUM onmousedown=location.href=’/?motor3med;’ target=inlineframe>”));
client.println(F(“<input type=button value=LOW onmousedown=location.href=’/?motor3low;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?motor3off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Motor 4 (Pin 9) Status = “) and client.print(motorfour) and client.println(“<br/>”);
client.println(F(“<input type=button value=VERYHIGH onmousedown=location.href=’/?motor4veryhigh;’ target=inlineframe>”));
client.println(F(“<input type=button value=HIGH onmousedown=location.href=’/?motor4high;’ target=inlineframe>”));
client.println(F(“<input type=button value=MEDIUM onmousedown=location.href=’/?motor4med;’ target=inlineframe>”));
client.println(F(“<input type=button value=LOW onmousedown=location.href=’/?motor4low;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?motor4off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 1 (Pin 22) Status = “) and client.print(status1) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump1on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump1off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 2 (Pin 24) Status = “) and client.print(status2) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump2on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump2off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 3 (Pin 26) Status = “) and client.print(status3) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump3on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump3off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 4 (Pin 28) Status = “) and client.print(status4) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump4on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump4off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 5 (Pin 30) Status = “) and client.print(status5) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump5on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump5off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 6 (Pin 32) Status = “) and client.print(status6) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump6on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump6off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“</BODY>”);
client.println(“</HTML>”);

delay(1);
//stopping client
client.stop();

//control motor 1
if (readString.indexOf(“?motor1veryhigh”) > 0){
int DELAY1 = 2000;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorone = ‘4’;
//clearing string for next read
readString = DELAY1;
}

if (readString.indexOf(“?motor1high”) > 0){
int DELAY1 = 1750;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorone = ‘3’;
readString = DELAY1;
}

if (readString.indexOf(“?motor1med”) > 0){
int DELAY1 = 1500;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorone = ‘2’;
readString = DELAY1;
}
if (readString.indexOf(“?motor1low”) > 0){
int DELAY1 = 1250;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorone = ‘1’;
readString = DELAY1;
}

if (readString.indexOf(“?motor1off”) > 0){
int DELAY1 = 1000;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorone = ‘0’;
readString = DELAY1;
}

//to control motor 2

if (readString.indexOf(“?motor2veryhigh”) > 0){
int DELAY2 = 2000;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motortwo = ‘4’;
readString = DELAY2;
}

if (readString.indexOf(“?motor2high”) > 0){
int DELAY2 = 1750;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motortwo = ‘3’;
readString = DELAY2;
}

if (readString.indexOf(“?motor2med”) > 0){
int DELAY2 = 1500;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motortwo = ‘2’;
readString = DELAY2;
}

if (readString.indexOf(“?motor2low”) > 0){
int DELAY2 = 1250;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motortwo = ‘1’;
readString = DELAY2;
}

if (readString.indexOf(“?motor2off”) > 0){
int DELAY2 = 1000;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motortwo = ‘0’;
readString = DELAY2;
}

//to control motor 3
if (readString.indexOf(“?motor3veryhigh”) > 0){
int DELAY3 = 2000;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorthree = ‘4’;
readString = DELAY3;
}

if (readString.indexOf(“?motor3high”) > 0){
int DELAY3 = 1750;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorthree = ‘3’;
readString = DELAY3;
}

if (readString.indexOf(“?motor3med”) > 0){
int DELAY3 = 1500;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorthree = ‘2’;
readString = DELAY3;
}

if (readString.indexOf(“?motor3low”) > 0){
int DELAY3 = 1250;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorthree = ‘1’;
readString = DELAY3;
}

if (readString.indexOf(“?motor3off”) > 0){
int DELAY3 = 1000;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorthree = ‘0’;
readString = DELAY3;
}

//to control motor 4
if (readString.indexOf(“?motor4veryhigh”) > 0){
int DELAY4 = 2000;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorfour = ‘4’;
readString = DELAY4;
}

if (readString.indexOf(“?motor4high”) > 0){
int DELAY4 = 1750;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorfour = ‘3’;
readString = DELAY4;
}

if (readString.indexOf(“?motor4med”) > 0){
int DELAY4 = 1500;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorfour = ‘2’;
readString = DELAY4;
}

if (readString.indexOf(“?motor4low”) > 0){
int DELAY4 = 1250;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorfour = ‘1’;
readString = DELAY4;
}

if (readString.indexOf(“?motor4off”) > 0){
int DELAY4 = 1000;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorfour = ‘0’;
readString = DELAY4;
}

//control water pump 1
if (readString.indexOf(“?pump1on”) > 0){
digitalWrite(PUMP_PIN1, HIGH); //turn water pump 1 on
status1 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump1off”) > 0){
digitalWrite(PUMP_PIN1,LOW); //turn water pump 1 off
status1 = ‘0’;
readString = “”;
}

//control water pump 2
if (readString.indexOf(“?pump2on”) > 0){
digitalWrite(PUMP_PIN2, HIGH); //turn water pump 2 on
status2 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump2off”) > 0){
digitalWrite(PUMP_PIN2,LOW); //turn water pump 2 off
status2 = ‘0’;
readString = “”;
}

//control water pump 3
if (readString.indexOf(“?pump3on”) > 0){
digitalWrite(PUMP_PIN3, HIGH); //turn water pump 3 on
status3 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump3off”) > 0){
digitalWrite(PUMP_PIN3,LOW); //turn water pump 3 off
status3 = ‘0’;
readString = “”;
}

//control water pump 4
if (readString.indexOf(“?pump4on”) > 0){
digitalWrite(PUMP_PIN4, HIGH); //turn water pump 4 on
status4 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump4off”) > 0){
digitalWrite(PUMP_PIN4,LOW); //turn water pump 4 off
status4 = ‘0’;
readString = “”;
}

//control water pump 5
if (readString.indexOf(“?pump5on”) > 0){
digitalWrite(PUMP_PIN5, HIGH); //turn water pump 5 on
status5 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump5off”) > 0){
digitalWrite(PUMP_PIN5,LOW); //turn water pump 5 off
status5 = ‘0’;
readString = “”;
}

//control water pump 6
if (readString.indexOf(“?pump6on”) > 0){
digitalWrite(PUMP_PIN6, HIGH); //turn water pump 6 on
status6 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump6off”) > 0){
digitalWrite(PUMP_PIN6,LOW); //turn water pump 6 off
status6 = ‘0’;
readString = “”;
}
}}}}}

 

25 July 2019 (Thursday) – The Final Code!

  • After the first few tests, we realised that even though we could control SNEK using the web server, it was not user friendly as we had to constantly refer the motors’ and pumps’ number to their position on SNEK to determine what direction they will move SNEK in when activated.
  • As such, we decided to upgrade our web server by integrating directions with their respective motors.

 

SNEK’s upgraded web server with directions integrated

  • Indeed, after adding in directions, we found that SNEK was even much easier to be controlled by any user as we could match the motors and pumps to their directions.
  • Moreover, from our test runs in the pool, we were also glad that the responses were generally fast (<1 s between the user pressing a button and SNEK responding accordingly).
  • Below is our final code:

#include “math.h”
#include <Servo.h>
#include <SPI.h>
#include <Ethernet.h>

#define MAX_SIGNAL 2000
#define MIN_SIGNAL 1000
#define MOTOR_PIN1 6
#define MOTOR_PIN2 7
#define MOTOR_PIN3 8
#define MOTOR_PIN4 9
#define PUMP_PIN1 22
#define PUMP_PIN2 26
#define PUMP_PIN3 38
#define PUMP_PIN4 28
#define PUMP_PIN5 30
#define PUMP_PIN6 32
char DELAY1;
char DELAY2;
char DELAY3;
char DELAY4;

Servo motor1; //create servo object to control bldc motor
Servo motor2;
Servo motor3;
Servo motor4;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //physical mac address
byte ip[] = {192,168,0,155}; // ip in lan
byte gateway[] = {192,168,0,1}; // internet access via router
byte subnet[] = {255, 255, 255, 0}; // subnet mask
EthernetServer server(80);;//create a server at port 80
String readString, newString;
char status1 = ‘0’;
char status2 = ‘0’;
char status3 = ‘0’;
char status4 = ‘0’;
char status5 = ‘0’;
char status6 = ‘0’;
char motorone = ‘0’;
char motortwo = ‘0’;
char motorthree = ‘0’;
char motorfour = ‘0’;

//for propellers, 0 status for off and 1 status for on
//for propellers, 0 (off), 1, 2, 3, 4 (highest speed)

void setup() {

//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet); // initialize Ethernet device
server.begin(); // start to listen for clients

//enable serial data print
Serial.begin(9600); //for diagnostics

Serial.print(“server is at”);
Serial.println(Ethernet.localIP());

Serial.println(“Welcome to SNEK!”);

pinMode(PUMP_PIN1,OUTPUT);//define control pin as output
pinMode(PUMP_PIN2,OUTPUT);//define control pin as output
pinMode(PUMP_PIN3,OUTPUT);//define control pin as output
pinMode(PUMP_PIN4,OUTPUT);//define control pin as output
pinMode(PUMP_PIN5,OUTPUT);//define control pin as output
pinMode(PUMP_PIN6,OUTPUT);//define control pin as output

digitalWrite(PUMP_PIN1,LOW);
digitalWrite(PUMP_PIN2,LOW);
digitalWrite(PUMP_PIN3,LOW);
digitalWrite(PUMP_PIN4,LOW);
digitalWrite(PUMP_PIN5,LOW);
digitalWrite(PUMP_PIN6,LOW);

Serial.println(“ESC calibration…”);
Serial.println(” “);
delay(1500);
Serial.println(“Program begin…”);
delay(1000);
Serial.println(“This program will start the ESC.”);

motor1.attach(MOTOR_PIN1);
motor2.attach(MOTOR_PIN2);
motor3.attach(MOTOR_PIN3);
motor4.attach(MOTOR_PIN4);

Serial.print(“Now writing maximum output: (“);Serial.print(MAX_SIGNAL);Serial.print(” us in this case)”);Serial.print(“\n”);
motor1.writeMicroseconds(MAX_SIGNAL);
motor2.writeMicroseconds(MAX_SIGNAL);
motor3.writeMicroseconds(MAX_SIGNAL);
motor4.writeMicroseconds(MAX_SIGNAL);

// Send min output
Serial.println(“\n”);
Serial.println(“\n”);
Serial.print(“Sending minimum output: (“);Serial.print(MIN_SIGNAL);Serial.print(” us in this case)”);Serial.print(“\n”);
motor1.writeMicroseconds(MIN_SIGNAL);
motor2.writeMicroseconds(MIN_SIGNAL);
motor3.writeMicroseconds(MIN_SIGNAL);
motor4.writeMicroseconds(MIN_SIGNAL);

Serial.println(“The ESC is calibrated”);
Serial.println(“—-“);

}

void loop() {
//create a client connection
EthernetClient client = server.available(); // try to get client

if (client){ //got client?
while(client.connected()){
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
Serial.print(c);
}

//if HTTP request has ended
if (c == ‘\n’) {
Serial.println(readString); //print to serial monitor and see what was captured for debuging

//now output HTML data header

client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println();

client.println(“<HTML>”);
client.println(“<HEAD>”);
client.println(“<TITLE>Welcome to SNEK (Underwater ROV) Control Centre</TITLE>”);
client.println(“<http-equiv=\”refresh\” content=\”1\”>”); //used to refresh the page in every 1 second

client.println(“</HEAD>”);
client.println(“<BODY>”);

client.println(“<H1>Welcome to SNEK (Underwater ROV) Control Centre (^_^)/ </H1>”);
client.println(“<hr />”);
client.println(“<br />”);

client.println(“<FORM ACTION=’/’ method=get>”); //uses IP/port of web page
client.println(“<br />”);

client.println(“Created by SNEK Team (^w^) consisting Jaslyn, Kiat Boon, Renee & Tiffany :)”);
client.println(“<br />”);
client.println(“<br />”);

client.println(“Click on the following buttons below to control your motors and water pumps!”);
client.println(“<br />”);
client.println(“<br />”);

client.println(“To check the status of motors: 0 – Off, 1 – Low, 2 – Medium, 3 – High, 4 – Very High”);
client.println(“<br />”);
client.println(“<br />”);

client.println(“To check the status of water pumps: 0 – Off, 1 – On”);
client.println(“<br />”);
client.println(“<br />”);

//controlling motors
client.println(“Motor 1 (Pin 6) – Move Downward: Status = “) and client.print(motorone) and client.println(“<br/>”);
client.println(F(“<input type=button value=VERYHIGH onmousedown=location.href=’/?motor1veryhigh;’ target=inlineframe>”));
client.println(F(“<input type=button value=HIGH onmousedown=location.href=’/?motor1high;’ target=inlineframe>”));
client.println(F(“<input type=button value=MEDIUM onmousedown=location.href=’/?motor1med;’ target=inlineframe>”));
client.println(F(“<input type=button value=LOW onmousedown=location.href=’/?motor1low;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?motor1off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Motor 2 (Pin 7) – Move Downward: Status = “) and client.print(motortwo) and client.println(“<br/>”);
client.println(F(“<input type=button value=VERYHIGH onmousedown=location.href=’/?motor2veryhigh;’ target=inlineframe>”));
client.println(F(“<input type=button value=HIGH onmousedown=location.href=’/?motor2high;’ target=inlineframe>”));
client.println(F(“<input type=button value=MEDIUM onmousedown=location.href=’/?motor2med;’ target=inlineframe>”));
client.println(F(“<input type=button value=LOW onmousedown=location.href=’/?motor2low;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?motor2off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Motor 3 (Pin 8) – Move Forward / Turn Left: Status = “) and client.print(motorthree) and client.println(“<br/>”);
client.println(F(“<input type=button value=VERYHIGH onmousedown=location.href=’/?motor3veryhigh;’ target=inlineframe>”));
client.println(F(“<input type=button value=HIGH onmousedown=location.href=’/?motor3high;’ target=inlineframe>”));
client.println(F(“<input type=button value=MEDIUM onmousedown=location.href=’/?motor3med;’ target=inlineframe>”));
client.println(F(“<input type=button value=LOW onmousedown=location.href=’/?motor3low;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?motor3off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Motor 4 (Pin 9) – Move Forward / Turn Right: Status = “) and client.print(motorfour) and client.println(“<br/>”);
client.println(F(“<input type=button value=VERYHIGH onmousedown=location.href=’/?motor4veryhigh;’ target=inlineframe>”));
client.println(F(“<input type=button value=HIGH onmousedown=location.href=’/?motor4high;’ target=inlineframe>”));
client.println(F(“<input type=button value=MEDIUM onmousedown=location.href=’/?motor4med;’ target=inlineframe>”));
client.println(F(“<input type=button value=LOW onmousedown=location.href=’/?motor4low;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?motor4off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 1 (Pin 22) – Move Forward: Status = “) and client.print(status1) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump1on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump1off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 2 (Pin 24) – Turn Right: Status = “) and client.print(status2) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump2on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump2off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 3 (Pin 26) – Move Forward: Status = “) and client.print(status3) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump3on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump3off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 4 (Pin 28) – Turn Left: Status = “) and client.print(status4) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump4on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump4off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 5 (Pin 30) – Move Backward: Status = “) and client.print(status5) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump5on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump5off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“Pump 6 (Pin 32) – Move Backward: Status = “) and client.print(status6) and client.println(“<br/>”);
client.println(F(“<input type=button value=ON onmousedown=location.href=’/?pump6on;’ target=inlineframe>”));
client.println(F(“<input type=button value=OFF onmousedown=location.href=’/?pump6off;’ target=inlineframe>”));
client.println(“<br />”);
client.println(“<br />”);

client.println(“</BODY>”);
client.println(“</HTML>”);

delay(1);
//stopping client
client.stop();

//control motor 1
if (readString.indexOf(“?motor1veryhigh”) > 0){
int DELAY1 = 2000;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorone = ‘4’;
//clearing string for next read
readString = DELAY1;
}

if (readString.indexOf(“?motor1high”) > 0){
int DELAY1 = 1750;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorone = ‘3’;
readString = DELAY1;
}

if (readString.indexOf(“?motor1med”) > 0){
int DELAY1 = 1500;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorone = ‘2’;
readString = DELAY1;
}
if (readString.indexOf(“?motor1low”) > 0){
int DELAY1 = 1250;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorone = ‘1’;
readString = DELAY1;
}

if (readString.indexOf(“?motor1off”) > 0){
int DELAY1 = 1000;
motor1.writeMicroseconds(DELAY1);
float SPEED = (DELAY1-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorone = ‘0’;
readString = DELAY1;
}

//to control motor 2

if (readString.indexOf(“?motor2veryhigh”) > 0){
int DELAY2 = 2000;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motortwo = ‘4’;
readString = DELAY2;
}

if (readString.indexOf(“?motor2high”) > 0){
int DELAY2 = 1750;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motortwo = ‘3’;
readString = DELAY2;
}

if (readString.indexOf(“?motor2med”) > 0){
int DELAY2 = 1500;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motortwo = ‘2’;
readString = DELAY2;
}

if (readString.indexOf(“?motor2low”) > 0){
int DELAY2 = 1250;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motortwo = ‘1’;
readString = DELAY2;
}

if (readString.indexOf(“?motor2off”) > 0){
int DELAY2 = 1000;
motor2.writeMicroseconds(DELAY2);
float SPEED = (DELAY2-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motortwo = ‘0’;
readString = DELAY2;
}

//to control motor 3
if (readString.indexOf(“?motor3veryhigh”) > 0){
int DELAY3 = 2000;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorthree = ‘4’;
readString = DELAY3;
}

if (readString.indexOf(“?motor3high”) > 0){
int DELAY3 = 1750;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorthree = ‘3’;
readString = DELAY3;
}

if (readString.indexOf(“?motor3med”) > 0){
int DELAY3 = 1500;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorthree = ‘2’;
readString = DELAY3;
}

if (readString.indexOf(“?motor3low”) > 0){
int DELAY3 = 1250;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorthree = ‘1’;
readString = DELAY3;
}

if (readString.indexOf(“?motor3off”) > 0){
int DELAY3 = 1000;
motor3.writeMicroseconds(DELAY3);
float SPEED = (DELAY3-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorthree = ‘0’;
readString = DELAY3;
}

//to control motor 4
if (readString.indexOf(“?motor4veryhigh”) > 0){
int DELAY4 = 2000;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorfour = ‘4’;
readString = DELAY4;
}

if (readString.indexOf(“?motor4high”) > 0){
int DELAY4 = 1750;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorfour = ‘3’;
readString = DELAY4;
}

if (readString.indexOf(“?motor4med”) > 0){
int DELAY4 = 1500;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorfour = ‘2’;
readString = DELAY4;
}

if (readString.indexOf(“?motor4low”) > 0){
int DELAY4 = 1250;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorfour = ‘1’;
readString = DELAY4;
}

if (readString.indexOf(“?motor4off”) > 0){
int DELAY4 = 1000;
motor4.writeMicroseconds(DELAY4);
float SPEED = (DELAY4-1000)/10;
Serial.print(“\n”);
Serial.println(“Motor speed:”); Serial.print(” “); Serial.print(SPEED); Serial.print(“%”);
motorfour = ‘0’;
readString = DELAY4;
}

//control water pump 1
if (readString.indexOf(“?pump1on”) > 0){
digitalWrite(PUMP_PIN1, HIGH); //turn water pump 1 on
status1 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump1off”) > 0){
digitalWrite(PUMP_PIN1,LOW); //turn water pump 1 off
status1 = ‘0’;
readString = “”;
}

//control water pump 2
if (readString.indexOf(“?pump2on”) > 0){
digitalWrite(PUMP_PIN2, HIGH); //turn water pump 2 on
status2 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump2off”) > 0){
digitalWrite(PUMP_PIN2,LOW); //turn water pump 2 off
status2 = ‘0’;
readString = “”;
}

//control water pump 3
if (readString.indexOf(“?pump3on”) > 0){
digitalWrite(PUMP_PIN3, HIGH); //turn water pump 3 on
status3 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump3off”) > 0){
digitalWrite(PUMP_PIN3,LOW); //turn water pump 3 off
status3 = ‘0’;
readString = “”;
}

//control water pump 4
if (readString.indexOf(“?pump4on”) > 0){
digitalWrite(PUMP_PIN4, HIGH); //turn water pump 4 on
status4 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump4off”) > 0){
digitalWrite(PUMP_PIN4,LOW); //turn water pump 4 off
status4 = ‘0’;
readString = “”;
}

//control water pump 5
if (readString.indexOf(“?pump5on”) > 0){
digitalWrite(PUMP_PIN5, HIGH); //turn water pump 5 on
status5 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump5off”) > 0){
digitalWrite(PUMP_PIN5,LOW); //turn water pump 5 off
status5 = ‘0’;
readString = “”;
}

//control water pump 6
if (readString.indexOf(“?pump6on”) > 0){
digitalWrite(PUMP_PIN6, HIGH); //turn water pump 6 on
status6 = ‘1’;
readString = “”;
}

if (readString.indexOf(“?pump6off”) > 0){
digitalWrite(PUMP_PIN6,LOW); //turn water pump 6 off
status6 = ‘0’;
readString = “”;
}
}}}}}