suria sarath
Published

Corona Fighter

The novel coronavirus is in all areas(Hospital, House, school). The sanitizing become hard. Corona fighter robot able to solve the problem

IntermediateProtip8 hours363
Corona Fighter

Things used in this project

Hardware components

FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
DFRobot FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
×1
Dual H-Bridge motor drivers L293D
Texas Instruments Dual H-Bridge motor drivers L293D
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
TRANSPARENT ACRYLIC ROBOT CHASSIS
×1
Low Voltage Transformer, Class II
Low Voltage Transformer, Class II
×1
STMicroelectronics STP55NF06
×1
UV Tube
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing Diagram

fritzing file

Code

Arduino code

C/C++
#include <WiFi.h>
#include <TroykaDHT.h>

void  right();
void left();
void stop1();
void backward();
void forward();

DHT dht(27, DHT11);
const char* ssid     = "agri";
const char* password = "datadata";
const int freq = 5000;
const int Channel0 = 0;
const int Channel1 = 1;
const int Channel2 = 2;
const int Channel3 = 3;
const int Channel4 = 4;
int startmove = 0;
int trigg = 13;
int echo = 12;
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement


const int resolution = 10;
int pin_array[5] = {4,16,5,18,26};
WiFiServer server(80);
 int calDistance(){
   digitalWrite(trigg, LOW);
  delayMicroseconds(2);
  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  digitalWrite(trigg, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigg, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echo, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
  // Displays the distance on the Serial Monitor
  Serial.print("Distance: ");
  return distance;
  }

  
void setup()
{
  pinMode(4,OUTPUT);
  pinMode(26,OUTPUT);
pinMode(5,OUTPUT);
pinMode(16,OUTPUT);
pinMode(18,OUTPUT);
pinMode(trigg, OUTPUT);
  pinMode(echo, INPUT);
for(int i =0;i<5;i++){
 ledcSetup(i, freq, resolution);
ledcAttachPin(pin_array[i], i);
  
  }


    Serial.begin(115200);
         // set the LED pin mode

    delay(10);

    // We start by connecting to a WiFi network

    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    
    server.begin();

}

int value = 0;

void forward (){
  if(calDistance()<20){
    stop1();
    left();
    }
    else{
  ledcWrite(0,0);
  ledcWrite(1, 600);
  
  ledcWrite(2,0);
  ledcWrite(3, 600);
    }
}
void inverter()
{
  for(int i=0;i<1023;i++){
    ledcWrite(4,i);
     delayMicroseconds(10);
    }
  for(int i=1024;i>1;i--){
    ledcWrite(4,i);
     delayMicroseconds(10);
    }
    digitalWrite(26,0);
  
}
void left()
{
  
  if(calDistance()<20){
    stop1();
    left();
    }
    else{
  ledcWrite(0,600);
  ledcWrite(1, 0);
  ledcWrite(2,0);
  ledcWrite(3, 600);
  
    }
}
  
void backward()
{
  /*digitalWrite(4,HIGH);
  digitalWrite(16,LOW);
  digitalWrite(5,HIGH);
  digitalWrite(18,0);*/

  ledcWrite(0,600);
  ledcWrite(1, 0);
  ledcWrite(2,600);
  ledcWrite(3, 0);
  startmove = 0;
}
void right()
{
  if(calDistance()<20){
    stop1();
    left();
    }
    else{

  ledcWrite(0,0);
  ledcWrite(1, 600);
  ledcWrite(2,600);
  ledcWrite(3, 0);
    }
}
void stop1()
{
  ledcWrite(0,0);
  ledcWrite(1, 0);
  ledcWrite(2,0);
  ledcWrite(3, 0);
  startmove = 0;
}
void axce()
{
  ledcWrite(0,0);
  ledcWrite(1, 1023);
  ledcWrite(2,0);
  ledcWrite(3, 1023);
  startmove = 1;
}

void loop(){
  inverter();
 WiFiClient client = server.available();   // listen for incoming clients
  Serial.println(calDistance());
  if(startmove){
    forward();
    }
  /////////////////////////
   dht.read();
  //   
  switch(dht.getState()) {
    //  OK
    case DHT_OK:
      //     
      Serial.print("Temperature = ");
      Serial.print(dht.getTemperatureC());
      Serial.println(" C \t");
      Serial.print("Temperature = ");
      Serial.print(dht.getTemperatureK());
      Serial.println(" K \t");
      Serial.print("Temperature = ");
      Serial.print(dht.getTemperatureF());
      Serial.println(" F \t");
      Serial.print("Humidity = ");
      Serial.print(dht.getHumidity());
      Serial.println(" %");
      break;
    //   
    case DHT_ERROR_CHECKSUM:
      Serial.println("Checksum error");
      break;
    //   
    case DHT_ERROR_TIMEOUT:
      Serial.println("Time out error");
      break;
    //  ,     
    case DHT_ERROR_NO_REPLY:
      Serial.println("Sensor not connected");
      break;
  }
  
  
  ////////////////////////
  if (client) {                             // if you get a client,
    Serial.println("New Client.");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("<center>");
            client.print("<h1><a href='left'>Left</a></h1>&nbsp;&nbsp;&nbsp;<h1><a href='lgo'>Left Go</a></h1><br>");
            
            client.print("</center>");
            
            client.print("<br>");
            client.print("<center>");
            client.print("<h1><a href='right'>Right</a>&nbsp;&nbsp;&nbsp;<a href='rgo'>Right Go</a></h1><br>");
            client.print("</center>");

            client.print("<br>");
            client.print("<center>");
            client.print("<h1><a href='forward'>Forward</a></h1><br>");
           client.print("</center>");

            client.print("<br>");
            client.print("<center>");
            client.print("<h1><a href='backward'>Backward</a></h1><br>");
            
            client.print("</center>");
            client.print("<br>");
            client.print("<center>");
            client.print("<h1><a href='stop'>Stop</a></h1><br>");
            
            client.print("</center>");
            client.print("</center>");
            client.print("<br>");
            client.print("<center>");
            client.print("<h1><a href='axce'>Acceleration</a></h1><br>");
            
            client.print("</center>");

            

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          } else {    // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (currentLine.endsWith("GET /left")) {
          left(); 
          delay(800);
          stop1();
        }
        if (currentLine.endsWith("GET /lgo")) {
          left(); 
          delay(800);
          forward();
        }
        if (currentLine.endsWith("GET /right")) {
                         // GET /L turns the LED off
         right();
        delay(800);
          stop1();
      
       }
       if (currentLine.endsWith("GET /rgo")) {
                         // GET /L turns the LED off
         right();
        delay(800);
          forward();
      
       }

        if (currentLine.endsWith("GET /forward")) {
                         // GET /L turns the LED off
         forward();
        
        }
         if (currentLine.endsWith("GET /backward")) {
                         // GET /L turns the LED off
         backward();
       
        }
        if (currentLine.endsWith("GET /stop")) {
                         // GET /L turns the LED off
         stop1();
       
        }
        if (currentLine.endsWith("GET /axce")) {
                         // GET /L turns the LED off
         axce();
       
        }
      }
    }
    // close the connection:
    client.stop();
    Serial.println("Client Disconnected.");
  }
}

Credits

suria sarath

suria sarath

8 projects • 25 followers
Embedded software programmer at Lanware Solutions

Comments