android – Blog eTechPath https://blog.etechpath.com Tue, 03 Jan 2023 12:36:51 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://blog.etechpath.com/wp-content/uploads/2017/08/BrandLogo12-150x150.png android – Blog eTechPath https://blog.etechpath.com 32 32 How to control RGB LED wirelessly using ESP8266 WiFi web interface https://blog.etechpath.com/how-to-control-rgb-led-wirelessly-using-esp8266-wifi-web-interface/ https://blog.etechpath.com/how-to-control-rgb-led-wirelessly-using-esp8266-wifi-web-interface/#comments Tue, 21 Nov 2017 22:59:50 +0000 https://blog.etechpath.com/?p=476 About:

In this project we are going to control 1 watt RGB full color LED diode using WiFi module ESP8266-01. You can use any WiFi enabled device to access web interface to control this RGB LED. Watch video at the bottom of this page.




Things you will need: 

  • 1W RGB LED
  • ESP-01  WiFi module
  • 10Ω Resistance
  • ASM1117 3.3v  (or any 3.3v voltage source)
  • USB to TTL converter (for programming esp-01)
  • Momentary push button (optional)
  • Android / Apple / Windows  Phone or any WiFi enabled Laptop / Desktop (to control RGB LED)

Circuit Diagram for programming ESP-01 : 

esp-01_circuit

Steps :

    1. Connect the circuit on breadboard as shown in above circuit diagram for programming ESP-01 WiFi module. You must use only 3.3v logic setting in TTL device.
    2. In this tutorial we will used Arduino IDE to download code into ESP module. So, install Arduino IDE and add supporting board manager and ESP library into it. (Download links are given in download section)



  1. Download and save source code on your computer and open it up using Arduino IDE.
  2. Connect USB to TTL module to your computer.
  3. Open Arduino IDE – Select board ‘Generic ESP8266 Module’ – Select Port of your TTL device (Here’s How to)
  4. Open downloaded code.ino file into arduino and upload the code into ESP module by pressing upload button.
  5. After uploading, Disconnect the ESP module from USB-TTL module and connect it to RGB LED as shown in bellow diagram.

Circuit Diagram for connecting RGB LED:

Steps: 

    1. Connect the final circuit as shown in above diagram and power it up using 5v battery or wall adapter.
    2. ESP module will boot up and LED light will show fade effect in all three colors at startup.



  1. Then open your device WiFi in discovery mode and you will see a new WiFi access point, named as RGB in discovery list.
  2. Connect that WiFi access point, Open any web browser in that device and open ip address 192.168.1.1 , thats it, you will see a colorful RGB control screen to control your wireless RGB LED.
        Note: Do not feed more than 3.3v to ESP-01 module

Source Code : 

/* RGB web server with ESP8266-01 (ESP-01)
* There are only 2 GPIOs available in ESP-01: 0 and 2
* but RX and TX can also be used as: 3 and 1
* Wiring Circuit 
* 0=Red (GPIO0) D3
* 2=Green (GPIO2) D4
* 3=Blue (GPIO3) Rx
* www.etechpath.com
*/

#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>

const char *ssid = "RGB";
//Uncomment below line if you wish to set a password for ESP wifi network...
// const char *password = "87654321";  

const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);   //IP address of your ESP 
DNSServer dnsServer;
ESP8266WebServer webServer(80);

