0% found this document useful (0 votes)
21 views4 pages

Python Esp 32 Communication by Othniel

The document is an Arduino sketch that sets up a WiFi connection and controls four motors based on client commands received over a server. It includes functions for driving the motors forward, stopping them, and handling infrared sensor interrupts. The code also manages LED indicators based on the state of the motors and client communication.

Uploaded by

Othniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Python Esp 32 Communication by Othniel

The document is an Arduino sketch that sets up a WiFi connection and controls four motors based on client commands received over a server. It includes functions for driving the motors forward, stopping them, and handling infrared sensor interrupts. The code also manages LED indicators based on the state of the motors and client communication.

Uploaded by

Othniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <WiFi.

h>

//setting up wifi
const char* ssid = "uofzStudents";
const char* password = "wkpProg219!";

WiFiServer server(8080);
//int flag1 = 0 ;
//
//motor 1

#define motor1_in1 19 //LA


#define motor1_in2 16 //RA
#define motor1_En1 2
//motor 2
#define motor2_in1 23 //LB
#define motor2_in2 17 //RB
#define motor2_En2 4
//motor 3
#define motor3_in1 32
#define motor3_in2 12
#define motor3_En1 18
//motor 4
#define motor4_in1 13
#define motor4_in2 14
#define motor4_En2 5
//
//ir sensors

void setup() {

//************************************WIFI SETUP ***********************


Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
Serial.println("Server started");
//
pinMode(25,OUTPUT);
//

pinMode(motor1_in1 ,OUTPUT);
pinMode(motor1_in2 ,OUTPUT);
pinMode(motor1_En1 ,OUTPUT);
//motor2
pinMode(motor2_in1 ,OUTPUT);
pinMode(motor2_in2 ,OUTPUT);
pinMode(motor2_En2 ,OUTPUT);
//motor3
pinMode(motor3_in1 ,OUTPUT);
pinMode(motor3_in2 ,OUTPUT);
pinMode(motor3_En1 ,OUTPUT);
//motor4
pinMode(motor4_in1 ,OUTPUT);
pinMode(motor4_in2 ,OUTPUT);
pinMode(motor4_En2 ,OUTPUT);
//
attachInterrupt(digitalPinToInterrupt(0) ,Ir1 ,RISING);
attachInterrupt(digitalPinToInterrupt(27) ,Ir2 ,RISING);
}

void loop() {

WiFiClient client = server.available();


if (client) {
while (client.connected()) {
if (client.available()) {
String data = client.readStringUntil('\n');
Serial.println(data);
if (data == "hello") {
// unsigned long start = micros();
// unsigned long duration ;
// while( duration <1000000){
digitalWrite(25, HIGH); // Turn on the LED
Serial.println("car stop...");
drive_stop();
Serial.println("watering identified plant");
//clearSerialMonitor();
//duration = micros() - start;
// }
}
else if(data != "hello") {
digitalWrite(25, LOW); // Turn off the LED
Serial.println("car in motion");
drive_forward();
data=" ";
//clearSerialMonitor();
}

}
}
client.stop();
}
/*
void clearSerialMonitor() {
for (int i = 0; i < 50; i++) {
Serial.println(); // Print 50 newline characters to clear the serial monitor
}
}
*/
void Ir1(){
drive_stop();
delay(1000);

void Ir2(){
//
drive_stop();
delay(1000);

}
void drive_forward(){
digitalWrite(motor1_in1 ,HIGH);
digitalWrite(motor1_in2 ,LOW);
digitalWrite(motor1_En1 ,150);
digitalWrite(motor2_in1 ,HIGH);
digitalWrite(motor2_in2 ,LOW);
digitalWrite(motor2_En2 ,150);
digitalWrite(motor3_in1 ,LOW);
digitalWrite(motor3_in2 ,HIGH);
digitalWrite(motor3_En1 ,150);
digitalWrite(motor4_in1 ,LOW);
digitalWrite(motor4_in2 ,HIGH);
digitalWrite(motor4_En2 ,150);
}

void drive_stop(){
digitalWrite(motor1_in1 ,LOW);
digitalWrite(motor1_in2 ,LOW);
digitalWrite(motor1_En1 ,150);
digitalWrite(motor2_in1 ,LOW);
digitalWrite(motor2_in2 ,LOW);
digitalWrite(motor2_En2 ,150);
digitalWrite(motor3_in1 ,LOW);
digitalWrite(motor3_in2 ,LOW);
digitalWrite(motor3_En1 ,150);
digitalWrite(motor4_in1 ,LOW);
digitalWrite(motor4_in2 ,LOW);
digitalWrite(motor4_En2 ,150);
}

void pump_on(){
Serial.println("pump on");
}

void pump_off(){

Serial.println("pump off");
}

You might also like