Search Results
163 results found with an empty search
- ESP8266 Web Server Based LM35 Temperature Data Logger
In this tutorial we will show how to build ESP8266 and interface LM35 Precision Centigrade Temperature sensor with html gauge, data plotter with logger. This project uses ESP8266 NodeMCU device that easily connects to existing WiFi network & creates a Web Server. When any connected device accesses this web server, ESP8266 reads in temperature from LM35 Temperature sensors & sends it to the web browser. In this project temperature range reads trimmed from 0°C to 100°C (Actual -55°C to 150°C). Here High chart is used to create reliable and secure data visualizations and data logger. You can export the data to CSV, EXCEL format and graph convert to PNG,JPEG,PDF format. Circuit Diagram Components Required NodeMCU ESP8266 12E Dev Board LM35 sensor Module LM35 Precision Centigrade Temperature Sensor The LM35 series are precision integrated-circuit temperature devices with an output voltage linearly proportional to the Centigrade temperature. The LM35 device has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to subtract a large constant voltage from the output to obtain convenient Centigrade scaling. The LM35 device does not require any external calibration or trimming to provide typical accuracies of ±¼°C at room temperature and ±¾°C over a full −55°C to 150°C temperature range. Lower cost is assured by trimming and calibration at the wafer level. The low-output impedance, linear output, and precise inherent calibration of the LM35 device makes interfacing to readout or control circuitry especially easy. The device is used with single power supplies, or with plus and minus supplies. As the LM35 device draws only 60 μA from the supply, it has very low self-heating of less than 0.1°C in still air. The LM35 device is rated to operate over a −55°C to 150°C temperature range, while the LM35C device is rated for a −40°C to 110°C range (−10° with improved accuracy). The LM35-series devices are available packaged in hermetic TO transistor packages, while the LM35C, LM35CA, and LM35D devices are available in the plastic TO-92 transistor package. The LM35D device is available in an 8-lead surface-mount small-outline package and a plastic TO-220 package. Temperature Sensor Output Voltage Linearity LM35 (LM35DZ) proportional to temperature in Celsius (ºC)10mV/ºC LM335 proportional to temperature in Kelvin (ºK)10mV/ºK LM34 proportional to temperature in Fahrenheit (ºF)10mV/ºF In this project LM35DZ is used to measure temperature range from 0ºC to 100ºC. For example, if the LM35 outputs a voltage of 245 mV, that means we have a temperature value of 24.5ºC. For example2, if the LM35 outputs a voltage of 1000 mV (1V), that means we have a temperature value of 100ºC. NodeMCU NodeMCU ESP8266-12E MCU is a development board with one analogue and many general-purpose input output (GPIO) pins. It has 4MB flash memory, and can operate at a default clock frequency of 80MHz. In this project, analog pin A0 of NodeMCU is used to read analog signal of LM35 Precision Centigrade Temperature Sensor. Analog Reading ESP8266 ADC pins have 10-bit resolution by default. These pins read voltage between 0 and 3.3V and then return a value between 0 and 1023. ESP32 ADC pins have 12-bit resolution by default. These pins read voltage between 0 and 3.3V and then return a value between 0 and 4095 Arduino ADC pins have 10-bit resolution by default. These pins read voltage between 0 and 5V and then return a value between 0 and 1023. 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. 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: Create an index.html file with the following content. Download 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 Temperature in degree (°C). Then, the set Interval function will send data from the server every 0.5 seconds by accessing the “/DStempCt” endpoint provided by the server and sending the data to the chart object earlier. arduino code #include #include #include #include #include #include const int LM35 = A0; int input_val = 0; float temp = 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 getDStempC() { input_val = analogRead(LM35); temp = (3300 * input_val ) / 1024; Serial.print("Temperature is : " ); Serial.println(temp);; return String(temp); } void setup () { // 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); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi.."); } // Print connection information 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 ("/DStempC", HTTP_GET, [] (AsyncWebServerRequest * request) { request-> send_P (200, "text / plain", getDStempC(). c_str ()); }); // start server server.begin (); } void loop() { } 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 After that Open the web browser and enter the IP address path for Temperature reading on High chart Gauge and plotter. Demo: Subscribe and Download code
- ESP8266 Webserver based Thermometer using DS18B20 and Fusion charts
In this tutorial, we will learn to create an ESP8266 NodeMCU web server using DS18B20 and Fusion charts widget. The chip DS18B20 is used to measure temperature in Celsius and Fahrenheit. This web server will act as a weather station as it will show fusion charts widget thermometer gauge readings will update in Celsius and Fahrenheit automatically on the web page. Circuit Diagram Components Required DS18B20 - 1no Node MCU ESP8266 12E Dev Module- 1 no Resistor 4.7K- 1 no Jumper wires 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. 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 #include #include // Include the libraries we need #include #include // Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS 2 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); //WiFi Connection configuration const char* ssid = "TP-Link_3200"; //YOUR SSID const char* password = "95001121379884265554"; //YOUR WIFI PASSWORD const char index_html[] PROGMEM={"\n" "\n" "\n" "\n" "\n" "\n" "ESP8266 NodeMCU DS18B20 Thermometer Display" "\n" "\n" "\n" "\n" "\n" "\t\n" "\n" "\n" "\n" "\n" "\n" " \n" " \n" "\n" " FusionCharts XT will load here!\n" " FusionCharts XT will load here!\n" " \n" "\n" "\n" "\t\n" "" }; ESP8266WebServer server(80); void handleRoot() { server.send_P(200, "text/html;charset=UTF-8", index_html); } void handleCTempRequest(){ sensors.requestTemperatures(); // Send the command to get temperatures Serial.println("Temperature is: "); float tempC = (sensors.getTempCByIndex(0)); Serial.println(tempC); //delay(1000); server.send(200,"text",String(tempC)); } void handleFTempRequest(){ sensors.requestTemperatures(); // Send the command to get temperatures float tempC = (sensors.getTempCByIndex(0)); // float tempF = (DallasTemperature::toFahrenheit(tempC)); float tempF = (sensors.getTempFByIndex(0)); Serial.println("Fahrenheit is: "); Serial.println(tempF); //delay(1000); server.send(200,"text",String(tempF)); } void handleNotFound(){ String message = "File Not Found\n\n"; server.send(404, "text/plain", message); } void runPeriodicFunc(){ static const unsigned long REFRESH_INTERVAL1 = 1000; // static unsigned long lastRefreshTime1 = 0; if(millis() - lastRefreshTime1 >= REFRESH_INTERVAL1) { lastRefreshTime1 = millis(); } } void setup(void){ // start serial port Serial.begin(115200); sensors.begin(); delay(100); WiFi.begin(ssid, password); Serial.println(""); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.print("IP address:"); Serial.println(WiFi.localIP()); server.on("/", handleRoot); server.on("/tempC",handleCTempRequest); server.on("/tempF",handleFTempRequest); server.onNotFound(handleNotFound); server.begin(); delay(2000); Serial.println("HTTP server started"); } void loop(void){ runPeriodicFunc(); server.handleClient(); // sensors.requestTemperatures(); // Send the command to get temperatures // float tempC = (sensors.getTempCByIndex(0)); // float tempF = (DallasTemperature::toFahrenheit(tempC)); } 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 and see the result in serial monitor. After that Open the web browser and enter the IP address path for Thermometer reading on Fusion chart Gauge. Demo: Subscribe and Download code
- ESP8266 NodeMCU ADC with Pot Interface, Fusion chart and OLED
In this tutorial, we will learn how to use the ADC pin of the ESP8266 12E and interfacing a potentiometer with an analog input pin of ESP8266 ADC and read voltage across the potentiometer. ESP8266 12E ADC Resolution has a 10-bit, which means you'll get values range 0 and 1023. ESP8266 12E ADC will convert this analog signal into a digital value range from 0 to 1023 and mapped 0 to 100. The measured values send to the Web server and feed in to fusion chart value and also display it on the 0.96 OLED display. Here note that the voltage not exceeded the 3.3 volts at the ESP8266 12E ADC pin, otherwise the ESP8266 12E burn out. Components Required 0.96 OLED 4wire Module - 1no Node MCU ESP8266 12E Dev Module- 1 no Trim potentiometer 4.7K- 1 no Jumper wires 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 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 //WiFi Connection configuration const char* ssid = "TP-Link_3200"; //YOUR SSID const char* password = "95001121379884265554"; //YOUR WIFI PASSWORD const char index_html[] PROGMEM={"\n" "\n" "\n" "\n" "\n" "\n" "ESP8266 NodeMCU ADC and Fusion Chart " "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" " \n" " \n" "\n" " FusionCharts XT will load here!\n" " \n" "\n" "\n" "\t\n" "" }; #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) // The pins for I2C are defined by the Wire-library. // On an arduino UNO: A4(SDA), A5(SCL) // On an arduino MEGA 2560: 20(SDA), 21(SCL) // On an arduino LEONARDO: 2(SDA), 3(SCL), ... #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 analog_percentage = 0; WiFiClient client; ESP8266WebServer server(80); void handleRoot() { server.send_P(200, "text/html;charset=UTF-8", index_html); } void handleLevelRequest(){ int a = analogRead(A0); a = map(a,0,1023,0,100); String analog_percentage = String(a); display.setCursor(0, 1); display.setTextColor(WHITE); display.setTextSize(1); display.println("ADC Percentage:"); // on écrit la valeur numérique de la tension un peu plus bas, en plus gros display.setCursor(35, 45); display.setTextSize(2); display.print(a/100); if ((a % 100) < 10){ display.print("0"); } display.print(a % 100); display.println(" %"); display.fillRect( 5, 17, 120, 20, BLACK); display.drawRect( 5, 17, 120, 20, WHITE); display.fillRect( 7, 19, map(a, 0, 100, 0, 116), 16, WHITE); display.display(); delay(500); display.clearDisplay(); Serial.println(analog_percentage); server.send(200,"text",String(analog_percentage)); } void handleNotFound(){ String message = "File Not Found\n\n"; server.send(404, "text/plain", message); } void runPeriodicFunc() { static const unsigned long REFRESH_INTERVAL1 = 1000; // 2.1sec static unsigned long lastRefreshTime1 = 0; if(millis() - lastRefreshTime1 >= REFRESH_INTERVAL1) { lastRefreshTime1 = millis(); } } void setup(void){ Serial.begin(115200); delay(100); WiFi.begin(ssid, password); Serial.println(""); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } // 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(); // Draw a single pixel in white display.drawPixel(10, 10, SSD1306_WHITE); // Show the display buffer on the screen. You MUST call display() after // drawing commands to make them visible on screen! display.display(); delay(2000); // display.display() is NOT necessary after every single drawing command, // unless that's what you want...rather, you can batch up a bunch of // drawing operations and then update the screen all at once by calling // display.display(). These examples demonstrate both approaches... // Invert and restore display, pausing in-between display.invertDisplay(true); delay(1000); display.invertDisplay(false); delay(1000); Serial.print("IP address:"); Serial.println(WiFi.localIP()); server.on("/", handleRoot); server.on("/level",handleLevelRequest); server.onNotFound(handleNotFound); server.begin(); Serial.println("HTTP server started"); } void loop(void){ runPeriodicFunc(); 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 and see the result. Subscribe and Download code Demo:
- Garbage Monitoring System with Bluetooth Interface
This project Arduino based Garbage Monitoring system is a very innovative system which will help to keep the home, restaurant, hospitals, Office clean. This system monitors the garbage bins about the level of garbage collected in the garbage bins via mobile. For this the system uses ultrasonic sensors placed over the bins to detect the garbage level and compare it with the garbage bins depth. The system makes use of Arduino family microcontroller, Bluetooth HC-05 for sending data to android application. The Mobile screen is used to display the status of the level of garbage collected in the bins, remaining of free space and Bin height. The android application can set the Garbage bin height when empty bin for level calculations. The Garbage bin depth is 0 % to 100%, if the value less than 33% the bin color should be Green, if the value less than 66% and grater than 34% the bin color should be light rose, if the value less than 100% and grater than 67%the bin color should be Red is assigned in this project using android application. Circuit diagram Components required Arduino Nano - 1 no Bluetooth module HC-05 - 1no HC-SR04 ultrasonic sensor-1no HC-SR04 This is the HC-SR04 ultrasonic distance sensor. This economical sensor provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm. Each HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit. There are only four pins that you need to worry about on the HC-SR04: VCC (Power) to Arduino Nano Vin Pin Trig (Trigger) to Arduino Nano D2 Pin Echo (Receive) to Arduino Nano D3 Pin GND (Ground) to Arduino Nano GND Pin. 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, 1.Key/EN: It is used to bring Bluetooth module in AT commands mode. If Key/EN pin is set to high, then this module will work in command mode. Otherwise by default it is in data mode. The default baud rate of HC-05 in command mode is 38400bps and 9600 in data mode. HC-05 module has two modes, Data mode: Exchange of data between devices. Command mode: It uses AT commands which are used to change setting of HC-05. To send these commands to module serial (USART) port is used. 2. VCC: Connect 5 V or 3.3 V to this Pin. 3. GND: Ground Pin of module. 4. TXD: Transmit Serial data (wirelessly received data by Bluetooth module transmitted out serially on TXD pin) 5. RXD: Receive data serially (received data will be transmitted wirelessly by Bluetooth module). 6. State: It tells whether module is connected or not. 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 Default Communication: Slave Default Mode: Data Mode Data Mode Baud Rate: 9600, 8, N, 1 Command Mode Baud Rate: 38400, 8, N, 1 Default firmware: LINVOR Installing the Arduino Library Download Ultrasonic library , we need to use this library. Follow the next steps to install those libraries. 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. Subscribe and Download code. Download Android application. Mobile Output The Arduino will send this data via Bluetooth then the mobile application will receive this data and will proceed to show the status of the garbage bin level , free space to the user and giving a additional Gauge view with color changes in depends on percentage of waste filled in the garbage bin. First open Mobile application Garbage BT and select Bluetooth connect button, after that select Bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234). Subscribe and Download code. Arduino Code #include Ultrasonic ultrasonic(2, 3); #include int addr = 0; int height = 0; int heightset; int BinHeight; long distance; float percentage,math; String waste; // remove wiring from Bluetooth when program upload void setup () { Serial.begin(9600); // We initialize serial connection so that we could print values from sensor. } void loop () { // Every 500 miliseconds, do a measurement using the sensor and print the distance in centimeters. distance = ultrasonic.read(); if(Serial.available()> 0) { height = Serial.read(); if(height == 'h') { BinHeight =distance; EEPROM.write(addr,BinHeight); } {BinHeight= EEPROM.read(addr); } } delay(500); heightset= EEPROM.read(addr); math = heightset-distance; percentage = (math/heightset)*100; waste = (String)distance + "," + (String)percentage + "," + (String)heightset; Serial.println(waste); } After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the Arduino Uno board and see the result in monitor. Download .aia file https://drive.google.com/file/d/1KbmXBIM9xpV4IUayfnqQMmNkh1fonpMz/view?usp=sharing
- Bluetooth Controlled Servo
Learn how to control servo motors using an Android application in a mobile device, an Arduino UNO, and HC-05 Bluetooth module. A servo motor is a closed-loop system that uses position feedback to control its motion and final position. RC servo motor works on the same principal. It contains a small DC motor connected to the output shaft through the gears. The output shaft drives a servo arm and is also connected to a potentiomete (pot). The potentiometer provides position feedback to the servo control unit where the current position of the motor is compared to the target position. According to the error, the control unit corrects the actual position of the motor so that it matches the target position. A servo motor is controlled by sending a series of pulses through the signal line. The frequency of the control signal should be 50Hz or a pulse should occur every 20ms. The width of pulse determines angular position of the servo and these type of servos can usually rotate 180 degrees The control wire is used to communicate the angle. The angle is determined by the duration of a pulse that is applied to the control wire. This is called Pulse Coded Modulation . The servo expects to see a pulse every 20 milliseconds (.02 seconds). The length of the pulse will determine how far the motor turns. A 1.5 millisecond pulse, for example, will make the motor turn to the 90-degree position (often called as the neutral position). If the pulse is shorter than 1.5 milliseconds, then the motor will turn the shaft closer to 0 degrees. If the pulse is longer than 1.5 milliseconds, the shaft turns closer to 180 degrees. Circuit Diagram: First, make the connections for the servo motors with the Arduino. Connect the black wire of both the servo motors with the GND of Arduino Connect the orange wire of both the motors to the 5V of Arduino Connect the Orange wire of the first motor to pin 9 of Arduino Subscribe and Download code. First, Test Servo motor sweep function without Bluetooth suing following arduino Code: #include Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } } The output result: After that, make the connections for the Bluetooth module with the Arduino. Connect the VCC of the Bluetooth module to 5V of Arduino Connect the GND of Bluetooth module to the GND of Arduino Connect the TX of Bluetooth module to pin Rx of Arduino Connect the RX of Bluetooth module to pin Tx of Arduino Subscribe and Download code. Arduino Code for Bluetooth Control: #include Servo myservo; const int Pin = 9; // myservo pin3 PWM char Text; String Spilt; String angle; int pos = 0; // variable to store the servo position int k1; void setup() { Serial.begin(9600); pinMode (Pin, OUTPUT); myservo.attach(Pin); } void loop() { if(Serial.available()) { Text = Serial.read(); Spilt = Spilt + Text; if (Text == '*') { Serial.println(Spilt); Spilt = Spilt.substring(0, Spilt.length() - 1); // Delete last char * k1 = Spilt.indexOf('*'); angle = Spilt.substring(0, k1); myservo.write(angle.toInt()); delay(15); Spilt = ""; } } } Once the program is uploaded, reconnect the TX and RX, and make sure the phone is paired with the appropriate Bluetooth module. The steps to connect to an Android phone follow: Power up the Bluetooth module and go to settings on the Android device. Pair the device. On some phones, this step must be performed twice for the phone to pair. Make sure to have the PIN codes handy (the default for most Bluetooth Mates is “1234”) > turn ON the power for both devices > search for the module in the Android “Settings” app under Bluetooth Icon. Once the device is paired to the phone, open the BT Servo app. Use the List to connect to and find the correct device name contains text HC-05. Download app: Servo 180: https://drive.google.com/file/d/12xVW9SVnDnypOcDeCbqwe8YYWuvCqr9z/view?usp=sharing servo 360: https://drive.google.com/file/d/1TdbP0bEyyg9ASixJinDNbbq6kTME3IqJ/view?usp=sharing Download .aia file https://drive.google.com/file/d/10GL4MpasAkuxRiUcPuNauw7l896d4oKE/view?usp=sharing Subscribe and Download code.
- Arduino graph using android app
Here is simplest component used and good accuracy for Signal Graph, Voltage and current measured reading value (DC) by using Android Application. In this project Bluetooth is used for serial communication, HC-05 is a Bluetooth device used for wireless communication with Bluetooth enabled devices (like smartphone). It communicates with arduino using serial communication. Circuit diagram: Component Required: Arduino UNO: 1 no Bluetooth HC-05: 1 no Potentiometer (Linear): 47K- 1 no Android Mobile for App Bluetooth HC_05 Default Bluetooth name of the device is “HC-05” and default PIN (password) for connection is either “0000” or “1234” Ardunio Analog Read: Serial reads the value from the specified analog pin. Arduino boards contain a multichannel, 10-bit analog to digital converter. This means that it will map input voltages between 0 and the operating voltage(5V or 3.3V) into integer values between 0 and 1023. On an Arduino UNO, for example, this yields a resolution between readings of: 5 volts / 1024 units or, 0.0049 volts (4.9 mV) per unit. On ATmega based boards (UNO, Nano, Mini, Mega), it takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second. The analog reading on the pin A0. Although it is limited to the resolution of the analog to digital converter 0-1023 for 10 bits. Subscribe and Download code. Arduino Code: int value_pot0; void setup() { Serial.begin(9600); } void loop() { value_pot0 = analogRead(A0); Serial.println(value_pot0); delay(100); // It should be slower than the Clock Interval. } Circuit Connection for 5VDC range Selection in the Android application: The 47K Potentio meter center point connected to the Arduino pin A0. For 110V DC range Selection in the Android application: The Series 100K with 5K Potentio meter and pot center point connected to the Arduino pin A0. Circuit Connection for 250VAC range Selection in the Android application: Circuit Connection for 5amp AC/DC range Selection in the Android application: Android Application: Download Code: https://drive.google.com/file/d/1Vh6baVJNDYlLhHkykqZ_mX0Tp0mi-8n8/view?usp=sharing Download .aia file: https://drive.google.com/file/d/1RWX94045u051pDwWsZZkyMxVnf2rB_Kx/view?usp=sharing Subscribe and Download code.
- 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 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 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
- 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