//Webpage html Code
String webpage = ""
"<!DOCTYPE html><html><head><title>RGB control eTechPath.com</title><meta name='mobile-web-app-capable' content='yes' />"
"<meta name='viewport' content='width=device-width' /></head><body style='margin: 0px; padding: 0px;'>"
"<canvas id='colorspace'></canvas>"
"</body>"
"<script type='text/javascript'>"
"(function () {"
" var canvas = document.getElementById('colorspace');"
" var ctx = canvas.getContext('2d');"
" function drawCanvas() {"
" var colours = ctx.createLinearGradient(0, 0, window.innerWidth, 0);"
" for(var i=0; i <= 360; i+=10) {"
" colours.addColorStop(i/360, 'hsl(' + i + ', 100%, 50%)');"
" }"
" ctx.fillStyle = colours;"
" ctx.fillRect(0, 0, window.innerWidth, window.innerHeight);"
" var luminance = ctx.createLinearGradient(0, 0, 0, ctx.canvas.height);"
" luminance.addColorStop(0, '#ffffff');"
" luminance.addColorStop(0.05, '#ffffff');"
" luminance.addColorStop(0.5, 'rgba(0,0,0,0)');"
" luminance.addColorStop(0.95, '#000000');"
" luminance.addColorStop(1, '#000000');"
" ctx.fillStyle = luminance;"
" ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);"
" }"
" var eventLocked = false;"
" function handleEvent(clientX, clientY) {"
" if(eventLocked) {"
" return;"
" }"
" function colourCorrect(v) {"
" return Math.round(1023-(v*v)/64);"
" }"
" var data = ctx.getImageData(clientX, clientY, 1, 1).data;"
" var params = ["
" 'r=' + colourCorrect(data[0]),"
" 'g=' + colourCorrect(data[1]),"
" 'b=' + colourCorrect(data[2])"
" ].join('&');"
" var req = new XMLHttpRequest();"
" req.open('POST', '?' + params, true);"
" req.send();"
" eventLocked = true;"
" req.onreadystatechange = function() {"
" if(req.readyState == 4) {"
" eventLocked = false;"
" }"
" }"
" }"
" canvas.addEventListener('click', function(event) {"
" handleEvent(event.clientX, event.clientY, true);"
" }, false);"
" canvas.addEventListener('touchmove', function(event){"
" handleEvent(event.touches[0].clientX, event.touches[0].clientY);"
"}, false);"
" function resizeCanvas() {"
" canvas.width = window.innerWidth;"
" canvas.height = window.innerHeight;"
" drawCanvas();"
" }"
" window.addEventListener('resize', resizeCanvas, false);"
" resizeCanvas();"
" drawCanvas();"
" document.ontouchmove = function(e) {e.preventDefault()};"
" })();"
"</script></html>";
void handleRoot() 
{
// Serial.println("handle root..");
String red = webServer.arg(0); // read RGB arguments
String green = webServer.arg(1);  // read RGB arguments
String blue = webServer.arg(2);  // read RGB arguments

//for common anode
analogWrite(0, red.toInt());
analogWrite(2, green.toInt());
analogWrite(3, blue.toInt());
//for common cathode
//analogWrite(0,1023 - red.toInt());
//analogWrite(2,1023 - green.toInt());
//analogWrite(3,1023 - blue.toInt());
webServer.send(200, "text/html", webpage);
}
void setup() 
{
pinMode(0, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);

analogWrite(0, 1023);
analogWrite(2, 1023);
analogWrite(3, 1023);
delay(1000);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid);
dnsServer.start(DNS_PORT, "rgb", apIP);
webServer.on("/", handleRoot);
webServer.begin();
testRGB();
}
void loop() 
{
dnsServer.processNextRequest();
webServer.handleClient();
}
void testRGB() 
{ 
// fade in and out of Red, Green, Blue
analogWrite(0, 1023); // Red off
analogWrite(2, 1023); // Green off
analogWrite(3, 1023); // Blue off

fade(0); // Red fade effect
fade(2); // Green fade effect
fade(3); // Blue fade effect
}
void fade(int pin) 
{
for (int u = 0; u < 1024; u++) 
{
analogWrite(pin, 1023 - u);
delay(1);
}
for (int u = 0; u < 1024; u++) 
{
analogWrite(pin, u);
delay(1);
}
}

 





Downloads:

  1. Code.ino
  2. Arduino IDE
  3. ESP8266 Board link for IDE board manager
  4. ESP8266 Arduino Library

 

]]>
https://blog.etechpath.com/how-to-control-rgb-led-wirelessly-using-esp8266-wifi-web-interface/feed/ 6
Bluetooth Controlled 8×8 LED MAX7219 Matrix using Android Phone. https://blog.etechpath.com/bluetooth-controlled-8x8-led-max7219-matrix-using-android-phone/ https://blog.etechpath.com/bluetooth-controlled-8x8-led-max7219-matrix-using-android-phone/#comments Thu, 12 Oct 2017 00:51:25 +0000 https://blog.etechpath.com/?p=416 About:

