top of page

Search Results

143 items found for ""

  • ESP8266 DHT11 Weather Monitor with OLED and Google Gauge

    In this project, how to make a weather monitor using an ESP8266, DHT11 and OLED display. The Temperature , humidity data to UI oled display and Google chart Gauge for visualization. The Google Charts provides a perfect way to visualize data on html page. The most common way to use Google Charts is with simple JavaScript that you embed in html page. You load some Google Chart libraries, list the data to be charted, select options to customize your chart, and finally create a chart object with an id that you choose. Then, later in the web page, you create a with that id to display the Google Chart. Circuit Diagram Components Required 0.96 OLED 4wire Module - 1no Node MCU ESP8266 12E Dev Module- 1 no DHT11 - 1 no Jumper wires DHT 11/22/AM2302 Connecting DHT11/DHT22/AM2302 sensor to ESP8266 NodeMCU is fairly simple. Connect VCC pin on the sensor to the 3.3V pin on the NodeMCU and ground to ground. Also connect Data pin on the sensor to D5 pin of the ESP8266 NodeMCU. Installing the library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Download SSD1306_Library , we need to use this library for SSD1306 OLED display Download DHT Library , we need to use this library for Temperature sensor. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE arduino code Subscribe and Download code #include #include #include #include #include #include #include "user_interface.h" #include #include #include "icons.h" #include "fonts.h" #define GAUGE_REFRESH 1000 // How oftern (in milliseconds) to refresh the gauge values #include "DHT.h" #define DHTPIN 14 // Digital pin connected to the DHT sensor // Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 -- // Pin 15 can work but DHT must be disconnected during program upload. #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) DHT dht(DHTPIN, DHTTYPE); String t,f,h; //WiFi Connection configuration const char* ssid = "TP-Link_3200"; //YOUR SSID const char* password = "95001121379884265554"; //YOUR PASSWORD WiFiServer server(80); // Setup const int UPDATE_INTERVAL_SECS = 1 * 60; // Update every 1 minutes // Display Settings const int I2C_DISPLAY_ADDRESS = 0x3C; const int SDA_PIN = D2; const int SDC_PIN = D1; SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN); OLEDDisplayUi ui ( &display ); bool readyForUpdate = false; void updateData(OLEDDisplay *display) { drawProgress(display, 50, "Updating Time..."); // worldClockClient.updateTime(); drawProgress(display, 100, "Done..."); readyForUpdate = false; delay(1000); } void drawProgress(OLEDDisplay *display, int percentage, String label) { display->clear(); display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(ArialMT_Plain_10); display->drawString(64, 10, label); display->drawProgressBar(10, 28, 108, 12, percentage); display->display(); } void drawFrame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { display->clear(); display->setFont(ArialMT_Plain_24); display->setTextAlignment(TEXT_ALIGN_LEFT); float t = dht.readTemperature(); display->drawString(0, 0,"ESP8266 "); display->drawString(0, 26,"SERVER"); delay(1000); } void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { display->clear(); display->setFont(ArialMT_Plain_24); display->setTextAlignment(TEXT_ALIGN_LEFT); float t = dht.readTemperature(); display->drawString(0, 0,"Celsius"); display->drawString(0, 26, String(t)+"°C"); delay(1000); } void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { display->clear(); display->setFont(ArialMT_Plain_24); display->setTextAlignment(TEXT_ALIGN_LEFT); float f = dht.readTemperature(true); display->drawString(0, 0,"Fahrenheit"); display->drawString(0, 26, String(f)+"°F"); delay(1000); } void drawFrame4(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { display->clear(); display->setFont(ArialMT_Plain_24); display->setTextAlignment(TEXT_ALIGN_LEFT); float h = dht.readHumidity(); display->drawString(0, 0,"Humidity"); display->drawString(0, 26, String(h)+"%"); delay(1000); } // this array keeps function pointers to all frames // frames are the single views that slide from right to left FrameCallback frames[] = { drawFrame1, drawFrame2, drawFrame3, drawFrame4}; int numberOfFrames = 4; void setup() { // Initialise serial communication, set baud rate = 115200 Serial.begin(115200); dht.begin(); // initialize dispaly display.init(); display.clear(); display.display(); //display.flipScreenVertically(); display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_CENTER); display.setContrast(255); // Connect to WiFi network WiFi.begin(ssid, password); int counter = 0; // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); display.clear(); display.drawString(64, 10, "Connecting to WiFi"); display.drawXbm(46, 30, 8, 8, counter % 3 == 0 ? activeSymbol : inactiveSymbol); display.drawXbm(60, 30, 8, 8, counter % 3 == 1 ? activeSymbol : inactiveSymbol); display.drawXbm(74, 30, 8, 8, counter % 3 == 2 ? activeSymbol : inactiveSymbol); display.display(); counter++; } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); //Print IP to console Serial.print("IP address: "); Serial.println(WiFi.localIP()); delay(3); // Start the server server.begin(); Serial.println("HTTP server started"); ui.setTargetFPS(30); // You can change this to // TOP, LEFT, BOTTOM, RIGHT ui.setIndicatorPosition(BOTTOM); // Defines where the first frame is located in the bar. ui.setIndicatorDirection(LEFT_RIGHT); // You can change the transition that is used // SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN ui.setFrameAnimation(SLIDE_LEFT); // Add frames ui.setFrames(frames, numberOfFrames); // Inital UI takes care of initalising the display too. ui.init(); Serial.println(""); updateData(&display); }//End of setup void loop() { // Wait a few seconds between measurements. delay(200); dht.begin(); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true) float f = dht.readTemperature(true); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) || isnan(f)) { Serial.println(F("Failed to read from DHT sensor!")); return; } delay(100); WiFiClient client = server.available(); if (readyForUpdate && ui.getUiState()->frameState == FIXED) { updateData(&display); } int remainingTimeBudget = ui.update(); if (remainingTimeBudget > 0) { delay(remainingTimeBudget); } ///////////////////////////////////// // Read the first line of the request ///////////////////////////////////// String sRequest = client.readStringUntil('\r'); client.flush(); // get path; end of path is either space or ? // Syntax is e.g. GET /?show=1234 HTTP/1.1 String sPath="",sParam="", sCmd=""; String sGetstart="GET "; int ifirst,isecond,ithirdt; ifirst = sRequest.indexOf(sGetstart); if (ifirst>=0) { ifirst+=+sGetstart.length(); isecond = sRequest.indexOf(" ",ifirst); ithirdt = sRequest.indexOf("?",ifirst); // are there parameters? if(isecond>0) { if(ithirdt>0) { // there are parameters sPath = sRequest.substring(ifirst,ithirdt); sParam = sRequest.substring(ithirdt,isecond); } else { // NO parameters sPath = sRequest.substring(ifirst,isecond); } } } String htmlContent ; if(sPath=="/"){ htmlContent = ("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"); htmlContent += ("\n"); htmlContent += ("\n"); htmlContent += ("ESP8266, Google Gauge and OLED Display\n"); htmlContent += ("Web Server Based DHT 11 Temperature and Humidity Monitor\n"); //include Jquery and graphing API htmlContent += ("\n"); htmlContent += ("\n"); htmlContent += ("\n"); htmlContent += ("\n"); // htmlContent += ("\n"); htmlContent += ("\n"); htmlContent += ("\n"); htmlContent += ("\n"); htmlContent += ("\n"); htmlContent += ("\n"); htmlContent += ("\n"); //Send the data to the client client.print(htmlContent); }//End root else if(sPath=="/data.json"){ htmlContent = ("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nConnection: close\r\n\r\n"); htmlContent += ("{\"tempC\":\"" + String(t) + "\",\"tempF\":\"" + String(f) + "\",\"humidity\":\"" + String(h) + "\"}"); client.print(htmlContent); } //// Serial.print("temperature: "); //Serial.print(t,2); //Serial.print(" deg C, "); //Serial.print(f,2); //Serial.print(" deg F "); //Serial.print(h,2); //Serial.print(" %, "); }//End of main loop After a successful upload, open the Serial Monitor at a baud rate of 152000. Press the “EN/RST” button on the ESP8266 board and see the IP address in serial monitor. After that Open the web browser and enter the IP address path for temperature gauge display. Subscribe and Download code Demo:

  • Web Server Based Temperature Controller With EEPROM and Auto/Manual Mode

    In this tutorial, I 'll Publish how to controlling the Room heater through Relay channel board using web server over WiFi using NodeMCU, DS18B20 and OLED display. In this project, the temperature controller have Auto and Manual mode function. The manual mode is manually ON / OFF the output in the HTML page and has been implemented in the basic version of the WiFi temperature controller with the possibility of switching automatic mode. The Automatic Mode is active until the target temperature + hysteresis is reached. And you change and set the target temperature and Hysteresis in the HTML page and has been implemented in the advanced version of the WiFi temperature controller with the possibility of switching manual mode. Example: Target temperature: 31.75 °C Hysteresis: 0.25 °C Measured data: 31.49 °C Output: ON (target temperature + hysteresis) Condition: If the temperature reaches 32.01 °C, the output is Turn OFF. And output is not reactivated until the temperature reaches 31.49 °C or lower. In order to keep the set values (Temperature & Hysteresis) of the thermostat even after a power failure, they are stored in the EEPROM memory. Circuit Diagram Components Required 0.96 OLED 4wire Module - 1no Node MU ESP8266 12E Dev Module- 1 no DS18B20 with Probe Relay single channel- 1no Resistor- 4k7 ohms https://www.dofbot.com/post/nodemcu-based-ds18b20-temperature-server DS18B20 DS18B20 is a temperature sensor of Maxim. The single-chip microcomputer can communicate with DS18B20 through 1-Wire protocol and finally read the temperature. The hardware interface of the 1-Wire bus is very simple, just connect the data pin of DS18B20 to an IO port of the microcontroller. Data sheet: https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf Installing the library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Download Adafruit_SSD1306_Library , we need to use this library for SSD1306 OLED display Download Adafruit_GFX_Library , we need to use this library for Graphics To interface with the DS18B20 temperature sensor, you need to install the One Wire library . Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open. Type “onewire” in the search box and install the OneWire library by Paul Stoffregen. Download Dallas Library , we need to use this library for temperature measurement. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. arduino code Subscribe and Download code const char *ssid = "TP-Link_3200"; //your ssid const char *password = "95001121379884265554"; //your wifi password #include #include #include ESP8266WebServer server(80); #include #include #include #include #define ONE_WIRE_BUS 2 //D4 of esp8266 12E OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensorsA(&oneWire); const int Relay = 14; //D5 of esp8266 12E unsigned long kase = 0; String Heater = "OFF"; float TempVal; #include #include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); float SysMode; boolean isFloat(String tString) { String tBuf; boolean decPt = false; if (tString.charAt(0) == '+' || tString.charAt(0) == '-') tBuf = &tString[1]; else tBuf = tString; for (int x = 0; x < tBuf.length(); x++) { if (tBuf.charAt(x) == '.' || tBuf.charAt(x) == ',') { if (decPt) return false; else decPt = true; } else if (tBuf.charAt(x) < '0' || tBuf.charAt(x) > '9') return false; } return true; } void writeString(char add, float data) { EEPROM.put(add, (data * 1000)); EEPROM.commit(); } float read_String(char add) { float payload = 0; float data = EEPROM.get(add, payload); return (data / 1000); } void handleRoot() { String Page = F(""); Page += F(""); Page += F(""); Page += ""; Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F("ESP8266 Web Server Based Temperature Control With EEPROM and Auto/Manual Mode"); Page += F("Current Temperature: "); Page += String(TempVal); Page += F(" °C"); Page += F(""); if (SysMode == 0.00) { Page += F(""); Page += "Temperature Set Point °C : "; Page += F(""); Page += "Hysteresis Set Point °C : "; Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F("Manual MODE"); Page += F(""); } else if (SysMode == 1.00) { if (Heater == "ON") { Page += F("Turn OFF"); } if (Heater == "OFF") { Page += F("Turn ON"); } Page += F("Automatic MODE"); } if (Heater == "ON") { Page += F("Heater Status: ON"); } if (Heater == "OFF") { Page += F("Heater Status: OFF"); } Page += F(""); Page += F(""); server.send(200, "text/html", Page); } void handleBody() { if (server.hasArg("TFrame")) { String target_temp = server.arg("TFrame"); if (isFloat(target_temp)) { float SetTemppoint = target_temp.toFloat(); writeString(10, SetTemppoint); } else { Serial.println(F("No number was entered in the input according to the target temperature!")); Serial.println(F("Writing into EEPROM prohibited!")); } } if (server.hasArg("TFrame2")) { String hysteresis = server.arg("TFrame2"); if (isFloat(hysteresis)) { float SetHss = hysteresis.toFloat(); writeString(100, SetHss); } else { Serial.println(F("No number was entered in the input according to the hysteresis!")); Serial.println(F("Writing into EEPROM prohibited!")); } } String Page = F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F("ESP Server received data from HTML form"); Page += "Temperature Set Point: " + String(read_String(10)) + " °C"; Page += "Hysteresis Set Point: " + String(read_String(100)) + " °C"; Page += F("Loading...."); Page += F(""); Page += F(""); server.send(200, "text/html", Page); } void handleGet() { String Page = "{\n"; Page += F("\"Hysteresis\":"); Page += String(read_String(100)); Page += F(",\n"); Page += F("\"Target_Temperature\":"); Page += String(read_String(10)); Page += F(",\n"); Page += F("\"Actual_Temperature\":"); Page += String(TempVal) + "\n"; Page += F("}\n"); server.send(200, "application/json", Page); } void handleRelConPn() { Heater = "ON"; digitalWrite(Relay, LOW); String Page = F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); server.send(200, "text/html", Page); } void handleAuto() { writeString(150, 0.00); SysMode = read_String(150); String Page = F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); server.send(200, "text/html", Page); Serial.println("Auto"); } void handleManual() { writeString(150, 1.00); SysMode = read_String(150); String Page = F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); server.send(200, "text/html", Page); Serial.println("Manual Mode"); } void handleRelConPf() { Heater = "OFF"; digitalWrite(Relay, HIGH); String Page = F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); Page += F(""); server.send(200, "text/html", Page); } void setup() { Serial.begin(115200); WiFiManager wifiManager; wifiManager.autoConnect("WiFi_TERMOSTAT_AP"); EEPROM.begin(512); //Initialize EEPROM float a = read_String(10); float b = read_String(100); float c = read_String(150); if (isnan(a)) { writeString(10, 20.25); } if (isnan(b)) { writeString(100, 0.25); } if (isnan(c)) { writeString(150, 0.00); } // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } // Show initial display buffer contents on the screen -- // the library initializes this with an Adafruit splash screen. display.display(); delay(2000); // Pause for 2 seconds // Clear the buffer display.clearDisplay(); sensorsA.begin(); pinMode(Relay, OUTPUT); digitalWrite(Relay, HIGH); sensorsA.requestTemperatures(); delay(750); Serial.println(F("WiFi thermostat - Author: Martin Chlebovec")); Serial.println(""); Serial.println(F("WiFi connected.")); Serial.println(F("IP address: ")); Serial.println(WiFi.localIP()); display.setTextSize(1); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(2, 2); display.println("IP: "); display.setCursor(22,2); display.println(WiFi.localIP()); display.display(); server.on("/", handleRoot); server.on("/get_data.json", handleGet); server.on("/automat.html", handleAuto); server.on("/manual.html", handleManual); server.on("/RelConPn.html", handleRelConPn); server.on("/RelConPf.html", handleRelConPf); server.on("/action.html", HTTP_POST, handleBody); server.begin(); } void loop() { if ((millis() - kase) >= 10000 || kase == 0) { kase = millis(); TempVal = sensorsA.getTempCByIndex(0); Serial.println(); Serial.println(F("----------------------------------------------")); Serial.print(F("IP address of ESP8266 thermostat: ")); Serial.print(WiFi.localIP()); Serial.print(F(", for access via mDNS use http://")); Serial.print(WiFi.localIP()); Serial.println(F("/")); Serial.print(F("Free HEAP: ")); Serial.print(ESP.getFreeHeap()); Serial.println(F(" B")); Serial.print(F("Actual DS18B20 temperature: ")); Serial.print(String(TempVal)); Serial.println(F(" °C")); display.clearDisplay(); display.setTextSize(1); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(2, 2); display.println("IP: "); display.setCursor(22,2); display.println(WiFi.localIP()); display.display(); display.setTextSize(3); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(0, 17); display.println(String(TempVal)); display.println(" "); display.drawRect(90, 17, 5, 5, WHITE); // put degree symbol ( ° ) display.setCursor(97, 17); display.println("C"); display.display(); sensorsA.requestTemperatures(); SysMode = read_String(150); if (SysMode == 0.00) { float SetTemppoint = read_String(10); float SetHss = read_String(100); float minus_SetHss_TempVal = (-1 * SetHss); float different = SetTemppoint - TempVal; //21 - 20 Serial.println(SetHss); display.setTextSize(1); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(0, 45); display.print(SetHss); display.display(); Serial.println(SetTemppoint); display.setTextSize(1); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(70, 45); display.print(SetTemppoint); display.display(); if (different > SetHss) { Serial.println(F("Output ON")); Heater = "ON"; digitalWrite(Relay, LOW); } else if (different < minus_SetHss_TempVal) { Serial.println(F("Output OFF")); Heater = "OFF"; digitalWrite(Relay, HIGH); } else { Serial.println(F("Difference between the target and actual temperature is not above or below the hysteresis. The output status does not change.")); Serial.print(F("Actual output state: ")); Serial.println(Heater); } } else { Serial.print(F("Manual operation mode is used, output status: ")); Serial.println(Heater); } } if (digitalRead(Relay)==LOW){ display.setTextSize(1); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(0, 55); display.print("Heater ON "); display.display();} else if (digitalRead(Relay)==HIGH){ display.setTextSize(1); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(0, 55); display.print("Heater OFF"); display.display();} if (SysMode==1){ display.setTextSize(1); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(70, 55); display.print("Manual"); display.display();} else if (SysMode==0){ display.setTextSize(1); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(70, 55); display.print("Auto "); display.display();} server.handleClient(); } After a successful upload, open the Serial Monitor at a baud rate of 152000. Press the “EN/RST” button on the ESP8266 board and see the result in serial monitor. After that Open the web browser and enter the IP address path for Monitoring and controlling the temperature controller. Subscribe and Download code Demo:

  • NodeMCU World Clock

    In this tutorial, we will see how to make NodeMCU based World Clock using OLED display. Here, you don’t need Real Time Clock Module and time will be updated through wifi. we have added world’s 4 popular cities, you can add more if you want. Purchase : https://www.dofbot.com/product-page/nodemcu-based-world-clock Circuit Diagram Components Required 0.96 OLED 4wire Module - 1no Node MCU ESP8266 12E Dev Module- 1 no Oled Display This 0.96” I2C OLED Display is an OLED monochrome 128×64 dot matrix display module with I2C Interface. It is perfect when you need an ultra-small display. Comparing to LCD, OLED screens are way more competitive, which has a number of advantages such as high brightness, self-emission, high contrast ratio, slim outline, wide viewing angle, wide temperature range, and low power consumption. It is compatible with any 3.3V-5V microcontroller, such as Arduino. Pin Definition 1.GND: Power ground 2.VCC: Power positive 3.SCL: Clock wire 4.SDA: Data wire. Specifications Size: 0.96 inch Resolution: 128 x 64 Controlling Chip: SSH1106 Driving Voltage: 3.3-5V Operating Temperature: -40~70 celsius Interface Type: IIC Light Color: White Data Sheet Download Installing Library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Download SSD1306Wire.h Library , we need to use this library for SSD1306 OLED display Download JsonListener.h_Library , we need to use this library for json-streaming-parser-master Download misc Library , we need to use this library for weather After installing the required libraries, copy the following code to your Arduino IDE. arduino code #include #include #include #include #include #include #include #include #include #include "icons.h" #include "fonts.h" const char* WIFI_SSID = "TP-Link_3200"; const char* WIFI_PWD = "95001121379884265554"; // Setup const int UPDATE_INTERVAL_SECS = 10 * 60; // Update every 10 minutes // Display Settings const int I2C_DISPLAY_ADDRESS = 0x3C; const int SDA_PIN = D2; const int SDC_PIN = D1; // TimeClient settings // Initialize the oled display for address 0x3c // sda-pin=14 and sdc-pin=12 SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN); OLEDDisplayUi ui ( &display ); /*************************** * End Settings **************************/ String timeZoneIds [] = {"America/New_York", "Europe/London", "Europe/Paris", "Australia/Sydney"}; WorldClockClient worldClockClient("de", "CH", "E, dd. MMMMM yyyy", 4, timeZoneIds); // flag changed in the ticker function every 10 minutes bool readyForUpdate = false; String lastUpdate = "--"; Ticker ticker; void updateData(OLEDDisplay *display) { drawProgress(display, 50, "Updating Time..."); worldClockClient.updateTime(); drawProgress(display, 100, "Done..."); readyForUpdate = false; delay(1000); } void drawProgress(OLEDDisplay *display, int percentage, String label) { display->clear(); display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(ArialMT_Plain_10); display->drawString(64, 10, label); display->drawProgressBar(10, 28, 108, 12, percentage); display->display(); } void drawClock(OLEDDisplay *display, int x, int y, int timeZoneIndex, String city, const uint8_t* icon) { display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(ArialMT_Plain_10); display->drawString(x + 60, y + 5, city); display->setFont(Crushed_Plain_36); display->drawXbm(x, y, 60, 60, icon); display->drawString(x + 60, y + 15, worldClockClient.getHours(timeZoneIndex) + ":" + worldClockClient.getMinutes(timeZoneIndex)); } void drawFrame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { drawClock(display, x, y, 0, "New York", new_york_bits); } void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { drawClock(display, x, y, 1, "London", london_bits); } void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { drawClock(display, x, y, 2, "Paris", paris_bits); } void drawFrame4(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { drawClock(display, x, y, 3, "Sydney", sydney_bits); } void setReadyForWeatherUpdate() { Serial.println("Setting readyForUpdate to true"); readyForUpdate = true; } // this array keeps function pointers to all frames // frames are the single views that slide from right to left FrameCallback frames[] = { drawFrame1, drawFrame2, drawFrame3, drawFrame4}; int numberOfFrames = 4; void setup() { Serial.begin(115200); Serial.println(); Serial.println(); // initialize dispaly display.init(); display.clear(); display.display(); //display.flipScreenVertically(); display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_CENTER); display.setContrast(255); WiFi.begin(WIFI_SSID, WIFI_PWD); int counter = 0; while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); display.clear(); display.drawString(64, 10, "Connecting to WiFi"); display.drawXbm(46, 30, 8, 8, counter % 3 == 0 ? activeSymbol : inactiveSymbol); display.drawXbm(60, 30, 8, 8, counter % 3 == 1 ? activeSymbol : inactiveSymbol); display.drawXbm(74, 30, 8, 8, counter % 3 == 2 ? activeSymbol : inactiveSymbol); display.display(); counter++; } ui.setTargetFPS(30); // You can change this to // TOP, LEFT, BOTTOM, RIGHT ui.setIndicatorPosition(BOTTOM); // Defines where the first frame is located in the bar. ui.setIndicatorDirection(LEFT_RIGHT); // You can change the transition that is used // SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN ui.setFrameAnimation(SLIDE_LEFT); // Add frames ui.setFrames(frames, numberOfFrames); // Inital UI takes care of initalising the display too. ui.init(); Serial.println(""); updateData(&display); ticker.attach(UPDATE_INTERVAL_SECS, setReadyForWeatherUpdate); } void loop() { if (readyForUpdate && ui.getUiState()->frameState == FIXED) { updateData(&display); } int remainingTimeBudget = ui.update(); if (remainingTimeBudget > 0) { // You can do some work here // Don't do stuff if you are below your // time budget. delay(remainingTimeBudget); } } Subscribe After a successful upload, open the Serial Monitor at a baud rate of 115200. Press the “EN/RST” button on the ESP8266 board. Now it should print its IP address. Demo Subscribe

  • NodeMCU Web Server Controlled Relay with OLED

    In this tutorial, I 'll Publish how to controlling Relay channel board using web server over WiFi using NodeMCU and OLED display. In this project, web page without refresh application uses javascript ajax and On/Off Flip Switch (CSS3 ) is used with animated transitions. Circuit Diagram Components Required 0.96 OLED 4wire Module - 1no Node MCU ESP8266 12E Dev Module- 1 no 4 Channel Relay Module The four-channel relay module contains four 5V relays and the associated switching and isolating components, which makes interfacing with a microcontroller or sensor easy with minimum components and connections. The contacts on each relay are specified for 250VAC and 30VDC and 10A in each case, as marked on the body of the relays. The driver circuit for this relay module is slightly different compared to traditional relay driving circuits since there is an optional additional layer of isolation. When the jumper is shorted, the relay and the input share the same VCC, and when it is open, a separate power supply must be provided to the JD-VCC jumper to power the relay coil and optocoupler output. The inputs for this module are active low, meaning that the relay is activated when the signal on the input header is low. This is because the indicator LED and the input of the optocoupler are connected in series to the VCC pin on one end, so the other end must be connected to the ground to enable the current flow. The optocouplers used here are the PCF817, which is a common optocoupler and can also be found in through-hole packaging. Download DATASHEET Installing Library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Installing SSD1306 OLED Library – ESP8266 There are several libraries available to control the OLED display with the ESP8266. In this tutorial we’ll use two Adafruit libraries: Adafruit_SSD1306 library Download Adafruit_GFX library. Download After installing the required libraries, copy the following code to your Arduino IDE. arduino code #include #include #include #include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); /********** PLEASE CHANGE THIS *************************/ const char* ssid = "TP-Link_3200"; // your wifi name const char* password = "95001121379884265554"; // your wifi password ESP8266WebServer server(80); uint8_t RELAY1Pin = D7; uint8_t RELAY2Pin = D6; uint8_t RELAY3Pin = D5; uint8_t RELAY4Pin = D4; bool RELAY1Status = LOW; bool RELAY2Status = LOW; bool RELAY3Status = LOW; bool RELAY4Status = LOW; /***********************************/ #define bitmap_height 61 #define bitmap_width 22 static const unsigned char PROGMEM bitmap1F[] = {0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xe7, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x78, 0xce, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0x98, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0x90, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x30, 0x00, 0x78, 0x3c, 0xfc, 0x18, 0x61, 0xc8, 0x20, 0x00, 0x3b, 0x98, 0xf9, 0xc9, 0xef, 0xe0, 0x20, 0x00, 0x3b, 0x90, 0xf9, 0xe9, 0xef, 0xe0, 0x20, 0x00, 0x38, 0x3c, 0xfb, 0xe8, 0x63, 0xe0, 0x20, 0x00, 0x39, 0x7c, 0xfb, 0xe9, 0xef, 0xe0, 0x20, 0x00, 0x3b, 0x3c, 0xf9, 0xe9, 0xef, 0xe0, 0x20, 0x00, 0x7b, 0x9c, 0xfd, 0xc9, 0xef, 0xe8, 0x30, 0x00, 0x7b, 0x9c, 0xfe, 0x39, 0xef, 0xc8, 0x30, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x98, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0xcc, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0xe7, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x78, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8 }; static const unsigned char PROGMEM bitmap1N[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x38, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x18, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x98, 0x81, 0xf0, 0x40, 0x78, 0xc8, 0x0f, 0xff, 0x88, 0x01, 0x98, 0xc0, 0xcc, 0xcc, 0x1f, 0xff, 0xc8, 0x01, 0x89, 0xc0, 0x84, 0xec, 0x1f, 0xff, 0xc0, 0x01, 0x98, 0xc1, 0x86, 0xec, 0x1f, 0xff, 0xc0, 0x01, 0xf0, 0xc1, 0x86, 0xfc, 0x1f, 0xff, 0xc0, 0x01, 0xb0, 0xc1, 0x84, 0x9c, 0x1f, 0xff, 0xc0, 0x01, 0x98, 0xc0, 0x8c, 0x9c, 0x1f, 0xff, 0xc8, 0x01, 0x98, 0xc0, 0xf8, 0x9c, 0x0f, 0xff, 0xc8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x88, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x18, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x78, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf8 }; static const unsigned char PROGMEM bitmap2F[] = {0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xe7, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x78, 0xce, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0x98, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0x90, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x30, 0x00, 0x70, 0x78, 0xfe, 0x1e, 0x18, 0x48, 0x20, 0x00, 0x37, 0x33, 0x7c, 0xe6, 0xfb, 0xe0, 0x20, 0x00, 0x37, 0xbf, 0x7d, 0xf6, 0xfb, 0xe0, 0x20, 0x00, 0x37, 0x3e, 0x7d, 0xf6, 0xfb, 0xe0, 0x20, 0x00, 0x30, 0x7c, 0x7d, 0xf6, 0x18, 0x60, 0x20, 0x00, 0x36, 0x78, 0xfd, 0xf6, 0xfb, 0xe0, 0x20, 0x00, 0x77, 0x39, 0xfd, 0xf6, 0xfb, 0xe8, 0x30, 0x00, 0x77, 0x33, 0xfc, 0xe6, 0xfb, 0xc8, 0x30, 0x00, 0xf7, 0x90, 0x7e, 0x1e, 0xfb, 0xc8, 0x98, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0xcc, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0xe7, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x78, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8 }; static const unsigned char PROGMEM bitmap2N[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x38, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x18, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x98, 0x83, 0xe1, 0xc0, 0x7c, 0x66, 0x0f, 0xff, 0x88, 0x03, 0x33, 0x60, 0xc6, 0x66, 0x1f, 0xff, 0xc8, 0x03, 0x10, 0x20, 0xc6, 0x76, 0x1f, 0xff, 0xc0, 0x03, 0x30, 0x61, 0x83, 0x76, 0x1f, 0xff, 0xc0, 0x03, 0xe0, 0xe1, 0x83, 0x7e, 0x1f, 0xff, 0xc0, 0x03, 0x61, 0xc1, 0x83, 0x6e, 0x1f, 0xff, 0xc0, 0x03, 0x33, 0x80, 0xc6, 0x6e, 0x1f, 0xff, 0xc8, 0x03, 0x33, 0x00, 0xc6, 0x66, 0x0f, 0xff, 0xc8, 0x83, 0x1f, 0xe0, 0x7c, 0x66, 0x0f, 0xff, 0x88, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x18, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x78, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf8 }; static const unsigned char PROGMEM bitmap3F[] = {0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xe7, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x78, 0xce, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0x98, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0x90, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x30, 0x00, 0x70, 0x78, 0xfe, 0x1e, 0x18, 0x48, 0x20, 0x00, 0x37, 0x32, 0x7c, 0xe6, 0xfb, 0xe0, 0x20, 0x00, 0x37, 0xbe, 0x7d, 0xf6, 0xfb, 0xe0, 0x20, 0x00, 0x37, 0x3c, 0xfd, 0xf6, 0xfb, 0xe0, 0x20, 0x00, 0x30, 0x7e, 0x7d, 0xf6, 0x18, 0x60, 0x20, 0x00, 0x36, 0x7f, 0x7d, 0xf6, 0xfb, 0xe0, 0x20, 0x00, 0x77, 0x3f, 0x7d, 0xf6, 0xfb, 0xe8, 0x30, 0x00, 0x77, 0x36, 0x7c, 0xe6, 0xfb, 0xc8, 0x30, 0x00, 0xf7, 0x98, 0xfe, 0x1e, 0xfb, 0xc8, 0x98, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0xcc, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0xe7, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x78, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8 }; static const unsigned char PROGMEM bitmap3N[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x38, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x18, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x98, 0x83, 0xe1, 0xc0, 0x7c, 0x66, 0x0f, 0xff, 0x88, 0x03, 0x33, 0x60, 0xc6, 0x66, 0x1f, 0xff, 0xc8, 0x03, 0x10, 0x60, 0xc6, 0x76, 0x1f, 0xff, 0xc0, 0x03, 0x30, 0xc1, 0x83, 0x76, 0x1f, 0xff, 0xc0, 0x03, 0xe0, 0x61, 0x83, 0x7e, 0x1f, 0xff, 0xc0, 0x03, 0x60, 0x21, 0x83, 0x6e, 0x1f, 0xff, 0xc0, 0x03, 0x30, 0x20, 0xc6, 0x6e, 0x1f, 0xff, 0xc8, 0x03, 0x33, 0x60, 0xc6, 0x66, 0x0f, 0xff, 0xc8, 0x83, 0x19, 0xc0, 0x7c, 0x66, 0x0f, 0xff, 0x88, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x18, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x78, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf8 }; static const unsigned char PROGMEM bitmap4F[] = {0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xe7, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x78, 0xce, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0x98, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0x90, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x30, 0x00, 0x70, 0x7e, 0xfe, 0x1e, 0x18, 0x48, 0x20, 0x00, 0x37, 0x3c, 0xfc, 0xe6, 0xfb, 0xe0, 0x20, 0x00, 0x37, 0xbc, 0xfd, 0xf6, 0xfb, 0xe0, 0x20, 0x00, 0x37, 0x38, 0xfd, 0xf6, 0xfb, 0xe0, 0x20, 0x00, 0x30, 0x72, 0xfd, 0xf6, 0x18, 0x60, 0x20, 0x00, 0x36, 0x76, 0xfd, 0xf6, 0xfb, 0xe0, 0x20, 0x00, 0x77, 0x20, 0x3d, 0xf6, 0xfb, 0xe8, 0x30, 0x00, 0x77, 0x3e, 0xfc, 0xe6, 0xfb, 0xc8, 0x30, 0x00, 0xf7, 0x9e, 0xfe, 0x1e, 0xfb, 0xc8, 0x98, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0xcc, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0xe7, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x78, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8 }; static const unsigned char PROGMEM bitmap4N[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x38, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x18, 0x83, 0xe0, 0x60, 0x7c, 0x66, 0x07, 0xff, 0x98, 0x83, 0x30, 0xe0, 0xc6, 0x66, 0x0f, 0xff, 0x88, 0x03, 0x11, 0xe0, 0xc6, 0x76, 0x1f, 0xff, 0xc8, 0x03, 0x31, 0xe1, 0x83, 0x76, 0x1f, 0xff, 0xc0, 0x03, 0xe3, 0x61, 0x83, 0x7e, 0x1f, 0xff, 0xc0, 0x03, 0x66, 0x61, 0x83, 0x6e, 0x1f, 0xff, 0xc0, 0x03, 0x37, 0xf0, 0xc6, 0x6e, 0x1f, 0xff, 0xc0, 0x03, 0x30, 0x60, 0xc6, 0x66, 0x1f, 0xff, 0xc8, 0x03, 0x18, 0x60, 0x7c, 0x66, 0x0f, 0xff, 0xc8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x88, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x18, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x78, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf8 }; /************************************************/ void setup() { Serial.begin(115200); pinMode(RELAY1Pin, OUTPUT); pinMode(RELAY2Pin, OUTPUT); pinMode(RELAY3Pin, OUTPUT); pinMode(RELAY4Pin, OUTPUT); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 Serial.println(F("SSD1306 allocation failed")); for (;;); // Don't proceed, loop forever } // Clear the buffer display.clearDisplay(); // Invert and restore display, pausing in-between display.invertDisplay(true); Serial.println("Connecting to "); Serial.println(ssid); //connect to your local wi-fi network WiFi.begin(ssid, password); //check wi-fi is connected to wi-fi network while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); server.on("/", handleRoot); server.on("/toggleLED1", updateRELAY1); server.on("/toggleLED2", updateRELAY2); server.on("/toggleLED3", updateRELAY3); server.on("/toggleLED4", updateRELAY4); server.onNotFound(handleNotFound); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); display.clearDisplay(); display.invertDisplay(true); display.setTextSize(1); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(2, 2); display.println(WiFi.localIP()); display.display(); // Show initial text if ((digitalRead(RELAY1Pin)) == 0) { display.drawBitmap(2, 18, bitmap1N, bitmap_height, bitmap_width, WHITE); display.display(); } if ((digitalRead(RELAY1Pin)) == 1) { display.drawBitmap(2, 18, bitmap1F, bitmap_height, bitmap_width, WHITE); display.display(); } if ((digitalRead(RELAY2Pin)) == 0) { display.drawBitmap(63, 18, bitmap2N, bitmap_height, bitmap_width, WHITE); display.display(); } if ((digitalRead(RELAY2Pin)) == 1) { display.drawBitmap(63, 18, bitmap2F, bitmap_height, bitmap_width, WHITE); display.display(); } if ((digitalRead(RELAY3Pin)) == 0) { display.drawBitmap(2, 40, bitmap3N, bitmap_height, bitmap_width, WHITE); display.display(); } if ((digitalRead(RELAY3Pin)) == 1) { display.clearDisplay(); display.drawBitmap(2, 40, bitmap3F, bitmap_height, bitmap_width, WHITE); display.display(); } if ((digitalRead(RELAY4Pin)) == 0) { display.drawBitmap(63, 40, bitmap4N, bitmap_height, bitmap_width, WHITE); display.display(); } if ((digitalRead(RELAY4Pin)) == 1) { display.drawBitmap(63, 40, bitmap4F, bitmap_height, bitmap_width, WHITE); display.display(); } delay(1000); } void handleRoot() { server.send(200, "text/html", prepareHTML()); } void updateRELAY1() { String LED1StatusParam = server.arg("LED1Status"); if (LED1StatusParam == "OFF") RELAY1Status = HIGH; else RELAY1Status = LOW; digitalWrite(RELAY1Pin, RELAY1Status); server.send(200, "text/plain", "Success!"); } void updateRELAY2() { String LED2StatusParam = server.arg("LED2Status"); if (LED2StatusParam == "OFF") RELAY2Status = HIGH; else RELAY2Status = LOW; digitalWrite(RELAY2Pin, RELAY2Status); server.send(200, "text/plain", "Success!"); } void updateRELAY3() { String LED3StatusParam = server.arg("LED3Status"); if (LED3StatusParam == "OFF") RELAY3Status = HIGH; else RELAY3Status = LOW; digitalWrite(RELAY3Pin, RELAY3Status); server.send(200, "text/plain", "Success!"); } void updateRELAY4() { String LED4StatusParam = server.arg("LED4Status"); if (LED4StatusParam == "OFF") RELAY4Status = HIGH; else RELAY4Status = LOW; digitalWrite(RELAY4Pin, RELAY4Status); server.send(200, "text/plain", "Success!"); } void handleNotFound() { server.send(404, "text/plain", "Not found"); } String prepareHTML() { // BuildMyString.com generated code. Please enjoy your string responsibly. String html = "\n" "\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " NodeMCU ESP8266 Web Server Relay Control with OLED Display\n" " \n" " \n" "\n" " \n" " \n" " WIFI Control Relay Panel\n" " \n" " \n" " RELAY1\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " RELAY2\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " RELAY3\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " RELAY4\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "\n"; return html; } Subscribe and Download code After a successful upload, open the Serial Monitor at a baud rate of 115200. Press the “EN/RST” button on the ESP8266 board. Now it should print its IP address. Now open webpage and it's address shown on OLED display. Demo Subscribe and Download code

  • Internet Weather Forecast

    Here to learn how to make an IOT based internet weather station with OLED. The ESP8266 can access the internet and gets weather data from www.openweathermap.org that provide Free/Paid weather information for many cities over the world. In this project to show how to get weather data from the internet and print it on OLED display. Circuit Diagram Components Required 0.96 OLED 4wire Module - 1no Node MCU ESP8266 12E Dev Module- 1 no Refer Weather station on before: https://www.dofbot.com/post/internet-weather-station Open weather map Internet weather station To get weather data, first we’ve to sign up for a free account in order to get an API key which is important in this project. Hourly forecast is available for 4days Forecast weather data for 96 timestamps JSON and XML formats Included in the Developer, Professional and Enterprise subscription plans Once you sign in to your account (of course after the free registration), you’ll be directed to member area, go to API keys and you’ll find your API key as shown in the following image: Replace CITY by with the city you want weather data for, and YOUR_API_KEY with your API key which is shown above and replace API key in the arduino code. For example the weather in Chennai, URL and API key. URL like https://openweathermap.org/city/1264527 String OPEN_WEATHER_MAP_LOCATION_ID = "1264527"; // for chennai Pick a language code from this list i below. // Arabic - ar, Bulgarian - bg, Catalan - ca, Czech - cz, German - de, Greek - el, // English - en, Persian (Farsi) - fa, Finnish - fi, French - fr, Galician - gl, // Croatian - hr, Hungarian - hu, Italian - it, Japanese - ja, Korean - kr, // Latvian - la, Lithuanian - lt, Macedonian - mk, Dutch - nl, Polish - pl, // Portuguese - pt, Romanian - ro, Russian - ru, Swedish - se, Slovak - sk, // Slovenian - sl, Spanish - es, Turkish - tr, Ukrainian - ua, Vietnamese - vi, // Chinese Simplified - zh_cn, Chinese Traditional - zh_tw. String OPEN_WEATHER_MAP_LANGUAGE = "en"; Hourly forecast is available for 4days const uint8_t MAX_FORECASTS = 4; Installing Library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Download SSD1306Wire.h Library , we need to use this library for SSD1306 OLED display Download JsonListener.h_Library , we need to use this library for json-streaming-parser-master Download misc Library , we need to use this library for weather After installing the required libraries, copy the following code to your Arduino IDE. arduino code Subscribe and Download code #include #include #include #include // time #include // time() ctime() #include // struct timeval #include // settimeofday_cb() #include "SSD1306Wire.h" #include "OLEDDisplayUi.h" #include "Wire.h" #include "OpenWeatherMapCurrent.h" #include "OpenWeatherMapForecast.h" #include "WeatherStationFonts.h" #include "WeatherStationImages.h" #include #include #include WiFiClient client; // WIFI const char* WIFI_SSID = "TP-Link_3200";// your SSID const char* WIFI_PWD = "95001121379884265554";//your wifi password #define TZ 5 // (utc+) TZ in hours India chennai time setting// your area #define DST_MN 30 // use 60mn for summer time in some countries'' // Setup const int UPDATE_INTERVAL_SECS = 20 * 60; // Update every 20 minutes // Display Settings const int I2C_DISPLAY_ADDRESS = 0x3c; #if defined(ESP8266) const int SDA_PIN = 5; const int SDC_PIN = 4; #else const int SDA_PIN = 5; //D3; const int SDC_PIN = 4; //D4; #endif // OpenWeatherMap Settings // Sign up here to get an API key: // https://docs.thingpulse.com/how-tos/openweathermap-key/ String OPEN_WEATHER_MAP_APP_ID = "add82e4e24d449f3a522f06621a3aaeb"; String OPEN_WEATHER_MAP_LOCATION_ID = "1264527"; // for chennai // Pick a language code from this list: // Arabic - ar, Bulgarian - bg, Catalan - ca, Czech - cz, German - de, Greek - el, // English - en, Persian (Farsi) - fa, Finnish - fi, French - fr, Galician - gl, // Croatian - hr, Hungarian - hu, Italian - it, Japanese - ja, Korean - kr, // Latvian - la, Lithuanian - lt, Macedonian - mk, Dutch - nl, Polish - pl, // Portuguese - pt, Romanian - ro, Russian - ru, Swedish - se, Slovak - sk, // Slovenian - sl, Spanish - es, Turkish - tr, Ukrainian - ua, Vietnamese - vi, // Chinese Simplified - zh_cn, Chinese Traditional - zh_tw. String OPEN_WEATHER_MAP_LANGUAGE = "en"; const uint8_t MAX_FORECASTS = 4; const boolean IS_METRIC = true; // Adjust according to your language const String WDAY_NAMES[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; const String MONTH_NAMES[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; // Initialize the oled display for address 0x3c // sda-pin=14 and sdc-pin=12 SSD1306Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN); OLEDDisplayUi ui( &display ); OpenWeatherMapCurrentData currentWeather; OpenWeatherMapCurrent currentWeatherClient; OpenWeatherMapForecastData forecasts[MAX_FORECASTS]; OpenWeatherMapForecast forecastClient; #define TZ_MN ((TZ)*60) #define TZ_SEC ((TZ)*3600) #define DST_SEC ((DST_MN)*60) time_t now; // flag changed in the ticker function every 10 minutes bool readyForWeatherUpdate = false; String lastUpdate = "--"; long timeSinceLastWUpdate = 0; //declaring prototypes void drawProgress(OLEDDisplay *display, int percentage, String label); void updateData(OLEDDisplay *display); void drawDateTime(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y); void drawCurrentWeather(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y); void drawForecast(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y); void drawForecastDetails(OLEDDisplay *display, int x, int y, int dayIndex); void drawHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state); void setReadyForWeatherUpdate(); // Add frames // this array keeps function pointers to all frames // frames are the single views that slide from right to left FrameCallback frames[] = { drawDateTime, drawCurrentWeather, drawForecast }; int numberOfFrames = 3; OverlayCallback overlays[] = { drawHeaderOverlay }; int numberOfOverlays = 1; void setup() { Serial.begin(115200); delay(1000); Serial.println("connected?... :)"); delay(1000); Serial.println(); Serial.println(); // initialize display display.init(); display.clear(); display.display(); //display.flipScreenVertically(); display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_CENTER); display.setContrast(255); WiFi.begin(WIFI_SSID, WIFI_PWD); int counter = 0; while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); display.clear(); display.drawString(64, 10, "Connecting to WiFi"); display.drawXbm(46, 30, 8, 8, counter % 3 == 0 ? activeSymbole : inactiveSymbole); display.drawXbm(60, 30, 8, 8, counter % 3 == 1 ? activeSymbole : inactiveSymbole); display.drawXbm(74, 30, 8, 8, counter % 3 == 2 ? activeSymbole : inactiveSymbole); display.display(); counter++; } // Get time from network time service configTime(TZ_SEC, DST_SEC, "pool.ntp.org"); ui.setTargetFPS(30); ui.setActiveSymbol(activeSymbole); ui.setInactiveSymbol(inactiveSymbole); // You can change this to // TOP, LEFT, BOTTOM, RIGHT ui.setIndicatorPosition(BOTTOM); // Defines where the first frame is located in the bar. ui.setIndicatorDirection(LEFT_RIGHT); // You can change the transition that is used // SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN ui.setFrameAnimation(SLIDE_LEFT); ui.setFrames(frames, numberOfFrames); ui.setOverlays(overlays, numberOfOverlays); // Inital UI takes care of initalising the display too. ui.init(); Serial.println(""); updateData(&display); } void loop() { if (millis() - timeSinceLastWUpdate > (1000L*UPDATE_INTERVAL_SECS)) { setReadyForWeatherUpdate(); timeSinceLastWUpdate = millis(); } if (readyForWeatherUpdate && ui.getUiState()->frameState == FIXED) { updateData(&display); } int remainingTimeBudget = ui.update(); if (remainingTimeBudget > 0) { // You can do some work here // Don't do stuff if you are below your // time budget. delay(remainingTimeBudget); } } void drawProgress(OLEDDisplay *display, int percentage, String label) { display->clear(); display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(ArialMT_Plain_10); display->drawString(64, 10, label); display->drawProgressBar(2, 28, 124, 10, percentage); display->display(); } void updateData(OLEDDisplay *display) { drawProgress(display, 10, "Updating time..."); drawProgress(display, 30, "Updating weather..."); currentWeatherClient.setMetric(IS_METRIC); currentWeatherClient.setLanguage(OPEN_WEATHER_MAP_LANGUAGE); currentWeatherClient.updateCurrentById(&currentWeather, OPEN_WEATHER_MAP_APP_ID, OPEN_WEATHER_MAP_LOCATION_ID); drawProgress(display, 50, "Updating forecasts..."); forecastClient.setMetric(IS_METRIC); forecastClient.setLanguage(OPEN_WEATHER_MAP_LANGUAGE); uint8_t allowedHours[] = {12}; forecastClient.setAllowedHours(allowedHours, sizeof(allowedHours)); forecastClient.updateForecastsById(forecasts, OPEN_WEATHER_MAP_APP_ID, OPEN_WEATHER_MAP_LOCATION_ID, MAX_FORECASTS); readyForWeatherUpdate = false; drawProgress(display, 100, "Done..."); delay(1000); } void drawDateTime(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { now = time(nullptr); struct tm* timeInfo; timeInfo = localtime(&now); char buff[16]; display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(ArialMT_Plain_10); String date = WDAY_NAMES[timeInfo->tm_wday]; sprintf_P(buff, PSTR("%s, %02d/%02d/%04d"), WDAY_NAMES[timeInfo->tm_wday].c_str(), timeInfo->tm_mday, timeInfo->tm_mon+1, timeInfo->tm_year + 1900); display->drawString(64 + x, 5 + y, String(buff)); display->setFont(ArialMT_Plain_24); sprintf_P(buff, PSTR("%02d:%02d:%02d"), timeInfo->tm_hour, timeInfo->tm_min, timeInfo->tm_sec); display->drawString(64 + x, 15 + y, String(buff)); display->setTextAlignment(TEXT_ALIGN_LEFT); } void drawCurrentWeather(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { display->setFont(ArialMT_Plain_10); display->setTextAlignment(TEXT_ALIGN_CENTER); display->drawString(64 + x, 38 + y, currentWeather.description); display->setFont(ArialMT_Plain_24); display->setTextAlignment(TEXT_ALIGN_LEFT); String temp = String(currentWeather.temp, 1) + (IS_METRIC ? "°C" : "°F"); display->drawString(60 + x, 5 + y, temp); display->setFont(Meteocons_Plain_36); display->setTextAlignment(TEXT_ALIGN_CENTER); display->drawString(32 + x, 0 + y, currentWeather.iconMeteoCon); } void drawForecast(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { drawForecastDetails(display, x, y, 0); drawForecastDetails(display, x + 44, y, 1); drawForecastDetails(display, x + 88, y, 2); } void drawForecastDetails(OLEDDisplay *display, int x, int y, int dayIndex) { time_t observationTimestamp = forecasts[dayIndex].observationTime; struct tm* timeInfo; timeInfo = localtime(&observationTimestamp); display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(ArialMT_Plain_10); display->drawString(x + 20, y, WDAY_NAMES[timeInfo->tm_wday]); display->setFont(Meteocons_Plain_21); display->drawString(x + 20, y + 12, forecasts[dayIndex].iconMeteoCon); String temp = String(forecasts[dayIndex].temp, 0) + (IS_METRIC ? "°C" : "°F"); display->setFont(ArialMT_Plain_10); display->drawString(x + 20, y + 34, temp); display->setTextAlignment(TEXT_ALIGN_LEFT); } void drawHeaderOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) { now = time(nullptr); struct tm* timeInfo; timeInfo = localtime(&now); char buff[14]; sprintf_P(buff, PSTR("%02d:%02d"), timeInfo->tm_hour, timeInfo->tm_min); display->setColor(WHITE); display->setFont(ArialMT_Plain_10); display->setTextAlignment(TEXT_ALIGN_LEFT); display->drawString(0, 54, String(buff)); display->setTextAlignment(TEXT_ALIGN_RIGHT); String temp = String(currentWeather.temp, 1) + (IS_METRIC ? "°C" : "°F"); display->drawString(128, 54, temp); display->drawHorizontalLine(0, 52, 128); } void setReadyForWeatherUpdate() { Serial.println("Setting readyForUpdate to true"); readyForWeatherUpdate = true; } After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the ESP8266 board. Now it should print its weather data. Demo Subscribe

  • Internet Weather Station

    Here to learn how to make an IOT based internet weather station with OLED. The ESP8266 can access the internet and gets weather data from www.openweathermap.org that provide Free/Paid weather information for many cities over the world. In this project to show how to get weather data from the internet and print it on Arduino IDE serial monitor and OLED display. Circuit Diagram Components Required 0.96 OLED 4wire Module - 1no Node MCU ESP8266 12E Dev Module- 1 no Open weather map Internet weather station To get weather data, first we’ve to sign up for a free account in order to get an API key which is important in this project. Feature Access current weather data for any location including over 200,000 cities Current weather is frequently updated based on global models and data from more than 40,000 weather stations Data is available in JSON, XML, or HTML format Available for Free and all other paid accounts Once you sign in to your account (of course after the free registration), you’ll be directed to member area, go to API keys and you’ll find your API key as shown in the following image: Replace CITY by with the city you want weather data for, COUNTRY_CODE with the country code for that city (for example uk for the United Kingdom, us for the USA …) and YOUR_API_KEY with your API key which is shown above and replace API key in the arduino code. For example the weather in Chennai, India URL and API key. String Location = "Chennai,India"; // your city,country String API_Key = "xxxxxxxxxxxxxxxxxxxxx";//your api (openweather) As mentioned above the openweathermap.org website provides weather data in JSON, XML, or HTML format. In this project we’ll use the JSON format which can be parsed using an Arduino library called ArduinoJSON. For more detail with JSON format: ArduinoJson Assistant With a built-in library named: ESP8266HTTPClient we can read http pages, accessing a page is simple with this library, just by putting its URL as shown below where I placed the URL of Chennai city weather: http.begin("http://api.openweathermap.org/data/2.5/weather?q=" + Location + "&APPID=" + API_Key); // !! After that we’ve to read and save the whole JSON page as a string: String payload = http.getString(); //Get the request response payload And finally the ArduinoJSON library does its job and decodes the JSON string: JsonObject& root = jsonBuffer.parseObject(payload); The openweathermap.org website provides temperature in °K (degree Kelvin) and to convert the °K into °C (degree Celsius) we’ve to substruct 273.15 from it. For that I used the following line: floattemp=(float)(root["main"]["temp"])-273.15;// get temperature Also, it gives the pressure in hPa (Hectopascal) with 1 hPa = 100 Pascal = 1/1000 bar: float pressure = (float)(root["main"]["pressure"]) / 1000; // get pressure Humidity is in %, wind speed in m/s (meters per second) and wind degree in degrees (°). Installing Library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Download Adafruit_SSD1306_Library , we need to use this library for SSD1306 OLED display Download Adafruit_GFX_Library , we need to use this library for Graphics Download ArduinoJson Library , we need to use this library for JSON decoding After installing the required libraries, copy the following code to your Arduino IDE. arduino code Subscribe and Download code #include #include #include // http web access library #include // JSON decoding library // Libraries for SSD1306 OLED display #include // include wire library (for I2C devices such as the SSD1306 display) #include // include Adafruit graphics library #include // include Adafruit SSD1306 OLED display driver #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 // define SSD1306 OLED reset at ESP8266 GPIO5 (NodeMCU D1) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D or 0x3C for 128x64 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // set Wi-Fi SSID and password const char *ssid = "TP-Link_3200"; //your SSID const char *password = "95001121379884265554";//your password // set location and API key String Location = "Chennai,India"; // your city,country String API_Key = "add82e4e24d449f3a522f06621a3aaeb";//your api (openweather) void setup(void) { Serial.begin(9600); delay(1000); // Wire.begin(4, 0); // set I2C pins [SDA = GPIO4 (D2), SCL = GPIO0 (D3)], default clock is 100kHz // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } // Wire.setClock(400000L); // set I2C clock to 400kHz display.clearDisplay(); // clear the display buffer display.setTextColor(WHITE, BLACK); display.setTextSize(1); display.setCursor(0, 0); display.println(" Internet Weather"); display.print(" Station - Chennai"); display.display(); WiFi.begin(ssid, password); Serial.print("Connecting."); display.setCursor(0, 24); display.println("Connecting..."); display.display(); while ( WiFi.status() != WL_CONNECTED ) { delay(500); Serial.print("."); } Serial.println("connected"); display.print("connected"); display.display(); delay(1000); } void loop() { if (WiFi.status() == WL_CONNECTED) //Check WiFi connection status { HTTPClient http; //Declare an object of class HTTPClient // specify request destination http.begin("http://api.openweathermap.org/data/2.5/weather?q=" + Location + "&APPID=" + API_Key); // !! int httpCode = http.GET(); // send the request if (httpCode > 0) // check the returning code { String payload = http.getString(); //Get the request response payload DynamicJsonBuffer jsonBuffer(512); // Parse JSON object JsonObject& root = jsonBuffer.parseObject(payload); if (!root.success()) { Serial.println(F("Parsing failed!")); return; } float temp = (float)(root["main"]["temp"]) - 273.15; // get temperature in °C int humidity = root["main"]["humidity"]; // get humidity in % float pressure = (float)(root["main"]["pressure"]) / 1000; // get pressure in bar float wind_speed = root["wind"]["speed"]; // get wind speed in m/s int wind_degree = root["wind"]["deg"]; // get wind degree in ° // print data Serial.printf("Temperature = %.2f°C\r\n", temp); Serial.printf("Humidity = %d %%\r\n", humidity); Serial.printf("Pressure = %.3f bar\r\n", pressure); Serial.printf("Wind speed = %.1f m/s\r\n", wind_speed); Serial.printf("Wind degree = %d°\r\n\r\n", wind_degree); display.setCursor(0, 24); display.printf("Temperature: %5.2f C\r\n", temp); display.printf("Humidity : %d %%\r\n", humidity); display.printf("Pressure : %.3fbar\r\n", pressure); display.printf("Wind speed : %.1f m/s\r\n", wind_speed); display.printf("Wind degree: %d", wind_degree); display.drawRect(109, 24, 3, 3, WHITE); // put degree symbol ( ° ) display.drawRect(97, 56, 3, 3, WHITE); display.display(); } http.end(); //Close connection } delay(60000); // wait 1 minute } // End of code. Subscribe and Download code After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the ESP8266 board. Now it should print its weather data. Demo Subscribe and Download code

  • RSSI Monitor with OLED and real time chart

    Here to learn how to make an IOT based WiFi signal strength monitor with OLED and highcharts to create reliable and secure data visualizations and on build java script. Nowadays for most of our daily tasks we often rely on WiFi router to connect to the internet be it home or workplace. If WiFi router is placed far from us, we will face connectivity issues due to weak signal strength. As a solution to this I have designed a WiFi strength indicator that can measure WiFi signal strength and display that to us in real time. Circuit Diagram Components Required 0.96 OLED 4wire Module - 1no Node MCU ESP8266 12E Dev Module- 1 no WiFi RSSI To get the signal strength data we will use WiFi function. In this code you need to change only the SSID and PASSWORD of your router and hit upload. Once you upload the code to ESP8266, open up the serial monitor and you will see the signal strength in dBm. highcharts The Highcharts library comes with all the tools you need to create reliable and secure data visualizations. Built on JavaScript and TypeScript, all our charting libraries work with any back-end database or server stack. Installing Library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. you need to Download and install the ESPAsyncWebServer library. Download and install the ESPAsyncTCP library. Download and install the SSD1306 library. After installing the required libraries, copy the following code to your Arduino IDE. Finally, to build the web server we need two different files. One is The Arduino sketch and the other is an HTML file. So, the HTML file should be saved inside a folder called data. It resides inside the Arduino sketch folder, as shown below: Creating the HTML File Create an index.html file with the following content. Subscribe and Download code The index.html file will contain web pages that will be displayed by the server along with JavaScript that will process the formation of graphics. While all server programs and sensor readings are in the .ino file. The code explains that a new Highcharts object was formed to be rendered to the tag with the chart-distance id in the HTML code. Then, the X-axis is defined as the time of reading the data, and the Y-axis is the value of the reading which is the distance in centimeters (cm). Then, the set Interval function will send data from the server every 0.5 seconds by accessing the “/ Decibelmwatt”endpoint provided by the server and sending the data to the chart object earlier. arduino code #include #include #include #include #include #include #include "SSD1306.h" //display(Address of Display, SDA_PIN, SCL_PIN) SSD1306 display(0x3C, D2, D1); // Enter the WiFi credentials //char wifissid[] = "TP-Link_3200"; //char wifipass[] = "95001121379884265554"; // The following values are from https://www.intuitibits.com/2016/03/23/dbm-to-percent-conversion/ int signal_dBM[] = { -100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69, -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}; int signal_percent[] = {0, 0, 0, 0, 0, 0, 4, 6, 8, 11, 13, 15, 17, 19, 21, 23, 26, 28, 30, 32, 34, 35, 37, 39, 41, 43, 45, 46, 48, 50, 52, 53, 55, 56, 58, 59, 61, 62, 64, 65, 67, 68, 69, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 90, 91, 92, 93, 93, 94, 95, 95, 96, 96, 97, 97, 98, 98, 99, 99, 99, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100}; int strength = 0; int percentage = 0; // Replace with your network credentials const char* ssid = "TP-Link_3200"; // your SSID const char* password = "95001121379884265554"; // Your Wifi password // Create AsyncWebServer object on port 80 AsyncWebServer server(80); String getDecibelmwatt() { if (WiFi.status() != WL_CONNECTED) { delay(1000); } // Get signal strength if ESP is connected to WiFi else if (WiFi.status() == WL_CONNECTED) { // Get the signal percentage value for (int x = 0; x < 100; x = x + 1) { if (signal_dBM[x] == strength) { // Print the received signal strength in percentage percentage = signal_percent[x]; return String(strength); // return String(percentage); break; } } delay(1000); } } void setup () { // Initialize display display.init(); // Choose to flip the screen depending upon the display orientation display.flipScreenVertically(); // Font for the text display.setFont(ArialMT_Plain_10); // Setting the text allignment to Center display.setTextAlignment(TEXT_ALIGN_CENTER); display.clear(); // Serial port for debugging purposes Serial.begin (115200); if (! SPIFFS.begin ()) { Serial.println ("An Error has occurred while mounting SPIFFS"); return; } // Connect to Wi-Fi WiFi.begin(ssid, password); display.drawString(64, 15, "Connecting to WiFi..."); display.display(); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi.."); } // Print connection information display.clear(); display.drawString(64, 15, "Connected to " + String(ssid)); display.display(); Serial.print("\nConnected to: "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); Serial.println(""); // Print ESP32 Local IP Address Serial.println(WiFi.localIP()); // Route for web page server.on ("/", HTTP_GET, [] (AsyncWebServerRequest * request) { request-> send (SPIFFS, "/index.html"); }); server.on ("/Decibelmwatt", HTTP_GET, [] (AsyncWebServerRequest * request) { request-> send_P (200, "text / plain", getDecibelmwatt(). c_str ()); }); // start server server.begin (); } void loop() { // While checking for signal strength, check if ESP got disconnected { if (WiFi.status() != WL_CONNECTED) { display.clear(); display.drawString(64, 15, "Connection lost"); display.display(); delay(1000); } // Get signal strength if ESP is connected to WiFi else if (WiFi.status() == WL_CONNECTED) { display.clear(); Serial.println(" "); Serial.print("WiFi Signal Strength - "); // Print the received signal strength in dBm Serial.print("RSSI: "); strength = WiFi.RSSI(); Serial.print(strength); Serial.print("dBm"); Serial.print(" "); // Get the signal percentage value for (int x = 0; x < 100; x = x + 1) { if (signal_dBM[x] == strength) { // Print the received signal strength in percentage Serial.print("Percentage: "); percentage = signal_percent[x]; Serial.print(percentage); Serial.println("%"); break; } } drawProgressBar(); display.display(); delay(1000); } } } // Using a progress bar for visual strength indication void drawProgressBar() { display.drawProgressBar(10, 32, 100, 10, percentage); display.drawString(64, 0, "WiFi Signal Strength"); display.drawString(64, 15, String(strength) + "dBm" + " | " + String(percentage) + "%"); if (percentage == 0) { display.drawString(64, 45, "No Signal"); } else if (percentage == 100) { display.drawString(64, 45, "Maximum Signal"); } } Subscribe and Download code Then, upload the code to your NodeMCU board. Make sure you have selected the right board and COM port. Also, make sure you’ve inserted your WiFi Credentials in the code. After a successful upload, open the Serial Monitor at a baud rate of 115200. Press the “EN/RST” button on the ESP8266 board. Now it should print its IP address Now open IP address in the Web page and see the result. Demo Subscribe and Download code

  • APDS-9960 Gesture, Proximity, RGB color sensor module interface with Voice

    In this tutorial we will learn How to Use APDS9960 Gesture Sensor with Arduino nano and to display gesture hand directions, Proximity value and RGB color range on the LCD Display. In addition to that Voice announcement using DFPlayer mini for Gesture direction. Proximity sensing range from 0 to 255. Example: 0 - Very close 255 - Far RGB color sensing range 0 to 4097 as per Arduino APDS 9960 library. Circuit diagram Components Required Arduino Nano - 1 no APDS-9960 Gesture- 1no DFPlayer Mini - 1 no Memory card 16gb- 1 no Resistor 1k - 1 no APDS-9960 The APDS-9960 is a multipurpose sensor that can be used for Ambient Light, RGB Sensing, Proximity Sensing, and Gesture Detection. It has been used in Samsung’s Galaxy S5 earlier and is used in many mobile phones as a proximity sensor. It is also used in gesture robotics because of its advanced gesture detection technique enabling it to detect the gesture very accurately and with a very high speed. Pin Number Pin Name Description 1 VL Optional power to the IR LED if the PS jumper is not connected. Can be 3.0V to 4.5V. 2 GND Connected to the ground of the circuit used. 3 VCC Power supply to the board. Can be 2.4V to 3.6V. 4 SDA I2C Serial Data Address pin. Used to transfer the data through I2C. 5 SCL I2C Serial Clock Line pin. Provides clock pulse for I2C communication. 6 INT External Interrupt pin. It is Active LOW during interrupt event. APDS-9960 Features Ambient Light and RGB Sensing, Proximity Sensing, and Advance Gesture Detection. Operating Voltage: 2.4V to 3.6V. Operating current: 0.2mA. Communication protocol: 400KHz Highly sensitive Ambient and RGB sensing through UV and IR blocking filters. For gesture sensing there are four photodiodes, which are sensitive to different to next directions so that it can detect complex gestures easily. The APDS9960 is used in many places. We can use it for gesture detection, ambient and RGB light sensing, proximity sensing etc. It can be used to give the RGB ratings of the light, because many times we need a particular RGB rated light, so that can be manipulated accordingly. It is used in many phones to disable the screen while someone is dialing the phone and keeping it on ear. The sensor uses I2C communication protocol so that makes it super easy to use with microcontrollers. It operates on voltage range of 2.4V-3.6V (Typically 3.3V) and consumes really small current of 0.2mA so it is a power efficient sensor. The sensor gives the RGB values directly so you don’t need to do any calculations to fetch them. Hardware of this sensor module is very simple. APDS9960 sensor is the main component for this board. As the board operates on 3.3V so a voltage regulator is used. The sensor has four photodiodes to detect the gestures. Whenever a gesture is performed, the IR signal transmitted by the LED gets reflected by the obstacle and is detected by the photodiodes and then the information is received about velocity and distance. This is how a gesture is detected. For RGB color sensing it has different channels for each kind of light red, blue, green and clear. And each channel has IR and UV blocking filters and a data converter which produces 16-bit data for each channel. This sensing can be used to calculate color temperature and can also be used to manipulate the backlight of displays. The interrupt is used to control the detect function. So it triggers the sensor to release the IR or detect it according to the interrupt. There are two jumpers PS and I2C PU. These both jumpers are soldered by default. The PS jumper connects the power of the board to the power supply of the sensor. So if it is closed then we need to connect the VCC pin only to power the board as well as sensor. And if it is open then we need to provide the power to the board by VCC pin (2.4V to 3.6V) and to sensor by VL pin (3.0V to 4.5V). The I2C PU jumper connects the pull up resistors to SDA and SCL lines. By default it is soldered. If you wish to not use these pull up resistors then you need to de-solder it and open it. Applications Used in gesture robotics, LCD displays for manipulation of backlight. Used in cell phones as proximity sensor. Mechanical switch replacement. Can be used in RGB monitor. APDS-9960 module Datasheet Installing Library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Arduino_APDS9960.h : you need to Download and install the Gesture library. DFRobotDFPlayerMini.h : you need to Download and install the MP3 player library. LiquidCrystal_I2C.h : you need to Download and install the LCD display library. After installing the required libraries, copy the following code to your Arduino IDE. Arduino code Subscribe and Download code #include #include LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display #include "Arduino.h" #include "SoftwareSerial.h" #include "DFRobotDFPlayerMini.h" SoftwareSerial mySoftwareSerial(10, 11); // RX, TX DFRobotDFPlayerMini myDFPlayer; void printDetail(uint8_t type, int value); void setup() { mySoftwareSerial.begin(9600); Serial.begin(9600); while (!Serial); // Wait for Serial Monitor to open if (!APDS.begin()) { Serial.println("Error initializing APDS-9960 sensor."); while (true); // Stop forever } lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); lcd.clear(); lcd.setCursor(6,0); lcd.print("APDS-9960"); lcd.setCursor(0,1); lcd.print("GESTURE: "); lcd.setCursor(0,2); lcd.print("PROXIMITY: "); lcd.setCursor(0,3); lcd.print("RGB: "); if (!myDFPlayer.begin(mySoftwareSerial, false)) { //Use softwareSerial to communicate with mp3. Serial.println(F("Unable to begin:")); Serial.println(F("1.Please recheck the connection!")); Serial.println(F("2.Please insert the SD card!")); while(true){ delay(0); // Code to compatible with ESP8266 watch dog. } } Serial.println(F("DFPlayer Mini online.")); myDFPlayer.volume(30); //Set volume value. From 0 to 30 myDFPlayer.play(5); //Play the 005.mp3 } int proximity = 0; int r = 0, g = 0, b = 0; unsigned long lastUpdate = 0; void loop() { // Check if a proximity reading is available. if (APDS.proximityAvailable()) { proximity = APDS.readProximity(); } // Check if a gesture reading is available if (APDS.gestureAvailable()) { int gesture = APDS.readGesture(); switch (gesture) { case GESTURE_UP: Serial.println("Detected UP gesture"); lcd.setCursor(9,1); lcd.print("UP "); myDFPlayer.play(2); //Play the 002.mp3 delay(3000); break; case GESTURE_DOWN: Serial.println("Detected DOWN gesture"); lcd.setCursor(9,1); lcd.print("DOWN "); myDFPlayer.play(1); //Play the 001.mp3 delay(3000); break; case GESTURE_LEFT: Serial.println("Detected LEFT gesture"); lcd.setCursor(9,1); lcd.print("LEFT "); myDFPlayer.play(3); //Play the 003.mp3 delay(3000); break; case GESTURE_RIGHT: Serial.println("Detected RIGHT gesture"); lcd.setCursor(9,1); lcd.print("RIGHT "); myDFPlayer.play(4); //Play 004.mp3 delay(3000); break; default: // Ignore break; } } // Check if a color reading is available if (APDS.colorAvailable()) { APDS.readColor(r, g, b); } // Print updates every 100 ms if (millis() - lastUpdate > 500) { lastUpdate = millis(); lcd.setCursor(11,2); lcd.print(proximity); lcd.setCursor(5,3); lcd.print(r); lcd.print(","); lcd.print(g); lcd.print(","); lcd.print(b); lcd.print(" "); } } Subscribe and Download code Demo Subscribe and Download code

  • Bluetooth Controlled RGB LED

    In this tutorial, you will learn about Arduino RGB LED control with Bluetooth. Here common cathode RGB LED and Bluetooth HC-05 used for interface. The android slider using to control for RGB values from 0 to 255 through An Android application. Circuit diagram Components Required Arduino Nano - 1 no Bluetooth module HC-05 - 1no RGB cc- 1 no Resistor 300E - 1no Bluetooth HC-05 Module HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. It has 6 pins, Key/EN- NC VCC to Connect 5 V power GND to power Ground TXD to Arduino Nano Rx (D0) RXD to Arduino Nano Tx (D1) State- NC HC-05 module Information HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Download Datasheet RGB LED A RGB LED is commonly used component in electronics, generally, as it is used for indication purpose. You can use RGB LED in various projects like portable flashlight, LED indicator, etc. An RGB LED can also be used for work according to condition like for condition 1st Red will glow, for condition 2nd green will glow and for condition 3rd blue will glow. Pin Configuration Pin No. Pin Name Description 1 R This terminal used for glowing LED in Red color 2 Gnd Common Cathode terminal (Ground) 3 G This terminal used for glowing LED in Green color 4 B This terminal used for glowing LED in Blue color Download Datasheet Installing the Arduino Library No need any special libraries. Arduino Code #include SoftwareSerial Bluetooth(10,11); // Rx,Tx pin to BT tx, rx pin char LED_CharRGB; // reads each character int RedPin = 5; // Red RGB pin -> D5 int GreenPin = 6; // Green RGB pin -> D6 int BluePin = 3; // Bluetoothe RGB pin -> D3 int RedValue = 255; // Red RGB pin -> D5 int GreenValue = 255; // Green RGB pin -> D6 int BlueValue = 255; // Bluetoothe RGB pin -> D3 String RedtempValue; String GreentempValue; String BluetempValue; char CurrentColor; void setup() { pinMode(RedPin,OUTPUT); pinMode(BluePin,OUTPUT); pinMode(GreenPin, OUTPUT); // initialize serial communication at 9600 bits per second: Serial.begin(9600); Bluetooth.begin(9600); } void loop() { //while is reading the message while(Bluetooth.available() > 0){ { LED_CharRGB = Bluetooth.read(); // Reads a character if(LED_CharRGB=='R'){ CurrentColor = 'R'; RedtempValue = ""; } else if(LED_CharRGB=='G'){ CurrentColor = 'G'; GreentempValue = ""; } else if(LED_CharRGB=='B'){ CurrentColor = 'B'; BluetempValue = ""; } if(CurrentColor == 'R' && LED_CharRGB!='R'){ RedtempValue += LED_CharRGB; } else if(CurrentColor == 'G' && LED_CharRGB!='G'){ GreentempValue += LED_CharRGB; } else if(CurrentColor == 'B' && LED_CharRGB!='B'){ BluetempValue += LED_CharRGB; } } Bluetooth.flush(); } analogWrite(RedPin, RedtempValue.toInt()); analogWrite(GreenPin, GreentempValue.toInt()); analogWrite(BluePin, BluetempValue.toInt()); } Subscribe and Download arduino code. ANDROID APPLICATION The Android app developers generally use JAVA language, but this Android app can also build without knowing the Java language. This app inventor is specially designed for Block programmers those who don’t know the JAVA language. Subscribe and Download android application. MIT main page MIT Block Demo Subscribe and Download arduino code. Subscribe and Download android application.

  • Arduino based MP3 Player using DF Player mini

    Here to learn arduino nano based Mp3 player to Play MP3 songs using using DFPlayermini module. In this DFPlayer SD card is used to store the MP3 files. Push Buttons using to control Volume +,Volume -, Previous, next and start from first. Circuit diagram Components Required Arduino Nano - 1 no DFPlayer Mini - 1 no Memory card 16gb- 1 no Push button - 3 nos Resistor 1k - 1 no DFPlayer Mini The DFPlayer Mini MP3 Player For Arduino is a small and low price MP3 module with an simplified output directly to the speaker. The module can be used as a stand alone module with attached battery, speaker and push buttons or used in combination with an Arduino UNO or any other with RX/TX capabilities. Specification supported sampling rates (kHz): 8/11.025/12/16/22.05/24/32/44.1/48 24 -bit DAC output, support for dynamic range 90dB , SNR support 85dB fully supports FAT16 , FAT32 file system, maximum support 32G of the TF card, support 32G of U disk, 64M bytes NORFLASH a variety of control modes, I/O control mode, serial mode, AD button control mode advertising sound waiting function, the music can be suspended. when advertising is over in the music continue to play audio data sorted by folder, supports up to 100 folders, every folder can hold up to 255 songs 30 level adjustable volume, 6 -level EQ adjustable Work Mode 1. Serial Mode Support for asynchronous serial communication mode via PC serial sending commands Communication Standard:9600 bps Data bits :1 Checkout :none Flow Control :none Instruction Description Serial Control CMD Serial Query CMD 2. AD KEY Mode We use the AD module keys, instead of the traditional method of matrix keyboard connection, it is to take advantage of increasingly powerful MCU AD functionality, Our module default configuration 2 AD port, 20 key resistance distribution. 3. I/O Mode Here comes the most simple way to use this module. Copy your mp3 into you micro SD card NOTE: The order you copy the mp3 into micro SD card will affect the order mp3 played , which means play(1) function will play the first mp3 copied into micro SD card. The folder name needs to be mp3, placed under the SD card root directory, and the mp3 file name needs to be 4 digits, for example, "0001.mp3", placed under the mp3 folder. If you want to name it in Both English and Chinese, you can add it after the number, for example, "0001hello.mp3" or "0001后来.mp3". Installing Library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. DFRobotDFPlayerMini.h : you need to Download and install the DFPlayer library. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code Arduino Code #include "SoftwareSerial.h" #include "DFRobotDFPlayerMini.h" // Use pins 2 and 3 to communicate with DFPlayer Mini static const uint8_t PIN_MP3_TX = 10; // Connects to DFPlayer Mini pin RX static const uint8_t PIN_MP3_RX = 11; // Connects to DFPlayer Mini pin TX SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX); // Create the Player object DFRobotDFPlayerMini player; void setup() { // Init USB serial port for debugging Serial.begin(9600); // Init serial port for DFPlayer Mini softwareSerial.begin(9600); // Start communication with DFPlayer Mini if (player.begin(softwareSerial)) { Serial.println("OK"); // Set volume to maximum (0 to 30). player.volume(10); // Play the first MP3 file on the SD card player.play(1); } else { Serial.println("Connecting to DFPlayer Mini failed!"); } } void loop() { } Subscribe and Download code Demo Subscribe and Download code

  • 4 channel Pulse Width Modulation with Bluetooth

    In this tutorial, LED Brightness Control using arduino PWM pins and Bluetooth HC-05 device for LED Brightness slider using android application. Here 4 PWM pins used to control 4 LEDs and 1 PWM pin for bluetooth communication of arduino nano. Circuit diagram Components Required Arduino Nano - 1 no Bluetooth module HC-05 - 1no LED 5mm/10mm - 4 nos Resistor 300E - 4 nos PWM Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between the full Vcc of the board (e.g., 5 V on Uno, 3.3 V on a MKR board) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of "on time" is called the pulse width. To get varying analog values, you change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an LED for example, the result is as if the signal is a steady voltage between 0 and Vcc controlling the brightness of the LED. In the graphic, the green lines represent a regular time period. This duration or period is the inverse of the PWM frequency. In other words, with Arduino's PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example. Once you get this example running, grab your arduino and shake it back and forth. What you are doing here is essentially mapping time across the space. To our eyes, the movement blurs each LED blink into a line. As the LED fades in and out, those little lines will grow and shrink in length. Now you are seeing the pulse width. Bluetooth HC-05 Module HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. It has 6 pins, Key/EN- NC VCC to Connect 5 V power GND to power Ground TXD to Arduino Nano Rx (D0) RXD to Arduino Nano Tx (D1) State- NC HC-05 module Information HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Download Datasheet Installing the Arduino Library No need any special libraries. Arduino Code #include SoftwareSerial Bluetooth(10,11); // RX, TX int PWMLED1=3; int PWMLED2=5; int PWMLED3=6; int PWMLED4=9; void setup(){ pinMode(PWMLED1,OUTPUT); pinMode(PWMLED2,OUTPUT); pinMode(PWMLED3,OUTPUT); pinMode(PWMLED4,OUTPUT); Bluetooth.begin(9600); } void loop(){ if (Bluetooth.available()){ int value1=Bluetooth.parseInt(); int value2=Bluetooth.parseInt(); int value3=Bluetooth.parseInt(); int value4=Bluetooth.parseInt(); if (Bluetooth.read() =='\n'){ analogWrite(PWMLED1,value1); analogWrite(PWMLED2,value2); analogWrite(PWMLED3,value3); analogWrite(PWMLED4,value4); }} } Subscribe and Download arduino code. ANDROID APPLICATION The Android app developers generally use JAVA language, but this Android app can also build without knowing the Java language. This app inventor is specially designed for Block programmers those who don’t know the JAVA language. Subscribe and Download android application. MIT main page MIT Block Demo Subscribe and Download MIT APP .aia code download. Subscribe and Download arduino code. Subscribe and Download android application.

  • GPS Coordinates and GPS Clock

    In this project, we have shown how to interface a GPS neo6M module with Arduino nano, 20x4 LCD display. GPS (global positioning system) coordinates are usually expressed as the combination of latitude and longitude. The GPS coordinates data for longitude, latitude and GPS clock is displayed on the LCD. GPS Coordinates GPS coordinates are formed by two components that are a latitude , giving the north-south position, and a longitude, giving the east-west position. Use this map to convert any address in its GPS coordinates. You can also find the location of any GPS coordinates, and geocode its address if available. clock-Time Local time is the date/time reported by your PC (as seen by your web browser). If your PC clock is accurate to a second then the other time scales displayed above will also be accurate to within one second. UTC, Coordinated Universal Time, popularly known as GMT (Greenwich Mean Time), or Zulu time. Local time differs from UTC by the number of hours of your timezone. GPS clock, Global Positioning System time, is the atomic time scale implemented by the atomic clocks in the GPS ground control stations and the GPS satellites themselves. GPS time was zero at 0h 6-Jan-1980 and since it is not perturbed by leap seconds GPS is now ahead of UTC by 18 seconds. Loran-C, Long Range Navigation time, is an atomic time scale implemented by the atomic clocks in Loran-C chain transmitter sites. Loran time was zero at 0h 1-Jan-1958 and since it is not perturbed by leap seconds it is now ahead of UTC by 27 seconds. TAI, Temps Atomique International, is the international atomic time scale based on a continuous counting of the SI second. TAI is currently ahead of UTC by 37 seconds. TAI is always ahead of GPS by 19 seconds. Circuit Diagram Components Required Arduino Nano - 1 no LCD 20x4 with I²C module - 1no NEO6MV2 GPS Module - 1no NEO6MV2 GPS The NEO-6MV2 is a GPS (Global Positioning System) module and is used for navigation. The module simply checks its location on earth and provides output data which is longitude and latitude of its position.It is from a family of stand-alone GPS receivers featuring the high performance u-blox 6 positioning engine. These flexible and cost effective receivers offer numerous connectivity options in a miniature (16 x 12.2 x 2.4 mm) package. The compact architecture, power and memory options make NEO-6 modules ideal for battery operated mobile devices with very strict cost and space constraints. Its Innovative design gives NEO-6MV2 excellent navigation performance even in the most challenging environments. NEO-6MV2 GPS Module Pin Configuration The module has four output pins and we will describe the function each pin of them below. The powering of module and communication interface is done through these four pins. Pin Name Description VCC Positive power pin RX UART receive pin TX UART transmit pin GND Ground Features and Electrical Characteristics Standalone GPS receiver Anti-jamming technology UART Interface at the output pins (Can use SPI ,I2C and USB by soldering pins to the chip core) Under 1 second time-to-first-fix for hot and aided starts Receiver type: 50 Channels - GPS L1 frequency - SBAS (WAAS, EGNOS, MSAS, GAGAN) Time-To-First-fix: For Cold Start 32s, For Warm Start 23s, For Hot Start <1s Maximum navigation update rate: 5Hz Default baud rate: 9600bps EEPROM with battery backup Sensitivity: -160dBm Supply voltage: 3.6V Maximum DC current at any output: 10mA Operation limits: Gravity-4g, Altitude-50000m, Velocity-500m/s Operating temperature range: -40ºC TO 85°C Overview of the NEO-6MV2 GPS Module This module is one of popular GPS modules in the market and is also cheap to buy. The location data provided by it is accurate enough to satisfy most applications. And for it to be included in smart phones and tablets design points out its efficiency. This module is famous among hobbyist and engineers altogether who want to work on applications involving navigation. How to use the NEO-6MV2 GPS Module Getting this module to work is very easy. For the application circuit below we have connected the power to board and interfaced the output to the microcontroller UART to get it done. After circuitry, you need to set the baud rate of the controller matching the module, if it’s not matched you will get error. With baud rate setting done you can read the serial data directly from the module. This data will be longitude and latitude values and the user can play with them as desired. The raw values provided by the module are cumbersome to read directly and so a simple decimal calculation can be done in programming for getting easy to read values. Applications GPS application Smart phone and tablets Navigation systems Drones Hobby projects NEO-6MV2 GPS module Datasheet Installing Library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. TinyGPSPlus.h : you need to Download and install the GPS library. LiquidCrystal_I2C.h : you need to Download and install the LiquidCrystal_I2C library. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code Arduino Code #include #include static const int RXPin = 4, TXPin = 3; static const uint32_t GPSBaud = 9600; // The TinyGPSPlus object TinyGPSPlus gps; // The serial connection to the GPS device SoftwareSerial ss(RXPin, TXPin); #include LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display void setup() { Serial.begin(115200); ss.begin(GPSBaud); lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); lcd.setCursor(0,0); lcd.print(" GPS LOCATION "); lcd.setCursor(0,1); lcd.print("LATITUDE, LONGITUDE"); lcd.setCursor(0,2); lcd.print("and GPS CLOCK "); delay(5000); lcd.clear(); } void loop() { // This sketch displays information every time a new sentence is correctly encoded. while (ss.available() > 0) if (gps.encode(ss.read())) displayInfo(); if (millis() > 5000 && gps.charsProcessed() < 10) { Serial.println(F("No GPS detected: check wiring.")); while(true); } } void displayInfo() { Serial.print(F("Location: ")); if (gps.location.isValid()) { lcd.setCursor(0,0); lcd.print("Latitude:"); lcd.setCursor(9,0); lcd.print(gps.location.lat(), 6); lcd.setCursor(0,1); lcd.print("Longitude:"); lcd.setCursor(10,1); lcd.print(gps.location.lng(), 6); } else { Serial.print(F("INVALID")); } Serial.print(F(" Date/Time: ")); if (gps.date.isValid()) { lcd.setCursor(0,2); lcd.print("Date:"); lcd.setCursor(6,2); lcd.print(gps.date.month()); lcd.print("/"); lcd.print(gps.date.day()); lcd.print(F("/")); lcd.print(gps.date.year()); } else { Serial.print(F("INVALID")); } Serial.print(F(" ")); lcd.setCursor(0,3); lcd.print("Time:"); if (gps.time.isValid()) { lcd.setCursor(6,3); if (gps.time.hour() < 10) lcd.print(F("0")); lcd.print(gps.time.hour()); lcd.print(F(":")); if (gps.time.minute() < 10) lcd.print(F("0")); lcd.print(gps.time.minute()); lcd.print(F(":")); if (gps.time.second() < 10) lcd.print(F("0")); lcd.print(gps.time.second()); } else { Serial.print(F("INVALID")); } Serial.println(); } Subscribe and Download code Demo Video Subscribe and Download code

bottom of page