<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bits&amp;Bots on Medium]]></title>
        <description><![CDATA[Stories by Bits&amp;Bots on Medium]]></description>
        <link>https://medium.com/@vaibhav01gour?source=rss-7a8a7aa11d04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yrmsUgXYuMpply5IJKfLdw.png</url>
            <title>Stories by Bits&amp;amp;Bots on Medium</title>
            <link>https://medium.com/@vaibhav01gour?source=rss-7a8a7aa11d04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 19:25:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vaibhav01gour/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mega project : “Smart Clock”]]></title>
            <link>https://medium.com/@vaibhav01gour/mega-project-smart-clock-34ab3e31b952?source=rss-7a8a7aa11d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/34ab3e31b952</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[smartclock]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[Bits&Bots]]></dc:creator>
            <pubDate>Sun, 19 May 2024 18:13:39 GMT</pubDate>
            <atom:updated>2024-05-25T03:42:00.937Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mega project : “Smart Clock”</h3><h4>A clock which displays Time as well as weather on an OLED display</h4><h4>Introduction</h4><p>Are you ready to bring the future into your living space? Imagine waking up to a sleek and sophisticated clock that not only tells you the time but also keeps you informed about the current weather conditions. Our mega project, the Smart Clock, combines the power of technology with elegant design to create a functional and stylish addition to any room.</p><p>In today’s fast-paced world, staying updated on the latest weather forecasts is essential for planning your day. Whether it’s deciding what to wear or determining your outdoor activities, having real-time weather information at your fingertips can make a significant difference. With the Smart Clock, you can do just that, all while adding a touch of modernity to your home decor.</p><p>In this project, we’ll leverage the capabilities of ESP32 or ESP8266 microcontrollers along with an OLED display to create a Smart Clock that not only displays accurate time but also fetches and displays current weather data. From temperature and humidity to weather icons, this clock will provide you with all the essential weather information you need to start your day right.</p><p>So, gear up and get ready to embark on a journey to build your very own Smart Clock. Let’s dive into the details and turn your vision of a futuristic timepiece into a reality!</p><h4>Ingredients Required</h4><p>Before we dive into the construction of our Smart Clock, let’s gather all the necessary ingredients. Here’s what you’ll need</p><ol><li><strong>ESP32 or ESP8266 Microcontroller Board:</strong> The heart of your Smart Clock, the ESP32 or ESP8266, will handle all the processing and communication tasks.</li><li><strong>OLED Display (e.g., SSD1306):</strong> An OLED display provides a clear and vibrant interface for displaying time and weather information. Choose a display size that suits your preferences and fits well with your desired design.</li><li><strong>RTC Module (e.g., DS3231): </strong>A Real-Time Clock module ensures accurate timekeeping, even when the microcontroller is powered off. This ensures that your Smart Clock always displays the correct time, even after power cycles.</li><li><strong>Pushbuttons or Rotary Encoder for User Input: </strong>Adding user input functionality allows you to configure settings such as location and display preferences. You can choose between pushbuttons or a rotary encoder, depending on your preference and design requirements.</li><li><strong>Breadboard and Jumper Wires:</strong> These essential components facilitate the connection between the microcontroller, display, RTC module, and sensor during prototyping and testing phases.</li><li><strong>OpenWeather API: </strong>To fetch weather data, we’ll utilize the OpenWeather API, which provides accurate and up-to-date weather information from around the world. You’ll need to sign up for an API key to access the weather data.</li><li><strong>Power Source:</strong> Ensure you have a stable power source for your Smart Clock, whether it’s a USB power bank for portability or an AC adapter for stationary installations.</li></ol><p>With these ingredients in hand, we’re ready to craft our Smart Clock masterpiece! Let’s dive into the next steps and bring this project to life.</p><p>Schematics</p><p>With these ingredients in hand, we’re now ready to embark on the journey of building our Smart Clock. By combining the power of ESP32 or ESP8266 microcontrollers with an OLED display, RTC module, and a weather sensor, we can create a functional and stylish timepiece that provides real-time weather updates alongside accurate timekeeping.</p><pre>#include &quot;SH1106Wire.h&quot;    // https://github.com/ThingPulse/esp8266-oled-ssd1306<br>#include &quot;OLEDDisplayUi.h&quot; // Part of SSD1306/SH1106<br><br>#include &lt;WiFi.h&gt;<br>#include &lt;ArduinoJson.h&gt;   // https://github.com/bblanchon/ArduinoJson - latest version<br>#include &quot;time.h&quot;<br><br>// WU Icon names, there are 37, but many are the same image, so use the *icon when required, giving 10 basic icons to be used<br>// nt means Night Time<br>// *snow            == chanceflurries == chancesnow == flurries == nt_chanceflurries == nt_chancesnow == nt_flurries == nt_snow<br>// *rain            == chancerain  == nt_chancerain  == nt_rain<br>// *sleet           == chancesleet == nt_chancesleet == nt_sleet<br>// *sunny           == clear<br>// *cloudy          == nt_cloudy<br>// *mostlysunny     == partlycloudy == partlysunny == mostlycloudy<br>// *fog             == nt_fog == nt_hazy == hazy<br>// *tstorms         == chancetstorms == nt_tstorms == nt_chancetstorms<br>// *nt_mostlycloudy == nt_mostlysunny == nt_partlycloudy == nt_partlysunny<br>// *nt_clear<br><br>#define icon_width  40<br>#define icon_height 40<br><br>#define DISPLAY_WIDTH 128<br><br>// Define each of the *icons for display<br>const uint8_t snow_icon[] PROGMEM = {<br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, <br>  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x01, 0x00, 0x00, 0x00, <br>  0xFC, 0x00, 0x00, 0x00, 0xC0, 0x78, 0x0C, 0x00, 0x00, 0xD8, 0x30, 0x6C, <br>  0x00, 0x00, 0xF8, 0x30, 0x7C, 0x00, 0x00, 0xF0, 0x31, 0x3E, 0x00, 0x00, <br>  0xF8, 0x7F, 0x3F, 0x00, 0x00, 0x70, 0xFF, 0x7B, 0x00, 0x00, 0x00, 0xCC, <br>  0x00, 0x00, 0x00, 0x00, 0xCC, 0x00, 0x00, 0x00, 0x78, 0xFF, 0x33, 0x00, <br>  0x00, 0xF0, 0xFB, 0x7F, 0x00, 0x00, 0xF0, 0x31, 0x3E, 0x00, 0x00, 0xF8, <br>  0x31, 0x7E, 0x40, 0x00, 0xD8, 0x70, 0x6C, 0xF0, 0x01, 0xC0, 0x78, 0x0C, <br>  0xE0, 0x01, 0x80, 0xFC, 0x00, 0xE5, 0x0C, 0x00, 0xFC, 0x01, 0x4F, 0x3C, <br>  0x00, 0x30, 0x00, 0xCF, 0x1E, 0x00, 0x20, 0x00, 0xFF, 0x3F, 0x00, 0x00, <br>  0x00, 0xB0, 0x01, 0x00, 0x00, 0x00, 0xF1, 0x03, 0x00, 0x00, 0x00, 0xFF, <br>  0x1F, 0x00, 0x00, 0x00, 0x4F, 0x1C, 0x00, 0x00, 0x00, 0xCF, 0x3C, 0x00, <br>  0x00, 0x00, 0xE4, 0x09, 0x00, 0x00, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00, <br>  0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };<br><br>const uint8_t rain_icon[] PROGMEM = {<br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, <br>  0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x78, 0x7A, 0x00, 0x00, 0x00, <br>  0x18, 0xF4, 0x0E, 0x00, 0x00, 0x0C, 0xE0, 0x7F, 0x00, 0x00, 0x0C, 0xC0, <br>  0x7B, 0x00, 0x00, 0x06, 0xA0, 0xEC, 0x00, 0xE0, 0x07, 0x40, 0xE1, 0x0F, <br>  0xF0, 0x07, 0x80, 0xE0, 0x1F, 0x1C, 0x00, 0x00, 0x60, 0x3E, 0x0C, 0x00, <br>  0x00, 0xA0, 0x79, 0x0C, 0x00, 0x00, 0x00, 0x74, 0x04, 0x00, 0x00, 0x00, <br>  0x74, 0x06, 0x00, 0x00, 0x00, 0x48, 0x0C, 0x00, 0x00, 0x00, 0x78, 0x1C, <br>  0x15, 0x45, 0x5A, 0x74, 0xF8, 0xFF, 0xFF, 0xFF, 0x3F, 0xF8, 0xFF, 0xFF, <br>  0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x0E, 0x07, 0x00, 0x00, 0x00, <br>  0x8F, 0x07, 0x00, 0x00, 0x00, 0x8F, 0x07, 0x00, 0x00, 0x00, 0x87, 0x03, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, <br>  0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x1C, <br>  0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };<br><br>const uint8_t sleet_icon[] PROGMEM = {<br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0xE0, 0x3F, 0x00, 0x00, 0x00, <br>  0xF0, 0x3D, 0x00, 0x00, 0x00, 0x38, 0x64, 0x00, 0x00, 0x00, 0x0C, 0xF8, <br>  0x1F, 0x00, 0x00, 0x0C, 0xE0, 0x7F, 0x00, 0x00, 0x04, 0xC0, 0xF9, 0x00, <br>  0xC0, 0x07, 0x40, 0xC5, 0x02, 0xF0, 0x07, 0x80, 0xE0, 0x0F, 0x18, 0x02, <br>  0x00, 0xE0, 0x3D, 0x1C, 0x00, 0x00, 0x40, 0x79, 0x0C, 0x00, 0x00, 0x40, <br>  0x72, 0x0C, 0x00, 0x00, 0x00, 0x68, 0x06, 0x00, 0x00, 0x00, 0x70, 0x04, <br>  0x00, 0x00, 0x00, 0x6C, 0x1C, 0x40, 0xA0, 0x04, 0x74, 0xFC, 0x7F, 0xFF, <br>  0xFF, 0x3F, 0xF0, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x12, 0x08, 0x20, 0x00, <br>  0x00, 0x40, 0x00, 0x08, 0x00, 0x00, 0xC0, 0x38, 0x0C, 0x00, 0x00, 0x60, <br>  0x18, 0x06, 0x00, 0x00, 0x30, 0x18, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x83, 0x01, 0x00, 0x00, <br>  0x0C, 0xC3, 0x00, 0x00, 0x00, 0x86, 0x41, 0x00, 0x00, 0x00, 0x82, 0x61, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };<br><br>const uint8_t sunny_icon[] PROGMEM = {<br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xC0, 0x1C, 0x01, <br>  0x00, 0x00, 0xC0, 0xDC, 0x01, 0x00, 0x00, 0xC6, 0xFF, 0x33, 0x00, 0x00, <br>  0xFC, 0xFF, 0x1F, 0x00, 0x00, 0x7C, 0x6E, 0x3F, 0x00, 0x40, 0xFC, 0xB2, <br>  0x1B, 0x01, 0xC0, 0x9F, 0x02, 0xFD, 0x01, 0x80, 0x1F, 0x48, 0xFC, 0x00, <br>  0x80, 0x5B, 0x08, 0xF8, 0x00, 0x80, 0x03, 0x51, 0xE2, 0x02, 0xF0, 0x0F, <br>  0x01, 0xF1, 0x07, 0xF0, 0xA1, 0xA8, 0x84, 0x07, 0xC0, 0x95, 0x40, 0x81, <br>  0x01, 0xC0, 0x03, 0x2A, 0xF8, 0x03, 0xF8, 0x05, 0x01, 0xC5, 0x0F, 0xF8, <br>  0x60, 0x28, 0x20, 0x0F, 0xE0, 0x03, 0x88, 0xF0, 0x03, 0xC0, 0x53, 0x12, <br>  0xC5, 0x01, 0xE0, 0x88, 0xAA, 0x88, 0x03, 0xF0, 0x17, 0x00, 0xF1, 0x07, <br>  0xF0, 0x17, 0x0A, 0xE8, 0x0B, 0x00, 0x53, 0xA0, 0xE1, 0x00, 0x80, 0x1F, <br>  0x22, 0xFC, 0x00, 0xC0, 0x4F, 0x84, 0xFC, 0x01, 0xC0, 0x6D, 0x02, 0xFB, <br>  0x01, 0x00, 0xFC, 0x76, 0x1F, 0x00, 0x00, 0xFC, 0xF7, 0x3F, 0x00, 0x00, <br>  0xCE, 0xFF, 0x1B, 0x00, 0x00, 0xC0, 0xBD, 0x23, 0x00, 0x00, 0xC0, 0x9C, <br>  0x01, 0x00, 0x00, 0x40, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };<br><br>const uint8_t cloudy_icon[] PROGMEM = {<br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, <br>  0x00, 0xE0, 0x3F, 0x00, 0x00, 0x00, 0xF8, 0x7A, 0x00, 0x00, 0x00, 0x38, <br>  0xF4, 0x0C, 0x00, 0x00, 0x0C, 0xE0, 0x3F, 0x00, 0x00, 0x0C, 0xA0, 0x77, <br>  0x00, 0x00, 0x06, 0xE0, 0xF9, 0x00, 0xE0, 0x07, 0xC0, 0xE8, 0x07, 0xF0, <br>  0x07, 0x00, 0xC0, 0x1F, 0x18, 0x00, 0x00, 0xA0, 0x3D, 0x0C, 0x00, 0x00, <br>  0x60, 0x7A, 0x0C, 0x00, 0x00, 0x00, 0x74, 0x06, 0x00, 0x00, 0x00, 0x68, <br>  0x04, 0x00, 0x00, 0x00, 0x68, 0x0E, 0x00, 0x00, 0x00, 0x64, 0x6C, 0xA6, <br>  0x1A, 0x9A, 0x76, 0xF8, 0xFF, 0xFF, 0xFF, 0x3F, 0xF0, 0xFF, 0xFF, 0xFF, <br>  0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };<br><br>const uint8_t mostlysunny_icon[] PROGMEM = {<br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x48, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, <br>  0x00, 0x00, 0xC0, 0xF7, 0x03, 0x00, 0x00, 0xF0, 0xED, 0x0F, 0x00, 0x00, <br>  0xF6, 0x10, 0x07, 0x00, 0xE0, 0x7F, 0x46, 0x1F, 0x00, 0xF0, 0x7F, 0x41, <br>  0x1E, 0x00, 0x38, 0xE4, 0x55, 0x0E, 0x00, 0x1C, 0xE0, 0x3F, 0x3D, 0x00, <br>  0x0C, 0xD0, 0xFF, 0x1E, 0x00, 0x0C, 0xE0, 0xE7, 0x0C, 0xA0, 0x06, 0x80, <br>  0xD8, 0x1F, 0xF0, 0x07, 0x40, 0xE0, 0x1F, 0x38, 0x04, 0x00, 0xC0, 0x3F, <br>  0x1C, 0x00, 0x00, 0xC0, 0x35, 0x0C, 0x00, 0x00, 0x00, 0x7A, 0x06, 0x00, <br>  0x00, 0x00, 0x68, 0x04, 0x00, 0x00, 0x00, 0x70, 0x06, 0x00, 0x00, 0x00, <br>  0x68, 0x8C, 0x01, 0x84, 0x82, 0x76, 0xFC, 0xFF, 0xFF, 0xFF, 0x3F, 0xF0, <br>  0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };<br><br>const uint8_t fog_icon[] PROGMEM = {<br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x80, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xF0, 0x7D, <br>  0x00, 0x00, 0x00, 0x18, 0xF8, 0x0A, 0x00, 0x00, 0x0C, 0xD0, 0x3F, 0x00, <br>  0x00, 0x0C, 0xA0, 0x77, 0x00, 0x00, 0x06, 0xE0, 0xFB, 0x00, 0xE0, 0x07, <br>  0x40, 0xD8, 0x0F, 0xF0, 0x07, 0xC0, 0xE0, 0x1F, 0x1C, 0x00, 0x00, 0xE0, <br>  0x3A, 0x0C, 0x00, 0x40, 0x40, 0x77, 0x0C, 0x00, 0xF8, 0x01, 0x74, 0x04, <br>  0x00, 0xFE, 0x07, 0x68, 0x04, 0x00, 0x86, 0x7F, 0x78, 0x0E, 0x00, 0x03, <br>  0xFE, 0x65, 0xDC, 0x56, 0x03, 0xFE, 0x7F, 0xFC, 0xFF, 0x03, 0x88, 0x3F, <br>  0xF0, 0xFF, 0x01, 0x80, 0x3F, 0x00, 0x0C, 0x00, 0x80, 0x37, 0x00, 0x0C, <br>  0x00, 0x00, 0x70, 0x00, 0x06, 0x00, 0x00, 0x78, 0x00, 0x0C, 0x00, 0x00, <br>  0x70, 0x00, 0xFC, 0x7B, 0xDD, 0x3F, 0x00, 0xF8, 0xFF, 0xFF, 0x3F, 0x00, <br>  0x80, 0x5A, 0x56, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };<br><br>const uint8_t tstorms_icon[] PROGMEM = {<br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, <br>  0x07, 0x00, 0x00, 0x00, 0xE0, 0x1F, 0x00, 0x00, 0x00, 0xF0, 0x7E, 0x00, <br>  0x00, 0x00, 0x18, 0x68, 0x02, 0x00, 0x00, 0x1C, 0xE0, 0x3F, 0x00, 0x00, <br>  0x0C, 0xD0, 0x7B, 0x00, 0x00, 0x04, 0xA0, 0xED, 0x00, 0xA0, 0x07, 0x80, <br>  0xD1, 0x01, 0xF0, 0x07, 0x40, 0xE0, 0x1F, 0x18, 0x04, 0x00, 0x80, 0x3D, <br>  0x0C, 0x00, 0x00, 0xA0, 0x7A, 0x0C, 0x00, 0x00, 0x00, 0x66, 0x06, 0x00, <br>  0x00, 0x00, 0x78, 0x04, 0x00, 0x00, 0x00, 0x60, 0x0C, 0x00, 0x00, 0x00, <br>  0x74, 0x1C, 0x11, 0x14, 0x21, 0x78, 0xF8, 0xFF, 0xFF, 0xFF, 0x3F, 0xF0, <br>  0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xD7, 0x00, 0x00, 0x00, 0x00, 0xEB, <br>  0x00, 0x00, 0x00, 0x80, 0xF3, 0x03, 0x00, 0x00, 0x80, 0xE5, 0x03, 0x00, <br>  0x00, 0x80, 0xC5, 0x01, 0x00, 0x00, 0xC0, 0xDD, 0x01, 0x00, 0x00, 0xC0, <br>  0xEF, 0x00, 0x00, 0x00, 0xC0, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, <br>  0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, <br>  0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, <br>  0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, <br>  0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };<br><br>const uint8_t nt_mostlycloudy_icon[] PROGMEM = {<br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, <br>  0x00, 0x00, 0x00, 0x9E, 0x0F, 0x00, 0x00, 0x00, 0xBC, 0x1E, 0x00, 0x00, <br>  0x00, 0x70, 0x3B, 0x00, 0x00, 0x00, 0x70, 0xFD, 0x00, 0x00, 0x00, 0xE0, <br>  0xFF, 0x01, 0x00, 0x00, 0xE0, 0xC7, 0x03, 0x00, 0x00, 0xE0, 0x81, 0x7F, <br>  0x00, 0x00, 0xE0, 0x00, 0xFF, 0x00, 0x00, 0xE8, 0x00, 0xDA, 0x01, 0x00, <br>  0xFC, 0x00, 0xA2, 0x1F, 0x00, 0x8E, 0x00, 0x80, 0x3D, 0x00, 0x03, 0x00, <br>  0x80, 0x39, 0x00, 0x03, 0x00, 0x00, 0x74, 0x00, 0x01, 0x00, 0x00, 0x30, <br>  0x00, 0x03, 0x00, 0x00, 0x70, 0xC8, 0xAF, 0xAD, 0xB9, 0x3E, 0xFC, 0xFF, <br>  0xFF, 0xFF, 0x1F, 0xFC, 0xFE, 0x7F, 0xA6, 0x05, 0x78, 0xA4, 0x1E, 0x00, <br>  0x00, 0xF0, 0xDB, 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x80, <br>  0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };<br><br>const uint8_t nt_clear_icon[] PROGMEM = {<br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x01, 0x00, 0x00, <br>  0xC0, 0xFF, 0x07, 0x00, 0x00, 0x00, 0xAF, 0x1F, 0x00, 0x00, 0x00, 0x5E, <br>  0x3E, 0x00, 0x00, 0x00, 0x9C, 0x79, 0x00, 0x00, 0x00, 0x78, 0x76, 0x00, <br>  0x00, 0x00, 0xF0, 0xF9, 0x00, 0x00, 0x00, 0x70, 0xE4, 0x01, 0x00, 0x00, <br>  0x70, 0xC9, 0x01, 0x00, 0x00, 0xE0, 0xB6, 0x03, 0x00, 0x00, 0xE0, 0xAA, <br>  0x03, 0x00, 0x00, 0xE0, 0x98, 0x03, 0x00, 0x00, 0xE0, 0xA5, 0x03, 0x00, <br>  0x00, 0xE0, 0x5A, 0x03, 0x00, 0x00, 0x70, 0x4A, 0x07, 0x00, 0x00, 0x70, <br>  0x95, 0x03, 0x00, 0x00, 0xF8, 0x5A, 0x03, 0x00, 0x00, 0x38, 0xA8, 0x03, <br>  0x00, 0x00, 0x3C, 0xA9, 0x03, 0x00, 0x00, 0xCF, 0x96, 0x01, 0x00, 0x80, <br>  0x5F, 0xD5, 0x01, 0x80, 0xFA, 0xAB, 0xEA, 0x01, 0xC0, 0xFF, 0x59, 0xF2, <br>  0x00, 0x80, 0xBF, 0x86, 0x7D, 0x00, 0x00, 0x67, 0xAA, 0x7E, 0x00, 0x00, <br>  0xBE, 0x54, 0x1E, 0x00, 0x00, 0xFC, 0xF3, 0x0F, 0x00, 0x00, 0xF0, 0xFF, <br>  0x07, 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, <br>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };<br><br>String apikey   = &quot;your Weather Underground API key&quot;;<br>String country  = &quot;your country&quot;; //e.g. &quot;UK&quot;;<br>String city     = &quot;your city&quot;;    //e.g. &quot;LONDON&quot;;<br><br>const char* host     = &quot;api.wunderground.com&quot;;<br>const char* ssid     = &quot;your SSID&quot;;<br>const char* password = &quot;password&quot;;<br><br>unsigned long        lastConnectionTime = 0;          // Last time you connected to the server, in milliseconds<br>const unsigned long  postingInterval = 30L*60L*1000L; // Delay between updates, in milliseconds, WU allows 500 requests per-day maximum, this sets it to every 30-mins or 48/day<br> <br>String currCondString, time_str; // strings to hold received API weather data and current time<br><br>SH1106Wire display(0x3c, 5,4); // OLED display object definition (address, SDA, SCL)<br>OLEDDisplayUi ui     ( &amp;display );<br><br>WiFiClient client; // wifi client object<br><br>void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {<br>  struct tm timeinfo;<br>  if(!getLocalTime(&amp;timeinfo)){<br>    Serial.println(&quot;Failed to obtain time&quot;);<br>    return;<br>  }<br>  //See http://www.cplusplus.com/reference/ctime/strftime/<br>  time_str = asctime(&amp;timeinfo); // Displays: Sat Jun 24 14:05:49 2017<br>  display-&gt;setTextAlignment(TEXT_ALIGN_CENTER); // The coordinates define the center of the screen!<br>  if (time_str.substring(0,3) ==&quot;Sun&quot;) display-&gt;drawString(64,0,&quot;Sunday&quot;);<br>  if (time_str.substring(0,3) ==&quot;Mon&quot;) display-&gt;drawString(64,0,&quot;Monday&quot;);<br>  if (time_str.substring(0,3) ==&quot;Tue&quot;) display-&gt;drawString(64,0,&quot;Tuesday&quot;);<br>  if (time_str.substring(0,3) ==&quot;Wed&quot;) display-&gt;drawString(64,0,&quot;Wednesday&quot;);<br>  if (time_str.substring(0,3) ==&quot;Thu&quot;) display-&gt;drawString(64,0,&quot;Thursday&quot;);<br>  if (time_str.substring(0,3) ==&quot;Fri&quot;) display-&gt;drawString(64,0,&quot;Friday&quot;);<br>  if (time_str.substring(0,3) ==&quot;Sat&quot;) display-&gt;drawString(64,0,&quot;Saturday&quot;);<br>  display-&gt;drawString(18,53,time_str.substring(4,10));<br>  display-&gt;drawString(107,53,time_str.substring(11,19));<br>  display-&gt;drawLine(0, 12, DISPLAY_WIDTH-1, 12);<br>}<br><br>void drawFrame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {<br>  struct tm timeinfo;<br>  if(!getLocalTime(&amp;timeinfo)){<br>    Serial.println(&quot;Failed to obtain time&quot;);<br>    return;<br>  }<br>  //See http://www.cplusplus.com/reference/ctime/strftime/<br>  time_str = asctime(&amp;timeinfo); // Displays: Sat Jun 24 14:05:49 2017<br>  display-&gt;setTextAlignment(TEXT_ALIGN_CENTER); // The coordinates define the center of the screen!<br>  display-&gt;drawString(x+64,y+25,time_str.substring(0,16));<br>  display-&gt;drawString(x+64,y+35,time_str.substring(20));<br>  display-&gt;setFont(ArialMT_Plain_10);<br>}<br><br>void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {<br>  if(CurrCondObj(currCondString)) {<br>    display-&gt;setFont(ArialMT_Plain_10);<br>    String icon = getWeatherIcon();<br>    // The icons are drawn within a 40x20 box, each position can be slighly diiferent depending on icon shape<br>    if (icon == &quot;snow&quot; ||<br>        icon == &quot;chanceflurries&quot; ||<br>        icon == &quot;chancesnow&quot; ||<br>        icon == &quot;flurries&quot; ||<br>        icon == &quot;nt_chanceflurries&quot; ||<br>        icon == &quot;nt_chancesnow&quot; ||<br>        icon == &quot;nt_flurries&quot; || <br>        icon == &quot;nt_snow&quot;) display-&gt;drawXbm(x+0,y+20, icon_width, icon_height, snow_icon);<br>    if (icon == &quot;rain&quot; ||<br>        icon == &quot;chancerain&quot; ||<br>        icon == &quot;nt_chancerain&quot; ||<br>        icon == &quot;nt_rain&quot;) display-&gt;drawXbm(x+0,y+20, icon_width, icon_height, rain_icon);<br>    if (icon == &quot;sleet&quot; ||<br>        icon == &quot;chancesleet&quot; ||<br>        icon == &quot;nt_chancesleet&quot; ||<br>        icon == &quot;nt_sleet&quot;) display-&gt;drawXbm(x+0,y+20, icon_width, icon_height, sleet_icon);<br>    if (icon == &quot;sunny&quot; || <br>        icon == &quot;clear&quot;) display-&gt;drawXbm(x+0,y+20, icon_width, icon_height, sunny_icon);<br>    if (icon == &quot;cloudy&quot; ||<br>        icon == &quot;nt_cloudy&quot;) display-&gt;drawXbm(x+0,y+20, icon_width, icon_height, cloudy_icon);<br>    if (icon == &quot;mostlysunny&quot; ||<br>        icon == &quot;partlycloudy&quot; ||<br>        icon == &quot;partlysunny&quot; ||<br>        icon == &quot;mostlycloudy&quot;) display-&gt;drawXbm(x+0,y+20, icon_width, icon_height, mostlysunny_icon);<br>    if (icon == &quot;fog&quot; || <br>        icon == &quot;nt_fog&quot; ||<br>        icon == &quot;nt_hazy&quot; ||<br>        icon == &quot;hazy&quot;) display-&gt;drawXbm(x+0,y+20, icon_width, icon_height, fog_icon);<br>    if (icon == &quot;tstorms&quot; ||<br>        icon == &quot;chancetstorms&quot; ||<br>        icon == &quot;nt_tstorms&quot; || <br>        icon == &quot;nt_chancetstorms&quot;) display-&gt;drawXbm(x+0,y+20, icon_width, icon_height, tstorms_icon);<br>    if (icon == &quot;nt_mostlycloudy&quot; ||<br>        icon == &quot;nt_mostlysunny&quot; || <br>        icon == &quot;nt_partlycloudy&quot; ||<br>        icon == &quot;nt_partlysunny&quot;) display-&gt;drawXbm(x+0,y+20, icon_width, icon_height, nt_mostlycloudy_icon);<br>    if (icon == &quot;nt_clear&quot;) display-&gt;drawXbm(x+0,y+20, icon_width, icon_height, nt_clear_icon);<br>    //display-&gt;drawRect(0,23,40,33); // Icon alignment rectangle<br>    display-&gt;setTextAlignment(TEXT_ALIGN_RIGHT);<br>    display-&gt;drawString(x+128,y+12,&quot;At: &quot;+getLocalTime().substring(0,12)+getLocalTime().substring(14,22)); <br>    display-&gt;drawString(x+128,y+24,getCurrWeather());<br>    display-&gt;drawString(x+128,y+36,getCurrC()+&quot;°C / &quot;+getRelHum()); // use getCurrF for fahrenheit<br>  }<br>}<br><br>void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {<br>  if(CurrCondObj(currCondString)) {<br>    display-&gt;drawString(x+64,y+12,getWindDir()+&quot; @ &quot;+getWindMPH()+&quot;mph&quot;);<br>    display-&gt;drawString(x+64,y+24,getPressure_mb()+&quot;mB [&quot;+display_Ptrend(getPressure_trend())+&quot;]&quot;); // &#39;-&#39; for falling &#39;0&#39; for no change and &#39;+&#39; for rising<br>    display-&gt;drawString(x+64,y+36,getDewPointC()+&quot;°C Dewpoint&quot;);<br>  }<br>}<br><br>String display_Ptrend(String indicator){<br>  if (indicator == &quot;+&quot;)return &quot;Rising&quot;;<br>   else if (indicator == &quot;-&quot;) return &quot;Falling&quot;;<br>     else return &quot;Steady&quot;;<br>}<br><br>void drawFrame4(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {<br>  if(CurrCondObj(currCondString)) {<br>    display-&gt;drawString(x+64,y+15,&quot;Visibility: &quot;+getVisibility_mi()+&quot; miles&quot;);<br>    display-&gt;drawString(x+64,y+30,getPrecipTodayString()+&quot; Rain&quot;);<br>  }<br>}<br><br>// This array keeps function pointers to all frames frames are the single views that slide in<br>FrameCallback frames[] = { drawFrame1, drawFrame2, drawFrame3, drawFrame4 };<br><br>// how many frames are there?<br>int frameCount = 4;<br><br>// Overlays are statically drawn on top of a frame eg. a clock<br>OverlayCallback overlays[] = { msOverlay };<br>int overlaysCount = 1;<br><br>void setup() { <br>  Serial.begin(115200);<br>    // The ESP is capable of rendering 60fps in 80Mhz mode but that won&#39;t give you much time for anything else run it in 160Mhz mode or just set it to 30 fps<br>  ui.setTargetFPS(30);<br>  // Customize the active and inactive symbol<br>//  ui.setActiveSymbol(activeSymbol);<br>//  ui.setInactiveSymbol(inactiveSymbol);<br>  // You can change this to TOP, LEFT, BOTTOM, RIGHT<br>  ui.setIndicatorPosition(BOTTOM);<br>  // Defines where the first frame is located in the bar.<br>  ui.setIndicatorDirection(LEFT_RIGHT);<br>  // You can change the transition that is used SLIDE_LEFT, SLIDE_RIGHT, SLIDE_UP, SLIDE_DOWN<br>  ui.setFrameAnimation(SLIDE_LEFT);<br>  // Add frames<br>  ui.setFrames(frames, frameCount);<br>  // Add overlays<br>  ui.setOverlays(overlays, overlaysCount);<br>  // Initialising the UI will init the display too.<br>  ui.init();<br>  display.flipScreenVertically();<br>  Start_WiFi(ssid,password);<br>  configTime(1, 3600, &quot;pool.ntp.org&quot;);<br>  lastConnectionTime = millis();<br>  Call_API(currCondString);      // Get data with an API call and place response in a String<br>}<br> <br>void loop() {<br>  int remainingTimeBudget = ui.update();<br>  if (remainingTimeBudget &gt; 0) {<br>    // You can do some work here<br>    // Don&#39;t do stuff if you are below your<br>    // time budget.<br>    if (millis() - lastConnectionTime &gt; postingInterval) {<br>      Call_API(currCondString);      // Get data with an API call and place response in a String<br>      Serial.println(currCondString); // Display the response<br>      lastConnectionTime = millis();<br>    }<br>    delay(remainingTimeBudget);<br>  }<br>}<br> <br>int Start_WiFi(const char* ssid, const char* password){<br> int connAttempts = 0;<br> Serial.println(&quot;\r\nConnecting to: &quot;+String(ssid));<br> WiFi.begin(ssid, password);<br> while (WiFi.status() != WL_CONNECTED ) {<br>   delay(500);<br>   Serial.print(&quot;.&quot;);<br>   if(connAttempts &gt; 20) return -5;<br>   connAttempts++;<br> }<br> Serial.println(&quot;WiFi connected\r\n&quot;);<br> Serial.print(&quot;IP address: &quot;);<br> Serial.println(WiFi.localIP());<br> return 1;<br>}<br> <br>int Call_API(String &amp;resultString) {<br>  client.stop();  // Clear any current connections<br>  Serial.println(&quot;Connecting to &quot;+String(host)); // start a new connection<br>  const int httpPort = 80;<br>  if (!client.connect(host, httpPort)) {<br>   Serial.println(&quot;Connection failed&quot;);<br>   return false;<br>  }<br>  // Weather Underground API address http://api.wunderground.com/api/YOUR_API_KEY/conditions/q/YOUR_STATE/YOUR_CITY.json<br>  String url = &quot;http://api.wunderground.com/api/&quot;+apikey+&quot;/conditions/q/&quot;+country+&quot;/&quot;+city+&quot;.json&quot;;<br>  Serial.println(&quot;Requesting URL: &quot;+String(url));<br>  client.print(String(&quot;GET &quot;) + url + &quot; HTTP/1.1\r\n&quot; +<br>  &quot;Host: &quot; + host + &quot;\r\n&quot; +<br>  &quot;Connection: close\r\n\r\n&quot;);<br>  unsigned long timeout = millis();<br>  while (client.available() == 0) {<br>    if (millis() - timeout &gt; 5000) {<br>      Serial.println(&quot;&gt;&gt;&gt; Client Connection Timeout...Stopping&quot;);<br>      client.stop();<br>      return false;<br>    }<br>  }<br>  Serial.print(&quot;Receiving API weather data&quot;);<br>  while(client.available()) {<br>    resultString = client.readStringUntil(&#39;\r&#39;);<br>    Serial.print(&quot;.&quot;);<br>  }<br>  Serial.println(&quot;\r\nClosing connection&quot;);<br>  return true;<br>}<br><br>bool  api_error;<br>const char* CurrentObservation_location_full;<br>const char* CurrentObservation_location_city;<br>const char* CurrentObservation_location_state;<br>const char* CurrentObservation_location_state_name;<br>const char* CurrentObservation_location_zip;<br>const char* CurrentObservation_location_country;<br>const char* CurrentObservation_location_country_iso3166;<br>const char* CurrentObservation_latitude;<br>const char* CurrentObservation_longitude;<br>const char* CurrentObservation_elevation;<br>const char* CurrentObservation_local_time_rfc822;<br>const char* CurrentObservation_observation_time;<br>const char* CurrentObservation_weather;<br>const char* CurrentObservation_temperature_string;<br>const char* CurrentObservation_temp_f;<br>const char* CurrentObservation_temp_c;<br>const char* CurrentObservation_dewpoint_f;<br>const char* CurrentObservation_dewpoint_c;<br>const char* CurrentObservation_heat_index_f;<br>const char* CurrentObservation_heat_index_c;<br>const char* CurrentObservation_windchill_f;<br>const char* CurrentObservation_windchill_c;<br>const char* CurrentObservation_relative_humidity;<br>const char* CurrentObservation_wind_string;<br>const char* CurrentObservation_wind_mph;<br>const char* CurrentObservation_wind_kph;<br>const char* CurrentObservation_wind_dir;<br>const char* CurrentObservation_wind_degrees;<br>const char* CurrentObservation_visibility_mi;<br>const char* CurrentObservation_visibility_km;<br>const char* CurrentObservation_pressure_mb;<br>const char* CurrentObservation_pressure_in;<br>const char* CurrentObservation_pressure_trend;<br>const char* CurrentObservation_precip_today_string;<br>const char* CurrentObservation_precip_today_in;<br>const char* CurrentObservation_precip_today_metric;<br>const char* CurrentObservation_icon;<br><br>bool  CurrCondObj(String currCondString){<br>  api_error = false;<br>  // When using a StaticJsonBuffer you must allocate sufficient memory for the json string returned by the WU api<br>  Serial.println(&quot;Creating object...&quot;);<br>  JsonDocument jsonBuffer;<br>  // Create root object and parse the json file returned from the api. The API returns errors and these need to be checked to ensure successful decoding<br>  deserializeJson(jsonBuffer, currCondString);<br>  JsonObject root = jsonBuffer.as&lt;JsonObject&gt;();<br>  auto error = deserializeJson(jsonBuffer, currCondString);<br>  if(!error) {<br>    Serial.println(&quot;root object created...&quot;);<br>    JsonObject CurrentObservation = root[&quot;current_observation&quot;];<br>    if(!error) {<br>      Serial.println(&quot;CurrentObservation object created...&quot;);<br>      // Now process the  &quot;display_location&quot;:<br>      JsonObject CurrentObservation_display_location     = CurrentObservation[&quot;display_location&quot;]; // Set root location<br>      <br>      CurrentObservation_location_full            = CurrentObservation_display_location[&quot;full&quot;]; <br>      CurrentObservation_location_city            = CurrentObservation_display_location[&quot;city&quot;];<br>      CurrentObservation_location_state           = CurrentObservation_display_location[&quot;state&quot;]; <br>      CurrentObservation_latitude                 = CurrentObservation_display_location[&quot;latitude&quot;]; <br>      CurrentObservation_longitude                = CurrentObservation_display_location[&quot;longitude&quot;]; <br>      CurrentObservation_elevation                = CurrentObservation_display_location[&quot;elevation&quot;]; <br>      CurrentObservation_location_state_name      = CurrentObservation_display_location[&quot;state_name&quot;]; <br>      CurrentObservation_location_country         = CurrentObservation_display_location[&quot;country&quot;]; <br>      CurrentObservation_location_country_iso3166 = CurrentObservation_display_location[&quot;country_iso3166&quot;]; <br>      CurrentObservation_location_zip             = CurrentObservation_display_location[&quot;zip&quot;]; <br>      <br>      CurrentObservation_local_time_rfc822        = CurrentObservation[&quot;local_time_rfc822&quot;]; <br>      CurrentObservation_observation_time         = CurrentObservation[&quot;observation_time&quot;]; <br>      CurrentObservation_weather                  = CurrentObservation[&quot;weather&quot;]; <br>      CurrentObservation_temperature_string       = CurrentObservation[&quot;temperature_string&quot;]; <br>      CurrentObservation_temp_f                   = CurrentObservation[&quot;temp_f&quot;]; <br>      CurrentObservation_temp_c                   = CurrentObservation[&quot;temp_c&quot;]; <br>      CurrentObservation_dewpoint_f               = CurrentObservation[&quot;dewpoint_f&quot;]; <br>      CurrentObservation_dewpoint_c               = CurrentObservation[&quot;dewpoint_c&quot;]; <br>      CurrentObservation_heat_index_f             = CurrentObservation[&quot;heat_index_f&quot;]; <br>      CurrentObservation_heat_index_c             = CurrentObservation[&quot;heat_index_c&quot;]; <br>      CurrentObservation_windchill_f              = CurrentObservation[&quot;windchill_f&quot;]; <br>      CurrentObservation_windchill_c              = CurrentObservation[&quot;windchill_c&quot;];       <br>      CurrentObservation_relative_humidity        = CurrentObservation[&quot;relative_humidity&quot;]; <br>      CurrentObservation_wind_string              = CurrentObservation[&quot;wind_string&quot;]; <br>      CurrentObservation_wind_mph                 = CurrentObservation[&quot;wind_mph&quot;]; <br>      CurrentObservation_wind_kph                 = CurrentObservation[&quot;wind_kph&quot;]; <br>      CurrentObservation_wind_dir                 = CurrentObservation[&quot;wind_dir&quot;]; <br>      CurrentObservation_wind_degrees             = CurrentObservation[&quot;wind_degrees&quot;]; <br>      CurrentObservation_pressure_mb              = CurrentObservation[&quot;pressure_mb&quot;]; <br>      CurrentObservation_pressure_in              = CurrentObservation[&quot;pressure_in&quot;]; <br>      CurrentObservation_pressure_trend           = CurrentObservation[&quot;pressure_trend&quot;]; <br>      CurrentObservation_precip_today_string      = CurrentObservation[&quot;precip_today_string&quot;]; <br>      CurrentObservation_precip_today_in          = CurrentObservation[&quot;precip_today_in&quot;];<br>      CurrentObservation_precip_today_metric      = CurrentObservation[&quot;precip_today_metric&quot;]; <br>      CurrentObservation_visibility_mi            = CurrentObservation[&quot;visibility_mi&quot;];<br>      CurrentObservation_visibility_km            = CurrentObservation[&quot;visibility_km&quot;];<br>      CurrentObservation_icon                     = CurrentObservation[&quot;icon&quot;]; <br>      return true;<br>    }<br>    else<br>    {<br>      // if the object could not be created, then return an error make an API call the next time around<br>      Serial.println(&quot;Unable to obtain current observation object&quot;);<br>      api_error = true;<br>      return false;<br>    }<br>  }<br>  else<br>  {<br>    // if the root object could not be created, then return an error make an API call the next time around<br>    Serial.println(&quot;Unable to create a root object&quot;);<br>    api_error = true;<br>    return false;<br>  }<br>}<br><br>// Functions for weather data.<br>String getCountry()          {return CurrentObservation_location_country;}<br>String getCity()             {return CurrentObservation_location_city;}<br>String getCityState()        {return CurrentObservation_location_full;}<br>String getState()            {return CurrentObservation_location_state_name;}<br>String getZip()              {return CurrentObservation_location_zip;}<br>String getLatitude()         {return CurrentObservation_latitude;}<br>String getLongitude()        {return CurrentObservation_longitude;}<br>String getElevation()        {return CurrentObservation_elevation;}; <br>String getLocalTime()        {return CurrentObservation_local_time_rfc822;}<br>String getObsTime()          {return CurrentObservation_observation_time;}<br>String getCurrWeather()      {return CurrentObservation_weather;}<br>String getCurrTempString()   {return CurrentObservation_temperature_string;}<br>String getCurrF()            {return CurrentObservation_temp_f;}<br>String getCurrC()            {return CurrentObservation_temp_c;}<br>String getDewPointF()        {return CurrentObservation_dewpoint_f;}<br>String getDewPointC()        {return CurrentObservation_dewpoint_c;}<br>String getHeatindexF()       {return CurrentObservation_heat_index_f;}<br>String getHeatindexC()       {return CurrentObservation_heat_index_c;}<br>String getWindchillF()       {return CurrentObservation_windchill_f;}<br>String getWindchillC()       {return CurrentObservation_windchill_c;}<br>String getRelHum()           {return CurrentObservation_relative_humidity;}<br>String getWindString()       {return CurrentObservation_wind_string;}<br>String getWindMPH()          {return CurrentObservation_wind_mph;}<br>String getWindKPH()          {return CurrentObservation_wind_kph;}<br>String getWindDir()          {return CurrentObservation_wind_dir;}<br>String getWindDegrees()      {return CurrentObservation_wind_degrees;}<br>String getPressure_mb()      {return CurrentObservation_pressure_mb;}<br>String getPressure_in()      {return CurrentObservation_pressure_in;}<br>String getPressure_trend()   {return CurrentObservation_pressure_trend;}<br>String getPrecipTodayString(){return CurrentObservation_precip_today_string;}<br>String getPrecipTodayInches(){return CurrentObservation_precip_today_in;}<br>String getPrecipTodayMet()   {return CurrentObservation_precip_today_metric;}<br>String getVisibility_mi()    {return CurrentObservation_visibility_mi;}<br>String getVisibility_km()    {return CurrentObservation_visibility_km;}<br>String getWeatherIcon()      {return CurrentObservation_icon;}<br><br>/* Typical API response:<br>{<br>  &quot;response&quot;: {<br>  &quot;version&quot;:&quot;0.1&quot;,<br>  &quot;termsofService&quot;:&quot;http://www.wunderground.com/weather/api/d/terms.html&quot;,<br>  &quot;features&quot;: {<br>  &quot;conditions&quot;: 1<br>  }<br>  }<br>  , &quot;CurrentObservation&quot;: {<br>    &quot;image&quot;: {<br>    &quot;url&quot;:&quot;http://icons.wxug.com/graphics/wu2/logo_130x80.png&quot;,<br>    &quot;title&quot;:&quot;Weather Underground&quot;,<br>    &quot;link&quot;:&quot;http://www.wunderground.com&quot;<br>    },<br>    &quot;display_location&quot;: {<br>    &quot;full&quot;:&quot;Bath, United Kingdom&quot;,<br>    &quot;city&quot;:&quot;Bath&quot;,<br>    &quot;state&quot;:&quot;WIL&quot;,<br>    &quot;state_name&quot;:&quot;United Kingdom&quot;,<br>    &quot;country&quot;:&quot;UK&quot;,<br>    &quot;country_iso3166&quot;:&quot;GB&quot;,<br>    &quot;zip&quot;:&quot;00000&quot;,<br>    &quot;magic&quot;:&quot;58&quot;,<br>    &quot;wmo&quot;:&quot;03740&quot;,<br>    &quot;latitude&quot;:&quot;51.36999893&quot;,<br>    &quot;longitude&quot;:&quot;-2.14000010&quot;,<br>    &quot;elevation&quot;:&quot;64.0&quot;<br>    },<br>    &quot;observation_location&quot;: {<br>    &quot;full&quot;:&quot;Bath, Bath, &quot;,<br>    &quot;city&quot;:&quot;Bath, Bath&quot;,<br>    &quot;state&quot;:&quot;&quot;,<br>    &quot;country&quot;:&quot;GB&quot;,<br>    &quot;country_iso3166&quot;:&quot;GB&quot;,<br>    &quot;latitude&quot;:&quot;51.364689&quot;,<br>    &quot;longitude&quot;:&quot;-2.129354&quot;,<br>    &quot;elevation&quot;:&quot;131 ft&quot;<br>    },<br>    &quot;estimated&quot;: {<br>    },<br>    &quot;station_id&quot;:&quot;IBATH2&quot;,<br>    &quot;observation_time&quot;:&quot;Last Updated on June 21, 9:00 AM BST&quot;,<br>    &quot;observation_time_rfc822&quot;:&quot;Wed, 21 Jun 2017 09:00:16 +0100&quot;,<br>    &quot;observation_epoch&quot;:&quot;1498032016&quot;,<br>    &quot;local_time_rfc822&quot;:&quot;Wed, 21 Jun 2017 09:09:36 +0100&quot;,<br>    &quot;local_epoch&quot;:&quot;1498032576&quot;,<br>    &quot;local_tz_short&quot;:&quot;BST&quot;,<br>    &quot;local_tz_long&quot;:&quot;Europe/London&quot;,<br>    &quot;local_tz_offset&quot;:&quot;+0100&quot;,<br>    &quot;weather&quot;:&quot;Clear&quot;,<br>    &quot;temperature_string&quot;:&quot;70.6 F (21.4 C)&quot;,<br>    &quot;temp_f&quot;:70.6,<br>    &quot;temp_c&quot;:21.4,<br>    &quot;relative_humidity&quot;:&quot;82%&quot;,<br>    &quot;wind_string&quot;:&quot;From the ENE at 2.3 MPH Gusting to 6.0 MPH&quot;,<br>    &quot;wind_dir&quot;:&quot;ENE&quot;,<br>    &quot;wind_degrees&quot;:71,<br>    &quot;wind_mph&quot;:2.3,<br>    &quot;wind_gust_mph&quot;:&quot;6.0&quot;,<br>    &quot;wind_kph&quot;:3.7,<br>    &quot;wind_gust_kph&quot;:&quot;9.7&quot;,<br>    &quot;pressure_mb&quot;:&quot;1016&quot;,<br>    &quot;pressure_in&quot;:&quot;30.01&quot;,<br>    &quot;pressure_trend&quot;:&quot;-&quot;,<br>    &quot;dewpoint_string&quot;:&quot;65 F (18 C)&quot;,<br>    &quot;dewpoint_f&quot;:65,<br>    &quot;dewpoint_c&quot;:18,<br>    &quot;heat_index_string&quot;:&quot;NA&quot;,<br>    &quot;heat_index_f&quot;:&quot;NA&quot;,<br>    &quot;heat_index_c&quot;:&quot;NA&quot;,<br>    &quot;windchill_string&quot;:&quot;NA&quot;,<br>    &quot;windchill_f&quot;:&quot;NA&quot;,<br>    &quot;windchill_c&quot;:&quot;NA&quot;,<br>    &quot;feelslike_string&quot;:&quot;70.6 F (21.4 C)&quot;,<br>    &quot;feelslike_f&quot;:&quot;70.6&quot;,<br>    &quot;feelslike_c&quot;:&quot;21.4&quot;,<br>    &quot;visibility_mi&quot;:&quot;7&quot;,<br>    &quot;visibility_km&quot;:&quot;11&quot;,<br>    &quot;solarradiation&quot;:&quot;--&quot;,<br>    &quot;UV&quot;:&quot;-1&quot;,&quot;precip_1hr_string&quot;:&quot;0.00 in ( 0 mm)&quot;,<br>    &quot;precip_1hr_in&quot;:&quot;0.00&quot;,<br>    &quot;precip_1hr_metric&quot;:&quot; 0&quot;,<br>    &quot;precip_today_string&quot;:&quot;0.00 in (0 mm)&quot;,<br>    &quot;precip_today_in&quot;:&quot;0.00&quot;,<br>    &quot;precip_today_metric&quot;:&quot;0&quot;,<br>    &quot;soil_temp_f&quot;: &quot;-88.0&quot;,<br>    &quot;soil_moisture&quot;: &quot;1.0&quot;,<br>    &quot;leaf_wetness&quot;: &quot;4.0&quot;,<br>    &quot;icon&quot;:&quot;clear&quot;,<br>    &quot;icon_url&quot;:&quot;http://icons.wxug.com/i/c/k/clear.gif&quot;,<br>    &quot;forecast_url&quot;:&quot;http://www.wunderground.com/global/stations/03740.html&quot;,<br>    &quot;history_url&quot;:&quot;http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IMELKSHA2&quot;,<br>    &quot;ob_url&quot;:&quot;http://www.wunderground.com/cgi-bin/findweather/getForecast?query=51.364689,-2.129354&quot;,<br>    &quot;nowcast&quot;:&quot;&quot;<br>  }<br>}<br>*/</pre><p>Building your Smart Clock is just the beginning. This project opens the door to countless other possibilities in the world of IoT and embedded systems. Whether you choose to enhance your clock with additional features or move on to new projects, the skills and knowledge you gain here will serve as a solid foundation for your future endeavors.</p><p>So, gear up, dive into the details, and turn your vision of a futuristic timepiece into reality. Stay tuned for more exciting projects and tutorials in our “Bits &amp; Bots” blog series. Happy building!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34ab3e31b952" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with MQTT on ESP32/ESP8266]]></title>
            <link>https://medium.com/@vaibhav01gour/getting-started-with-mqtt-on-esp32-esp8266-2a2cf916503f?source=rss-7a8a7aa11d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a2cf916503f</guid>
            <category><![CDATA[mqtt]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Bits&Bots]]></dc:creator>
            <pubDate>Sun, 19 May 2024 17:57:14 GMT</pubDate>
            <atom:updated>2024-05-19T17:57:14.560Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><p>Ever wondered how your smart devices communicate with each other so efficiently? In the realm of IoT, seamless communication is key to creating interconnected systems that can share data and respond to commands in real-time. One of the most effective protocols for such communication is MQTT (Message Queuing Telemetry Transport). Designed specifically for lightweight, low-bandwidth communication, MQTT is a perfect fit for IoT applications. In this tutorial, we’ll delve into how to set up MQTT on the ESP32 and ESP8266 microcontrollers, enabling them to interact with other devices and cloud platforms with ease.</p><h4>Understanding the Basics</h4><p><strong>What is MQTT?</strong></p><p>MQTT is a publish/subscribe messaging protocol that was designed for constrained devices and low-bandwidth, high-latency networks. Unlike traditional client-server communication, MQTT follows a publish/subscribe model, where devices (clients) publish messages to topics or subscribe to topics to receive messages. An MQTT broker manages these topics and routes messages between clients.</p><p>Key Features of MQTT:</p><ul><li>Lightweight: MQTT messages are small, reducing the bandwidth required for communication.</li><li>Publish/Subscribe Model: This model allows multiple clients to communicate with each other indirectly through the broker.</li><li>Quality of Service (QoS): MQTT supports three levels of QoS to ensure reliable message delivery.</li><li>Retained Messages: Brokers can store the last message sent to a topic, ensuring new subscribers receive the most recent message.</li><li>Last Will and Testament (LWT): Clients can specify a message that the broker sends if it detects that the client has disconnected unexpectedly.</li></ul><p><strong>Benefits of Using MQTT:</strong></p><ol><li>Low Bandwidth Usage: MQTT’s lightweight nature makes it ideal for applications where bandwidth is limited or expensive.</li><li>Efficient Communication: The publish/subscribe model allows for efficient, real-time communication between many devices.</li><li>Reliability: MQTT ensures that messages are delivered reliably, even in unreliable network conditions.</li><li>Scalability: MQTT can easily scale to handle a large number of devices, making it suitable for extensive IoT deployments.</li></ol><p><strong>Why Use ESP32/ESP8266 with MQTT?</strong></p><p>The ESP32 and ESP8266 microcontrollers are widely used in IoT projects due to their built-in Wi-Fi capabilities, low cost, and ease of use. Integrating MQTT with these microcontrollers brings several advantages:</p><ul><li>Wireless Connectivity: Both ESP32 and ESP8266 have built-in Wi-Fi modules, making it easy to connect to MQTT brokers over the internet.</li><li>Low Power Consumption: These microcontrollers are designed to operate efficiently, conserving power during idle periods.</li><li>Rich Ecosystem: There is extensive community support and a wealth of libraries and resources available for both ESP32 and ESP8266, simplifying the development process.</li><li>Flexibility: With support for various sensors and peripherals, these microcontrollers can be used in a wide range of applications, from home automation to industrial monitoring.</li></ul><h4><strong>Hands on MQTT</strong></h4><p>Gear up and get ready to ignite your project! Here’s some code to help you understand how the MQTT protocol works in action:</p><pre>#include &lt;WiFi.h&gt;  // For ESP32<br>//#include &lt;ESP8266WiFi.h&gt;  // Uncomment for ESP8266<br>#include &lt;PubSubClient.h&gt;<br><br>// WiFi credentials<br>const char* ssid = &quot;your_SSID&quot;;<br>const char* password = &quot;your_PASSWORD&quot;;<br><br>// MQTT broker address<br>const char* mqtt_server = &quot;test.mosquitto.org&quot;;<br><br>WiFiClient espClient;<br>PubSubClient client(espClient);<br><br>// Callback function to handle incoming messages<br>void callback(char* topic, byte* payload, unsigned int length) {<br>  Serial.print(&quot;Message arrived [&quot;);<br>  Serial.print(topic);<br>  Serial.print(&quot;] &quot;);<br>  for (int i = 0; i &lt; length; i++) {<br>    Serial.print((char)payload[i]);<br>  }<br>  Serial.println();<br>}<br><br>void setup() {<br>  Serial.begin(115200);<br>  setup_wifi();<br>  client.setServer(mqtt_server, 1883);<br>  client.setCallback(callback);<br>}<br><br>void setup_wifi() {<br>  delay(10);<br>  Serial.println();<br>  Serial.print(&quot;Connecting to &quot;);<br>  Serial.println(ssid);<br>  <br>  WiFi.begin(ssid, password);<br><br>  while (WiFi.status() != WL_CONNECTED) {<br>    delay(500);<br>    Serial.print(&quot;.&quot;);<br>  }<br><br>  Serial.println(&quot;&quot;);<br>  Serial.println(&quot;WiFi connected&quot;);<br>  Serial.println(&quot;IP address: &quot;);<br>  Serial.println(WiFi.localIP());<br>}<br><br>void reconnect() {<br>  while (!client.connected()) {<br>    Serial.print(&quot;Attempting MQTT connection...&quot;);<br>    if (client.connect(&quot;ESP32Client&quot;)) {  // Change to &quot;ESP8266Client&quot; for ESP8266<br>      Serial.println(&quot;connected&quot;);<br>      client.subscribe(&quot;test/topic&quot;);<br>    } else {<br>      Serial.print(&quot;failed, rc=&quot;);<br>      Serial.print(client.state());<br>      Serial.println(&quot; try again in 5 seconds&quot;);<br>      delay(5000);<br>    }<br>  }<br>}<br><br>void loop() {<br>  if (!client.connected()) {<br>    reconnect();<br>  }<br>  client.loop();<br><br>  // Example: Publish a message every 10 seconds<br>  static unsigned long lastMsg = 0;<br>  unsigned long now = millis();<br>  if (now - lastMsg &gt; 10000) {<br>    lastMsg = now;<br>    String msg = &quot;Hello from ESP32/ESP8266&quot;;<br>    Serial.print(&quot;Publish message: &quot;);<br>    Serial.println(msg);<br>    client.publish(&quot;test/topic&quot;, msg.c_str());<br>  }<br>}</pre><p>By integrating MQTT with the ESP32/ESP8266, you’ve unlocked powerful, efficient communication capabilities for your IoT projects. The lightweight and reliable nature of MQTT ensures smooth data exchange between devices, enabling real-time responses and actions. Whether you’re building a smart home system or a sophisticated industrial application, MQTT provides a robust foundation for your interconnected devices.</p><p>Stay tuned for more exciting tutorials and innovative project ideas in our “Bits &amp; Bots” blog series. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a2cf916503f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using SD Cards with ESP32/ESP8266]]></title>
            <link>https://medium.com/@vaibhav01gour/to-be-contiued-634ef822ea74?source=rss-7a8a7aa11d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/634ef822ea74</guid>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[embedded]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[Bits&Bots]]></dc:creator>
            <pubDate>Sun, 19 May 2024 07:21:20 GMT</pubDate>
            <atom:updated>2024-05-19T18:03:20.416Z</atom:updated>
            <content:encoded><![CDATA[<p>SD Card</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=634ef822ea74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reading Sensor Data with ESP32/ESP8266]]></title>
            <link>https://medium.com/@vaibhav01gour/to-be-contiued-073517024dc0?source=rss-7a8a7aa11d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/073517024dc0</guid>
            <category><![CDATA[embedded]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[Bits&Bots]]></dc:creator>
            <pubDate>Sun, 19 May 2024 07:21:00 GMT</pubDate>
            <atom:updated>2024-05-19T11:15:45.985Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><p>Ever wondered how a machine is able to detect or compute environmental conditions like temperature, humidity, or light intensity? The secret lies in sensors, which are vital components in the realm of electronics and the Internet of Things (IoT). Sensors convert physical parameters into electrical signals that microcontrollers, such as the ESP32 and ESP8266, can understand and process.</p><p>Welcome back to the “Bits &amp; Bots” blog series! Today, we’ll delve into one of the most fascinating aspects of working with ESP32 and ESP8266 microcontrollers: reading sensor data. Whether you’re building a weather station, a smart home device, or a robotics project, understanding how to read sensor data is fundamental.</p><p>The ESP32 and ESP8266 microcontrollers are powerful and versatile, equipped with a variety of I/O pins that make them ideal for interfacing with different types of sensors. By leveraging the capabilities of these microcontrollers, you can build intelligent systems that monitor environmental conditions, automate processes, and even make decisions based on sensor inputs.</p><p>In this tutorial, we’ll guide you through connecting a sensor to your ESP32 or ESP8266 and reading data from it. Specifically, we’ll be using the DHT11 temperature and humidity sensor, which is a popular choice for many IoT projects due to its simplicity and reliability. By the end of this tutorial, you’ll have a solid understanding of how to set up your hardware, write the necessary code, and read sensor data in real-time.</p><h4>Understanding the Basics</h4><p><strong>What are Sensors?</strong></p><p>Sensors are devices that detect and respond to physical phenomena such as temperature, humidity, light, and motion. They convert these physical parameters into electrical signals that can be read by microcontrollers like the ESP32 and ESP8266. Sensors come in various types, each designed to measure specific parameters. For example, temperature sensors measure thermal energy, while humidity sensors measure the moisture content in the air.</p><p>The signals generated by sensors can be analog or digital. Analog sensors produce a continuous signal that varies with the parameter being measured, such as a varying voltage. Digital sensors, on the other hand, provide discrete signals, often in binary form, representing the measurement in a more straightforward format for microcontrollers to interpret.</p><p><strong>Common Sensors:</strong></p><ul><li><strong>Temperature and Humidity Sensors: </strong>Such as the DHT11 or DHT22. These sensors provide digital output and are widely used in environmental monitoring systems. They are crucial for applications like weather stations, HVAC systems, and agriculture.</li><li><strong>Light Sensors:</strong> Such as the LDR (Light Dependent Resistor), which changes its resistance based on the light intensity. These are commonly used in automatic lighting systems, light meters, and devices that need to adjust based on ambient light conditions.</li><li><strong>Motion Sensors:</strong> Such as the PIR (Passive Infrared) sensor, which detects movement by measuring changes in infrared radiation. These sensors are essential for security systems, motion-activated lights, and automated doors.</li><li><strong>Pressure Sensors:</strong> Such as the BMP180, which can measure atmospheric pressure and is often used in weather stations and altitude monitoring. These sensors are also found in automotive and industrial applications for monitoring and control.</li><li><strong>Proximity Sensors:</strong> Such as ultrasonic sensors, which measure the distance to an object by sending out ultrasonic waves and measuring the time it takes for the echo to return. These are widely used in robotics, obstacle detection, and object counting systems.</li></ul><p><strong>Why Use ESP32/ESP8266 with Sensors?</strong></p><p>The ESP32 and ESP8266 microcontrollers are excellent choices for sensor-based projects because of their built-in Wi-Fi capabilities, low power consumption, and rich set of I/O pins. These features enable you to collect data from sensors and transmit it wirelessly to a server or cloud platform for further analysis and action.</p><ul><li><strong>Built-in Wi-Fi: </strong>This allows the ESP32 and ESP8266 to connect to the internet and communicate with other devices or cloud services. You can monitor and control your projects remotely, making it ideal for IoT applications.</li><li><strong>Low Power Consumption: </strong>Both microcontrollers are designed to be energy efficient, making them suitable for battery-powered devices and applications where power consumption is a critical concern.</li><li><strong>Rich I/O Pins:</strong> The availability of numerous input/output pins allows you to connect multiple sensors and actuators, providing flexibility in designing complex projects.</li><li><strong>Affordable and Accessible: </strong>The cost-effectiveness of these microcontrollers makes them accessible for hobbyists, students, and professionals. Additionally, a large community of users provides extensive resources, tutorials, and support, making it easier to troubleshoot and expand your projects.</li></ul><p>For this tutorial, we’ll use the DHT11 temperature and humidity sensor as an example. The DHT11 is a basic, low-cost digital sensor that provides accurate and reliable data. It is widely used in various DIY electronics projects due to its ease of use and good performance.</p><p>The DHT11 sensor measures temperature and humidity and outputs a digital signal on the data pin. It is highly suitable for basic projects that require simple and straightforward measurements of these environmental parameters. The DHT11’s accuracy and reliability make it a popular choice among beginners and experts alike. It operates within a temperature range of 0–50°C and a humidity range of 20–90%, providing sufficient coverage for most home and hobby projects.</p><h4>Wiring</h4><figure><img alt="DHT11 Pinout" src="https://cdn-images-1.medium.com/max/500/1*j_0X8aj10gutLg6zGSoF4Q.jpeg" /><figcaption>DHT11 Pinout diagram</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sop6olQp7hiGQtrU6Ag_Uw.png" /><figcaption>Pins of DHT11 Sensor</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*QjNt7AKnMox420_s.jpg" /><figcaption>Schematic Diagram of connections with DHT11 Sensor</figcaption></figure><p>You need to download a couple of libraries so that ESP32 will properly communicate with DHT11 Sensor. First is main DHT11 Sensor Library. Go to Tools -&gt; Manage Libraries… in Arduino IDE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*APwswZDdncyreEDP.jpg" /></figure><p>In the search bar, enter ‘dht’. Scroll through the options and install ‘DHT sensor library’ by Adafruit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*6IbdnyJ6XhXTukh3.jpg" /></figure><p>The next library is associated with the Adafruit itself. Search for ‘adafruit unified’, scroll down and install ‘Adafruit Unified Sensor’ library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*axUPI8YolzEPmVCn.jpg" /></figure><p>Now you have downloaded the required libraries, let’s get this sensor working, and start reading values on the serial monitor.</p><h4>Code</h4><pre>#include &quot;DHT.h&quot;<br>#define DHT11PIN 15<br><br>DHT dht(DHT11PIN, DHT11);<br>void setup()<br>{<br>  <br>  Serial.begin(115200);<br>/* Start the DHT11 Sensor */<br>  dht.begin();<br>}<br><br>void loop()<br>{<br>  float humidity = dht.readHumidity();<br>  float temperature = dht.readTemperature();<br>  Serial.print(&quot;Temperature: &quot;);<br>  Serial.print(temperature);<br>  Serial.print(&quot;ºC &quot;);<br>  Serial.print(&quot;Humidity: &quot;);<br>  Serial.println(humidity);<br>  delay(1000);<br>}</pre><p>The following image shows the screenshot of the Serial Monitor, which is continuously printing the humidity and temperature reading every 3 seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/0*HX0WikIWdslFFzby.jpg" /></figure><h4>Conclusion</h4><p>In summary, sensors are vital for detecting physical phenomena, and microcontrollers like the ESP32/ESP8266 facilitate their integration into projects. With built-in Wi-Fi and ample I/O pins, these microcontrollers enable wireless communication and data processing. Using the DHT11 sensor as an example, we’ve explored how to harness its capabilities for temperature and humidity monitoring. By understanding sensor principles and microcontroller functionalities, endless possibilities for innovation emerge, driving advancements in IoT and beyond.</p><p>Stay connected, keep building…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=073517024dc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Power Management and Deep Sleep Mode]]></title>
            <link>https://medium.com/@vaibhav01gour/to-be-contiued-3e8014b07071?source=rss-7a8a7aa11d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e8014b07071</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[embedded]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[Bits&Bots]]></dc:creator>
            <pubDate>Sun, 19 May 2024 07:20:50 GMT</pubDate>
            <atom:updated>2024-05-19T17:48:08.311Z</atom:updated>
            <content:encoded><![CDATA[<p>Introduction:</p><p>In the world of microcontrollers and IoT devices, managing power consumption is crucial for maximizing battery life and minimizing energy costs. One powerful feature that aids in efficient power management is deep sleep mode. In this tutorial, we’ll explore how to leverage deep sleep mode on the ESP32 and ESP8266 microcontrollers to achieve ultra-low power consumption when idle.</p><p>Understanding Deep Sleep Mode:</p><p>Deep sleep mode is a power-saving state where the microcontroller shuts down most of its internal components, including the CPU, peripherals, and Wi-Fi/Bluetooth radios. By doing so, it drastically reduces power consumption, often to just a few microamps, while still retaining the ability to wake up from external triggers such as timers, GPIO interrupts, or touch sensors.</p><p>Benefits of Deep Sleep Mode:</p><ol><li>Ultra-Low Power Consumption: Deep sleep mode enables microcontrollers to operate at minimal power levels, making it ideal for battery-powered and energy-efficient applications.</li><li>Extended Battery Life: By conserving power during idle periods, devices can operate for longer durations on a single battery charge, reducing the frequency of battery replacements or recharging.</li><li>Reduced Energy Costs: For mains-powered devices, deep sleep mode helps minimize energy consumption, leading to lower electricity bills and reduced environmental impact.</li></ol><p>Implementing Deep Sleep Mode on ESP32/ESP8266:</p><ol><li>Configure Sleep Duration: Determine the desired sleep duration based on application requirements and power constraints. Longer sleep durations result in lower overall power consumption but may impact responsiveness.</li><li>Enter Deep Sleep Mode: Utilize the appropriate deep sleep functions provided by the ESP32/ESP8266 SDK to put the microcontroller into deep sleep mode. Ensure that any necessary wake-up triggers are configured before entering deep sleep.</li><li>Handle Wake-Up Events: Implement wake-up event handlers to handle interrupts or triggers that cause the microcontroller to exit deep sleep mode. Common wake-up sources include timers, GPIO interrupts, and external signals.</li></ol><p>Advanced Techniques and Considerations:</p><ul><li>RTC Wake Up: Utilize the Real-Time Clock (RTC) module available on the ESP32/ESP8266 to schedule wake-up events at specific times, enabling precise power management strategies.</li><li>Low-Power Sensors: Integrate low-power sensors into your design to further minimize power consumption during active operation, complementing the benefits of deep sleep mode.</li><li>Dynamic Power Management: Implement dynamic power management algorithms to adaptively adjust sleep durations and wake-up intervals based on environmental conditions, user interactions, or system workload.</li></ul><p>Benefits in Real-World Applications:</p><ul><li>Battery-Powered Devices: Deep sleep mode is ideal for battery-powered IoT devices such as sensor nodes, wearable gadgets, and remote sensors, where maximizing battery life is paramount.</li><li>Energy-Efficient Systems: In applications where energy efficiency is critical, such as smart buildings, industrial automation, and environmental monitoring, deep sleep mode helps minimize overall power consumption without sacrificing functionality.</li><li>Solar-Powered Solutions: Deep sleep mode can be combined with energy harvesting techniques, such as solar panels, to create self-sustaining IoT devices that operate indefinitely with minimal external power sources.</li></ul><p>Conclusion:</p><p>Deep sleep mode is a powerful tool for achieving ultra-low power consumption in microcontroller-based systems. By intelligently managing power usage during idle periods, developers can prolong battery life, reduce energy costs, and create more sustainable and efficient IoT solutions. Whether for battery-powered devices, energy-efficient systems, or renewable energy applications, deep sleep mode empowers developers to design smarter and greener solutions for the connected world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e8014b07071" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Over-the-Air (OTA) Updates for ESP32/ESP8266]]></title>
            <link>https://medium.com/@vaibhav01gour/over-the-air-ota-updates-for-esp32-esp8266-6a7e4f913c4b?source=rss-7a8a7aa11d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a7e4f913c4b</guid>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[embedded]]></category>
            <dc:creator><![CDATA[Bits&Bots]]></dc:creator>
            <pubDate>Sun, 19 May 2024 07:20:34 GMT</pubDate>
            <atom:updated>2024-05-19T10:55:29.642Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><p>Ever wondered how you can avoid plugging in to the system in order to upload code, and get the system working. Suppose if you find a bug in the program and the microcontroller is placed in the rooftop where you can’t reach, or somewhere in basement. Well, here comes OTA in the play.</p><p>Welcome back to our “Bits &amp; Bots” blog series! In this installment, we delve into a feature that can significantly streamline your development and deployment process: Over-the-Air (OTA) updates for the ESP32 microcontroller. The ESP32, with its built-in Wi-Fi capabilities, allows for wireless updates, enabling you to deploy new firmware to your IoT devices without needing a physical connection. This is especially beneficial for devices installed in remote or hard-to-reach locations, as it eliminates the need to manually connect and disconnect cables for firmware updates. OTA updates not only save time but also enhance the flexibility and maintainability of your IoT projects. In this comprehensive guide, we will walk you through the steps to set up and use OTA updates on your ESP32, ensuring your devices remain up-to-date with the latest features and security patches.</p><h4>The Basics</h4><p>Before we jump into the step-by-step process, it’s important to understand the basics of OTA updates and why they are useful for your ESP32 projects.</p><p><strong>What is OTA?</strong></p><p>OTA stands for Over-the-Air programming, a method that allows you to upload new firmware to your microcontroller wirelessly. Instead of connecting your ESP32 to your computer via USB every time you want to update the code, OTA updates enable you to send new firmware over your Wi-Fi network.</p><p><strong>Benefits of OTA Updates:</strong></p><ul><li>Convenience: Update firmware without needing to physically access the device.</li><li>Remote Maintenance: Perfect for devices deployed in remote or inaccessible locations.</li><li>Time-Saving: No need to disconnect and reconnect cables for updates.</li><li>Scalability: Easily update multiple devices over the network simultaneously.</li></ul><p><strong>How OTA Works:</strong></p><p>The OTA process involves the following steps:</p><ol><li>Preparation: Ensure your ESP32 is connected to Wi-Fi and the initial OTA firmware is uploaded via USB.</li><li>OTA Initialization: The firmware includes OTA routines that handle the process of receiving and applying updates.</li><li>Firmware Transfer: New firmware is sent to the ESP32 over the network.</li><li>Verification and Application: The ESP32 verifies the integrity of the new firmware and applies the update.</li></ol><h4><strong>Writing the OTA Code</strong></h4><p>Let’s write the code for enabling OTA updates on your ESP32. This code will connect your ESP32 to a Wi-Fi network and initialize the OTA service.</p><pre>//ESP32 / ESP8266 OTA<br><br>#include &lt;WiFi.h&gt;<br>#include &lt;ArduinoOTA.h&gt;<br><br>// Replace with your network credentials<br>const char* ssid = &quot;YourNetworkSSID&quot;;<br>const char* password = &quot;YourNetworkPassword&quot;;<br><br>void setup() {<br>  Serial.begin(115200);<br>  <br>  // Connect to Wi-Fi<br>  WiFi.begin(ssid, password);<br>  while (WiFi.status() != WL_CONNECTED) {<br>    delay(1000);<br>    Serial.println(&quot;Connecting to WiFi...&quot;);<br>  }<br>  Serial.println(&quot;Connected to WiFi&quot;);<br><br>  // Configure OTA settings<br>  ArduinoOTA.setHostname(&quot;esp32-ota&quot;);  // Optional: Set a custom hostname<br><br>  ArduinoOTA.onStart([]() {<br>    String type;<br>    if (ArduinoOTA.getCommand() == U_FLASH) {<br>      type = &quot;sketch&quot;;<br>    } else { // U_SPIFFS<br>      type = &quot;filesystem&quot;;<br>    }<br>    Serial.println(&quot;Start updating &quot; + type);<br>  });<br><br>  ArduinoOTA.onEnd([]() {<br>    Serial.println(&quot;\nEnd&quot;);<br>  });<br><br>  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {<br>    Serial.printf(&quot;Progress: %u%%\r&quot;, (progress / (total / 100)));<br>  });<br><br>  ArduinoOTA.onError([](ota_error_t error) {<br>    Serial.printf(&quot;Error[%u]: &quot;, error);<br>    if (error == OTA_AUTH_ERROR) {<br>      Serial.println(&quot;Auth Failed&quot;);<br>    } else if (error == OTA_BEGIN_ERROR) {<br>      Serial.println(&quot;Begin Failed&quot;);<br>    } else if (error == OTA_CONNECT_ERROR) {<br>      Serial.println(&quot;Connect Failed&quot;);<br>    } else if (error == OTA_RECEIVE_ERROR) {<br>      Serial.println(&quot;Receive Failed&quot;);<br>    } else if (error == OTA_END_ERROR) {<br>      Serial.println(&quot;End Failed&quot;);<br>    }<br>  });<br><br>  // Start the OTA service<br>  ArduinoOTA.begin();<br>  Serial.println(&quot;OTA Ready&quot;);<br>  Serial.print(&quot;IP address: &quot;);<br>  Serial.println(WiFi.localIP());<br>}<br><br>void loop() {<br>  // Handle OTA updates<br>  ArduinoOTA.handle();<br>}Initial Firmware Upload via USB:</pre><p>Before you can perform OTA updates, you need to upload the initial firmware (the OTA-enabled sketch) via USB:</p><ol><li>Connect your ESP32 to your computer using a USB cable.</li><li>Select the correct board and port in the Arduino IDE.</li><li>Upload the sketch to your ESP32.</li></ol><h4>Performing OTA Updates:</h4><p>Once the initial firmware is uploaded, you can perform OTA updates wirelessly:</p><p><strong>1) Prepare Your New Sketch:</strong></p><p>Make changes to your sketch as needed.</p><p><strong>2) Select the Network Port:</strong></p><ol><li>In the Arduino IDE, go to Tools &gt; Port.</li><li>You should see a network port named after your ESP32’s hostname (e.g., “esp32-ota at your_ip_address”).</li><li>Select this network port.</li></ol><p><strong>3) Upload the New Sketch:</strong></p><ol><li>Click the upload button in the Arduino IDE.</li><li>The new sketch will be uploaded to your ESP32 over Wi-Fi.</li></ol><h4>Conclusion</h4><p>In this tutorial, we covered the basics and step-by-step process of enabling Over-the-Air (OTA) updates on your ESP32 microcontroller. OTA updates are a powerful tool for maintaining and upgrading your IoT devices, allowing you to deploy new firmware wirelessly without physical connections. By following these steps, you can ensure your devices are always running the latest and most secure firmware, enhancing the functionality and reliability of your IoT projects.</p><p>Stay tuned for more tutorials and project ideas in our “Bits &amp; Bots” blog series. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a7e4f913c4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up a Web Server on ESP8266]]></title>
            <link>https://medium.com/@vaibhav01gour/1-reading-sensor-data-with-esp32-esp8266-419b257311bc?source=rss-7a8a7aa11d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/419b257311bc</guid>
            <category><![CDATA[embedded]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[esp8266]]></category>
            <dc:creator><![CDATA[Bits&Bots]]></dc:creator>
            <pubDate>Sun, 19 May 2024 07:17:26 GMT</pubDate>
            <atom:updated>2024-05-19T10:30:17.445Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><h4>Introduction</h4><p>Welcome to the next chapter in our exploration of the Internet of Things (IoT) with ESP8266 microcontrollers. In this installment, we delve into the fundamental aspect of IoT development: setting up a web server on ESP8266. By establishing a web server, you gain the ability to control and monitor your IoT devices remotely, opening up a world of opportunities for automation, data visualization, and remote management.</p><p>In this comprehensive guide, we’ll walk you through the process of setting up a web server on ESP8266, from understanding the basics to implementing practical examples. Whether you’re a seasoned IoT enthusiast or just starting your journey into the world of connected devices, this tutorial will equip you with the knowledge and skills to take your projects to the next level.</p><p>Please note that setting up a web server on ESP8266 involves using different libraries and approaches compared to ESP32, which we covered in a <a href="https://medium.com/@vaibhav01gour/setting-up-a-web-server-on-esp32-esp8266-1ae794fb453d">previous blog post</a>. For now, let’s focus on unleashing the full potential of ESP8266 microcontrollers with web server capabilities.</p><p>So, grab your ESP8266 board, fire up the Arduino IDE, and let’s embark on this exciting journey of empowering your IoT projects with the magic of web servers.</p><h4>The Basics</h4><p>Before we dive into the specifics of setting up a web server on the ESP8266, it’s essential to grasp some foundational concepts. A web server is a system that processes incoming network requests over HTTP (HyperText Transfer Protocol) and several other related protocols. It responds to these requests with resources such as HTML documents, images, and other content, enabling communication between a client (typically a web browser) and the server.</p><p>In the context of IoT (Internet of Things), a web server running on an ESP8266 microcontroller can serve as an interface for controlling and monitoring connected devices. This means you can remotely access and interact with your IoT devices through a web browser, making it incredibly convenient to manage your smart home projects, sensor networks, and other IoT applications.</p><p>Here are the key advantages of using a web server with your ESP8266:</p><p>1. Accessibility:A web server allows you to control your IoT devices from any web browser, whether it’s on a computer, smartphone, or tablet. This universal accessibility makes it easy to monitor and manage your devices from anywhere within your network.</p><p>2. User-Friendly Interface:By serving web pages with HTML, CSS, and JavaScript, you can create intuitive and interactive interfaces for your IoT projects. These interfaces can include buttons, sliders, graphs, and more, providing a user-friendly experience for controlling and visualizing data.</p><p>3. Scalability:A web server can handle multiple client requests simultaneously, making it suitable for applications that require interaction from several users or devices at once.</p><p>4. Integration with Other Services:With a web server, you can integrate your IoT devices with other web services and APIs. This opens up possibilities for data logging, remote notifications, and more complex automation scenarios.</p><p>5. Lightweight and Efficient:The ESP8266 is a powerful yet low-cost microcontroller with built-in Wi-Fi capabilities. Setting up a web server on this platform allows you to leverage its efficiency and cost-effectiveness for your IoT applications.</p><p><strong>Understanding HTTP Basics:</strong></p><p>Before setting up the web server, let’s briefly cover some basic concepts of HTTP:</p><ul><li>HTTP Requests: Clients send requests to the server using HTTP methods such as GET, POST, PUT, DELETE, etc. For instance, when you type a URL into your browser, it sends a GET request to the server.</li><li>HTTP Responses: The server processes the request and sends back an HTTP response. This response contains a status code (e.g., 200 for success, 404 for not found), headers, and the requested resource (e.g., an HTML page).</li><li>Endpoints: The server defines specific URLs (endpoints) that clients can interact with. Each endpoint corresponds to a particular resource or functionality. For example, an endpoint might be /toggle to toggle an LED.</li></ul><p><strong>Why Use ESP8266 for a Web Server?</strong></p><p>The ESP8266 is a popular choice for IoT projects due to its affordability, small size, and built-in Wi-Fi. It’s capable of hosting a web server while also handling various other tasks, making it ideal for building smart home devices, sensor networks, and other connected applications.</p><p>By setting up a web server on the ESP8266, you can:</p><ul><li>Create a user interface to interact with sensors and actuators.</li><li>Visualize sensor data in real-time.</li><li>Control devices remotely via a web browser.</li><li>Integrate with cloud services for data logging and remote notifications.</li></ul><p>With a solid understanding of these basics, you’re now ready to proceed with preparing your development environment and writing the code to set up the web server on your ESP8266 board. This knowledge will empower you to create versatile and interactive IoT applications with ease.</p><pre>//ESP8226 Web Server<br><br>// Load Wi-Fi library<br>#include &lt;ESP8266WiFi.h&gt;<br><br>// Replace with your network credentials<br>const char* ssid     = &quot;REPLACE_WITH_YOUR_SSID&quot;;<br>const char* password = &quot;YourNetworkPassword&quot;;<br><br>// Set web server port number to 80<br>WiFiServer server(80);<br><br>// Variable to store the HTTP request<br>String header;<br><br>// Auxiliar variables to store the current output state<br>String output5State = &quot;off&quot;;<br>String output4State = &quot;off&quot;;<br><br>// Assign output variables to GPIO pins<br>const int output5 = 5;<br>const int output4 = 4;<br><br>// Current time<br>unsigned long currentTime = millis();<br>// Previous time<br>unsigned long previousTime = 0; <br>// Define timeout time in milliseconds (example: 2000ms = 2s)<br>const long timeoutTime = 2000;<br><br>void setup() {<br>  Serial.begin(115200);<br>  // Initialize the output variables as outputs<br>  pinMode(output5, OUTPUT);<br>  pinMode(output4, OUTPUT);<br>  // Set outputs to LOW<br>  digitalWrite(output5, LOW);<br>  digitalWrite(output4, LOW);<br><br>  // Connect to Wi-Fi network with SSID and password<br>  Serial.print(&quot;Connecting to &quot;);<br>  Serial.println(ssid);<br>  WiFi.begin(ssid, password);<br>  while (WiFi.status() != WL_CONNECTED) {<br>    delay(500);<br>    Serial.print(&quot;.&quot;);<br>  }<br>  // Print local IP address and start web server<br>  Serial.println(&quot;&quot;);<br>  Serial.println(&quot;WiFi connected.&quot;);<br>  Serial.println(&quot;IP address: &quot;);<br>  Serial.println(WiFi.localIP());<br>  server.begin();<br>}<br><br>void loop(){<br>  WiFiClient client = server.available();   // Listen for incoming clients<br><br>  if (client) {                             // If a new client connects,<br>    Serial.println(&quot;New Client.&quot;);          // print a message out in the serial port<br>    String currentLine = &quot;&quot;;                // make a String to hold incoming data from the client<br>    currentTime = millis();<br>    previousTime = currentTime;<br>    while (client.connected() &amp;&amp; currentTime - previousTime &lt;= timeoutTime) { // loop while the client&#39;s connected<br>      currentTime = millis();         <br>      if (client.available()) {             // if there&#39;s bytes to read from the client,<br>        char c = client.read();             // read a byte, then<br>        Serial.write(c);                    // print it out the serial monitor<br>        header += c;<br>        if (c == &#39;\n&#39;) {                    // if the byte is a newline character<br>          // if the current line is blank, you got two newline characters in a row.<br>          // that&#39;s the end of the client HTTP request, so send a response:<br>          if (currentLine.length() == 0) {<br>            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)<br>            // and a content-type so the client knows what&#39;s coming, then a blank line:<br>            client.println(&quot;HTTP/1.1 200 OK&quot;);<br>            client.println(&quot;Content-type:text/html&quot;);<br>            client.println(&quot;Connection: close&quot;);<br>            client.println();<br>            <br>            // turns the GPIOs on and off<br>            if (header.indexOf(&quot;GET /5/on&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 5 on&quot;);<br>              output5State = &quot;on&quot;;<br>              digitalWrite(output5, HIGH);<br>            } else if (header.indexOf(&quot;GET /5/off&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 5 off&quot;);<br>              output5State = &quot;off&quot;;<br>              digitalWrite(output5, LOW);<br>            } else if (header.indexOf(&quot;GET /4/on&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 4 on&quot;);<br>              output4State = &quot;on&quot;;<br>              digitalWrite(output4, HIGH);<br>            } else if (header.indexOf(&quot;GET /4/off&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 4 off&quot;);<br>              output4State = &quot;off&quot;;<br>              digitalWrite(output4, LOW);<br>            }<br>            <br>            // Display the HTML web page<br>            client.println(&quot;&lt;!DOCTYPE html&gt;&lt;html&gt;&quot;);<br>            client.println(&quot;&lt;head&gt;&lt;meta name=\&quot;viewport\&quot; content=\&quot;width=device-width, initial-scale=1\&quot;&gt;&quot;);<br>            client.println(&quot;&lt;link rel=\&quot;icon\&quot; href=\&quot;data:,\&quot;&gt;&quot;);<br>            // CSS to style the on/off buttons <br>            // Feel free to change the background-color and font-size attributes to fit your preferences<br>            client.println(&quot;&lt;style&gt;html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}&quot;);<br>            client.println(&quot;.button { background-color: #195B6A; border: none; color: white; padding: 16px 40px;&quot;);<br>            client.println(&quot;text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}&quot;);<br>            client.println(&quot;.button2 {background-color: #77878A;}&lt;/style&gt;&lt;/head&gt;&quot;);<br>            <br>            // Web Page Heading<br>            client.println(&quot;&lt;body&gt;&lt;h1&gt;ESP8266 Web Server&lt;/h1&gt;&quot;);<br>            <br>            // Display current state, and ON/OFF buttons for GPIO 5  <br>            client.println(&quot;&lt;p&gt;GPIO 5 - State &quot; + output5State + &quot;&lt;/p&gt;&quot;);<br>            // If the output5State is off, it displays the ON button       <br>            if (output5State==&quot;off&quot;) {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/5/on\&quot;&gt;&lt;button class=\&quot;button\&quot;&gt;ON&lt;/button&gt;&lt;/a&gt;&lt;/p&gt;&quot;);<br>            } else {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/5/off\&quot;&gt;&lt;button class=\&quot;button button2\&quot;&gt;OFF&lt;/button&gt;&lt;/a&gt;&lt;/p&gt;&quot;);<br>            } <br>               <br>            // Display current state, and ON/OFF buttons for GPIO 4  <br>            client.println(&quot;&lt;p&gt;GPIO 4 - State &quot; + output4State + &quot;&lt;/p&gt;&quot;);<br>            // If the output4State is off, it displays the ON button       <br>            if (output4State==&quot;off&quot;) {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/4/on\&quot;&gt;&lt;button class=\&quot;button\&quot;&gt;ON&lt;/button&gt;&lt;/a&gt;&lt;/p&gt;&quot;);<br>            } else {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/4/off\&quot;&gt;&lt;button class=\&quot;button button2\&quot;&gt;OFF&lt;/button&gt;&lt;/a&gt;&lt;/p&gt;&quot;);<br>            }<br>            client.println(&quot;&lt;/body&gt;&lt;/html&gt;&quot;);<br>            <br>            // The HTTP response ends with another blank line<br>            client.println();<br>            // Break out of the while loop<br>            break;<br>          } else { // if you got a newline, then clear currentLine<br>            currentLine = &quot;&quot;;<br>          }<br>        } else if (c != &#39;\r&#39;) {  // if you got anything else but a carriage return character,<br>          currentLine += c;      // add it to the end of the currentLine<br>        }<br>      }<br>    }<br>    // Clear the header variable<br>    header = &quot;&quot;;<br>    // Close the connection<br>    client.stop();<br>    Serial.println(&quot;Client disconnected.&quot;);<br>    Serial.println(&quot;&quot;);<br>  }<br>}</pre><h4>Conclusion</h4><p>In this tutorial, we explored the fundamentals of setting up a web server on the ESP8266 microcontroller. By leveraging its built-in Wi-Fi capabilities, we created a web-based interface to control and monitor an LED, demonstrating how you can interact with your IoT devices remotely. This powerful feature of the ESP8266 opens up a world of possibilities for creating user-friendly, scalable, and accessible IoT projects. Stay tuned for more tutorials and project ideas in our “Bits &amp; Bots” blog series. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=419b257311bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up a Web Server on ESP32]]></title>
            <link>https://medium.com/@vaibhav01gour/setting-up-a-web-server-on-esp32-esp8266-1ae794fb453d?source=rss-7a8a7aa11d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ae794fb453d</guid>
            <category><![CDATA[embedded-development]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Bits&Bots]]></dc:creator>
            <pubDate>Sun, 19 May 2024 07:16:38 GMT</pubDate>
            <atom:updated>2024-05-19T09:38:02.026Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><p>Welcome to the next chapter in our journey of exploring the vast possibilities of IoT with ESP32 microcontrollers. In this installment, we delve into a fundamental aspect of IoT development: setting up a web server on ESP32. By establishing a web server, you gain the ability to control and monitor your IoT devices remotely, opening up a world of opportunities for automation, data visualization, and remote management.</p><p>In this comprehensive guide, we’ll walk you through the process of setting up a web server on ESP32, from understanding the basics to implementing practical examples. Whether you’re a seasoned IoT enthusiast or just starting your journey into the world of connected devices, this tutorial will equip you with the knowledge and skills to take your projects to the next level.</p><p>Please note that setting up a web server on ESP8266 involves using a different library and approach, which will be covered in another blog post. For now, let’s focus on unleashing the full potential of ESP32 microcontrollers with web server capabilities.</p><p>So, grab your ESP32 board, fire up the Arduino IDE, and let’s embark on this exciting journey of empowering your IoT projects with the magic of web servers.</p><h4>Understanding the Basics:</h4><p>Before we dive into setting up a web server on ESP32, it’s essential to grasp the fundamentals of web servers and their significance in IoT projects.</p><p><strong>What is a Web Server? — </strong>A web server is a software application or hardware device responsible for serving web pages to clients over the internet or a local network. It acts as a mediator between clients (such as web browsers) and web applications, facilitating the exchange of data and resources.</p><p><strong>How Does a Web Server Work? — </strong>When a client requests a web page, such as typing a URL into a browser’s address bar, the browser sends a request to the web server hosting that page. The web server processes the request, retrieves the necessary resources (HTML, CSS, JavaScript, images, etc.), and sends them back to the client’s browser, which then renders the page for the user.</p><p><strong>Web Servers in IoT: </strong>In the context of IoT, web servers play a crucial role in enabling remote control and monitoring of connected devices. By hosting a web server on an IoT device like the ESP32, you can create a user-friendly interface accessible from any web browser. This interface allows users to interact with their IoT devices, such as toggling LEDs, adjusting settings, or viewing sensor data, without the need for specialized software or apps.</p><p>Advantages of Using Web Servers in IoT:</p><ul><li>Accessibility: Web-based interfaces are accessible from any device with a web browser, making them platform-independent and user-friendly.</li><li>Scalability: Web servers can handle multiple client connections simultaneously, making them suitable for IoT applications with multiple users or devices.</li><li>Flexibility: Web servers offer flexibility in designing custom interfaces tailored to specific IoT applications or user requirements.</li><li>Integration: Web servers can easily integrate with other web services, APIs, and cloud platforms, enabling seamless data exchange and interoperability in IoT ecosystems.</li></ul><p>By harnessing the power of web servers, IoT developers can create dynamic and interactive experiences for users, unlocking the full potential of their connected devices.</p><h4>Setting up the web server</h4><p>We’ll start by including the required libraries and defining some variables:</p><pre>#include &lt;WiFi.h&gt;<br>#include &lt;WebServer.h&gt;<br><br>// Replace with your network credentials<br>const char* ssid = &quot;YourNetworkSSID&quot;;<br>const char* password = &quot;YourNetworkPassword&quot;;<br><br>// Create a WebServer object listening on port 80<br>WebServer server(80);<br><br>// HTML content for the main page<br>const char* html_page = R&quot;(<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;title&gt;ESP32 Web Server&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;h1&gt;Control Your IoT Devices&lt;/h1&gt;<br>  &lt;p&gt;Click the button below to toggle the LED:&lt;/p&gt;<br>  &lt;button onclick=\&quot;toggleLED()\&quot;&gt;Toggle LED&lt;/button&gt;<br>  &lt;script&gt;<br>    function toggleLED() {<br>      var xhr = new XMLHttpRequest();<br>      xhr.open(&quot;GET&quot;, &quot;/toggle&quot;, true); // Send GET request to /toggle route<br>      xhr.send(); // Send the request<br>    }<br>  &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br>)&quot;;<br><br>// Handler for the root page (&quot;/&quot;)<br>void handleRoot() {<br>  server.send(200, &quot;text/html&quot;, html_page); // Send HTML page to client<br>}<br><br>// Handler for the &quot;/toggle&quot; route<br>void handleToggle() {<br>  // Toggle the LED (assuming built-in LED is connected to pin LED_BUILTIN)<br>  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));<br>  server.send(200, &quot;text/plain&quot;, &quot;OK&quot;); // Send response to client<br>}<br><br>void setup() {<br>  // Initialize built-in LED pin as an output<br>  pinMode(LED_BUILTIN, OUTPUT);<br><br>  Serial.begin(115200);<br>  <br>  // Connect to Wi-Fi network<br>  WiFi.begin(ssid, password);<br>  while (WiFi.status() != WL_CONNECTED) {<br>    delay(1000);<br>    Serial.println(&quot;Connecting to WiFi...&quot;);<br>  }<br>  Serial.println(&quot;Connected to WiFi&quot;);<br><br>  // Define routes and their corresponding handlers<br>  server.on(&quot;/&quot;, HTTP_GET, handleRoot); // Handle requests to the root (&quot;/&quot;) route<br>  server.on(&quot;/toggle&quot;, HTTP_GET, handleToggle); // Handle requests to the &quot;/toggle&quot; route<br><br>  // Start the web server<br>  server.begin();<br>  Serial.println(&quot;Web server started&quot;);<br>}<br><br>void loop() {<br>  // Handle client requests<br>  server.handleClient();<br>}</pre><h4>Conclusion</h4><p>In this tutorial, we’ve explored the process of setting up a web server on the ESP32 microcontroller, empowering you to control and monitor your IoT devices remotely. By leveraging the power of web-based interfaces, you can create dynamic and interactive experiences for users, opening up a world of possibilities for automation, data visualization, and remote management.</p><p>We began by understanding the basics of web servers and their role in IoT projects, highlighting their accessibility, scalability, flexibility, and integration capabilities. We then walked through the steps to prepare your development environment, including installing the necessary libraries and configuring your ESP32 board.</p><p>With your environment set up, we proceeded to write the code to configure the web server, define routes, and handle client requests. By serving a simple HTML page with a button to toggle an LED, we demonstrated how you can interact with your IoT devices through the web-based interface.</p><p>Finally, we concluded with a complete code example and explanations of key concepts, ensuring that you have everything you need to get started with building your own web-based IoT projects on the ESP32 platform. Further, blog for web server on ESP8266 will be published soon…</p><p>As you continue your journey into the world of IoT development, remember that the possibilities are endless with ESP32 as your trusty companion. Stay tuned for more tutorials and project ideas in our “Bits &amp; Bots” blog series, where we’ll continue to explore the exciting realm of IoT with practical examples and insights.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ae794fb453d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Gateway to IoT : Connecting ESP32 and ESP8266 to Wi-Fi]]></title>
            <link>https://medium.com/@vaibhav01gour/the-gateway-to-iot-connecting-esp32-and-esp8266-to-wi-fi-6cef590cf20a?source=rss-7a8a7aa11d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cef590cf20a</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[Bits&Bots]]></dc:creator>
            <pubDate>Sat, 18 May 2024 17:47:53 GMT</pubDate>
            <atom:updated>2024-05-18T18:15:48.620Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Gateway to IoT: Connecting ESP32 and ESP8266 to WiFi</h3><h4>Bits&amp;Bots</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*T8gZxLjRsz3Tn69ovLuIQg.gif" /></figure><h4>Introduction</h4><p>Welcome to another exciting chapter in our “Bits &amp; Bots” series! Today, we’re diving into the essential first step of any IoT project: connecting your ESP32 and ESP8266 microcontrollers to Wi-Fi. With this crucial connection established, your devices gain access to the vast world of the internet, enabling them to send and receive data, interact with other devices, and unleash their full potential as IoT wonders.</p><h4>The Basics</h4><p>Before we dive into the nitty-gritty of Wi-Fi connection, let’s take a moment to understand the basics. Wi-Fi, short for Wireless Fidelity, is a wireless networking technology that allows devices to connect to the internet and communicate with each other over a local network. ESP32 and ESP8266 microcontrollers come equipped with built-in Wi-Fi capabilities, making them ideal candidates for IoT projects.</p><p>Wi-Fi operates on the 2.4 GHz and 5 GHz frequency bands, offering various channels to avoid interference and ensure reliable communication. The ESP32 supports both 2.4 GHz and 5 GHz bands, whereas the ESP8266 supports only the 2.4 GHz band. This built-in Wi-Fi capability simplifies the process of connecting your microcontroller to a network, eliminating the need for additional hardware.</p><p>When connecting to a Wi-Fi network, several key concepts come into play:</p><p><strong>SSID (Service Set Identifier):</strong> This is the name of the Wi-Fi network you want to connect to. It’s the identifier that distinguishes one Wi-Fi network from another. When you open your device to search for available networks, the list you see is composed of SSIDs.</p><p><strong>Password: </strong>To prevent unauthorized access, Wi-Fi networks are often secured with a password. This password uses encryption protocols like WPA (Wi-Fi Protected Access) or WPA2, which is the most common and secure method available.</p><p><strong>IP Address:</strong> Once connected to a network, each device is assigned a unique IP address, allowing it to communicate with other devices on the network. The IP address can be assigned dynamically by a DHCP (Dynamic Host Configuration Protocol) server or set statically.</p><p><strong>MAC Address:</strong> This is a unique identifier assigned to each network interface. It’s used by the network to identify and manage devices.</p><h4>Preparing Your Environment</h4><p>To get started, you’ll need a development environment set up with the Arduino IDE and the necessary board definitions for ESP32 and ESP8266. If you haven’t already done so, follow our handy setup guide to get everything up and running smoothly.</p><p>You can setup the environment following this article — <a href="https://medium.com/@vaibhav01gour/setting-up-your-development-environment-esp32-esp8266-92c9de2ba92d">Setting Up Your Development Environment : ESP32/ESP8266</a></p><h4>Connecting to Wi-Fi</h4><p>Now, let’s get down to business. In your Arduino sketch, include the WiFi.h library to gain access to the Wi-Fi functionality provided by the ESP32 and ESP8266 platforms.</p><p>Use the WiFi.begin() function to initiate a connection to your Wi-Fi network, providing the SSID and password as parameters. Here’s a step-by-step example:</p><pre>#include &lt;WiFi.h&gt;  // Include the WiFi library for ESP32 and ESP8266<br><br>const char* ssid = &quot;your_SSID&quot;;  // Replace with your network SSID<br>const char* password = &quot;your_PASSWORD&quot;;  // Replace with your network password<br><br>void setup() {<br>  // Initialize Serial Monitor<br>  Serial.begin(115200);<br><br>  // Begin WiFi connection<br>  Serial.print(&quot;Connecting to &quot;);<br>  Serial.println(ssid);<br>  WiFi.begin(ssid, password);<br><br>  // Wait for connection<br>  while (WiFi.status() != WL_CONNECTED) {<br>    delay(1000);<br>    Serial.print(&quot;.&quot;);<br>  }<br><br>  // When connected<br>  Serial.println(&quot;&quot;);<br>  Serial.println(&quot;WiFi connected.&quot;);<br>  Serial.print(&quot;IP address: &quot;);<br>  Serial.println(WiFi.localIP());<br>}<br><br>void loop() {<br>  // Your main code here<br>}</pre><h4>Conclusion</h4><p>And there you have it — a comprehensive guide to connecting ESP32 and ESP8266 to Wi-Fi. With this vital step accomplished, your devices are ready to embark on their IoT journey, communicating with the world and making magic happen. Stay tuned for more adventures in our “Bits &amp; Bots” series, where we’ll explore advanced topics in IoT development and unleash the full potential of these incredible microcontrollers.</p><h4>Coming up!</h4><p>Ready to take your Wi-Fi-connected projects to the next level? Stay tuned for our next blog post, where we’ll dive into the exciting world of remote data communication and control with ESP32 and ESP8266. Until then, happy tinkering!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cef590cf20a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Illuminating Your Projects: Toggling an LED with a Switch : ESP32/ESP8266]]></title>
            <link>https://medium.com/@vaibhav01gour/illuminating-your-projects-toggling-an-led-with-a-switch-esp32-esp8266-0da081a21719?source=rss-7a8a7aa11d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/0da081a21719</guid>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[led]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[Bits&Bots]]></dc:creator>
            <pubDate>Fri, 19 Apr 2024 08:30:33 GMT</pubDate>
            <atom:updated>2024-04-19T08:30:33.912Z</atom:updated>
            <content:encoded><![CDATA[<h3>Illuminating Your Projects: Toggling an LED with a Switch : ESP32/ESP8266</h3><p>Welcome to another exciting tutorial in our “Bits &amp; Bots” series! In this guide, we’ll explore a fundamental yet powerful concept in electronics projects: using a physical switch to control an LED with ESP32 and ESP8266 microcontrollers. Whether you’re a beginner looking to learn the basics or an experienced maker seeking to expand your skills, this project is a great starting point.</p><figure><img alt="LED with a switch" src="https://cdn-images-1.medium.com/max/648/1*oa4f_9iEFtnCrnM_pzNsIw.gif" /><figcaption>LED with a Switch</figcaption></figure><ol><li>Understanding the Components:<br>Before we dive into the fun stuff, let’s briefly discuss the components involved. The switch serves as an input device, allowing us to manually control the flow of electricity in the circuit. On the other hand, the LED acts as an output device, providing visual feedback based on the state of the switch. Our trusty ESP32 and ESP8266 microcontrollers will serve as the brains behind the operation, interpreting our commands and controlling the LED accordingly.</li><li>Wiring the Circuit:<br>Let’s get hands-on! To wire up our circuit, connect one terminal of the switch to a GPIO pin on your ESP32 or ESP8266 board. Then, connect the other terminal of the switch to either the 3.3V or 5V pin, depending on the type of switch you’re using. Next, connect one terminal of the LED to another GPIO pin and the other terminal to a current-limiting resistor (usually around 220 ohms), and finally, connect the other end of the resistor to the ground (GND) pin on the board. Make sure to consult your board’s pinout diagram to identify the appropriate GPIO pins.<br>For demonstration purpose, i have used Arduino Uno from Tinkercad.</li><li>Writing the Code: <br>Now that our circuit is set up, let’s write some code to control the LED based on the state of the switch. In the Arduino IDE, start by defining the GPIO pins used for the switch and LED as well as declaring any necessary variables. Then, in the setup function, initialize the GPIO pins as inputs and outputs, respectively. In the loop function, use digitalRead() to read the state of the switch, and use digitalWrite() to control the LED accordingly. For example, if the switch is pressed (i.e., its state is HIGH), turn on the LED; otherwise, turn it off.<br>Code is provided below.</li><li>Uploading and Testing: <br>With our code written, it’s time to upload it to our ESP32 or ESP8266 board. Connect your board to your computer via USB, select the appropriate board and port in the Arduino IDE, and click the upload button. Once the upload is complete, disconnect the board from your computer and power it using a USB power source or battery. Test your circuit by toggling the switch and observing the corresponding behavior of the LED.</li><li>Enhancements and Extensions:<br>Congratulations! You’ve successfully built a switch-controlled LED project with ESP32 or ESP8266. To take your project to the next level, consider adding debounce functionality to the switch to eliminate bounce effects, or expand the project by incorporating multiple switches and LEDs for more complex interactions.</li><li>Practical Applications:<br>The possibilities are endless! You can use this switch-controlled LED project in various practical applications, such as replacing a manual light switch or building a simple alarm system. Let your creativity soar and explore the countless ways you can incorporate this basic yet versatile functionality into your own projects.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*t7P9Xf3-XoPSFx1CN0Bl9w.png" /><figcaption>Circuit Diagram</figcaption></figure><pre>// Interfacing Switch using ESP32/ESP8266<br><br>// Define the GPIO pins for the switch and LED<br>const int switchPin = 2;  // Common pin mapping for ESP32 and ESP8266<br>const int ledPin = 4;     // Common pin mapping for ESP32 and ESP8266<br><br>// Variable to store the state of the switch<br>int switchState = 0;<br><br>void setup() {<br>  // Initialize the Serial Monitor for debugging<br>  Serial.begin(9600);<br><br>  // Initialize the switch pin as an input<br>  pinMode(switchPin, INPUT);<br>  <br>  // Initialize the LED pin as an output<br>  pinMode(ledPin, OUTPUT);<br>}<br><br>void loop() {<br>  // Read the state of the switch (HIGH or LOW)<br>  switchState = digitalRead(switchPin);<br><br>  // Print the switch state to the Serial Monitor<br>  Serial.print(&quot;Switch state: &quot;);<br>  Serial.println(switchState);<br><br>  // Check if the switch is pressed (HIGH)<br>  if (switchState == HIGH) {<br>    // Turn on the LED<br>    digitalWrite(ledPin, HIGH);<br>    Serial.println(&quot;LED turned ON&quot;);<br>  } else {<br>    // Turn off the LED<br>    digitalWrite(ledPin, LOW);<br>    Serial.println(&quot;LED turned OFF&quot;);<br>  }<br><br>  // Add a delay to avoid rapid toggling due to switch bounce<br>  delay(100);<br>}</pre><p>Conclusion: In conclusion, toggling an LED with a switch on ESP32 and ESP8266 microcontrollers is a fundamental yet powerful concept in electronics projects. By mastering this simple project, you’ll gain a solid foundation for exploring more advanced topics in the exciting world of IoT and embedded development.</p><p>Next Steps -&gt; Ready to take your skills to the next level? Stay tuned for more tutorials and project ideas in our “Bits &amp; Bots” series, covering topics such as sensor integration, wireless communication, and IoT applications. Happy shot circuiting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0da081a21719" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>