This project is about moving LED matrix display. In this project we will use MAX7219 8×8 LED module for display, Arduino UNO for brain and Bluetooth serial  module for communication. You will need an Android phone for controlling this display.




Things you will need: 

  1. Arduino UNO.
  2. MAX7219 LED modules – 3Nos.   (You can add many of these for increasing length of display)
  3. HC-05 Serial Bluetooth Module.      (You can use any other similar serial Bluetooth module instead )
  4. Android Phone.

 

Circuit Diagram:

Circuit Diagram

wiring diagram

 

Code :

    /*
          8x8 LED Matrix MAX7219 Scrolling Text
              Android Control via Bluetooth
    */
    #include <MaxMatrix.h>
    #include <SoftwareSerial.h>
    #include <avr/pgmspace.h>
    PROGMEM const unsigned char CH[] = {
      3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
      1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
      3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
      5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
      4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
      5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
      5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
      1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
      3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
      3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
      5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
      5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
      2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
      4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
      2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
      4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
      4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
      3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
      4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
      4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
      4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
      4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
      4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
      4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
      4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
      4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
      2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
      2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
      3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
      3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
      3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
      4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
      5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
      4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
      4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
      4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
      4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
      4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
      4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
      4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
      4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
      3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
      4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
      4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
      4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
      5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
      5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
      4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
      4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
      4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
      4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
      4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
      5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
      4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
      5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
      5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
      5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
      5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
      4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
      2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
      4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
      2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
      3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
      4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
      2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
      4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
      4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
      4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
      4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
      4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
      3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
      4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
      4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
      3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
      4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
      4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
      3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
      5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
      4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
      4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
      4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
      4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
      4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
      4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
      3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
      4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
      5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
      5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
      5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
      4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
      3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
      3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
      1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
      3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
      4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
    };
    int dIn = 7;   // DIN pin of MAX7219 module
    int clk = 6;   // CLK pin of MAX7219 module
    int cs = 5;    // CS pin of MAX7219 module
    int maxInUse = 2;    // Number of MAX7219's connected
    MaxMatrix m(dIn, cs, clk, maxInUse);
    SoftwareSerial Bluetooth(8, 7); // Bluetooth
    byte buffer[10];
    char incomebyte;
    int scrollSpeed = 100;
    char text[100] = "www.etechpath.com  "; // Initial text message
    int brightness = 15;
    int count = 0;
    char indicator;
    void setup() {
      m.init(); // MAX7219 initialization
      m.setIntensity(brightness); // initial led matrix intensity, 0-15
      Bluetooth.begin(38400); // Default communication rate of the Bluetooth module
    }
    void loop() {
      // Printing the text
      printStringWithShift(text, scrollSpeed);
      
      if (Bluetooth.available()) {   // Checks whether data is comming from the serial port
        indicator = Bluetooth.read();   // Starts reading the serial port, the first byte from the incoming data
        // If we have pressed the "Send" button from the Android App, clear the previous text
        if (indicator == '1') {
          for (int i = 0; i < 100; i++) {
            text[i] = 0;
            m.clear();
          }
          // Read the whole data/string comming from the phone and put it into text[] array.
          while (Bluetooth.available()) {
            incomebyte = Bluetooth.read();
            text[count] = incomebyte;
            count++;
          }
          count = 0;
        }
        // Adjusting the Scrolling Speed
        else if (indicator == '2') {
          String sS = Bluetooth.readString();
          scrollSpeed = 150 - sS.toInt(); // Milliseconds, subtraction because lower value means higher scrolling speed
        }
        // Adjusting the brightness
        else if (indicator == '3') {
          String sB = Bluetooth.readString();
          brightness = sB.toInt();
          m.setIntensity(brightness);
        }
      }
    }
    void printCharWithShift(char c, int shift_speed) {
      if (c < 32) return;
      c -= 32;
      memcpy_P(buffer, CH + 7 * c, 7);
      m.writeSprite(32, 0, buffer);
      m.setColumn(32 + buffer[0], 0);
      for (int i = 0; i < buffer[0] + 1; i++)
      {
        delay(shift_speed);
        m.shiftLeft(false, false);
      }
    }
    void printStringWithShift(char* s, int shift_speed) {
      while (*s != 0) {
        printCharWithShift(*s, shift_speed);
        s++;
      }
    }
    void printString(char* s)
    {
      int col = 0;
      while (*s != 0)
      {
        if (*s < 32) continue;
        char c = *s - 32;
        memcpy_P(buffer, CH + 7 * c, 7);
        m.writeSprite(col, 0, buffer);
        m.setColumn(col + buffer[0], 0);
        col += buffer[0] + 1;
        s++;
      }
    }

 

 

