AhmedAzouz
Published

GO-4 Smart Home Arduino Bot

A robot that uses IoT technology to control your home appliances remotely through the Internet.

IntermediateWork in progressOver 2 days5,881
GO-4 Smart Home Arduino Bot

Things used in this project

Story

Read more

Schematics

Real Circuit

File missing, please reupload.

Code

GO-4_bot_Code.ino

C/C++
// Include WIFI module
#include <ESP8266WiFi.h>

// Include LCD
#include <LiquidCrystal.h>

// WiFi parameters
const char* ssid = "YOUR_SSID";//type your ssid
const char* password = "YOUR_PASSWORD";//type your password

// Relay pin (contcted to TV or Light)
int relayPin = 10; // GPIO2 of ESP8266

int botled = 9; // this led will flash to help is if its working

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Create an instance of the server
WiFiServer server(80);
 
void setup() {
  Serial.begin(115200);
  delay(50);
 
  pinMode(relayPin, OUTPUT);
  pinMode(botled, OUTPUT);
  
  digitalWrite(botled, HIGH); // turn on robot led as a guide
     
  // Connect to 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");
   
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");


  //*************** set up the LCD's number of columns and rows: *** ********
  lcd.begin(16, 2);
  lcd.clear();
  
}
 
void loop() {

    // Sets the cursor to col 0 and row 0
    lcd.setCursor(0,0);
      // Print a message to the LCD.
    lcd.print("GO-4");
    
    lcd.setCursor(0,1); // Sets the cursor second line to write other msgs
    
    
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
   
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
   
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
   
  // Read the request from the web server
 
  int value = LOW;
  if (request.indexOf("/LED=ON") != -1) {
    digitalWrite(relayPin, HIGH);
    value = HIGH;

    BlinkRobotLed(2);
  } 
  if (request.indexOf("/LED=OFF") != -1){
    digitalWrite(relayPin, LOW);
    value = LOW;

    BlinkRobotLed(2);
  }
   
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
   
  client.print("Relay pin is now: ");
   
  if(value == HIGH) {
    client.print("On"); 
    lcd.print("Relay bin On"); // you can change the msg as you like
  } else {
    client.print("Off");
    lcd.print("Relay bin OFF"); // you can change the msg as you like
  }
  client.println("<br><br>");
  client.println("Click <a href=\"/LED=ON\">here</a> turn the LED on pin 2 ON<br>");
  client.println("Click <a href=\"/LED=OFF\">here turn the LED on pin 2 OFF<br>");
  client.println("</html>");
 
  delay(1);
  Serial.println("Client disconnected");
  Serial.println("");
}

void BlinkRobotLed(int x)
{
  //blink robot led
    for(int i = 0 ; i < x; i++)
    {
      digitalWrite(botled, LOW);
      delay(50);
      digitalWrite(botled, HIGH);
      delay(50);
    }
  }

Credits

AhmedAzouz

AhmedAzouz

10 projects • 95 followers
High qualified software engineer, Creativity and Technology have always been a big part of my life.

Comments