Translate

Membuat Robot Wall AVOIDER SRF04 Kendali WIFI ARDUINO DAN NODEMCU ESP 8266 WIFI 12E dan Penampil LCD NOKIA 5110

Membuat Robot Wall AVOIDER SRF04 Kendali WIFI ARDUINO DAN NODEMCU ESP 8266 WIFI 12E dan Penampil LCD NOKIA 5110 / 3310


           Pada malam yang berbahagia kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah robot wall avoider dengan penampil lcd nokia 5110 / 3310 dan kendali wifi, robot ini menggunakan mikrokontroller Arduino Uno dan juga di barengi dengan Nodemcu ESP8266 sebagai kendali wifi-nya, jadi robot akan berjalan saat ada perintah tombol ON dari wifi dan seketika robot off saat ada perintah OFF dari wifi. robot ini menggunakan 3 buah sensor jarak yang mendeteksi jarak depan, kanan dan kiri dari robot. untuk lebih jelasnya berikut adalah program dan skemanya.

 Link Tutorial Pemasangan LCD NOKIA
 LINK BLOG




a. Arduino UNO





b. Sensor Jarak SRF04





c. Nodemcu ESP 8266 12E Wifi





d. Motor Driver L293





e. LCD Nokia 5110 / 3310





f. Program Arduino IDE

#include <U8glib.h>
#include <stdlib.h>

#define trigPin1 A0
#define echoPin1 A1

#define trigPin2 A2
#define echoPin2 A3

#define trigPin3 A4
#define echoPin3 A5

U8GLIB_PCD8544 u8g(8, 9, 11, 10, 12);  // CLK=8, DIN=9, CE=11, DC=10, RST=12

char tmp_string1[8];
char tmp_string2[8];
char tmp_string3[8];

int x;

int EN2 = 3;
int EN1 = 2;
int IN1 = 4;
int IN2 = 5;
int IN3 = 6;
int IN4 = 7;

int duration1, distance1;
int duration2, distance2;
int duration3, distance3;
 
void draw(void) {
 
 
  itoa(distance1, tmp_string1, 10);
  itoa(distance2, tmp_string2, 10);
  itoa(distance3, tmp_string3, 10);

 //u8g.setFont(u8g_font_fub30);
  //u8g.setFont(u8g_font_profont11);
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  //u8g.setFont(u8g_font_profont11);
 
  u8g.drawStr(0, 10, "Depan= ");
  u8g.drawStr(50, 10, tmp_string1);
 
  u8g.drawStr(0, 25, "Kanan= ");
  u8g.drawStr(50, 25, tmp_string2);

  u8g.drawStr(0, 40, "Kiri= "); 
  u8g.drawStr(50, 40, tmp_string3);
 
}


void setup(void) {
  Serial.begin (9600);
 
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);

  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);

  pinMode(trigPin3, OUTPUT);
  pinMode(echoPin3, INPUT);
 
  pinMode(EN1,OUTPUT);
  pinMode(EN2,OUTPUT);
 
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
 
  pinMode(13,INPUT);
 
}



void loop(void) {

   x = digitalRead(13);
  
 if(x == LOW){
  analogWrite(EN1, 0);
  analogWrite(EN2, 0);
 
 //KANAN
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,LOW);
 //KIRI
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,LOW);
 
   }
  
  
 if(x == HIGH){  
  analogWrite(EN1, 250);
  analogWrite(EN2, 250);
  delay(200);
  analogWrite(EN1, 0);
  analogWrite(EN2, 0);
  delay(100);
 }
 

  digitalWrite(trigPin1, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;



  digitalWrite(trigPin2, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;



  digitalWrite(trigPin3, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin3, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin3, LOW);
  duration3 = pulseIn(echoPin3, HIGH);
  distance3 = (duration3/2) / 29.1;


 
  if((distance1 > 10)&&(distance2 > 10)&&(distance3 > 10)&&(x == HIGH)){
 //MAJU
 //KANAN
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
 //KIRI
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW); 
  }
 
 
  if((distance1 < 10)&&(distance2 > 10)&&(distance3 > 10)&&(x == HIGH)){
 //MUNDUR
 //KANAN
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
 //KIRI
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH); 
  }
 
 if((distance1 < 10)&&(distance2 < 10)&&(distance3 < 10)&&(x == HIGH)){
 //MUNDUR
 //KANAN
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);
 //KIRI
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH); 
  }
 
 
  if((distance1 < 10)&&(distance2 < 10)&&(distance3 > 10)&&(x == HIGH)){
 //KIRI
 //KANAN
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);
 //KIRI
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,LOW);
  }
 
 if((distance1 < 10)&&(distance2 > 10)&&(distance3 < 10)&&(x == HIGH)){
 //KANAN
 //KANAN
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,LOW);
 //KIRI
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);
  }
 
 
  u8g.firstPage(); 
  do {
    draw();
  } while( u8g.nextPage() );
 

  delay(100);


}






g. Program Arduino for Nodemcu esp8266

 #include <ESP8266WiFi.h>

const char* ssid = "EVERCOSS WIFI";
const char* password = "12345";

int ledPin = D0; // GPIO13
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);

  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

  // 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("/");

}

void loop() {
  // 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();

  // Match the request

  int value = LOW;
  if (request.indexOf("/LED=ON") != -1)  {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED=OFF") != -1)  {
    digitalWrite(ledPin, LOW);
    value = LOW;
  }

// Set ledPin according to the request
//digitalWrite(ledPin, value);

  // 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("Led pin is now: ");

  if(value == HIGH) {
    client.print("On");
  } else {
    client.print("Off");
  }
  client.println("<br><br>");
  client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");
  client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");
  client.println("</html>");

  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

}





 h. Hasil Tamplan Server Page






i. VIDEO HASILNYA











 

No comments:

Post a Comment