Steps :

  1. Connect MAX7219 LED modules with each other as shown in above wiring diagram.
  2. Connect led modules data pins to arduino data pins and connect source power as shown in circuit diagram.
  3. Now connect HC-05 serial module to RX TX pins of Arduino. Arduino RX to HC-05 TX and arduino TX to HC-05 RX.
  4. Download code into arduino using Arduino IDE.
  5. Download android application from download section and install it in your phone .
  6. Now you can connect your phone with this display using provided application to control matrix display.



Downloads :

  1. Android appliation
  2. MAX7219 Datasheet
  3. MaxMatrix.h


Check this WiFi controlled MAX7219 LED Matrix using ESP-12 NodeMCU module

]]>
https://blog.etechpath.com/bluetooth-controlled-8x8-led-max7219-matrix-using-android-phone/feed/ 1
How to operate home appliances wirelessly using ESP8266 and android phone https://blog.etechpath.com/how-to-operate-home-appliances-wirelessly-using-esp8266-and-android-phone/ https://blog.etechpath.com/how-to-operate-home-appliances-wirelessly-using-esp8266-and-android-phone/#respond Fri, 08 Sep 2017 01:37:04 +0000 https://blog.etechpath.com/?p=236 Required Components: 



  1. NodeMCU or any ESP8266
  2. Relay Module
  3. 128×64 OLED display (Optional)
  4. Android Phone

Circuit Diagram :

 

Source Code:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <Adafruit_GFX.h>
#include <ESP_Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

 

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

const char* ssid = "xxxxxxx"; //replace xxxxxxx with your wifi ssid
const char* password = "xxxxxxx"; //replace xxxxxxx with your wifi password

ESP8266WebServer server(80);

const int output1 = 14;
const int output2 = 12;
const int output3 = 13;
const int output4 = 15;

boolean device1 = false;
boolean device2 = false;
boolean device3 = false;
boolean device4 = false;

void handleRoot() {
//digitalWrite(led, 1);
//server.send(200, "text/plain", "hello from esp8266!");
//digitalWrite(led, 0);

String cmd;
cmd += "<!DOCTYPE HTML>\r\n";
cmd += "<html>\r\n";
//cmd += "<header><title>ESP8266 Webserver</title><h1>\"ESP8266 Web Server Control\"</h1></header>";
cmd += "<head>";
cmd += "<meta http-equiv='refresh' content='5'/>";
cmd += "</head>";

if(device1){
cmd +=("<br/>Device1 : ON");
}
else{
cmd +=("<br/>Device1 : OFF");
}

if(device2){
cmd +=("<br/>Device2 : ON");
}
else{
cmd +=("<br/>Device2 : OFF");
}

if(device3){
cmd +=("<br/>Device3 : ON");
}
else{
cmd +=("<br/>Device3 : OFF");
}

if(device4){
cmd +=("<br/>Device4 : ON");
}
else{
cmd +=("<br/>Device4 : OFF");
}

cmd += "<html>\r\n";
server.send(200, "text/html", cmd);
}

void handleNotFound(){

String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);

}

