<?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 Hilmi Baskara Radanto on Medium]]></title>
        <description><![CDATA[Stories by Hilmi Baskara Radanto on Medium]]></description>
        <link>https://medium.com/@radantohilmi?source=rss-e16235d71560------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ALD1G3AZAzyRDpg0Mua-VQ.jpeg</url>
            <title>Stories by Hilmi Baskara Radanto on Medium</title>
            <link>https://medium.com/@radantohilmi?source=rss-e16235d71560------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 10:00:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@radantohilmi/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[“Who knows where life will take you?”]]></title>
            <link>https://medium.com/@radantohilmi/who-knows-where-life-will-take-you-925eb814bd08?source=rss-e16235d71560------2</link>
            <guid isPermaLink="false">https://medium.com/p/925eb814bd08</guid>
            <category><![CDATA[slice-of-life]]></category>
            <category><![CDATA[hiking]]></category>
            <category><![CDATA[attack-on-titan]]></category>
            <category><![CDATA[reflections]]></category>
            <category><![CDATA[study-abroad]]></category>
            <dc:creator><![CDATA[Hilmi Baskara Radanto]]></dc:creator>
            <pubDate>Thu, 25 Dec 2025 15:56:12 GMT</pubDate>
            <atom:updated>2025-12-25T15:56:12.381Z</atom:updated>
            <content:encoded><![CDATA[<p>I know.</p><p>It’s an album which recently just released by Reality Club.</p><p>However, this piece of medium article won’t be talking about the album itself, but the literal meaning from the sentence.</p><p>One premise I’m bringing for this article: Do you believe that I climbed the highest mountain in South Wales just because my friend randomly commented an aircraft at the airport?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*46XMWiq9KsAK94mG0sF3lQ.png" /><figcaption>A view from Pen Y Fan, South Wales’s Highest Peak</figcaption></figure><p>So here’s the story…</p><p>From my 22 years of life, I have learned that I don’t know where life will take me year after year. As if it’s all a snowball effect of the coincidences that has happened from time to time.</p><p>Before reaching up to this point, as a kid I’ve always dreamed myself to be an aerospace engineer inspired by Habbie and its sophisticated aircraft. But, if actually you’re asking where was the starting point, it’s really a simple, or you can say, a really a trivial, trivial, moment.</p><p>I still remember it until this day, somewhere around August 2014 in which I participated in a math competition in Singapore. Some time in the morning before the flight from Jakarta to Singapore, I was with my friend watching the window at one of the gate at Terminal 2 Soekarno-Hatta airport waiting for the aircraft to come. And just when the aircraft was seen and taxiing to the gate, one of my friend, Halif, if I’m not mistaken (say hi in the comment if you still remember me! haha) says calmly “Hey, that’s an A330!”, while I did not know what that mean. But, somehow it triggered my curiosity about aircraft and I still remember that moment fully well, the situation, the view, the aircraft, even the sound and the feeling felt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jWdbPrz38yf9rcc4R9Pseg.png" /><figcaption>The airport atmosphere at the time. Not the original photo since the OG photos are in harddisk that is left behind in another city LOL by the time i write this article.</figcaption></figure><p>I entered the aircraft afterwards and was also stunned by the wide cabin since it’s my first ever wide-body aircraft. My 11-year-old-ish mind kept on asking in my head, “How do engineers build this to fly a gigantic aircraft?” and basically, everything stemmed from that point and has cause butterfly effect from there.</p><p>Since 4th grader until 12th grader, I put my top of mind of school going for aerospace engineering ITB (FTMD). I fought every day and night tirelessly to chase FTMD ITB. I joined more math competitions to easen myself being accepted to junior high and senior high school. I also struggled my way to keep my senior high school report score competitive, grinding through exams, (i once almost acing my math exam score), and getting good at basically everything. Not sure that if I didn’t have the motivation for FTMD I’d went that far.</p><p>After long struggles and journey, it was time to choose the faculty and university, and, I don’t know, maybe I got too distracted and I chose STEI ITB. And at the next year, I don’t even know why I chose the major of Information Systems and Technology. Maybe it’s God’s plan, or I’m being <em>delulu </em>scammed by the promise of “high salary” in IT job in which I encountered tech winter the year I graduated :D. Although years I’m regretting the path I chose, there’s nothing else I can do except than just accept the fact, right? Again, I believe that God knows the best plan for me.</p><p>Long story short, time comes and at the fourth year of my university I ended up in a small, boring, a one of the top 10 most dangerous city in the UK with random woman (actually Godiva) riding a horse monument in its city centre, a city named Coventry. Still, this got so many coincidences that doesn’t make any sense if I think about it again. There’s one that kept bugging my mind: how weird it is to happen, and how impactful it is to my life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hZ5O8n8t4eE4WwoofPYvMA.jpeg" /><figcaption>Godiva Statue and PRIMARK. Photo by Hilmi Baskara Radanto.</figcaption></figure><p>So, one day, I signed up for a rock-up tennis session, yet that day there was a storm and I was too lazy to get out of my room. I even procrastinated by showering in the morning — <em>who in the world would shower before doing sports? </em>— and basically I was late 20 minutes to go out according to my plan. I went out and I walked to the usual bus stop I used for going to the <em>uni.</em> Two busses passed by and didn’t stop because it was too full, so I walked further to go to the main terminal bus stop. Then, by the world, I went to the upper deck of the bus and met my badminton friend which I usually met during the club session.</p><p>We were actually talking like usual initially, <em>blah blah, </em>and somehow he was actually going for a badminton as well for a private session with his own friend group and I was asked to join. Then, sure, why not? I can still set aside the tennis rockup and sign up for other sessions (<em>spoiler</em>: it didn’t happen)</p><p>Because of that event, I spent the holiday after the semester by playing badminton, almost routine 3x a week. The badminton friend group was also growing time to time.</p><p>One of the guy that came after was Azib, my malaysian friend, and coincidentally we prayed maghrib together after a badminton session and met my other IISMA friend, Sya. We did small talk and somehow we decided to hike together! and at the start of January we were eating cup noodles at the summit of Pen Y Fan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*5JmIPxCoPu7H7CYcQULfDQ.png" /><figcaption>bringing #SEAculture</figcaption></figure><p>So, taking things back again, can you just imagine? All those stories above happened because of a random comment that my friend said when I was in 4th grade. Can you imagine if I walked with friends to South Wales instead, just because I was too lazy and weirdly took a shower in the morning, or I was late for the bus?</p><p>This piece of reflection also makes me remember this page of Attack on Titan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/0*KCWX7lyQaKcep7ev" /><figcaption>Bro got brother-zoned and decided to rumble the world.</figcaption></figure><p>That page stayed with me because of how ordinary the question was. “What am I to you?” Simple, 6 words, no grand high-level english words. And yet, two entirely different timeline branched out from the answer, either Eren live happily ever after with Mikasa in the woods or destroy the whole world. (Honestly, mine is not that extreme).</p><p>None of these moments felt important when they happened. They only became something I realize as “turning points” later, once I tried to make sense of how I ended up here.</p><p>And this is just a small example from mine. What about the world? Maybe Aristotle somehow was being asked a random silly question by pedestrians when he was buying foods before he thought that much, or maybe Hitler was not really in the mood for painting so he wasn’t accepted to the art school. So,</p><p><strong>Who knows where life will take you?</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=925eb814bd08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[11,800 km away from “home”?]]></title>
            <link>https://medium.com/@radantohilmi/11-800-km-away-from-home-240a1dafa952?source=rss-e16235d71560------2</link>
            <guid isPermaLink="false">https://medium.com/p/240a1dafa952</guid>
            <category><![CDATA[study-abroad]]></category>
            <category><![CDATA[adventure]]></category>
            <category><![CDATA[nostalgia]]></category>
            <category><![CDATA[reflections]]></category>
            <category><![CDATA[slice-of-life]]></category>
            <dc:creator><![CDATA[Hilmi Baskara Radanto]]></dc:creator>
            <pubDate>Sat, 20 Dec 2025 17:11:38 GMT</pubDate>
            <atom:updated>2025-12-20T17:14:14.717Z</atom:updated>
            <content:encoded><![CDATA[<p>There’s this unexplainable feeling when you’re 11,800 km+ away from your country. A feeling that lays somewhere between solitude and warmth. It’s the kind of feeling that sneaks up on you in the in-between moments, when you’re walking alone on unfamiliar streets, when laughter echoes through a tiny apartment kitchen, and when the sky looks different.</p><p>Since I was a kid, I have always dreamed of studying abroad. Not just for the academics or the travel, but for *that* feeling. The one where you’re far from home, yet find a piece of home in a so far away land.</p><p>I grew up watching Gitasav’s YouTube videos. For the context, she was an Indonesian student in Germany in 2015, and through her videos, I saw warmth of laughter and companionships, miles away from home. I always imagined what it would be like to experience that and create my own version of those moments.</p><p>Long story short, I was lucky. I studied at one of university in the UK for a semester, and I can safely say — I finally felt it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*giYI74iWFPQO7Ilq4vw-QQ.jpeg" /><figcaption>The kitchen</figcaption></figure><p>There was a moment when I stood still in a tiny kitchen with my friends cooking our mixed cultured-ish dishes. The rich aroma of quiche, soto, and tempe goreng filled the air, mixing with quiet conversation and our burst of unintentional laughter. Outside, the neighborhood was so quiet and cold where the winter had brought. Meanwhile inside, the warmth of companionship made the space feel like home, even though we were thousands of kilometers away from where we came from.</p><p>There were nights in the Axo Paradise kitchen, our home at that time, where time seemed to slow down whenever we were together, as we swapped recipes, made steaming mugs of hot chocolate, and deep talked together through the night while the temperature outside occasionally dropped to -6°C. The wall was the witness of our voices, our laughter, our stories. It felt so familiar. and safe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*9_sVBTEJkAha8KhiiSJQZw.jpeg" /><figcaption>2 minutes of golden sunset behind the hills</figcaption></figure><p>Then there was Quiraing. I was standing on a ridge, looking out at landscapes straight from Vinland Saga and Frieren. I watched the sun set at 3 PM, which felt too surreal. The wind blew at us at 30 mph, then rain came in bursts of 10 minutes, followed by golden sunshine in just 2 minutes, before the clouds swallowed the sky again. We hiked through it all, pushing forward as the landscape shifted around us. It was so raw, breathtaking, and almost unreal. We were so far from home, yet at that moment, <strong>nothing felt closer</strong>.</p><p>Then there was Londonderry. Alone, on a rare sunny day, I wandered through a city steeped in history. I spoke with locals, was invited to take a photo in the middle of a church, and stumbled upon a tiny, packed bookstore where I found Indonesia written in the pages of an old book. It felt like a quiet reminder that no matter how far I went, home would always find a way to reach me. As the day fold up, it ended with a sunset walk across a quiet bridge with the golden light casting long shadows as I let my empty thoughts drift in the evening breeze.</p><p>I don’t know how to describe it. That feeling — being so far away from home, yet completely at peace. A quiet kind of joy, a chill that runs down your spine, a moment so surreal you know it will never come again. It’s the kind of feeling that printed itself on your heart, waiting to be revisited in memories, in dreams, in quiet moments of longing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=240a1dafa952" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IISMA: 24 Lessons Learned]]></title>
            <link>https://medium.com/@radantohilmi/iisma-24-lessons-learned-88ea17b8af1f?source=rss-e16235d71560------2</link>
            <guid isPermaLink="false">https://medium.com/p/88ea17b8af1f</guid>
            <dc:creator><![CDATA[Hilmi Baskara Radanto]]></dc:creator>
            <pubDate>Wed, 23 Apr 2025 17:08:14 GMT</pubDate>
            <atom:updated>2025-05-06T03:39:02.622Z</atom:updated>
            <content:encoded><![CDATA[<p>So, I just had a semester exchange abroad to the University of Warwick, as part of IISMA 2024. Some people actually doubted me on participating in this program since my background is in STEM, specifically Information System and Technology, and IISMA mostly focuses in social sciences matter. However, I’m glad that I still continue since I expect to get human connections and life lessons. Surprisingly, it turned out to be far better than I expected.</p><p>In this short medium post, I have compiled 24 life lessons from my experience in IISMA 2024 as a reminder to myself until whenever to jump back into reading this post when life gets tough. Well, hopefully you guys, readers, may also pick some life lessons too from here if you feel like you relate to me haha.</p><p>This post will be a remembrance that I was happy! and that life is going to be alright! You’re gonna get what you want, just enjoy the struggle and the moment. Anyway, why specifically 24, I guess because it is the year 24 haha and I will turn to 24 in a year. So, here you go!</p><p>1.	Everything is can, but takes time and efforts. Slowly but surely, you’ll get there. Trust me.</p><p>2.	Act first, figure out later (thanks life of riza) as long as you think it’s good for you.</p><p>3.	Inaction is a slow death (thanks sya’s phone wallpaper). When in doubt, do something! when anxious, move! when overthinks, exercise! Just a small thing you’re doing gonna help your feeling better rather than crawling on the bed while doomscrolling X.</p><p>4.	Cherish and enjoy every moment because time will never come back, even the second you experienced one second ago.</p><p>5.	God is the best planner of your life. No matter how hard you fought for a thing, if it’s not meant to be yours, it won’t be yours, because God knows better. I used to be really sad got rejected from the IISMA regular program. But experiencing life in the University of Warwick made me realie that God has better plan for me!</p><p>6.	I will go to lake district or scottish highlands again someday, to come home. I will fight for it!</p><p>7.	Don’t be shy! People won’t remember you for asking silly things to the lecturer or having a conversation with strangers at random places.</p><p>8.	I am a words of affirmation and giving gift person.</p><p>9.	Coincidences happen mysteriously, so create the moment and seize every opportunity!</p><p>10.	Show empathy and care to people, don’t forget to be genuine and don’t ask for any return. I promise it will fulfill your heart.</p><p>11.	Smile and be expressive is also sign of respecting people you interact with.</p><p>12.	Take photo and video MORE!</p><p>13.	Eat a LOT if you have activities. The more activities you have, the more nutrients intake u need, and apparently you can directly feel the effect. The quality of foods correlates to your mental health honestly (both nutrients and taste wise). So, invest in foods!</p><p>14.	Confront people if you have problem with them, but do it politely, calmly, involve logics, no temperamental. It will return good things.</p><p>15.	Food and cooking is the best way to connect with International people</p><p>16.	Family (i mean real family, mom dad, sisters) is the most precious thing existed on earth</p><p>17.	My islam practices is apparently important as part of my identity (second to your own faith)</p><p>18.	Writing is the best way to structure your mind, communicate your ideas, and touch people’s heart</p><p>19.	Talking to strangers opens up opportunities</p><p>20.	Your closest friends are your greatest influencer</p><p>21.	Mental health, wellbeing, are so important. Hard work also has a limit, where when you over the limit, your productivity will actually curved down.</p><p>22.	Easiest way to connect with people are with people who share the same condition as you, so apparently Asian bond in westerner world is really a thing🤣🤣</p><p>23.	The importance of shooting your shot!!! because u miss 100% the shot that you don’t shoot.</p><p>24.	Reflective essay taught me that it’s important to take some steps back to reflect what you did good and bad and bounce multiple steps further</p><p>Dear myself in the future, have a great life ahead and thanks for getting back here. I’m still on my post IISMA depression while writing this. I seek GPT for therapy and (he/she/it???) says it’s completely normal and it’s actually a good sign that you’ve experienced a really strong core memories. Lastly,</p><blockquote>Life goes on and just keep swimming!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88ea17b8af1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded System Project #10 — Data Visualization & Data Logging]]></title>
            <link>https://medium.com/@radantohilmi/embedded-system-project-10-data-visualization-data-logging-80523f28a3b5?source=rss-e16235d71560------2</link>
            <guid isPermaLink="false">https://medium.com/p/80523f28a3b5</guid>
            <dc:creator><![CDATA[Hilmi Baskara Radanto]]></dc:creator>
            <pubDate>Sun, 07 May 2023 16:12:21 GMT</pubDate>
            <atom:updated>2023-05-07T17:03:53.521Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embedded System Project #10 — Data Visualization &amp; Data Logging</h3><p>Hello!</p><p>It’s now my last project in embedded system. This is a continuation of the last project, so click <a href="https://medium.com/@radantohilmi/embedded-project-9-database-2cc5f61f2e55">here</a> if you haven’t seen it. Without further ado, let’s just get going!</p><h4>Data Visualization</h4><ul><li>Create a new file named ‘esp32-chart.php’. Here’s the code:</li></ul><pre>&lt;!--<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com<br>  <br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br>  <br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br><br>--&gt;<br>&lt;?php<br><br>$servername = &quot;localhost&quot;;<br><br>// REPLACE with your Database name<br>$dbname = &quot;REPLACE_WITH_YOUR_DATABASE_NAME&quot;;<br>// REPLACE with Database user<br>$username = &quot;REPLACE_WITH_YOUR_USERNAME&quot;;<br>// REPLACE with Database user password<br>$password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;<br><br>// Create connection<br>$conn = new mysqli($servername, $username, $password, $dbname);<br>// Check connection<br>if ($conn-&gt;connect_error) {<br>    die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>} <br><br>$sql = &quot;SELECT id, temperature, pressure, reading_time FROM SensorMeasurements order by reading_time desc limit 40&quot;;<br><br>$result = $conn-&gt;query($sql);<br><br>while ($data = $result-&gt;fetch_assoc()){<br>    $sensor_data[] = $data;<br>}<br><br>$readings_time = array_column($sensor_data, &#39;reading_time&#39;);<br><br>// ******* Uncomment to convert readings time array to your timezone ********<br>/*$i = 0;<br>foreach ($readings_time as $reading){<br>    // Uncomment to set timezone to - 1 hour (you can change 1 to any number)<br>    $readings_time[$i] = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$reading - 1 hours&quot;));<br>    // Uncomment to set timezone to + 4 hours (you can change 4 to any number)<br>    //$readings_time[$i] = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$reading + 4 hours&quot;));<br>    $i += 1;<br>}*/<br><br>$temperature = json_encode(array_reverse(array_column($sensor_data, &#39;temperature&#39;)), JSON_NUMERIC_CHECK);<br>$pressure = json_encode(array_reverse(array_column($sensor_data, &#39;pressure&#39;)), JSON_NUMERIC_CHECK);<br>$reading_time = json_encode(array_reverse($readings_time), JSON_NUMERIC_CHECK);<br><br>/*echo $temperature;<br>echo $pressure;<br>echo $reading_time;*/<br><br>$result-&gt;free();<br>$conn-&gt;close();<br>?&gt;<br><br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;<br>  &lt;script src=&quot;https://code.highcharts.com/highcharts.js&quot;&gt;&lt;/script&gt;<br>  &lt;style&gt;<br>    body {<br>      min-width: 310px;<br>     max-width: 1280px;<br>     height: 500px;<br>      margin: 0 auto;<br>    }<br>    h2 {<br>      font-family: Arial;<br>      font-size: 2.5rem;<br>      text-align: center;<br>    }<br>  &lt;/style&gt;<br>  &lt;body&gt;<br>    &lt;h2&gt;ESP Weather Station&lt;/h2&gt;<br>    &lt;div id=&quot;chart-temperature&quot; class=&quot;container&quot;&gt;&lt;/div&gt;<br>    &lt;div id=&quot;chart-pressure&quot; class=&quot;container&quot;&gt;&lt;/div&gt;<br>&lt;script&gt;<br><br>var temperature = &lt;?php echo $temperature; ?&gt;;<br>var pressure = &lt;?php echo $pressure; ?&gt;;<br>var reading_time = &lt;?php echo $reading_time; ?&gt;;<br><br>var chartT = new Highcharts.Chart({<br>  chart:{ renderTo : &#39;chart-temperature&#39; },<br>  title: { text: &#39;BMP280 Temperature&#39; },<br>  series: [{<br>    showInLegend: false,<br>    data: temperature<br>  }],<br>  plotOptions: {<br>    line: { animation: false,<br>      dataLabels: { enabled: true }<br>    },<br>    series: { color: &#39;#059e8a&#39; }<br>  },<br>  xAxis: { <br>    type: &#39;datetime&#39;,<br>    categories: reading_time<br>  },<br>  yAxis: {<br>    title: { text: &#39;Temperature (Celsius)&#39; }<br>    //title: { text: &#39;Temperature (Fahrenheit)&#39; }<br>  },<br>  credits: { enabled: false }<br>});<br><br><br>var chartP = new Highcharts.Chart({<br>  chart:{ renderTo:&#39;chart-pressure&#39; },<br>  title: { text: &#39;BMP280 Pressure&#39; },<br>  series: [{<br>    showInLegend: false,<br>    data: pressure<br>  }],<br>  plotOptions: {<br>    line: { animation: false,<br>      dataLabels: { enabled: true }<br>    },<br>    series: { color: &#39;#18009c&#39; }<br>  },<br>  xAxis: {<br>    type: &#39;datetime&#39;,<br>    categories: reading_time<br>  },<br>  yAxis: {<br>    title: { text: &#39;Pressure (hPa)&#39; }<br>  },<br>  credits: { enabled: false }<br>});<br><br>&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><ul><li>Remember to replace $dbname, $username, $password with your own data.</li><li>Upload ‘esp32-chart.php’ to public_html folder.</li><li>Go to <a href="https://yourdomain.000webhostapp.com/esp32-chart.php">https://yourdomain.000webhostapp.com/esp32-chart.php</a> to see the data visualization</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*wvI9ldrv0pzhpzjlbtWtnQ.png" /><figcaption>VOILA!</figcaption></figure><h4>Data Logging</h4><p>Here’s the overview of the project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*lymqQK3xJo16FoVA" /></figure><h4>Step 1 — Create IFTT Account</h4><p>Go to <a href="https://ifttt.com/">https://www.iftt.com</a> and just follow the steps needed.</p><h4>Step 2 — Create an Applet</h4><p>1 — Go to “My Applet”, then click “Create Your Own”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*_Qw9qRFWD68ZTiRkQz6r9w.png" /></figure><p>2 — Click “Add” at the right side of “if this”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*r6HOPpAjRupBW1nt29QkLw.png" /></figure><p>3 — Search for “Webhooks” service and select webhooks icon</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*Mxo-mOfxx3ZJcNYYoi6sEQ.png" /></figure><p>4 — Choose the “Receive a web request” trigger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*w3avLIR_PI582WaTW6BDuA.png" /></figure><p>5 — Give a name to the event. In this case “bmp280_readings” as shown in the figure below. Click “Create trigger” button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*90SBcOYeQjO1TfQXb3l0-Q.png" /></figure><p>6 — Click “Add” at the right side of Then That.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*0kPsqW_FIsWsj1-RxA6dfA.png" /></figure><p>7 — Search for “Google Sheets” service, select the Google Sheets icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*5TKVu918-cVuxkwdrzFfCg.png" /></figure><p>8 — Choose “Add a row to spreadsheet” action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*lIM3piKJLtpVuoYUmQoLKw.png" /></figure><p>9 — Complete the action fields. Give the spreadsheet a name, leave the “Formatted row” field as default. Choose a Google Drive folder path. Finally, click the “Create action” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*Pt7a0bc7ngML30ljLWn5Uw.png" /></figure><p>10 — Click “Finish” and the applet will be created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*igo7L2NdqbKYEyp_dajyqQ.png" /></figure><h4>Step 3 — Testing Applet</h4><p>1 — Go to <a href="https://ifttt.com/maker_webhooks">Webhooks Service Page</a> and click “Documentation”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*ZeGSnBYzr1EfkjxJzhLthA.png" /></figure><p>2 — The page will be shown your unique API key. Fill the “To trigger an Event” section as shown below. Then, click the “Test it” button. If the event is successfully triggered, there will be green message saying “Event has been triggeres”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*JBEEnZ5QUiuJf6FauuQNxA.png" /></figure><p>3 — Go to Google Drive, The IFTTT service should have created a folder called “IFTTT” with the “BMP280_Readings” spreadsheet inside.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*VfqyBofS09JTvQMQUrI3vQ.png" /></figure><p>4 — Open the spreadsheet, and you should see the values you’ve filled previously to test the applet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*YVSyO2rcd5q_ml73nUa5zQ.png" /></figure><h4>Step 4 — ESP32 Setup</h4><p><strong>Schematics Diagram</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*IkfS9sH_DGrmEHp6" /></figure><p><strong>ESP32 code:</strong></p><pre>/*<br> * Rui Santos <br> * Complete Project Details https://randomnerdtutorials.com<br> */<br><br>#include &lt;WiFi.h&gt;<br><br>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_Sensor.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br><br>// Replace with your network credentials<br>const char* ssid     = &quot;REPLACE_WITH_YOUR_SSID&quot;;<br>const char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;<br><br>// Replace with your unique IFTTT URL resource<br>const char* resource = &quot;REPLACE_WITH_YOUR_IFTTT_URL_RESOURCE&quot;;<br><br>// How your resource variable should look like, but with your own API KEY (that API KEY below is just an example):<br>//const char* resource = &quot;/trigger/bme280_readings/with/key/nAZjOphL3d-ZO4N3k64-1A7gTlNSrxMJdmqy3&quot;;<br><br>// Maker Webhooks IFTTT<br>const char* server = &quot;maker.ifttt.com&quot;;<br><br>// Time to sleep<br>uint64_t uS_TO_S_FACTOR = 1000000;  // Conversion factor for micro seconds to seconds<br>// sleep for 10 minutes = 600 seconds<br>uint64_t TIME_TO_SLEEP = 600;<br><br>// Uncomment to use BMP280 SPI<br>/*#include &lt;SPI.h&gt;<br>#define BMP_SCK 18<br>#define BMP_MISO 19<br>#define BMP_MOSI 23<br>#define BMP_CS 5*/<br><br>#define SEALEVELPRESSURE_HPA (1013.25)<br><br>Adafruit_BMP280 bmp;  // I2C<br>//Adafruit_BMP280 bmp(BMP_CS);  // hardware SPI<br>//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);  // software SPI<br><br>void setup() {<br>  Serial.begin(115200);<br>  delay(2000);<br>  <br>  // initialize BMP280 sensor<br>  bool status = bmp.begin(0x76);<br>  if (!status) {<br>    Serial.println(&quot;Could not find a valid BMP280 sensor, check wiring or change I2C address!&quot;);<br>    while (1);<br>  }<br><br>  initWifi();<br>  makeIFTTTRequest();<br><br>  // enable timer deep sleep<br>  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);    <br>  Serial.println(&quot;Going to sleep now&quot;);<br>  // start deep sleep for 3600 seconds (60 minutes)<br>  esp_deep_sleep_start();<br>}<br><br>void loop() {<br>  // sleeping so wont get here <br>}<br><br>// Establish a Wi-Fi connection with your router<br>void initWifi() {<br>  Serial.print(&quot;Connecting to: &quot;); <br>  Serial.print(ssid);<br>  WiFi.begin(ssid, password);  <br><br>  int timeout = 10 * 4; // 10 seconds<br>  while(WiFi.status() != WL_CONNECTED  &amp;&amp; (timeout-- &gt; 0)) {<br>    delay(250);<br>    Serial.print(&quot;.&quot;);<br>  }<br>  Serial.println(&quot;&quot;);<br><br>  if(WiFi.status() != WL_CONNECTED) {<br>     Serial.println(&quot;Failed to connect, going back to sleep&quot;);<br>  }<br><br>  Serial.print(&quot;WiFi connected in: &quot;); <br>  Serial.print(millis());<br>  Serial.print(&quot;, IP address: &quot;); <br>  Serial.println(WiFi.localIP());<br>}<br><br>// Make an HTTP request to the IFTTT web service<br>void makeIFTTTRequest() {<br>  Serial.print(&quot;Connecting to &quot;); <br>  Serial.print(server);<br>  <br>  WiFiClient client;<br>  int retries = 5;<br>  while(!!!client.connect(server, 80) &amp;&amp; (retries-- &gt; 0)) {<br>    Serial.print(&quot;.&quot;);<br>  }<br>  Serial.println();<br>  if(!!!client.connected()) {<br>    Serial.println(&quot;Failed to connect...&quot;);<br>  }<br>  <br>  Serial.print(&quot;Request resource: &quot;); <br>  Serial.println(resource);<br><br>  // Temperature in Celsius<br>  String jsonObject = String(&quot;{\&quot;value1\&quot;:\&quot;&quot;) + String(bmp.readTemperature()) + &quot;\&quot;,\&quot;value2\&quot;:\&quot;&quot; + String(bmp.readPressure()/100.0F)<br>                      + &quot;\&quot;,\&quot;value3\&quot;:\&quot;&quot; + String(bmp.readAltitude(SEALEVELPRESSURE_HPA)) + &quot;\&quot;}&quot;;<br>                      <br>  // Comment the previous line and uncomment the next line to publish temperature readings in Fahrenheit                    <br>  /*String jsonObject = String(&quot;{\&quot;value1\&quot;:\&quot;&quot;) + String(1.8 * bmp.readTemperature() + 32) + &quot;\&quot;,\&quot;value2\&quot;:\&quot;&quot; <br>                      + String(bmp.readPressure()/100.0F) + &quot;\&quot;,\&quot;value3\&quot;:\&quot;&quot; + String(bmp.readAltitude(SEALEVELPRESSURE_HPA)) + &quot;\&quot;}&quot;;*/<br>                      <br>  client.println(String(&quot;POST &quot;) + resource + &quot; HTTP/1.1&quot;);<br>  client.println(String(&quot;Host: &quot;) + server); <br>  client.println(&quot;Connection: close\r\nContent-Type: application/json&quot;);<br>  client.print(&quot;Content-Length: &quot;);<br>  client.println(jsonObject.length());<br>  client.println();<br>  client.println(jsonObject);<br>        <br>  int timeout = 5 * 10; // 5 seconds             <br>  while(!!!client.available() &amp;&amp; (timeout-- &gt; 0)){<br>    delay(100);<br>  }<br>  if(!!!client.available()) {<br>    Serial.println(&quot;No response...&quot;);<br>  }<br>  while(client.available()){<br>    Serial.write(client.read());<br>  }<br>  <br>  Serial.println(&quot;\nclosing connection&quot;);<br>  client.stop(); <br>}</pre><p>Some things to take notes:</p><ul><li>Modify this code part with your network credentials.</li></ul><pre>// Replace with your SSID and Password<br>const char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;<br>const char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;</pre><ul><li>Modify this code part with your unique IFTT URL resorce</li></ul><pre>// Replace with your unique IFTTT URL resource<br>const char* resource = &quot;REPLACE_WITH_YOUR_IFTTT_URL_RESOURCE&quot;;</pre><p>In my case, my resource is:</p><pre>/trigger/bme280_readings/with/key/cIIkAUzv2WM1Of9O71K6iH</pre><p>So, the line looks as follows</p><pre>// Replace with your unique IFTTT URL resource<br>const char* resource = &quot;/trigger/bme280_readings/with/key/cIIkAUzv2WM1Of9O71K6iH&quot;;</pre><ul><li>Set sleep time</li></ul><pre>uint64_t TIME_TO_SLEEP = 600; // Every 10 minutes</pre><h4>Step 5 — Demonstration</h4><p>Every 10 minutes, ESP32 will wake up to do sensor readings and upload the readings to the spreadsheet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*0gIf7aT-Ra1jznrwONDxtQ.png" /><figcaption>VOILA DONE!</figcaption></figure><p>That’s all for me, All for embedded system course. Thank you soo much pak Soni and all friends and readers that has follow through these series of embedded system projects. Wish us all success in the future!!</p><p>Terima kasih. Hatur Nuhun. Matur Suwun. ありがとう ございます. 감사 합니다. tack så mycket. Vielen Dank. Gracias. Grazie mille. 太感谢了.شكراً جزيلاً.</p><h3>Reference</h3><p><a href="https://randomnerdtutorials.com/esp32-esp8266-plot-chart-web-server/">ESP32/ESP8266 Plot Sensor Readings in Real Time Charts | Random Nerd Tutorials</a></p><p><a href="https://randomnerdtutorials.com/esp32-esp8266-publish-sensor-readings-to-google-sheets/">https://randomnerdtutorials.com/esp32-esp8266-publish-sensor-readings-to-google-sheets/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80523f28a3b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded Project #9 — Database]]></title>
            <link>https://medium.com/@radantohilmi/embedded-project-9-database-2cc5f61f2e55?source=rss-e16235d71560------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cc5f61f2e55</guid>
            <dc:creator><![CDATA[Hilmi Baskara Radanto]]></dc:creator>
            <pubDate>Sun, 07 May 2023 15:59:10 GMT</pubDate>
            <atom:updated>2023-05-07T16:01:04.607Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embedded System Project #9 — Database</h3><p>Hello!</p><p>In this article, I’m gonna build a web server using MySQL database with data provided from ESP32. I’m using HTTP POST request to a PHP script to insert data to the database. This project is highly guided by randomnerdtutorials.com. So, without further ado, let’s get going!</p><h3>STEP 1 — Hosting PHP Application and MySQL Database</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*TsXvrtVODddixKOl" /><figcaption>Overview of the project scheme by randomnerdtutorials.com</figcaption></figure><p>I’m using free hosting service by <a href="https://www.000webhost.com/">https://www.000webhost.com/</a> because, well, it’s free. Sign yourself up to make an account.</p><h3>STEP 2 — Preparing MySQL Database</h3><p>After making an account, I’m immediately directed to make a website project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*OaaSdv85ypZWizZgYntkYw.png" /></figure><p>To prepare the database, go to Tools &gt; Database Manager &gt; New Database. It required database name, username, and password. Database is already created, click manage and choose PhpMyAdmin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*GrGzWEuAkJT8Oy0bdH7VXg.png" /><figcaption>Remember the database name and database user well because it will be used in the later stage.</figcaption></figure><p>To create SQL table, go to SQL tab in the dashboard. Fill that out with this code.</p><pre>CREATE TABLE SensorData (<br>    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,<br>    sensor VARCHAR(30) NOT NULL,<br>    location VARCHAR(30) NOT NULL,<br>    value1 VARCHAR(10),<br>    value2 VARCHAR(10),<br>    value3 VARCHAR(10),<br>    reading_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*FrHCowW50KvrmJD7wLrFmQ.png" /></figure><p>After that, click ‘Go’ at the bottom right corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*G2SwWDOyjICgVnx1On_bNA.png" /><figcaption>MySQL table successfully created</figcaption></figure><h3>STEP 3 — PHP Script HTTP POST, Inserting Data to MySQL Database</h3><p>First, make a file named “post-esp-data.php” and use this code. Remember to replace $dbname, $username, $password with your own data.</p><pre>&lt;?php<br><br>/*<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com/esp32-esp8266-mysql-database-php/<br>  <br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br>  <br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br>*/<br><br>$servername = &quot;localhost&quot;;<br><br>// REPLACE with your Database name<br>$dbname = &quot;REPLACE_WITH_YOUR_DATABASE_NAME&quot;;<br>// REPLACE with Database user<br>$username = &quot;REPLACE_WITH_YOUR_USERNAME&quot;;<br>// REPLACE with Database user password<br>$password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;<br><br>// Keep this API Key value to be compatible with the ESP32 code provided in the project page. <br>// If you change this value, the ESP32 sketch needs to match<br>$api_key_value = &quot;tPmAT5Ab3j7F9&quot;;<br><br>$api_key= $sensor = $location = $value1 = $value2 = $value3 = &quot;&quot;;<br><br>if ($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;) {<br>    $api_key = test_input($_POST[&quot;api_key&quot;]);<br>    if($api_key == $api_key_value) {<br>        $sensor = test_input($_POST[&quot;sensor&quot;]);<br>        $location = test_input($_POST[&quot;location&quot;]);<br>        $value1 = test_input($_POST[&quot;value1&quot;]);<br>        $value2 = test_input($_POST[&quot;value2&quot;]);<br>        $value3 = test_input($_POST[&quot;value3&quot;]);<br>        <br>        // Create connection<br>        $conn = new mysqli($servername, $username, $password, $dbname);<br>        // Check connection<br>        if ($conn-&gt;connect_error) {<br>            die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>        } <br>        <br>        $sql = &quot;INSERT INTO SensorData (sensor, location, value1, value2, value3)<br>        VALUES (&#39;&quot; . $sensor . &quot;&#39;, &#39;&quot; . $location . &quot;&#39;, &#39;&quot; . $value1 . &quot;&#39;, &#39;&quot; . $value2 . &quot;&#39;, &#39;&quot; . $value3 . &quot;&#39;)&quot;;<br>        <br>        if ($conn-&gt;query($sql) === TRUE) {<br>            echo &quot;New record created successfully&quot;;<br>        } <br>        else {<br>            echo &quot;Error: &quot; . $sql . &quot;&lt;br&gt;&quot; . $conn-&gt;error;<br>        }<br>    <br>        $conn-&gt;close();<br>    }<br>    else {<br>        echo &quot;Wrong API Key provided.&quot;;<br>    }<br><br>}<br>else {<br>    echo &quot;No data posted with HTTP POST.&quot;;<br>}<br><br>function test_input($data) {<br>    $data = trim($data);<br>    $data = stripslashes($data);<br>    $data = htmlspecialchars($data);<br>    return $data;<br>}</pre><p>Then, go to Tools &gt; File Manager. Click the Upload Files and you will see this interface. Open public_html the upload the “post-esp-data.php” file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5eEzcxEjD2wSY_BVm-U_mg.png" /><figcaption>The upload file button is at the top right corner.</figcaption></figure><p>Check <a href="https://yourdomain.000webhostapp.com/post-esp-data.php">https://yourdomain.000webhostapp.com/post-esp-data.php</a> to check if the php file uploaded is working successfully. Here’s what it should look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*R0yLlsiemS_Y9_LuOg5nvA.png" /></figure><h3>STEP 4 — PHP Script, Displaying Database Content</h3><p>Create another PHP file in /public-html to display database content to the web. Name it “esp-data.php”. Use the following code.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;&lt;body&gt;<br>&lt;?php<br>/*<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com/esp32-esp8266-mysql-database-php/<br>  <br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br>  <br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br>*/<br><br>$servername = &quot;localhost&quot;;<br><br>// REPLACE with your Database name<br>$dbname = &quot;REPLACE_WITH_YOUR_DATABASE_NAME&quot;;<br>// REPLACE with Database user<br>$username = &quot;REPLACE_WITH_YOUR_USERNAME&quot;;<br>// REPLACE with Database user password<br>$password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;<br><br>// Create connection<br>$conn = new mysqli($servername, $username, $password, $dbname);<br>// Check connection<br>if ($conn-&gt;connect_error) {<br>    die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);<br>} <br><br>$sql = &quot;SELECT id, sensor, location, value1, value2, value3, reading_time FROM SensorData ORDER BY id DESC&quot;;<br><br>echo &#39;&lt;table cellspacing=&quot;5&quot; cellpadding=&quot;5&quot;&gt;<br>      &lt;tr&gt; <br>        &lt;td&gt;ID&lt;/td&gt; <br>        &lt;td&gt;Sensor&lt;/td&gt; <br>        &lt;td&gt;Location&lt;/td&gt; <br>        &lt;td&gt;Value 1&lt;/td&gt; <br>        &lt;td&gt;Value 2&lt;/td&gt;<br>        &lt;td&gt;Value 3&lt;/td&gt; <br>        &lt;td&gt;Timestamp&lt;/td&gt; <br>      &lt;/tr&gt;&#39;;<br> <br>if ($result = $conn-&gt;query($sql)) {<br>    while ($row = $result-&gt;fetch_assoc()) {<br>        $row_id = $row[&quot;id&quot;];<br>        $row_sensor = $row[&quot;sensor&quot;];<br>        $row_location = $row[&quot;location&quot;];<br>        $row_value1 = $row[&quot;value1&quot;];<br>        $row_value2 = $row[&quot;value2&quot;]; <br>        $row_value3 = $row[&quot;value3&quot;]; <br>        $row_reading_time = $row[&quot;reading_time&quot;];<br>        // Uncomment to set timezone to - 1 hour (you can change 1 to any number)<br>        //$row_reading_time = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$row_reading_time - 1 hours&quot;));<br>      <br>        // Uncomment to set timezone to + 4 hours (you can change 4 to any number)<br>        //$row_reading_time = date(&quot;Y-m-d H:i:s&quot;, strtotime(&quot;$row_reading_time + 4 hours&quot;));<br>      <br>        echo &#39;&lt;tr&gt; <br>                &lt;td&gt;&#39; . $row_id . &#39;&lt;/td&gt; <br>                &lt;td&gt;&#39; . $row_sensor . &#39;&lt;/td&gt; <br>                &lt;td&gt;&#39; . $row_location . &#39;&lt;/td&gt; <br>                &lt;td&gt;&#39; . $row_value1 . &#39;&lt;/td&gt; <br>                &lt;td&gt;&#39; . $row_value2 . &#39;&lt;/td&gt;<br>                &lt;td&gt;&#39; . $row_value3 . &#39;&lt;/td&gt; <br>                &lt;td&gt;&#39; . $row_reading_time . &#39;&lt;/td&gt; <br>              &lt;/tr&gt;&#39;;<br>    }<br>    $result-&gt;free();<br>}<br><br>$conn-&gt;close();<br>?&gt; <br>&lt;/table&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Check <a href="https://yourdomain.000webhostapp.com/post-esp-data.php">https://yourdomain.000webhostapp.com/esp-data.php</a> to check if the php file uploaded is working successfully. Here’s what it should look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*kpGbIUUYkaA8MZ1LohIFJw.png" /></figure><h3>STEP 5 — Setting up the ESP32</h3><h4>Parts and Components</h4><ol><li>ESP32</li><li>BMP280</li><li>Jumper wires</li><li>Breadboard</li></ol><h4>Schematics Diagram</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*CSsPamhRMs-USOZj" /><figcaption>By randomnerdtutorials.com</figcaption></figure><p>ESP32 pins:</p><ul><li>GPIO22: SCL</li><li>GPIO21: SDA</li></ul><h4>ESP32 Code</h4><pre>/*<br>  Rui Santos<br>  Complete project details at https://RandomNerdTutorials.com/esp32-esp8266-mysql-database-php/<br>  <br>  Permission is hereby granted, free of charge, to any person obtaining a copy<br>  of this software and associated documentation files.<br>  <br>  The above copyright notice and this permission notice shall be included in all<br>  copies or substantial portions of the Software.<br><br>*/<br><br>#include &lt;WiFi.h&gt;<br>#include &lt;WiFiClientSecure.h&gt;<br>#include &lt;HTTPClient.h&gt;<br>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_Sensor.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br><br>// Replace with your network credentials<br>const char* ssid     = &quot;WRITE_YOUR_SSID_HERE&quot;;<br>const char* password = &quot;WRITE_YOUR_PASSWORD_HERE&quot;;<br><br>// REPLACE with your Domain name and URL path or IP address with path<br>const char* serverName = &quot;https://yourdomain.000webhostapp.com/post-esp-data.php&quot;;<br><br>// Keep this API Key value to be compatible with the PHP code provided in the project page. <br>// If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key <br>String apiKeyValue = &quot;tPmAT5Ab3j7F9&quot;;<br><br>String sensorName = &quot;BMP280&quot;;<br>String sensorLocation = &quot;Home&quot;;<br><br>/*#include &lt;SPI.h&gt;<br>#define BMP_SCK 18<br>#define BMP_MISO 19<br>#define BMP_MOSI 23<br>#define BMP_CS 5*/<br><br>#define SEALEVELPRESSURE_HPA (1013.25)<br><br>Adafruit_BMP280 bmp;  // I2C<br>//Adafruit_BMP280 bmp(BMP_CS);  // hardware SPI<br>//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);  // software SPI<br><br>void setup() {<br>  Serial.begin(115200);<br>  <br>  WiFi.begin(ssid, password);<br>  Serial.println(&quot;Connecting&quot;);<br>  while(WiFi.status() != WL_CONNECTED) { <br>    delay(500);<br>    Serial.print(&quot;.&quot;);<br>  }<br>  Serial.println(&quot;&quot;);<br>  Serial.print(&quot;Connected to WiFi network with IP Address: &quot;);<br>  Serial.println(WiFi.localIP());<br><br>  // (you can also pass in a Wire library object like &amp;Wire2)<br>  bool status = bmp.begin(0x76);<br>  if (!status) {<br>    Serial.println(&quot;Could not find a valid BMP280 sensor, check wiring or change I2C address!&quot;);<br>    while (1);<br>  }<br>}<br><br>void loop() {<br>  //Check WiFi connection status<br>  if(WiFi.status()== WL_CONNECTED){<br>    WiFiClientSecure *client = new WiFiClientSecure;<br>    client-&gt;setInsecure(); //don&#39;t use SSL certificate<br>    HTTPClient https;<br>    <br>    // Your Domain name with URL path or IP address with path<br>    https.begin(*client, serverName);<br>    <br>    // Specify content-type header<br>    https.addHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);<br>    <br>    // Prepare your HTTP POST request data<br>    String httpRequestData = &quot;api_key=&quot; + apiKeyValue + &quot;&amp;sensor=&quot; + sensorName<br>                          + &quot;&amp;location=&quot; + sensorLocation + &quot;&amp;temperature=&quot; + String(bmp.readTemperature()) +<br>                          + &quot;&amp;pressure=&quot; + String(bmp.readPressure()/100.0F) + &quot;&amp;altitude=&quot; + String(bmp.readAltitude(SEALEVELPRESSURE_HPA)) + &quot;&quot;;<br>    Serial.print(&quot;httpRequestData: &quot;);<br>    Serial.println(httpRequestData);<br>    <br>    // You can comment the httpRequestData variable above<br>    // then, use the httpRequestData variable below (for testing purposes without the BMP280 sensor)<br>    //String httpRequestData = &quot;api_key=tPmAT5Ab3j7F9&amp;sensor=BMP280&amp;location=Office&amp;value1=24.75&amp;value2=49.54&amp;value3=1005.14&quot;;<br><br>    // Send HTTP POST request<br>    int httpResponseCode = https.POST(httpRequestData);<br>     <br>    // If you need an HTTP request with a content type: text/plain<br>    //https.addHeader(&quot;Content-Type&quot;, &quot;text/plain&quot;);<br>    //int httpResponseCode = https.POST(&quot;Hello, World!&quot;);<br>    <br>    // If you need an HTTP request with a content type: application/json, use the following:<br>    //https.addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);<br>    //int httpResponseCode = https.POST(&quot;{\&quot;value1\&quot;:\&quot;19\&quot;,\&quot;value2\&quot;:\&quot;67\&quot;,\&quot;value3\&quot;:\&quot;78\&quot;}&quot;);<br>    <br>    if (httpResponseCode&gt;0) {<br>      Serial.print(&quot;HTTP Response code: &quot;);<br>      Serial.println(httpResponseCode);<br>    }<br>    else {<br>      Serial.print(&quot;Error code: &quot;);<br>      Serial.println(httpResponseCode);<br>    }<br>    // Free resources<br>    https.end();<br>  }<br>  else {<br>    Serial.println(&quot;WiFi Disconnected&quot;);<br>  }<br>  //Send an HTTP POST request every 30 seconds<br>  delay(30000);  <br>}</pre><p>Two things to take notes,</p><ul><li>Modify the following lines with SSID and password of your WiFi credentials.</li></ul><pre>// Replace with your network credentials<br>const char* ssid     = &quot;REPLACE_WITH_YOUR_SSID&quot;;<br>const char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;</pre><ul><li>Modify the following line with your domain name, so the ESP will upload the measurement to the server.</li></ul><pre>const char* serverName = &quot;https://yourdomain.000webhost.com/post-esp-data.php&quot;;</pre><h3>STEP 6 — Demonstration</h3><p>Open your serial monitor. If it’s shown HTTP Response code: 200, the data is successfully uploaded the web server. If it’s shown Error code: -1, it isn’t successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*IdEpy9vAN5OG2uNeO1JM2w.png" /></figure><p>Go to <a href="https://yourdomain.000webhostapp.com/esp-data.php.">https://yourdomain.000webhostapp.com/esp-data.php</a> to see the data measured by BMP280.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*z8ThGMn4KoC0d74XsmPTzg.png" /></figure><p>YAY VOILA IT’S DONE. Arigatou Gozaimasu.</p><h4>Problem that (is frustating) I faced</h4><p>At the very last step, my data isn’t showing up at the website, it’s only giving me empty screen. After some LOTS of time, I realized that I mistakenly filled the $dbname, $username data in the php files without the codes before “esp_data” and “hilmi”. When I reuploaded the right code, It’s working properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*GrGzWEuAkJT8Oy0bdH7VXg.png" /><figcaption>I didnt include those id20714454_</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cc5f61f2e55" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded System Project #8 — Web Server & Advanced Weather Station]]></title>
            <link>https://medium.com/@radantohilmi/embedded-system-project-8-web-server-advanced-weather-station-2665adc67d7a?source=rss-e16235d71560------2</link>
            <guid isPermaLink="false">https://medium.com/p/2665adc67d7a</guid>
            <dc:creator><![CDATA[Hilmi Baskara Radanto]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 15:26:35 GMT</pubDate>
            <atom:updated>2023-04-03T04:24:01.340Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embedded System Project #8 — Web Server &amp; Advanced Weather Station</h3><p>좋은 오후에요!!</p><p>Hello and welcome to the last mandatory project of Embedded System, that is web server &amp; advanced weather station.</p><h3>Parts and components</h3><ul><li>ESP32 with Breadboard</li><li>Micro USB data cable</li><li>Some jumper wires</li><li>2 LEDs</li><li>2 Resistor 330<strong>Ω</strong></li><li>BMP280</li></ul><h3>Sub-Project 1</h3><h4>Step 1. Craft the circuit</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*STNiRf1QHUG7MQTI" /><figcaption>Diagram scheme</figcaption></figure><h4>Step 2. Upload the code</h4><pre>/*********<br>  Rui Santos<br>  Complete project details at https://randomnerdtutorials.com  <br>*********/<br><br>// Load Wi-Fi library<br>#include &lt;WiFi.h&gt;<br><br>// Replace with your network credentials<br>const char* ssid = &quot;Lantai 3&quot;;<br>const char* password = &quot;1122334455&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 output26State = &quot;off&quot;;<br>String output27State = &quot;off&quot;;<br><br>// Assign output variables to GPIO pins<br>const int output26 = 26;<br>const int output27 = 27;<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(output26, OUTPUT);<br>  pinMode(output27, OUTPUT);<br>  // Set outputs to LOW<br>  digitalWrite(output26, LOW);<br>  digitalWrite(output27, 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>    currentTime = millis();<br>    previousTime = currentTime;<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>    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 /26/on&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 26 on&quot;);<br>              output26State = &quot;on&quot;;<br>              digitalWrite(output26, HIGH);<br>            } else if (header.indexOf(&quot;GET /26/off&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 26 off&quot;);<br>              output26State = &quot;off&quot;;<br>              digitalWrite(output26, LOW);<br>            } else if (header.indexOf(&quot;GET /27/on&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 27 on&quot;);<br>              output27State = &quot;on&quot;;<br>              digitalWrite(output27, HIGH);<br>            } else if (header.indexOf(&quot;GET /27/off&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 27 off&quot;);<br>              output27State = &quot;off&quot;;<br>              digitalWrite(output27, 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: #4CAF50; 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: #555555;}&lt;/style&gt;&lt;/head&gt;&quot;);<br>            <br>            // Web Page Heading<br>            client.println(&quot;&lt;body&gt;&lt;h1&gt;ESP32 Web Server&lt;/h1&gt;&quot;);<br>            <br>            // Display current state, and ON/OFF buttons for GPIO 26  <br>            client.println(&quot;&lt;p&gt;Lampu Hijau- State &quot; + output26State + &quot;&lt;/p&gt;&quot;);<br>            // If the output26State is off, it displays the ON button       <br>            if (output26State==&quot;off&quot;) {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/26/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;/26/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 27  <br>            client.println(&quot;&lt;p&gt;Lampu Merah - State &quot; + output27State + &quot;&lt;/p&gt;&quot;);<br>            // If the output27State is off, it displays the ON button       <br>            if (output27State==&quot;off&quot;) {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/27/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;/27/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><p>After that, open serial monitor to see the IP Address</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*qM2ADSFfs8ZuWp4rmQW-kg.png" /><figcaption>Successfully connected with WiFi</figcaption></figure><h4>Step 3. Open your browser and go to the IP address</h4><p>Open the IP address found from the step before</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*4EfCAVZ8A6pHLPBK4w7eng.png" /><figcaption>Here’s the appearance of the web</figcaption></figure><h4>Step 4. Voila!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*ChRRFnFS3Jv42bXb_lyfgQ.gif" /></figure><p>You can turn on and off each light from the web. Pretty cool isn’t it?</p><h3>Sub-Project 2</h3><h4>Step 1. Craft the circuit</h4><p>Below is the schematic diagram for BMP280 only, you just need add those pins and components after successfully done the above project without needing to change or move pins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*HGD75MmiqO04BEQF" /><figcaption>BME280 = BMP280. No difference in circuit.</figcaption></figure><h4>Step 2. Upload the code</h4><pre>/*********<br>  Rui Santos<br>  Complete project details at https://randomnerdtutorials.com  <br>*********/<br><br>// Load Wi-Fi library<br>#include &lt;WiFi.h&gt;<br>#include &lt;Wire.h&gt;<br>#include &lt;SPI.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br>#define BMP_SCK  (13)<br>#define BMP_MISO (12)<br>#define BMP_MOSI (11)<br>#define BMP_CS   (10)<br>Adafruit_BMP280 bmp;<br><br>#define SEALEVELPRESSURE_HPA (1013.25)<br><br>// Replace with your network credentials<br>const char* ssid = &quot;Lantai 3&quot;;<br>const char* password = &quot;1122334455&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 output26State = &quot;off&quot;;<br>String output27State = &quot;off&quot;;<br><br>// Assign output variables to GPIO pins<br>const int output26 = 26;<br>const int output27 = 27;<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(output26, OUTPUT);<br>  pinMode(output27, OUTPUT);<br>  // Set outputs to LOW<br>  digitalWrite(output26, LOW);<br>  digitalWrite(output27, LOW);<br><br>  if (!bmp.begin(0x76)) {<br>    Serial.println(&quot;Could not find a valid BMP280 sensor, check wiring!&quot;);<br>    while (1);<br>  }<br><br>  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */<br>                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */<br>                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */<br>                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */<br>                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */<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>    currentTime = millis();<br>    previousTime = currentTime;<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>    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 /26/on&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 26 on&quot;);<br>              output26State = &quot;on&quot;;<br>              digitalWrite(output26, HIGH);<br>            } else if (header.indexOf(&quot;GET /26/off&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 26 off&quot;);<br>              output26State = &quot;off&quot;;<br>              digitalWrite(output26, LOW);<br>            } else if (header.indexOf(&quot;GET /27/on&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 27 on&quot;);<br>              output27State = &quot;on&quot;;<br>              digitalWrite(output27, HIGH);<br>            } else if (header.indexOf(&quot;GET /27/off&quot;) &gt;= 0) {<br>              Serial.println(&quot;GPIO 27 off&quot;);<br>              output27State = &quot;off&quot;;<br>              digitalWrite(output27, 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: #4CAF50; 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: #555555;}&lt;/style&gt;&lt;/head&gt;&quot;);<br>            <br>            // Web Page Heading<br>            client.println(&quot;&lt;body&gt;&lt;h1&gt;ESP32 Web Server&lt;/h1&gt;&quot;);<br>            client.println(&quot;&lt;table&gt;&lt;tr&gt;&lt;th&gt;MEASUREMENT&lt;/th&gt;&lt;th&gt;VALUE&lt;/th&gt;&lt;/tr&gt;&quot;);<br>            client.println(&quot;&lt;tr&gt;&lt;td&gt;Temp. Celsius&lt;/td&gt;&lt;td&gt;&lt;span class=\&quot;sensor\&quot;&gt;&quot;);<br>            client.println(bmp.readTemperature());<br>            client.println(&quot; *C&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&quot;);  <br>            client.println(&quot;&lt;tr&gt;&lt;td&gt;Temp. Fahrenheit&lt;/td&gt;&lt;td&gt;&lt;span class=\&quot;sensor\&quot;&gt;&quot;);<br>            client.println(1.8 * bmp.readTemperature() + 32);<br>            client.println(&quot; *F&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&quot;);       <br>            client.println(&quot;&lt;tr&gt;&lt;td&gt;Pressure&lt;/td&gt;&lt;td&gt;&lt;span class=\&quot;sensor\&quot;&gt;&quot;);<br>            client.println(bmp.readPressure() / 100.0F);<br>            client.println(&quot; hPa&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&quot;);<br>            client.println(&quot;&lt;tr&gt;&lt;td&gt;Approx. Altitude&lt;/td&gt;&lt;td&gt;&lt;span class=\&quot;sensor\&quot;&gt;&quot;);<br>            client.println(bmp.readAltitude(SEALEVELPRESSURE_HPA));<br>            client.println(&quot; m&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&quot;); <br>            client.println(&quot;&lt;/body&gt;&lt;/html&gt;&quot;);<br><br>            // Display current state, and ON/OFF buttons for GPIO 26  <br>            client.println(&quot;&lt;p&gt;Lampu Hijau- State &quot; + output26State + &quot;&lt;/p&gt;&quot;);<br>            // If the output26State is off, it displays the ON button       <br>            if (output26State==&quot;off&quot;) {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/26/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;/26/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 27  <br>            client.println(&quot;&lt;p&gt;Lampu Merah - State &quot; + output27State + &quot;&lt;/p&gt;&quot;);<br>            // If the output27State is off, it displays the ON button       <br>            if (output27State==&quot;off&quot;) {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/27/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;/27/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><p>You’ll get the IP address from serial monitor. Remember the numbers.</p><h4>Step 3. Open your browser and go to the IP address</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*jfA62zt1R4nfOSK5gcyEhA.png" /><figcaption>Here’s the web apperance</figcaption></figure><h4>Step 4. Voila!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*WZyb_ezK5A5hMFAjv9PQPg.gif" /></figure><h3>References</h3><ul><li><a href="https://randomnerdtutorials.com/esp32-web-server-arduino-ide/">ESP32 Web Server - Arduino IDE | Random Nerd Tutorials</a></li><li><a href="https://randomnerdtutorials.com/esp32-web-server-with-bme280-mini-weather-station/">ESP32 Web Server with BME280 - Advanced Weather Station | Random Nerd Tutorials</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2665adc67d7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bluetooth Communication — Embedded System Project #7]]></title>
            <link>https://medium.com/@radantohilmi/bluetooth-communication-embedded-system-project-7-ea6f602f64b?source=rss-e16235d71560------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea6f602f64b</guid>
            <dc:creator><![CDATA[Hilmi Baskara Radanto]]></dc:creator>
            <pubDate>Sun, 26 Mar 2023 10:48:50 GMT</pubDate>
            <atom:updated>2023-03-26T10:48:50.486Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bluetooth Communication — Embedded System Project #7</h3><p><em>Hej! God kväll!</em></p><p>Happy balinese day of silence to y’all who celebrates and happy ramadhan fasting to all moslem readers! Today, amidst the rainy weather of the rain city of Bogor, I’m going to try another feature of the great ESP32, that is <strong>Bluetooth communication</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*HCQBYUFaa9AWDF3g" /><figcaption>Bluetooth logo.</figcaption></figure><p>Aside from Wi-Fi, ESP32 comes with <strong>Bluetooth Low Energy (BLE) </strong>and B<strong>luetootch Classic</strong>. BLE is a power-conserving variant of Bluetooth. BLE’s primary application is short distance transmission of small amounts of data (low bandwidth). Unlike Bluetooth Classic that is always on, BLE remains in sleep mode constantly except for when a connection is initiated. This makes it consume very low power. BLE consumes approximately 100x less power than Bluetooth Classic (depending on the use case).</p><p>In this project I will try both version of bluetooth down below. Without further a do, let’s just get going! p.s. this project works only on Android.</p><h3>Parts and Components</h3><ul><li>ESP32</li><li>BMP280</li><li>2 Breadboard</li><li>Some male-to-male and male-to-female jumper wires</li><li>LED</li><li>330 Ohm resistor</li><li>Android phone</li><li>LCD Display (as the additional component)</li></ul><p>There are 3 sub-project in Bluetooth communication, which are:</p><h3>Project 1 — Bluetooth Classic</h3><p><strong>Step 1. Install Bluetooth Serial Terminal in your Android phone!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*9zIySGmi08k_KAqSsQCVmg.jpeg" /></figure><p><strong>Step 2. Connect ESP32 to laptop!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0HWedfVPz2K1If16F1TGkQ.png" /></figure><p><strong>Step 3. Use the example code provided by Arduino IDE!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*Do8HjJm9Q5gzLWTZF0tx-g.png" /></figure><p><strong>Step 4. Upload the Code and open serial monitor!</strong></p><p>Here’s the code in case you don’t find the example in the Arduino IDE</p><pre>#include &quot;BluetoothSerial.h&quot;<br><br><br>#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)<br>#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it<br>#endif<br><br><br>BluetoothSerial SerialBT;<br><br><br>void setup() {<br>  Serial.begin(115200);<br>  SerialBT.begin(&quot;ESP32test&quot;); //Bluetooth device name<br>  Serial.println(&quot;The device started, now you can pair it with bluetooth!&quot;);<br>}<br><br><br>void loop() {<br>  if (Serial.available()) {<br>    SerialBT.write(Serial.read());<br>  }<br>  if (SerialBT.available()) {<br>    Serial.write(SerialBT.read());<br>  }<br>  delay(20);<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*CHMcSDan4hRXBEoHLLEERw.png" /><figcaption>The code is successfully uploaded and you can pair it with your phone’s bluetooth</figcaption></figure><p><strong>Step 5. Pair your phone’s bluetooth to ESP32!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*4yK1Sm17fah_hNNmWpfyiQ.jpeg" /></figure><p><strong>Step 6. Open Bluetooth Serial Terminal!</strong></p><p>Press the three line menu at the top left corner, go to devices and choose ESP32!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OQ3VVrmig7LL_WVLLtR5fw.jpeg" /></figure><p><strong>Step 7. Voila! You can exchange messages from phone and serial monitor!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*8PdC73JgB5EtYMJNKm6fDA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*eB1VTi_EjWItWVgBQD0Nvw.jpeg" /></figure><h3>Project 2 — Bluetooth classic with LED lamp and BMP280 sensor</h3><p><strong>Step 1. Craft the circuit!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U4ZBKIsne7vPyPwCvZl35Q.jpeg" /><figcaption>It’s actually looks like a bit of a mess.</figcaption></figure><p><strong>Pin Schema</strong></p><ul><li>BMP280</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*lhjMm6hKh-tSzT19GKVrPw.png" /></figure><ul><li>LED</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*BVrGPxFES529jMXOF4Sluw.png" /></figure><ul><li>Resistor</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*7U4ZI2dEyP204XJNH9Op_A.png" /></figure><p>Actually, there’s no difference between each side of the resistor. You can connect whichever side to connect with LED and ESP32’s GND.</p><p><strong>Step 2. Upload the code!</strong></p><pre>/*********<br>  Rui Santos<br>  Complete project details at https://randomnerdtutorials.com<br>*********/<br><br><br>// Load libraries<br>#include &quot;BluetoothSerial.h&quot;<br>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br>#define BMP_SCK  (13)<br>#define BMP_MISO (12)<br>#define BMP_MOSI (11)<br>#define BMP_CS   (10)<br>Adafruit_BMP280 bmp;<br><br><br>// Check if Bluetooth configs are enabled<br>#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)<br>#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it<br>#endif<br><br><br>// Bluetooth Serial object<br>BluetoothSerial SerialBT;<br><br><br>// GPIO where LED is connected to<br>const int ledPin =  25;<br><br><br>// Handle received and sent messages<br>String message = &quot;&quot;;<br>char incomingChar;<br>String temperatureString = &quot;&quot;;<br><br><br>// Timer: auxiliar variables<br>unsigned long previousMillis = 0;    // Stores last time temperature was published<br>const long interval = 10000;         // interval at which to publish sensor readings<br><br><br>void setup() {<br>  Serial.begin(115200);<br>  SerialBT.begin(&quot;ESP32&quot;);<br>  Serial.println(&quot;The device started, now you can pair it with bluetooth!&quot;);<br>  pinMode(ledPin, OUTPUT);<br>  if (!bmp.begin(0x76)) { // use the address you found<br>      Serial.println(F(&quot;Could not find a valid BMP280 sensor, check wiring!&quot;));<br>      while (1);<br>    }<br>  /* Default settings from datasheet. */<br>    bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */<br>                    Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */<br>                    Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */<br>                    Adafruit_BMP280::FILTER_X16,      /* Filtering. */<br>                    Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */<br>  // Bluetooth device name<br>}<br><br><br>void loop() {<br>  unsigned long currentMillis = millis();<br>  // Send temperature readings<br>  if (currentMillis - previousMillis &gt;= interval){<br>    previousMillis = currentMillis;<br>    temperatureString = String(bmp.readTemperature()) + &quot;C  &quot;;<br>    SerialBT.println(temperatureString);<br>  }<br>  // Read received messages (LED control command)<br>  if (SerialBT.available()){<br>    char incomingChar = SerialBT.read();<br>    if (incomingChar != &#39;\n&#39;){<br>      message += String(incomingChar);<br>    }<br>    else{<br>      message = &quot;&quot;;</pre><p><strong>Step 3. Open bluetooth terminal and send “led_on” or “led_off” from your phone!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ZykD9gy2W7U7c_Vi4b33Kw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*ZQZBTl03Ni4iaNmUCL129Q.jpeg" /><figcaption>COOL!!</figcaption></figure><p>The LED lamp would be turned on and off based on my the command sent in the bluetooth terminal. The bluetooth terminal would also send me measurement of the temperature done by BMP280 sensor.</p><h3>Project 2.5 — Bluetooth classic with LED lamp + Display</h3><p><strong>Step 1. Craft the circuit!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LucJXj7OKbwqb5J_VjFNTw.jpeg" /></figure><p>Additional Pin schema for LCD Display:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*oeY05TUB-885fkiZIfcaFA.png" /></figure><p><strong>Step 2. Upload the code!</strong></p><pre>#include &quot;BluetoothSerial.h&quot;<br>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br>#include &lt;LiquidCrystal_I2C.h&gt;<br>// Cek konfigurasi Bluetooth apakah sudah enabled<br>#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)<br>#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it<br>#endif<br>// Objek Bluetooth Serial<br>BluetoothSerial SerialBT;<br>// Variabel GPIO yang terhubung ke LED<br>const int ledPin =  25;<br>// Objek BMP280<br>Adafruit_BMP280 bmp;<br>//Objek I2C LCD<br>int lcdColumns = 16;<br>int lcdRows = 2;<br>LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);<br>// Variabel untuk pertukaran pesan<br>String message = &quot;&quot;;<br>char incomingChar;<br>// Timer<br>unsigned long previousMillis = 0;    // Menyimpan waktu suhu terakhir yang dipublikasikan<br>const long interval = 5000;         // Interval publikasi hasil pembacaan suhu dari sensor<br>void setup() {<br>  // Bluetooth<br>  Serial.begin(115200);<br>  SerialBT.begin(&quot;ESP32&quot;); // Bluetooth device name<br>  Serial.println(&quot;The device started, now you can pair it with bluetooth!&quot;);<br>// LED<br>  pinMode(ledPin, OUTPUT);<br>// BMP280<br>  if (!bmp.begin(0x76)) {<br>    Serial.println(F(&quot;Could not find a valid BMP280 sensor, check wiring!&quot;));<br>    while (1);<br>  }<br>  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */<br>                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */<br>                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */<br>                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */<br>                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */<br> <br>  // I2C LCD<br>  lcd.init(); //Inisiasi  <br>  lcd.backlight(); //Menyalakan backlight LCD<br>}<br>void loop() {<br>    unsigned long currentMillis = millis();<br>   <br>  // Mengirimkan suhu hasil pembacaan<br>  if (currentMillis - previousMillis &gt;= interval){<br>    previousMillis = currentMillis;<br>    SerialBT.print(bmp.readTemperature());<br>    SerialBT.println(&quot; *C&quot;);<br>    SerialBT.print(bmp.readAltitude(1013.25));<br>    SerialBT.println(&quot; m&quot;);<br>  }<br>  // Membaca pesan yang diterima untuk kontrol LED<br>  if (SerialBT.available()){<br>    char incomingChar = SerialBT.read();<br>    if (incomingChar != &#39;\n&#39;){<br>      message += String(incomingChar);<br>    }<br>    else{<br>      message = &quot;&quot;;<br>    }<br>    Serial.write(incomingChar);  <br>  }<br> <br>  // Menyesuaikan input pesan dengan output state LED dan mencetak status command ke LCD<br>  if (message == &quot;led_on&quot;){<br>    digitalWrite(ledPin, HIGH);<br>    lcd.clear();<br>    lcd.setCursor(0, 0);<br>    //Tampilkan pesan<br>    lcd.print(&quot;Sukses!&quot;);<br>    //Set kursor ke kolom 1 baris 2<br>    lcd.setCursor(0,1);<br>    //Tampilkan temperatur<br>    lcd.print(&quot;LED menyala&quot;);<br>  }<br>  else if (message == &quot;led_off&quot;){<br>    digitalWrite(ledPin, LOW);<br>    lcd.clear();<br>    lcd.setCursor(0, 0);<br>    //Tampilkan pesan<br>    lcd.print(&quot;Sukses!&quot;);<br>    //Set kursor ke kolom 1 baris 2<br>    lcd.setCursor(0,1);<br>    //Tampilkan temperatur<br>    lcd.print(&quot;LED mati&quot;);<br>  }<br> <br>  delay(20);<br>}</pre><p><strong>Step 3. Send “led_on” or “led_off” from your phone. Voila!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*uhl8iavhezKH43mXpyPzIg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*PVUCc-Ux0cnVVNCngBcT4g.gif" /><figcaption>“led_on” to turn on and “led_off” to turn off!</figcaption></figure><h3>Project 3 — Bluetooth Low Energy (BLE)</h3><p><strong>Step 1. Download nRF Connect in your Android phone</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*lTqkPjXxih8unfAsgCe3_w.jpeg" /><figcaption>I already installed it!</figcaption></figure><p><strong>Step 2. Connect ESP32 to Laptop</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b3_X4R-w5hCZ-nneXilePQ.jpeg" /></figure><p><strong>Step 3. Upload the code</strong></p><p>The code is actually provided by Arduino IDE. <strong>File &gt; Examples</strong> &gt; <strong>ESP32 BLE Arduino</strong> and select the <strong>BLE_scan</strong> example. The following code should load.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*XbaiP0zTvLo_E_mD_AVUbQ.png" /></figure><pre>/*<br>   Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp<br>   Ported to Arduino ESP32 by Evandro Copercini<br>*/<br><br>#include &lt;BLEDevice.h&gt;<br>#include &lt;BLEUtils.h&gt;<br>#include &lt;BLEScan.h&gt;<br>#include &lt;BLEAdvertisedDevice.h&gt;<br><br>int scanTime = 5; //In seconds<br>BLEScan* pBLEScan;<br><br>class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {<br>    void onResult(BLEAdvertisedDevice advertisedDevice) {<br>      Serial.printf(&quot;Advertised Device: %s \n&quot;, advertisedDevice.toString().c_str());<br>    }<br>};<br><br>void setup() {<br>  Serial.begin(115200);<br>  Serial.println(&quot;Scanning...&quot;);<br><br>  BLEDevice::init(&quot;&quot;);<br>  pBLEScan = BLEDevice::getScan(); //create new scan<br>  pBLEScan-&gt;setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());<br>  pBLEScan-&gt;setActiveScan(true); //active scan uses more power, but get results faster<br>  pBLEScan-&gt;setInterval(100);<br>  pBLEScan-&gt;setWindow(99);  // less or equal setInterval value<br>}<br><br>void loop() {<br>  // put your main code here, to run repeatedly:<br>  BLEScanResults foundDevices = pBLEScan-&gt;start(scanTime, false);<br>  Serial.print(&quot;Devices found: &quot;);<br>  Serial.println(foundDevices.getCount());<br>  Serial.println(&quot;Scan done!&quot;);<br>  pBLEScan-&gt;clearResults();   // delete results fromBLEScan buffer to release memory<br>  delay(2000);<br>}</pre><p><strong>Step 4. Pair ESP32 with phone’s bluetooth</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*YqcJzunMSYp999LAieJ2Eg.jpeg" /><figcaption>It’s named MyESP32 for Bluetooth Low Energy Project</figcaption></figure><p><strong>Step 5. Open nRF Connect then connect to MyESP32</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AOggEyZ1g0czJQIkSFlgLQ.jpeg" /><figcaption>I already connected it, so I just needed to open tab!</figcaption></figure><p><strong>Step 6. Click UART Service, then open Unknown Characteritic</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*__qdSvVTqZ3Hl1oYJwvx7Q.jpeg" /></figure><p><strong>Step 7. Choose TEXT (UTF-8) as the type of new value</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*Ep_4arxKd5-dunk6-B3uGg.jpeg" /></figure><p><strong>Step 8. Add value 1 or 0</strong></p><ul><li>Value 1 to turn on the LED</li><li>Value 0 to turn off the LED</li></ul><p><strong>Step 9. VOILA!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*YrEPB1OfV1hPfeqQ9OjkfA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*YASk9JmXWiZ_ikVbB80WPA.gif" /><figcaption>1 to turn on the LED, 0 to turn off</figcaption></figure><h4>Errors</h4><p>My Serial Monitor kept giving me weird symbols. I suspected that it’s coming from my faulty data cable because when I tried it with my friend’s cable data is working properly. However and luckily, It didn’t affect much in my project!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*CDQjSFAqueuznjlhjIt51w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*CDQjSFAqueuznjlhjIt51w.png" /></figure><h4>References</h4><p><a href="https://randomnerdtutorials.com/esp32-bluetooth-classic-arduino-ide/">https://randomnerdtutorials.com/esp32-bluetooth-classic-arduino-ide/</a></p><p><a href="https://randomnerdtutorials.com/esp32-bluetooth-low-energy-ble-arduino-ide/">https://randomnerdtutorials.com/esp32-bluetooth-low-energy-ble-arduino-ide/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea6f602f64b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded Project #6]]></title>
            <link>https://medium.com/@radantohilmi/embedded-project-6-482cb25c86cc?source=rss-e16235d71560------2</link>
            <guid isPermaLink="false">https://medium.com/p/482cb25c86cc</guid>
            <dc:creator><![CDATA[Hilmi Baskara Radanto]]></dc:creator>
            <pubDate>Sun, 19 Mar 2023 16:19:54 GMT</pubDate>
            <atom:updated>2023-03-20T05:01:32.019Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Hola!</em></p><p>It’s just another day in my life and this day I’m going to experiment combining two of my previous projects, display and external sensor with OLED and BME280. Without further ado, let’s just get going!</p><h3>Parts and Component</h3><ol><li>Breadboard</li><li>ESP32</li><li>USB type-B cable</li><li>A set of male-to-male jumper cable. In this case, I used 11 cables.</li><li>BME280</li><li>OLED</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wajWcyxLTX07p-0gxCB7UQ.png" /><figcaption>Parts and components I used (+LED lamp for bonus)</figcaption></figure><h3>Pre-project</h3><p>In my previous projects, I used BMP280 as my external sensor and LCD as my display. However, I encountered some problems with mine and it is said like this below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tHdXeKD1tuIyNARvV-I44A.png" /><figcaption>“Could not find a BMP280. Check the wiring!”</figcaption></figure><p>I tried many things to fix the problem, such as tried another kind of code, varying different cables and breadboard, re-upload the code, and none of them worked. I tried to check the functionality of the LCD and it was still working, but when I tried the BMP280 only with serial monitor as the display, it shown nothing! I don’t know how else could I fix the problem and time was running out, I needed to go to attend an event. So, I borrow my friend’s BME280 and OLED. Thank God, IT WORKED!</p><p>And so, I installed the library needed, Adafruit SSD1305 for LED and Adafruit BME280 for BME280.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*lCvFf0uhJtWfCSZfLXwpgw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*aMHFIM99LTPuyy4IX5N7tQ.png" /></figure><p>Pre-project is done, let’s go to the next step:</p><h3>Steps</h3><h4>1. Craft the circuit</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v_GaUZZqpowysFvgRNt46w.png" /></figure><h4>2. Upload the code</h4><pre>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_GFX.h&gt;<br>#include &lt;Adafruit_SSD1306.h&gt;<br>#include &lt;Adafruit_Sensor.h&gt;<br>#include &lt;SPI.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br>#define BMP_SCK  (13)<br>#define BMP_MISO (12)<br>#define BMP_MOSI (11)<br>#define BMP_CS   (10)<br>Adafruit_BMP280 bmp; // I2C<br><br>#define SCREEN_WIDTH 128 // OLED display width, in pixels<br>#define SCREEN_HEIGHT 64 // OLED display height, in pixels<br><br>Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &amp;Wire, -1);<br><br>void setup() {<br>  Serial.begin(115200);<br>  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {<br>    Serial.println(F(&quot;SSD1306 allocation failed&quot;));<br>    for(;;);<br>  }<br>  <br>  bool status = bmp.begin(0x76);  <br>  if (!status) {<br>    Serial.println(&quot;Could not find a valid BMP280 sensor, check wiring!&quot;);<br>    while (1);<br>  }<br>  <br>  delay(2000);<br>  display.clearDisplay();<br>  display.setTextColor(WHITE);<br>}<br><br>void loop() {<br>  display.clearDisplay();<br>  // display temperature<br>  display.setTextSize(1);<br>  display.setCursor(0,0);<br>  display.print(&quot;Suhu: &quot;);<br>  display.setTextSize(2);<br>  display.setCursor(0,10);<br>  display.print(String(bmp.readTemperature()));<br>  display.print(&quot; &quot;);<br>  display.setTextSize(1);<br>  display.cp437(true);<br>  display.write(167);<br>  display.setTextSize(2);<br>  display.print(&quot;C&quot;);<br>  <br>  // display Altitude<br>  display.setTextSize(1);<br>  display.setCursor(0, 35);<br>  display.print(&quot;Ketinggian: &quot;);<br>  display.setTextSize(2);<br>  display.setCursor(0, 45);<br>  display.print(String(bmp.readAltitude()));<br>  display.print(&quot;mdpl&quot;);</pre><h4>3. Voila</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*mcvm6feOI6ZQPjVF3xRf2w.gif" /></figure><h4>Bonus</h4><p>As a bonus, I added LED lamp to be turned on when the temperature is above 30 degrees celcius. The temperature went above 30 when I touched the sensor. I made minor tweaks to the circuit and code. Here it is,</p><p><strong>Circuit</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v_GaUZZqpowysFvgRNt46w.png" /></figure><p><strong>Code</strong></p><pre>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_GFX.h&gt;<br>#include &lt;Adafruit_SSD1306.h&gt;<br>#include &lt;Adafruit_Sensor.h&gt;<br>#include &lt;SPI.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br>#define BMP_SCK  (13)<br>#define BMP_MISO (12)<br>#define BMP_MOSI (11)<br>#define BMP_CS   (10)<br>Adafruit_BMP280 bmp; // I2C<br>const int ledPin1 = 18;<br><br>#define SCREEN_WIDTH 128 // OLED display width, in pixels<br>#define SCREEN_HEIGHT 64 // OLED display height, in pixels<br><br>Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &amp;Wire, -1);<br><br>void setup() {<br>  Serial.begin(115200);<br>  pinMode(ledPin1, OUTPUT);<br>  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {<br>    Serial.println(F(&quot;SSD1306 allocation failed&quot;));<br>    for(;;);<br>  }<br>  <br>  bool status = bmp.begin(0x76);  <br>  if (!status) {<br>    Serial.println(&quot;Could not find a valid BMP280 sensor, check wiring!&quot;);<br>    while (1);<br>  }<br>  <br>  delay(2000);<br>  display.clearDisplay();<br>  display.setTextColor(WHITE);<br>}<br><br>void loop() {<br>  display.clearDisplay();<br>  // display temperature<br>  display.setTextSize(1);<br>  display.setCursor(0,0);<br>  display.print(&quot;Suhu: &quot;);<br>  display.setTextSize(2);<br>  display.setCursor(0,10);<br>  display.print(String(bmp.readTemperature()));<br>  display.print(&quot; &quot;);<br>  display.setTextSize(1);<br>  display.cp437(true);<br>  display.write(167);<br>  display.setTextSize(2);<br>  display.print(&quot;C&quot;);<br>  <br>  // display Altitude<br>  display.setTextSize(1);<br>  display.setCursor(0, 35);<br>  display.print(&quot;Ketinggian: &quot;);<br>  display.setTextSize(2);<br>  display.setCursor(0, 45);<br>  display.print(String(bmp.readAltitude()));<br>  display.print(&quot;mdpl&quot;); <br>  <br>  display.display();<br>  if (bmp.readTemperature() &gt; 30){<br>    digitalWrite(ledPin1, HIGH);<br>  } else {<br>    digitalWrite(ledPin1, LOW);<br>  }<br>  delay(1000);<br>}</pre><p><strong>Result</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*0d4ZICsSP7S52ICFkVvWRg.gif" /></figure><h4>REFERENCE</h4><p><a href="https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/">https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=482cb25c86cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Display— ESP32 Embedded System Project #5 (+Bonus Project)]]></title>
            <link>https://medium.com/@radantohilmi/display-esp32-embedded-system-project-5-bonus-project-4cec143100b0?source=rss-e16235d71560------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cec143100b0</guid>
            <dc:creator><![CDATA[Hilmi Baskara Radanto]]></dc:creator>
            <pubDate>Wed, 15 Mar 2023 16:30:25 GMT</pubDate>
            <atom:updated>2023-03-15T16:30:25.489Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Bonjour!</em></p><p>Okay, coming back with me, Hilmi, and today I’m gonna show you my 5th project of learning Embedded System. The component I used to demonstrate ESP32 display was with LCD on I2C. Without further a do, let’s just dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7574Qj3HJU5rqW2fc_rtyA.png" /></figure><h3>Parts and Component</h3><ul><li>ESP32</li><li>Breadboard</li><li>16x2 I2C LCD Display</li><li>4x jumper male-to-female cable</li><li>USB type-B cable</li></ul><h3>Steps</h3><h4>1. Install the LiquidCrystal_I2C Library!</h4><p>For today’s project, I used a library that isn’t available in the Arduino IDE. You can <a href="https://github.com/marcoschwartz/LiquidCrystal_I2C/archive/master.zip">click here</a> to install the library. Then, extract the file and put the folder into the Arduino IDE installation libraries folder. Reopen the Arduino IDE to make sure the library is loaded.</p><h4>2. Craft the circuit!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/0*TCOQnDVEGOtSi9Go" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*XsEmgBWysEkiG3m1-Vwd6Q.png" /><figcaption><a href="https://randomnerdtutorials.com/">https://randomnerdtutorials.com/</a></figcaption></figure><p>I used 2 breadboards put side by side to make the ESP32 able to be connected with jumper cables at both side to accomodate all the pins needed.</p><h4>3. Find the I2C address!</h4><p>To verify and find the I2C address for LCD you need to upload these code first to the ESP3</p><pre>/*********<br>  Rui Santos<br>  Complete project details at https://randomnerdtutorials.com  <br>*********/<br><br>#include &lt;Wire.h&gt;<br> <br>void setup() {<br>  Wire.begin();<br>  Serial.begin(115200);<br>  Serial.println(&quot;\nI2C Scanner&quot;);<br>}<br> <br>void loop() {<br>  byte error, address;<br>  int nDevices;<br>  Serial.println(&quot;Scanning...&quot;);<br>  nDevices = 0;<br>  for(address = 1; address &lt; 127; address++ ) {<br>    Wire.beginTransmission(address);<br>    error = Wire.endTransmission();<br>    if (error == 0) {<br>      Serial.print(&quot;I2C device found at address 0x&quot;);<br>      if (address&lt;16) {<br>        Serial.print(&quot;0&quot;);<br>      }<br>      Serial.println(address,HEX);<br>      nDevices++;<br>    }<br>    else if (error==4) {<br>      Serial.print(&quot;Unknow error at address 0x&quot;);<br>      if (address&lt;16) {<br>        Serial.print(&quot;0&quot;);<br>      }<br>      Serial.println(address,HEX);<br>    }    <br>  }<br>  if (nDevices == 0) {<br>    Serial.println(&quot;No I2C devices found\n&quot;);<br>  }<br>  else {<br>    Serial.println(&quot;done\n&quot;);<br>  }<br>  delay(5000);          <br>}</pre><p>I found mine located in 0x27 address</p><h4>4. Upload the display code!</h4><p>Here’s the code, you can change the “Hello, World!” part as free as you want :D.</p><pre>/*********<br>  Rui Santos<br>  Complete project details at https://randomnerdtutorials.com  <br>*********/<br><br>#include &lt;LiquidCrystal_I2C.h&gt;<br><br>// set the LCD number of columns and rows<br>int lcdColumns = 16;<br>int lcdRows = 2;<br><br>// set LCD address, number of columns and rows<br>// if you don&#39;t know your display address, run an I2C scanner sketch<br>LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);  <br><br>void setup(){<br>  // initialize LCD<br>  lcd.init();<br>  // turn on LCD backlight                      <br>  lcd.backlight();<br>}<br><br>void loop(){<br>  // set cursor to first column, first row<br>  lcd.setCursor(0, 0);<br>  // print message<br>  lcd.print(&quot;Hello, World!&quot;);<br>  delay(1000);<br>  // clears the display to print new message<br>  lcd.clear();<br>  // set cursor to first column, second row<br>  lcd.setCursor(0,1);<br>  lcd.print(&quot;Hello, World!&quot;);<br>  delay(1000);<br>  lcd.clear(); <br>}</pre><h4>5. VOILA</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*mqJUazvTJfV0x-6ZRoHfxw.gif" /></figure><h3>BONUS PROJECT</h3><p>And also, there’s a bonus project challenged by my lecturer, that is ESP32 PWM. It’s a project where the LED lamp can dim and light by itself with certain frequencies. So, just let’s go!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6IlSc1R-Z_6IJqVZhTWtbQ.png" /></figure><h3>Parts and Component</h3><ol><li>ESP32</li><li>Breadboard</li><li>3x resistors</li><li>3x LED lamps</li><li>4 jumper male-to-male cable</li><li>USB type-B cable</li></ol><h3>Steps</h3><h4>1. Craft the circuit!</h4><p>Here’s the circuit diagram</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*HAZcJ8WFxQcBLoV5UVcrnw.png" /><figcaption><a href="https://randomnerdtutorials.com/">https://randomnerdtutorials.com/</a></figcaption></figure><h4>2. Upload the code!</h4><p>Here’s the code to be uploaded</p><pre>// the number of the LED pin<br>const int ledPin = 16;  // 16 corresponds to GPIO16<br>const int ledPin2 = 17; // 17 corresponds to GPIO17<br>const int ledPin3 = 5;  // 5 corresponds to GPIO5<br><br>// setting PWM properties<br>const int freq = 5000;<br>const int ledChannel = 0;<br>const int resolution = 8;<br> <br>void setup(){<br>  // configure LED PWM functionalitites<br>  ledcSetup(ledChannel, freq, resolution);<br>  <br>  // attach the channel to the GPIO to be controlled<br>  ledcAttachPin(ledPin, ledChannel);<br>  ledcAttachPin(ledPin2, ledChannel);<br>  ledcAttachPin(ledPin3, ledChannel);<br>}<br> <br>void loop(){<br>  // increase the LED brightness<br>  for(int dutyCycle = 0; dutyCycle &lt;= 255; dutyCycle++){   <br>    // changing the LED brightness with PWM<br>    ledcWrite(ledChannel, dutyCycle);<br>    delay(15);<br>  }<br><br>  // decrease the LED brightness<br>  for(int dutyCycle = 255; dutyCycle &gt;= 0; dutyCycle--){<br>    // changing the LED brightness with PWM<br>    ledcWrite(ledChannel, dutyCycle);   <br>    delay(15);<br>  }<br>}</pre><h4>3. VOILA!</h4><p>Here’s the result!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*NkonhWi0Ur7RQlBf.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cec143100b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[External Sensor — Embedded System ESP32 Project #4]]></title>
            <link>https://medium.com/@radantohilmi/external-sensor-embedded-system-esp32-project-4-77f6d3c998be?source=rss-e16235d71560------2</link>
            <guid isPermaLink="false">https://medium.com/p/77f6d3c998be</guid>
            <dc:creator><![CDATA[Hilmi Baskara Radanto]]></dc:creator>
            <pubDate>Sat, 04 Mar 2023 05:35:27 GMT</pubDate>
            <atom:updated>2023-03-04T05:35:27.372Z</atom:updated>
            <content:encoded><![CDATA[<h3>External Sensor — Embedded System ESP32 Project #4</h3><p><em>Sampurasun!</em></p><p>Cloudy and rainy weather days after days with little to no sunlight made my living city now, Bandung, is soo coldd. Some says the temperature might be as low as 19°C, feels like a winter in Europe <em>innit</em>? haha. But, is it true? Let’s test it with my ESP32’s 4th project, external sensor!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*WFR6qlu4zpQuSWjS.jpg" /></figure><p>There are so many external sensor module available for ESP32. However, for today’s project, there’s module who I think is very powerful to use, the barometric pressure &amp; altitude sensor of <strong>BMP280</strong>. Why? because it’s able to measure temperature, pressure, and altitude of the environment. The most surprising thing for me is, it’s <strong>very</strong> <strong>cheap</strong>! You can get BMP280 for only Rp.11k in <a href="https://www.tokopedia.com/cncstorebandung/cnc-gy-bmp280-3-3-bmp280-barometric-pressure-temperature-sensor">Tokopedia</a> (+Rp3k for solder service). The BMP280 is the next-generation of sensors and is the upgrade to the BMP085/BMP180/BMP183. For simple easy wiring, I used I2C communication protocol.</p><p>Without further a do, let’s get going!</p><h4>— Tools and Component</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wWUdxF4NbtmXKQzQvY3hnA.png" /><figcaption>p.s. I forgot to include the USB Type-B cable</figcaption></figure><ul><li>Laptop/computer with Arduino IDE</li><li>ESP32 Devkit V1</li><li>Breadboard</li><li>USB type-B data cable</li><li>BMP280 (there’s another option actually with additional humidity sensor feature (BME280), but the BMP280 is the cheaper one, so I go with that HAHA)</li><li>4 jumper cable (male-to-female)</li></ul><p>And some additional component for bonus!</p><ul><li>2 jumper cable (male-to-male)</li><li>LED lamp</li><li>330 Ω resistor</li></ul><h4>— Steps</h4><p><strong>Pre-project</strong></p><p>Before starting anything, I need to download the BMP280 library first. To download, open Arduino IDE and head to Sketch → Include Library → Manage Libraries. Search for Adafruit BMP280 Library and click Install.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/0*qEj-OEdqV9h26lBs" /><figcaption>After clicking install, I got option to install adafruit unified sensor and just click Install all.</figcaption></figure><p><strong>Wiring Diagram</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*6oqz00czuS0Uz29RwwKxYQ.png" /></figure><p><strong>Project Starts!</strong></p><ol><li>Connect the wires, ESP32, and BMP280 according to the diagram.<br>- 3V3 pin to VCC<br>- GND pin to GND<br>- GPIO21 pin to SCA<br>- GPIO22 pin to SCL</li><li>Connect ESP32 to laptop using USB Type-B data cable.</li><li>Find out the device’s I2C address by uploading the code below.</li></ol><pre>#include &lt;Wire.h&gt;<br> <br>void setup() {<br>  Wire.begin();<br>  Serial.begin(115200);<br>  Serial.println(&quot;\nI2C Scanner&quot;);<br>}<br> <br>void loop() {<br>  byte error, address;<br>  int nDevices;<br>  Serial.println(&quot;Scanning...&quot;);<br>  nDevices = 0;<br>  for(address = 1; address &lt; 127; address++ ) {<br>    Wire.beginTransmission(address);<br>    error = Wire.endTransmission();<br>    if (error == 0) {<br>      Serial.print(&quot;I2C device found at address 0x&quot;);<br>      if (address&lt;16) {<br>        Serial.print(&quot;0&quot;);<br>      }<br>      Serial.println(address,HEX);<br>      nDevices++;<br>    }<br>    else if (error==4) {<br>      Serial.print(&quot;Unknown error at address 0x&quot;);<br>      if (address&lt;16) {<br>        Serial.print(&quot;0&quot;);<br>      }<br>      Serial.println(address,HEX);<br>    }    <br>  }<br>  if (nDevices == 0) {<br>    Serial.println(&quot;No I2C devices found\n&quot;);<br>  }<br>  else {<br>    Serial.println(&quot;done\n&quot;);<br>  }<br>  delay(5000);          <br>}</pre><p>Open the serial monitor, I found mine at address 0x76</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/0*RTL0yj2HOEEB9d6k" /></figure><p>4. Upload the following code.</p><pre>#include &lt;Wire.h&gt;<br>#include &lt;SPI.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br>#define BMP_SCK  (13)<br>#define BMP_MISO (12)<br>#define BMP_MOSI (11)<br>#define BMP_CS   (10)<br>Adafruit_BMP280 bmp; // I2C<br>//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI<br>//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);<br>void setup() {<br>  Serial.begin(9600);<br>  Serial.println(F(&quot;BMP280 test&quot;));<br>if (!bmp.begin(0x76)) { // use the address you found<br>    Serial.println(F(&quot;Could not find a valid BMP280 sensor, check wiring!&quot;));<br>    while (1);<br>  }<br>/* Default settings from datasheet. */<br>  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */<br>                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */<br>                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */<br>                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */<br>                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */<br>}<br>void loop() {<br>    Serial.print(F(&quot;Temperature = &quot;));<br>    Serial.print(bmp.readTemperature());<br>    Serial.println(&quot; *C&quot;);<br>Serial.print(F(&quot;Pressure = &quot;));<br>    Serial.print(bmp.readPressure());<br>    Serial.println(&quot; Pa&quot;);<br>Serial.print(F(&quot;Approx altitude = &quot;));<br>    Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */<br>    Serial.println(&quot; m&quot;);<br>Serial.println();<br>    delay(2000);<br>}</pre><p>5. Open Serial Monitor and VOILA!</p><p><strong>Result</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*jKQhyjjLw3Ubxt_kanV8Kg.gif" /></figure><p>COOL! It’s not 19°C though HAHA of course because it’s noon now and I’m in Starbucks Ciumbuleuit, comfy place to study or do something productive, <em>fyi!</em> The serial monitor shows these data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*97xisKi1PJsbJt18mdqzMw.png" /></figure><p>Ah I see, no wonder Bandung weather is pretty cold. Its altitude is really high compared to my hometown, Bogor. Then I was curious, is it true though? I checked my altitude now with <a href="https://whataltitude.com/">https://whataltitude.com/</a> and it’s 833 meters! Weird.</p><p>Actually, I’ve already once tried in my flat (read: kosan) it was rather accurate. The BMP280 measured the altitude for 783 meters and in <a href="https://whataltitude.com/">https://whataltitude.com/</a> showed 767 meters (My flat was in 3rd floor). Anyway, maybe it’s because Bandung’s very irregular shaped contour.</p><p>Okay, the BMP280 is success! Let’s move to the bonus project yay!</p><p><strong>Bonus Project</strong></p><p>I was drinking a cold coffee and stumbled upon an idea for the bonus project. I thought “<em>Why don’t I put my BMP280 near my iced vanilla latte, then an LED lamp will be turned on after the temperature decreased?”. </em>And just like that, with my knowledges from previous projects, I do the project!</p><p>Read: <a href="https://medium.com/@radantohilmi/basic-input-output-embedded-system-esp32-project-2-63e927948e13">https://medium.com/@radantohilmi/basic-input-output-embedded-system-esp32-project-2-63e927948e13</a></p><p><strong>Wiring Diagram</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*rUinNbRIL7lD1st_x1dQLA.png" /><figcaption>I used fritzing! anyway, the bmp280 component in the fritzing is not completed with vcc, gnd, scl, sca. You can use the previous diagram as a guide for the bmp280 part. It’s actually perfectly the same.</figcaption></figure><p><strong>Steps</strong></p><p>It’s simple, I’m adding some jumper cables and resistor to make the LED lamp work and moved the cables connected to GND just like the diagram above. After that, I made some tweaks to the code.</p><pre>#include &lt;Wire.h&gt;<br>#include &lt;SPI.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br>#define BMP_SCK  (13)<br>#define BMP_MISO (12)<br>#define BMP_MOSI (11)<br>#define BMP_CS   (10)<br>Adafruit_BMP280 bmp; // I2C<br>// led PIN initialization<br>const int ledPin1 = 18;<br>//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI<br>//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);<br>void setup() {<br>  Serial.begin(9600);<br>  Serial.println(F(&quot;BMP280 test&quot;));<br>  pinMode (ledPin1, OUTPUT);<br>if (!bmp.begin(0x76)) {<br>    Serial.println(F(&quot;Could not find a valid BMP280 sensor, check wiring!&quot;));<br>    while (1);<br>  }<br>/* Default settings from datasheet. */<br>  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */<br>                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */<br>                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */<br>                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */<br>                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */<br>}<br>void loop() {<br>    Serial.print(F(&quot;Temperature = &quot;));<br>    Serial.print(bmp.readTemperature());<br>    Serial.println(&quot; *C&quot;);<br>Serial.print(F(&quot;Pressure = &quot;));<br>    Serial.print(bmp.readPressure());<br>    Serial.println(&quot; Pa&quot;);<br>Serial.print(F(&quot;Approx altitude = &quot;));<br>    Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */<br>    Serial.println(&quot; m&quot;);<br>Serial.println();<br>  if (bmp.readTemperature() &lt; 26){<br>    digitalWrite(ledPin1, HIGH);<br>    Serial.println(&quot;Lampu menyala&quot;);<br>  } else {<br>    digitalWrite(ledPin1, LOW);<br>    Serial.println(&quot;Lampu mati&quot;);<br>  }<br>    delay(2000);<br>}</pre><p>Some codes I tweaked:</p><ul><li>added const int ledPin1 = 18; after Adafruit_BMP280 bmp;</li><li>added pinMode (ledPin1, OUTPUT); in void setup();</li><li>added the code below in void loop();</li></ul><pre>if (bmp.readTemperature() &lt; 26){<br>    digitalWrite(ledPin1, HIGH);<br>    Serial.println(&quot;Lampu menyala&quot;);<br>  } else {<br>    digitalWrite(ledPin1, LOW);<br>    Serial.println(&quot;Lampu mati&quot;);<br>  }</pre><p>The mechanism is, LED lamp will be turned on when BMP280 measures the temperature under 26°C. So, I put my BMP near my coffee and VOILA again!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*Gk7DJvdsrmG8DM9xO2TByg.gif" /></figure><p>Just like that, my 4th project done! It’s time to study for my midterm exam, wish me some lucks🤞.</p><p><em>Arigathanks Gozaimuch!</em></p><p><strong>Reference</strong></p><p><a href="https://www.circuitschools.com/interfacing-bmp280-with-esp-32-on-i2c-with-errors-and-solutions/">Interfacing BMP280 with ESP32 on I2C with errors and solutions - Circuit Schools</a></p><p><a href="https://www.bosch-sensortec.com/products/environmental-sensors/pressure-sensors/bmp280/">https://www.bosch-sensortec.com/products/environmental-sensors/pressure-sensors/bmp280/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77f6d3c998be" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>