void setup(void){
pinMode(output1, OUTPUT);
pinMode(output2, OUTPUT);
pinMode(output3, OUTPUT);
pinMode(output4, OUTPUT);

digitalWrite(output1, LOW);
digitalWrite(output2, LOW);
digitalWrite(output3, LOW);
digitalWrite(output4, LOW);

Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");

 

// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
//display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64)
display.begin(SSD1306_SWITCHCAPVCC, 0x78>>1); // init done

display.clearDisplay(); // Clear the buffer.

display.setTextSize(2);
display.setTextColor(WHITE);
//display.setTextColor(BLACK, WHITE); // 'inverted' text
display.setCursor(0,0);
display.println(" ESP8266");

display.setTextSize(3); //Size4 = 5 digit , size3 = 7 digits
//display.setTextColor(BLACK, WHITE); // 'inverted' text
display.setTextColor(WHITE);
display.setCursor(0,18);
display.println("Control");

display.setTextSize(1);
display.setTextColor(WHITE);
//display.setTextColor(BLACK, WHITE); // 'inverted' text
display.setCursor(0,52);
display.println("Version 0.1");

display.display();
delay(2000);

display.clearDisplay();

display.setTextSize(2);
display.setTextColor(WHITE);
//display.setTextColor(BLACK, WHITE); // 'inverted' text
display.setCursor(0,0);
display.println("Connecting");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");

display.print(".");
display.display();
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

display.clearDisplay();
display.setTextSize(1); display.setTextColor(WHITE);
display.setCursor(0,0); display.println(ssid);
display.setTextSize(2); display.setTextColor(WHITE);
display.setCursor(0,18); display.println(WiFi.localIP());
//display.setCursor(0,36); display.println(WiFi.localIP());

display.display();

if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}

server.on("/", handleRoot);

server.on("/status1=1", [](){
server.send(200, "text/plain", "device1 = ON");
digitalWrite(output1, HIGH);
device1 = true;
});

server.on("/status1=0", [](){
server.send(200, "text/plain", "device1 = OFF");
digitalWrite(output1, LOW);
device1 = false;
});

server.on("/status2=1", [](){
server.send(200, "text/plain", "device2 = ON");
digitalWrite(output2, HIGH);
device2 = true;
});

server.on("/status2=0", [](){
server.send(200, "text/plain", "device2 = OFF");
digitalWrite(output2, LOW);
device2 = false;
});

server.on("/status3=1", [](){
server.send(200, "text/plain", "device3 = ON");
digitalWrite(output3, HIGH);
device3 = true;
});

server.on("/status3=0", [](){
server.send(200, "text/plain", "device3 = OFF");
digitalWrite(output3, LOW);
device3 = false;
});

server.on("/status4=1", [](){
server.send(200, "text/plain", "device4 = ON");
digitalWrite(output4, HIGH);
device4 = true;
});

server.on("/status4=0", [](){
server.send(200, "text/plain", "device4 = OFF");
digitalWrite(output4, LOW);
device4 = false;
});

server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}

void loop(void){
server.handleClient();
}

Steps:

    1. Build up the circuit as shown in circuit diagram.
    2. Download source code from download section, edit downloaded code and input your home router’s SSID and Password in the code.
      const char* ssid = "xxxxxxx"; //replace xxxxxxx with your wifi ssid
      const char* password = "xxxxxxx"; //replace xxxxxxx with your wifi password
    3. Compile and upload the source code in NodeMCU or any ESP8266 you are using. You can use Arduino IDE to upload the code.



  1. Once your uploading process is completed, power up the circuit and reset the ESP once.
  2. Now ESP will connect to your router and it will show IP address of your ESP in OLED display.
  3. Install android application in your phone and open it, application link is given bellow in download section.
  4. Input IP address shown in OLED display and port i.e 80 in application page and hit connect button.
  5. Now you can operate relay from your phone and can connect any appliances to these relays. (consider relay amps rating )

 

Note: You can not use direct 5v relay in this project, because NodeMCU control output is only 3.3v which is not enough to trigger 5v relay. That is- why we are using relay  module to work on this project.

 



Downloads:

esp8266_relay_control.ino

Android application

Circuit diagram

]]>
https://blog.etechpath.com/how-to-operate-home-appliances-wirelessly-using-esp8266-and-android-phone/feed/ 0