<?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 Laurensia Audrey Pramashinta on Medium]]></title>
        <description><![CDATA[Stories by Laurensia Audrey Pramashinta on Medium]]></description>
        <link>https://medium.com/@Laurensia_Audrey?source=rss-b128545a082------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*87a38T78t_FKychjZ7Pj6Q.jpeg</url>
            <title>Stories by Laurensia Audrey Pramashinta on Medium</title>
            <link>https://medium.com/@Laurensia_Audrey?source=rss-b128545a082------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:54:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Laurensia_Audrey/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[Embedded System Project #10 : Data Visualization & Data Logging]]></title>
            <link>https://medium.com/@Laurensia_Audrey/embedded-system-project-10-data-visualization-data-logging-5d75334f8d8?source=rss-b128545a082------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d75334f8d8</guid>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[datalogging]]></category>
            <category><![CDATA[esp32-tutorial]]></category>
            <category><![CDATA[embedded-system-design]]></category>
            <dc:creator><![CDATA[Laurensia Audrey Pramashinta]]></dc:creator>
            <pubDate>Sun, 07 May 2023 07:23:54 GMT</pubDate>
            <atom:updated>2023-05-07T07:27:31.180Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embedded System Project #10 : Data Visualization &amp; Data Logging</h3><p>Hi there, good to see you. Welcome back to another embedded system project ❤. This time, we’re going to create a web page that displays sensor readings that can be accessed from anywhere in the world. In this project, I choose BMP180 as my sensor of choice.</p><p>I will use the tutorial from this <a href="https://randomnerdtutorials.com/visualize-esp32-esp8266-sensor-readings-from-anywhere/">link</a> as a reference. There will be some small changes because I’m using BMP180, but overall it’s pretty much the same. Well, let’s get started !</p><h3>Steps</h3><p>To start, we’ll create a domain on 000webhost.com.If you haven’t read my <a href="https://medium.com/@Laurensia_Audrey/embedded-system-project-9-database-c59b10978263"><strong>previous article</strong></a> , kindly check it out.</p><h4><strong>Creating MySQL Database</strong></h4><p>After creating the site, click <strong>Tools &gt; Database Manager &gt; New Database.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*TU0bNQbngZUgsnzt1lu5uA.png" /></figure><p>Fill out the blanks and make sure to remember your Password.</p><h4>Creating SQL Table</h4><p>After creating your database, click <strong>Manage Database&gt; PhpMyAdmin &gt; id_your database name &gt; SQL. </strong>Then, insert the SQL Query down below and click the “Go” button.</p><pre>CREATE TABLE Sensor (<br>    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,<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/1024/1*FNRf3H1wxPxNofKx9ZDDPQ.jpeg" /></figure><p>Once you have successfully created the table, you can locate it in the Structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*8MWy9Aj3Wi6CmYT9-PCrHg.png" /></figure><p><strong>Insert Data to Database</strong></p><p>Go to the 000webhost dashboard. Click <strong>File Manager &gt; Upload Files</strong>. Then click <strong>public_html</strong>. This time, I’m going to name it “post-data.php”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*6nHAruFzeOj0WbzDTJxGkA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*9FrBzKdDZttAhI-F5cJfng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*RhSJG1vBvASvpwvMkS_plQ.png" /></figure><p>Click the ‘New File’ icon to add a new file and copy the script below.</p><pre>&lt;?php<br>/*<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><br>$servername = &quot;localhost&quot;;<br><br>// REPLACE with your Database name<br>$dbname = &quot;REPLACE_WITH_YOUR_DATABASENAME&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. If you change this value, the ESP32 sketch needs to match<br>$api_key_value = &quot;tPmAT5Ab3j7F9&quot;;<br><br>$api_key = $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>        $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 Sensor (value1, value2, value3)<br>        VALUES (&#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>Don’t forget to change the credentials.</p><pre>// REPLACE with your Database name<br>$dbname = &quot;REPLACE_WITH_YOUR_DATABASENAME&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;;</pre><p>Then, check it by visiting yourdomain.000webhostapp.com/post-data.php and this will appear on your screen :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*4Neb2ngoyzkYnN8fCe5qzw.png" /></figure><p><strong>Data Visualization</strong></p><p>Go to File Manager and upload a new PHP script to visualize data. This time, I’m going to name it “chart.php”</p><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>--&gt;<br>&lt;?php<br>$servername = &quot;localhost&quot;;<br>// REPLACE with your Database name<br>$dbname = &quot;REPLACE_WITH_YOUR_DATABASENAME&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>// 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>$sql = &quot;SELECT id, value1, value2, value3, reading_time FROM Sensor order by reading_time desc limit 40&quot;;<br>$result = $conn-&gt;query($sql);<br>while ($data = $result-&gt;fetch_assoc()){<br>    $sensor_data[] = $data;<br>}<br>$readings_time = array_column($sensor_data, &#39;reading_time&#39;);<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>$value1 = json_encode(array_reverse(array_column($sensor_data, &#39;value1&#39;)), JSON_NUMERIC_CHECK);<br>$value2 = json_encode(array_reverse(array_column($sensor_data, &#39;value2&#39;)), JSON_NUMERIC_CHECK);<br>$value3 = json_encode(array_reverse(array_column($sensor_data, &#39;value3&#39;)), JSON_NUMERIC_CHECK);<br>$reading_time = json_encode(array_reverse($readings_time), JSON_NUMERIC_CHECK);<br>/*echo $value1;<br>echo $value2;<br>echo $value3;<br>echo $reading_time;*/<br>$result-&gt;free();<br>$conn-&gt;close();<br>?&gt;<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-humidity&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>var value1 = &lt;?php echo $value1; ?&gt;;<br>var value2 = &lt;?php echo $value2; ?&gt;;<br>var value3 = &lt;?php echo $value3; ?&gt;;<br>var reading_time = &lt;?php echo $reading_time; ?&gt;;<br>var chartT = new Highcharts.Chart({<br>  chart:{ renderTo : &#39;chart-temperature&#39; },<br>  title: { text: &#39;BME280 Temperature&#39; },<br>  series: [{<br>    showInLegend: false,<br>    data: value1<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>var chartH = new Highcharts.Chart({<br>  chart:{ renderTo:&#39;chart-humidity&#39; },<br>  title: { text: &#39;BME280 Humidity&#39; },<br>  series: [{<br>    showInLegend: false,<br>    data: value2<br>  }],<br>  plotOptions: {<br>    line: { animation: false,<br>      dataLabels: { enabled: true }<br>    }<br>  },<br>  xAxis: {<br>    type: &#39;datetime&#39;,<br>    //dateTimeLabelFormats: { second: &#39;%H:%M:%S&#39; },<br>    categories: reading_time<br>  },<br>  yAxis: {<br>    title: { text: &#39;Humidity (%)&#39; }<br>  },<br>  credits: { enabled: false }<br>});<br>var chartP = new Highcharts.Chart({<br>  chart:{ renderTo:&#39;chart-pressure&#39; },<br>  title: { text: &#39;BME280 Pressure&#39; },<br>  series: [{<br>    showInLegend: false,<br>    data: value3<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>&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Don’t forget to change this part of the script :</p><pre>// REPLACE with your Database name<br>$dbname = &quot;REPLACE_WITH_YOUR_DATABASENAME&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;;</pre><p>Go to the site and this should appear on your screen :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PmWJ6byiRogDsdInb-gNYw.png" /></figure><h3><strong>ESP32</strong></h3><p><strong>Schematic</strong></p><p>The schematic of this project remains unchanged from the recent one (project #9).</p><p>BMP180 sensor — ESP32</p><ul><li>GND — GND</li><li>VCC — VIN</li><li>SDA — GPIO 21</li><li>SCL — GPIO 22</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3nZCmVOOfl1bnt4n-7z9Pg.jpeg" /></figure><p>Open your Arduino IDE and copy the code down below :</p><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>#ifdef ESP32<br>  #include &lt;WiFi.h&gt;<br>  #include &lt;HTTPClient.h&gt;<br>#else<br>  #include &lt;ESP8266WiFi.h&gt;<br>  #include &lt;ESP8266HTTPClient.h&gt;<br>  #include &lt;WiFiClient.h&gt;<br>#endif<br><br>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_BMP085.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 Domain name and URL path or IP address with path<br>const char* serverName = &quot;DOMAIN_NAME_AND_URL_PATH&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;BMP180&quot;;<br>String sensorLocation = &quot;Home&quot;;<br><br>#define SEALEVELPRESSURE_HPA (1013.25)<br><br>Adafruit_BMP085 bmp;  // I2C<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 BME280 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>    HTTPClient http;<br>    <br>    // Your Domain name with URL path or IP address with path<br>    http.begin(serverName);<br>    <br>    // Specify content-type header<br>    http.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;value1=&quot; + String(bmp.readTemperature())<br>                          + &quot;&amp;value2=&quot; + String(bmp.readAltitude()) + &quot;&amp;value3=&quot; + String(bmp.readPressure()/100.0F) + &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 BMP180 sensor)<br>    //String httpRequestData = &quot;api_key=tPmAT5Ab3j7F9&amp;sensor=BMP180&amp;location=Home&amp;value1=24.75&amp;value2=49.54&amp;value3=1005.14&quot;;<br><br>    // Send HTTP POST request<br>    int httpResponseCode = http.POST(httpRequestData);<br>     <br>    // If you need an HTTP request with a content type: text/plain<br>    //http.addHeader(&quot;Content-Type&quot;, &quot;text/plain&quot;);<br>    //int httpResponseCode = http.POST(&quot;Hello, World!&quot;);<br>    <br>    // If you need an HTTP request with a content type: application/json, use the following:<br>    //http.addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);<br>    //int httpResponseCode = http.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>    http.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>}Adafruit_BMP085 bmp;<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 Domain name and URL path or IP address with path<br>const char* serverName = &quot;http://example.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;BME280&quot;;<br>String sensorLocation = &quot;Office&quot;;<br><br>/*#include &lt;SPI.h&gt;<br>#define BME_SCK 18<br>#define BME_MISO 19<br>#define BME_MOSI 23<br>#define BME_CS 5*/<br><br>#define SEALEVELPRESSURE_HPA (1013.25)<br><br>Adafruit_BME280 bme;  // I2C<br>//Adafruit_BME280 bme(BME_CS);  // hardware SPI<br>//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_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 = bme.begin(0x76);<br>  if (!status) {<br>    Serial.println(&quot;Could not find a valid BME280 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>    HTTPClient http;<br>    <br>    // Your Domain name with URL path or IP address with path<br>    http.begin(serverName);<br>    <br>    // Specify content-type header<br>    http.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;value1=&quot; + String(bme.readTemperature())<br>                          + &quot;&amp;value2=&quot; + String(bme.readHumidity()) + &quot;&amp;value3=&quot; + String(bme.readPressure()/100.0F) + &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 BME280 sensor)<br>    //String httpRequestData = &quot;api_key=tPmAT5Ab3j7F9&amp;sensor=BME280&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 = http.POST(httpRequestData);<br>     <br>    // If you need an HTTP request with a content type: text/plain<br>    //http.addHeader(&quot;Content-Type&quot;, &quot;text/plain&quot;);<br>    //int httpResponseCode = http.POST(&quot;Hello, World!&quot;);<br>    <br>    // If you need an HTTP request with a content type: application/json, use the following:<br>    //http.addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);<br>    //int httpResponseCode = http.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>    http.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>As usual, don’t forget to change this part of the code :</p><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;;<br><br>// REPLACE with your Domain name and URL path or IP address with path<br>const char* serverName = &quot;DOMAIN_NAME_AND_URL_PATH&quot;;</pre><p>As you can see, the serial monitor displayed “HTTP Response code : 200” which is the expected output for this experiment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*X6GB0VXdPPDFWyTsuRp5Ww.png" /></figure><p>Now, let’s check the <a href="https://audarcy.000webhostapp.com/esp-chart.php">site</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HuMOxUEzWUd-kYnsKyDaFA.png" /><figcaption>Temperature</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*69Ou2ouHk6bo1U_qG5Y2rw.png" /><figcaption>Approximate Altitude</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KkWbHBBUf4H-ev0ydGUW6A.png" /><figcaption>Pressure</figcaption></figure><p>Yayyyy, it worked !!</p><p>I’m satisfied with how this week’s project turned out. It’s pretty challenging, but I had a lot of fun. I hope that this article can guide and help you through the process of your own project. Well, until next time. Byee ❤!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d75334f8d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded System Project #9 : Database]]></title>
            <link>https://medium.com/@Laurensia_Audrey/embedded-system-project-9-database-c59b10978263?source=rss-b128545a082------2</link>
            <guid isPermaLink="false">https://medium.com/p/c59b10978263</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[Laurensia Audrey Pramashinta]]></dc:creator>
            <pubDate>Sun, 07 May 2023 01:19:26 GMT</pubDate>
            <atom:updated>2023-05-07T01:20:31.813Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embedded System Project #9 : Database</h3><p>Hi there ! Welcome back to another embedded system project. This time, we’ll resume our work on project 9. Our goal is to create a database capable of receiving sensor readings from BMP280. To achieve this, we will build an ESP32 client that can send an HTTP POST request to a PHP script, allowing us to insert data in the form of sensor readings into a MySQL database.</p><h4>[Preparation]</h4><p>Components required :</p><ul><li>ESP32 board</li><li>BMP280 sensor</li><li>Breadboard</li><li>Jumper wires</li><li>USB cable</li><li>Arduino IDE</li><li>Hosting server and domain name</li><li>PHP script to insert data into MySQL and display it on a webpage</li><li>MySQL database</li></ul><h4>Hosting PHP Application and MySQL Database</h4><p>The objective of this project is to obtain a personal domain name and hosting account that will enable you to store sensor readings from the ESP32 or ESP8266. By accessing your server domain, you can view the sensor readings from anywhere in the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*0igUiT5tm-_DsBZE" /><figcaption>High-level overview</figcaption></figure><p>The tutorial from <a href="https://randomnerdtutorials.com/esp32-esp8266-mysql-database-php/">randomnerdtutorials</a> suggests using BlueHost or Digital Ocean as hosting services. But don’t worry (^-^), I found a free option <a href="https://www.000webhost.com/">000webhost</a> . For this project, I’ll be using 000webhost as my hosting service.</p><h4>MySQL Database</h4><p>The first step is to create your own website from 000webhost. Then, to create your own MySQL database, go to <strong>Tools &gt; Database Manager &gt; New Database</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*GpCP8xMJPyXwGMbGLlOz3g.png" /></figure><p>Fill in the form. Then, click <strong>Manage &gt; PhpMyAdmin</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*_s0s1R-JeNX4PPEgdlWKWw.jpeg" /></figure><p>Click SQL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*UXkC6No-15q4Jg4f5ShYCw.jpeg" /></figure><p>You can go ahead and copy the code down below and Click the ‘<strong>Go’ </strong>button on the bottom right corner</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><p>Yey, we’re finished ! Let’s go the next step.</p><h4>PHP Script HTTP POST</h4><p>Return to 000webhost and go to <strong>Tools &gt; File Manager &gt; Upload Files</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DkazqG3UmjXfvJ4cBQHTGw.png" /></figure><p>Open the public_html folder and copy the PHP script down below and save it the folder.</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>Note : Don’t forget to change your database credentials to the database you’ve created earlier.</p><pre>// 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;;</pre><p>Access it by going to <strong>yourdomain.000webhostapp.com/DATA.php</strong> . If I open the <a href="https://audarcy.000webhostapp.com/DATA.php">link</a> , it will display this result :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*mvXl7GGoUrDl4Ag3EU1djQ.png" /></figure><h4>PHP Script to Display Database Content</h4><p>Return to the <strong>File Manager</strong> and upload a different .php file that will display the database content to the web. Copy the code down below and save it in the /public_html directory. In this case, I named the file with “DISPLAY_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>}<br></pre><p>Like before, don’t forget to change your credentials.</p><pre>// 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;;</pre><p>Upload the file and check it by visiting yourdomain.000webhostapp.com/DISPLAY_DATA.php . If I open the <a href="https://audarcy.000webhostapp.com/DISPLAY_DATA.php">link</a> , it will display this result :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*3WOH6AHBvH3guQatGh9TnQ.png" /></figure><h4>ESP32</h4><p>We’ll build a simple circuit using the same schematic diagram from our previous project (but this time I’m using BMP180).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PR_NPkq1rpQKOxeyvYE3xA.jpeg" /></figure><p>Then, copy the code and paste the code down below to your Arduino IDE.</p><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>#ifdef ESP32<br>  #include &lt;WiFi.h&gt;<br>  #include &lt;HTTPClient.h&gt;<br>#else<br>  #include &lt;ESP8266WiFi.h&gt;<br>  #include &lt;ESP8266HTTPClient.h&gt;<br>  #include &lt;WiFiClient.h&gt;<br>#endif<br>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_BMP085.h&gt;<br>// Replace with your network credentials<br>const char* ssid     = &quot;FAMILY&quot;;<br>const char* password = &quot;password&quot;;<br>// REPLACE with your Domain name and URL path or IP address with path<br>const char* serverName = &quot;http://chintyaw.000webhostapp.com/post-esp-data.php&quot;;<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>String sensorName = &quot;BMP180&quot;;<br>String sensorLocation = &quot;Home&quot;;<br>#define SEALEVELPRESSURE_HPA (1013.25)<br>Adafruit_BMP085 bmp;  // I2C<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>// (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 BMP180 sensor, check wiring or change I2C address!&quot;);<br>    while (1);<br>  }<br>}<br>void loop() {<br>  //Check WiFi connection status<br>  if(WiFi.status()== WL_CONNECTED){<br>    HTTPClient http;<br>    <br>    // Your Domain name with URL path or IP address with path<br>    http.begin(serverName);<br>    <br>    // Specify content-type header<br>    http.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;value1=&quot; + String(bmp.readTemperature())<br>                          + &quot;&amp;value2=&quot; + String(bmp.readAltitude()) + &quot;&amp;value3=&quot; + String(bmp.readPressure()/100.0F) + &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 BMP180 sensor)<br>    //String httpRequestData = &quot;api_key=tPmAT5Ab3j7F9&amp;sensor=BMP180&amp;location=Home&amp;value1=24.75&amp;value2=49.54&amp;value3=1005.14&quot;;<br>// Send HTTP POST request<br>    int httpResponseCode = http.POST(httpRequestData);<br>     <br>    // If you need an HTTP request with a content type: text/plain<br>    //http.addHeader(&quot;Content-Type&quot;, &quot;text/plain&quot;);<br>    //int httpResponseCode = http.POST(&quot;Hello, World!&quot;);<br>    <br>    // If you need an HTTP request with a content type: application/json, use the following:<br>    //http.addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);<br>    //int httpResponseCode = http.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>    http.end();<br>  }<br>  else {<br>    Serial.println(&quot;WiFi Disconnected&quot;);<br>  }<br>  //Send an HTTP POST request every 30 seconds<br>  delay(5000);  <br>}</pre><h4>Results</h4><p>Here are the results!</p><p>I checked the serial monitor to make sure the output is as expected. Fortunately, HTTP Response code: 200!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*74y3wXAfg6fBhVuBH_mYCA.png" /></figure><p>But I encountered a problem, there are no updated database even though the output on the serial monitor is true.</p><p>I’ve already tried many solutions such as changing the server name, using VPN, checked the database credentials, and many more. But it still didn’t worked.</p><p>I also tried using a different sensor (BMP280), but the output is still the same. Even though the serial monitor showed the expected response code, there are no updated data on the server.</p><p>I’m sorry that this project didn’t go as planned :( But I hope that this article will guide you through the process needed for this week’s experiment. See you on my next project, byee!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c59b10978263" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded System Project #8 : Room Monitoring and Controlling System]]></title>
            <link>https://medium.com/@Laurensia_Audrey/embedded-system-project-8-room-monitoring-and-controlling-system-a40ca659ac83?source=rss-b128545a082------2</link>
            <guid isPermaLink="false">https://medium.com/p/a40ca659ac83</guid>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[web-server]]></category>
            <dc:creator><![CDATA[Laurensia Audrey Pramashinta]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 08:15:05 GMT</pubDate>
            <atom:updated>2023-04-02T08:17:42.782Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embedded System Project #8 : Room Monitoring and Controlling System</h3><p>Hello there, welcome back to another Embedded System Project. This time, we will conduct an experiment to build a monitoring and controlling server that is connected to a Wi-Fi network so that it can be accessed by other devices from a remote location using a browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*2NuVo9n46xm0NufXz3Tl7g.jpeg" /></figure><h4><strong>The criteria :</strong></h4><ol><li>ESP32 is equipped with a temperature sensor placed in a room, and connected to a WiFi network.</li><li>ESP32 is also connected to a motor that drives a fan (this fan can be modeled using LEDs ).</li><li>Temperature information can be read remotely using a browser (on a PC or mobile phone).</li><li>Users can turn on/off the fan from a remote location using a browser.</li></ol><h3><strong>[Preparation]</strong></h3><h4><strong>Required Components :</strong></h4><ul><li>ESP32 board</li><li>2 LEDs</li><li>BMP280 Sensor</li><li>330 Ohm resistors</li><li>Jumper wires (male to male)</li><li>Breadboard</li><li>USB cable</li></ul><h4><strong>Circuit</strong></h4><p>For the BMP280 sensor, I followed the same schematic that I previously used on <a href="https://medium.com/@Laurensia_Audrey/embedded-system-project-4-esp-32-external-sensor-69a3cd34992a">project 4</a>.</p><p>Then, I connected the first LED to GPIO4 and the other one to GPIO5. Don’t forget to connect both LEDs with the 330 Ohm resistors. Here are the circuit that I assembled. You can go ahead and follow the pictures down below to build your own circuit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5oSZOvDSxRwVsWff3UKnNQ.jpeg" /></figure><p>Even though it’s basically the same circuit as the one we used on project 4 (with additional LEDs) , there’s a small modification needed. Instead of connecting the BMP280 GND to ESP32 GND, I connected both of them to the negative side of the breadboard using male-to-male jumpers .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LuaJTvf_oFt0e3-BNvArNQ.jpeg" /></figure><h3>[Steps]</h3><h4><strong>The Code</strong></h4><p>Now that we’ve assembled our circuit, let’s start building our code. This is the code that I used to make my web server.</p><pre>#include &lt;WiFi.h&gt;<br>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br>#include &lt;Adafruit_Sensor.h&gt;<br><br>#define SEALEVELPRESSURE_HPA (1013.25)<br><br>Adafruit_BMP280 bmp; // I2C<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>// Set web server port number to 80<br>WiFiServer server(80);<br><br>// Variable to store the HTTP request<br>String header;<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>String outputFan1State = &quot;off&quot;;<br>String outputFan2State = &quot;off&quot;;<br><br>const int fan1 = 4;<br>const int fan2 = 5;<br><br>void setup() {<br>  Serial.begin(115200);<br><br>  pinMode(fan1, OUTPUT);<br>  pinMode(fan2, OUTPUT);<br><br>  digitalWrite(fan1,LOW);<br>  digitalWrite(fan2,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>  // 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>            if (header.indexOf(&quot;GET /4/on&quot;) &gt;= 0){<br>              Serial.println(&quot;GPIO 4 on&quot;);<br>              outputFan1State = &quot;on&quot;;<br>              digitalWrite(fan1, HIGH);<br>            } else if (header.indexOf(&quot;GET /4/off&quot;) &gt;= 0){<br>              Serial.println(&quot;GPIO 4 off&quot;);<br>              outputFan1State = &quot;off&quot;;<br>              digitalWrite(fan1, LOW);<br>            } else if (header.indexOf(&quot;GET /5/on&quot;) &gt;= 0){<br>              Serial.println(&quot;GPIO 5 on&quot;);<br>              outputFan2State = &quot;on&quot;;<br>              digitalWrite(fan2, HIGH);<br>            } else if (header.indexOf(&quot;GET /5/off&quot;) &gt;= 0){<br>              Serial.println(&quot;GPIO 5 off&quot;);<br>              outputFan2State = &quot;off&quot;;<br>              digitalWrite(fan2, 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;Audrey&#39;s Fan Control&lt;/h1&gt;&quot;);   <br><br>            // Display current state, and ON/OFF buttons for GPIO 4  <br>            client.println(&quot;&lt;p&gt;GPIO 4 - State &quot; + outputFan1State + &quot;&lt;/p&gt;&quot;);<br>            // If the outputFan1State is off, it displays the ON button       <br>            if (outputFan1State==&quot;off&quot;) {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/4/on\&quot;&gt;&lt;button class=\&quot;button\&quot;&gt;ON&lt;/button&gt;&lt;/a&gt;&lt;/p&gt;&quot;);<br>            } else {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/4/off\&quot;&gt;&lt;button class=\&quot;button button2\&quot;&gt;OFF&lt;/button&gt;&lt;/a&gt;&lt;/p&gt;&quot;);<br>            } <br>               <br>            // Display current state, and ON/OFF buttons for GPIO 5  <br>            client.println(&quot;&lt;p&gt;GPIO 5 - State &quot; + outputFan2State + &quot;&lt;/p&gt;&quot;);<br>            // If the outputFan2State is off, it displays the ON button       <br>            if (outputFan2State==&quot;off&quot;) {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/5/on\&quot;&gt;&lt;button class=\&quot;button\&quot;&gt;ON&lt;/button&gt;&lt;/a&gt;&lt;/p&gt;&quot;);<br>            } else {<br>              client.println(&quot;&lt;p&gt;&lt;a href=\&quot;/5/off\&quot;&gt;&lt;button class=\&quot;button button2\&quot;&gt;OFF&lt;/button&gt;&lt;/a&gt;&lt;/p&gt;&quot;);<br>            }<br>            client.println(&quot;&lt;/body&gt;&lt;/html&gt;&quot;);<br>            // CSS to style the table <br>            client.println(&quot;&lt;style&gt;body { text-align: center; font-family: \&quot;Trebuchet MS\&quot;, Arial;}&quot;);<br>            client.println(&quot;table { border-collapse: collapse; width:35%; margin-left:auto; margin-right:auto; }&quot;);<br>            client.println(&quot;th { padding: 12px; background-color: #4CAF50; color: white; }&quot;);<br>            client.println(&quot;tr { border: 1px solid #ddd; padding: 12px; }&quot;);<br>            client.println(&quot;tr:hover { background-color: #bcbcbc; }&quot;);<br>            client.println(&quot;td { border: none; padding: 12px; }&quot;);<br>            client.println(&quot;.sensor { color:white; font-weight: bold; background-color: #bcbcbc; padding: 1px; }&quot;);<br>            <br>            // Web Page Heading<br>            client.println(&quot;&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Audrey&#39;s Advance Weather Station&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;/span&gt;&lt;/td&gt;&lt;/tr&gt;&quot;); <br>            client.println(&quot;&lt;/body&gt;&lt;/html&gt;&quot;);<br>            <br>            // The HTTP response ends with another blank line<br>            client.println();<br>            // Break out of the while loop<br>            break;<br>          } else { // if you got a newline, then clear currentLine<br>            currentLine = &quot;&quot;;<br>          }<br>        } else if (c != &#39;\r&#39;) {  // if you got anything else but a carriage return character,<br>          currentLine += c;      // add it to the end of the currentLine<br>        }<br>      }<br>    }<br>    // Clear the header variable<br>    header = &quot;&quot;;<br>    // Close the connection<br>    client.stop();<br>    Serial.println(&quot;Client disconnected.&quot;);<br>    Serial.println(&quot;&quot;);<br>  }<br>}</pre><h4>Code Explanation</h4><p>Initially, we will include the necessary libraries to the project. The four libraries utilized in this project include the WiFi library, Wire library, Adafruit sensor library, and Adafruit BMP280 library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*DuiRM3z2stoMYkvLablgcg.png" /></figure><p>We’ll define the sea level as 1013.25 (default) and create a bmp280 object (we’ll name it bmp).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*_Hb27EkEQLZ_rJvc-h29lQ.png" /></figure><p>The SSID of your WiFi connection will be stored in a string variable named “ssid”. The string variable “password” will hold your WiFi password. After that, the port number for the web server is declared as 80. Finally, a variable is declared to store the HTTP request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*cCNYLiB6wlsliUW9uXhS_A.png" /></figure><p>The variables down below serve as timers for the program that we are executing. These timers are utilized to keep track of the present time, the previous time, and the duration of a timeout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*Tk2WkMZlCxGNFN8t6-PLWg.png" /></figure><p>The variables “outputFan1State” and “outputFan2State” indicate the current state of the fans, which can either be on or off. Additionally, the variables “fan1” and “fan2” represent the GPIO pins of the first and second fan, respectively. However, it is worth noting that we are utilizing LEDs as fans in this case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*jTGULZBydsGUJd_OZLUVaw.png" /></figure><p>The initial part of the setup consists of typical code that we have seen numerous times before. We establish the baud frequency as 115200. Subsequently, we set “fan1” and “fan2” as system outputs and set their default state as “LOW” (indicating that they are off).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*h8xs0PobujxlVyJUiIEIFA.png" /></figure><p>This section of the code is utilized to connect to the WiFi network that has already been established. The variables “ssid” and “password”, which we have previously declared, will handle the required parameters. The function WiFi.begin takes two arguments: SSID and password. If a connection hasn’t been established, the program will display dots in the serial monitor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*vvHTH8dc3MSy6JA5qqQ8ZQ.png" /></figure><p>This program will display the IP address of the server on your serial monitor, which you should take note of. This IP address will be necessary to access the server. The last function is utilized to initiate the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*IPpZQ2_dQzpbeV7vMD811Q.png" /></figure><p>Once a client establishes a connection to the server’s IP address, it enters a while loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*NTeZmwTxfydy7eQh-Vv6ag.png" /></figure><p>The initial step in the while loop is to receive the HTTP request from the client (sensor readings and control the board’s fans).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*Fj7ACv-7ywZDVdmG87h_iA.png" /></figure><p>This is the header of the HTTP response from the server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*Zwg2lvQz6DhS9UDJaznZJQ.png" /></figure><p>The program will regularly examine the client’s request message to determine what the client wants to accomplish. Apart from viewing the sensor readings, the client has the ability to execute four actions: switch on the first fan, switch off the first fan, switch on the second fan, and switch off the second fan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*q9RU7tH8ehL6TjollDPAJQ.png" /></figure><p>This code will display the web page and add some CSS styling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*0PEepmM_FsBZV0Kw88OaOg.png" /></figure><p>This piece of code is utilized to exhibit the button section of our web server. It indicates the current state of the buttons and fans, and will automatically update in accordance with the status of the fans.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*9_eV0cBW5l_W0f6fAzFQ8Q.png" /></figure><p>This code is implemented to exhibit the readings obtained from the bmp280 sensor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*xFRAKlPMyw-_dyk-PXu1RA.png" /></figure><p>The code is merely a blank line and a break to halt the loop. The else and else if statements are employed to finalize the if statements at the beginning of the loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*B5iA9s91vBgyBiAYT9F6Yg.png" /></figure><p>Once the client terminates the connection, the server will sever the connection with the client and generate a message confirming that the client has disconnected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*AuwSE5kYNpKGqxb3cNcnOQ.png" /></figure><h4>Things to Note</h4><p>Don’t forget to change these lines with your network credentials : SSID and password.</p><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><p>Verify and upload the sketch on your Arduino IDE, then open the serial monitor at 115200 baud rate and press ‘EN’ on the ESP32 board.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*JX2yAaSm4XD-DYJqb3_PHA.png" /></figure><h4>Accessing the Web Server</h4><p>Open your browser and paste the ESP32 IP Address that you got from the serial monitor. In my case, it’s 172.20.10.2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MS64ekSP1uRWijWLWeowcw.png" /></figure><h3>[Results]</h3><h4><strong>Turn on fan</strong></h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FIqmcTEUVH9BmucdygP%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExM2U0MDU5Y2MyNmQyYWNjYWYyNGE4YWQ3N2U0Y2U2NzYzZjA4MWU5NSZjdD1n%2FIqmcTEUVH9BmucdygP%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FIqmcTEUVH9BmucdygP%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="773" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c016ddef126d5be4eee17a9bd918285/href">https://medium.com/media/2c016ddef126d5be4eee17a9bd918285/href</a></iframe><h4><strong>Turn off fan</strong></h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F0060bKzfah16Lcr8fp%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNDRlZmYwOGJmYmI1ODliYzBhZDJhNGU5NGY4OTVlYjllMGQwN2FhOCZjdD1n%2F0060bKzfah16Lcr8fp%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F0060bKzfah16Lcr8fp%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="773" frameborder="0" scrolling="no"><a href="https://medium.com/media/8438d5e87680871600f81e91451a7d5d/href">https://medium.com/media/8438d5e87680871600f81e91451a7d5d/href</a></iframe><p>Well, we have reached the end of the experiment. Overall, I am satisfied with the results of this project. Hopefully, this article will be useful for those of you who are reading it. See you on my next project !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a40ca659ac83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded System Project #7 : Bluetooth]]></title>
            <link>https://medium.com/@Laurensia_Audrey/embedded-system-project-7-bluetooth-e06ef9c43e51?source=rss-b128545a082------2</link>
            <guid isPermaLink="false">https://medium.com/p/e06ef9c43e51</guid>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[esp32-project]]></category>
            <dc:creator><![CDATA[Laurensia Audrey Pramashinta]]></dc:creator>
            <pubDate>Sun, 26 Mar 2023 13:15:47 GMT</pubDate>
            <atom:updated>2023-03-26T13:15:47.230Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embedded System Project #7 : Bluetooth</h3><p>Hi there ! Welcome back to another embedded system project. This week, I’ll walk you through my experiment on Bluetooth Classic and Bluetooth Low Energy and how it worked on ESP32. Bluetooth is a wireless technology that uses low-energy radio waves to send wireless data between Bluetooth-enabled devices. In this project, we’re going to learn about 2 types of Bluetooth : <strong>Bluetooth classic and Bluetooth Low Energy.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*g6JAy0dFZTllANeSA2k3hw.jpeg" /></figure><h4>[Preparation]</h4><p>Required Components :</p><ul><li>ESP32 Board</li><li>Breadboard</li><li>Male to male jumper wires</li><li>330 Ohm resistor</li><li>LED</li><li>USB Cable</li></ul><p>For this project, there are 2 new tools required. The first one is an app called <strong>Serial Bluetooth Terminal</strong> (available in the Play Store) and the second one is an app called <strong>nRF Connect for Mobile</strong> (available in the App Store and Play Store).</p><h3>Bluetooth Classic</h3><p>I installed the <strong>Serial Bluetooth Terminal</strong> application on my mobile phone. Then, I connected the ESP32 to my laptop using a USB cable. Once that was done, I uploaded the following code and opened the serial monitor at a baud rate of 115200. Finally, I pressed the “EN” (Enable) button.</p><p>You can find this code on <strong>File &gt; Examples &gt; BluetoothSerial &gt; SerialtoSerialBT</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HzLebNtv_H4hIffQFtZFpQ.png" /></figure><p>You can go ahead and copy the code down below to your Arduino IDE :</p><pre>//This example code is in the Public Domain (or CC0 licensed, at your option.)<br>//By Evandro Copercini - 2018<br>//<br>//This example creates a bridge between Serial and Classical Bluetooth (SPP)<br>//and also demonstrate that SerialBT have the same functionalities of a normal Serial<br><br>#include &quot;BluetoothSerial.h&quot;<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>BluetoothSerial SerialBT;<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>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><p>The serial monitor shown :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oyWLGS_KZfhByTqMDkCbrw.png" /></figure><p>After I uploaded the code, I turned on the Bluetooth on my phone and opened the <strong>Serial Bluetooth Terminal </strong>app. Then, I paired the devices by clicking “Devices”. After that, I tried to type and send a “hello” message to the serial monitor .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MLkzfbmr9uow1RLTaEVJBQ.png" /></figure><p>Success ! Well, I wanted to experiment a lil bit more.. So I made some small changes and here’s how it all went down.</p><h4><strong>LED On and Off Using Bluetooth</strong></h4><p>The circuit that I used :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AuG6GJBpl9Tt_YabpH_msg.jpeg" /></figure><p>The code that I used :</p><pre>#include &quot;BluetoothSerial.h&quot;<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>// Bluetooth Serial object<br>BluetoothSerial SerialBT;<br>const int ledPin1 =  21;<br>const int ledPin2 =  22;<br>String message = &quot;&quot;;<br>char incomingChar;<br>String temperatureString = &quot;&quot;;<br>void setup() {<br>  pinMode(ledPin1, OUTPUT);<br>  pinMode(ledPin2, OUTPUT);<br>  Serial.begin(115200);<br>  // Bluetooth device name<br>  SerialBT.begin(&quot;ESP32&quot;);<br>  Serial.println(&quot;The device started, now you can pair it with bluetooth!&quot;);<br>}<br>void loop() {<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;;<br>    }<br>    Serial.write(incomingChar);  <br>  }<br>  // Check received message and control output accordingly<br>  if (message ==&quot;turn on yellow led&quot;){<br>    digitalWrite(ledPin1, HIGH);<br>    SerialBT.println(&quot;yellow LED is on&quot;);<br>  }<br>  else if (message ==&quot;turn on red led&quot;){<br>    digitalWrite(ledPin2, HIGH);<br>    SerialBT.println(&quot;red LED is on&quot;);<br>  }  <br>  else if (message ==&quot;turn off yellow led&quot;){<br>    digitalWrite(ledPin1, LOW);<br>    SerialBT.println(&quot;yellow LED is off&quot;);<br>  }<br>  else if (message ==&quot;turn off red led&quot;){<br>    digitalWrite(ledPin2, LOW);<br>    SerialBT.println(&quot;red LED is off&quot;);<br>  }<br>  delay(20);<br>}</pre><p>After you connected your smartphone with ESP32, you’ll be able to turn on both of the LED by sending a message from your smartphone and vice versa. Type “turn on yellow led” or “turn on red led” to turn the LED on and “turn off yellow led” or “turn off red led” to turn the LED off. You can check the results at the end of this article.</p><h3>Bluetooth Low Energy</h3><p>Bluetooth Low Energy (BLE) is a power-conserving Bluetooth for short distance transmission of small data. For this part, don’t forget to install the <strong>nRF Connect for Mobile </strong>application.</p><p>The code that I used :</p><pre>/*<br>    Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp<br>    Ported to Arduino ESP32 by Evandro Copercini<br>    updates by chegewara<br>*/<br><br>#include &lt;BLEDevice.h&gt;<br>#include &lt;BLEUtils.h&gt;<br>#include &lt;BLEServer.h&gt;<br><br>// See the following for generating UUIDs:<br>// https://www.uuidgenerator.net/<br><br>#define SERVICE_UUID        &quot;4fafc201-1fb5-459e-8fcc-c5c9c331914b&quot;<br>#define CHARACTERISTIC_UUID &quot;beb5483e-36e1-4688-b7f5-ea07361b26a8&quot;<br><br>void setup() {<br>  Serial.begin(115200);<br>  Serial.println(&quot;Starting BLE work!&quot;);<br><br>  BLEDevice::init(&quot;Audrey&#39;s BLE&quot;);<br>  BLEServer *pServer = BLEDevice::createServer();<br>  BLEService *pService = pServer-&gt;createService(SERVICE_UUID);<br>  BLECharacteristic *pCharacteristic = pService-&gt;createCharacteristic(<br>                                         CHARACTERISTIC_UUID,<br>                                         BLECharacteristic::PROPERTY_READ |<br>                                         BLECharacteristic::PROPERTY_WRITE<br>                                       );<br><br>  pCharacteristic-&gt;setValue(&quot;Hi All, it&#39;s Audrey&quot;);<br>  pService-&gt;start();<br>  // BLEAdvertising *pAdvertising = pServer-&gt;getAdvertising();  // this still is working for backward compatibility<br>  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();<br>  pAdvertising-&gt;addServiceUUID(SERVICE_UUID);<br>  pAdvertising-&gt;setScanResponse(true);<br>  pAdvertising-&gt;setMinPreferred(0x06);  // functions that help with iPhone connections issue<br>  pAdvertising-&gt;setMinPreferred(0x12);<br>  BLEDevice::startAdvertising();<br>  Serial.println(&quot;Characteristic defined! Now you can read it in your phone!&quot;);<br>}<br><br>void loop() {<br>  // put your main code here, to run repeatedly:<br>  delay(2000);<br>}</pre><p>The serial monitor shown :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*HKlt3ku0tIwFjykTiEPUkA.png" /></figure><p>Then, turn on the Bluetooth on your smartphone and open the application. I downloaded the app from App Store. Then, go ahead and click the “start” button on the top-right side of the scanner display and connect your BLE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*z9N3RYXLcwABulNw6gCAAQ.jpeg" /></figure><p>You can customize your BLE’s name by changing this part of the code :</p><pre>BLEDevice::init(&quot;Audrey&#39;s BLE&quot;);<br>  BLEServer *pServer = BLEDevice::createServer();<br>  BLEService *pService = pServer-&gt;createService(SERVICE_UUID);<br>  BLECharacteristic *pCharacteristic = pService-&gt;createCharacteristic(<br>                                         CHARACTERISTIC_UUID,<br>                                         BLECharacteristic::PROPERTY_READ |<br>                                         BLECharacteristic::PROPERTY_WRITE<br>                                       );</pre><h3>Results</h3><p>LED On Using Bluetooth</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FBtsDes5ZxjdJDhMiBt%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExYWM4ZjY0NDk4YTEzY2FmMjU2OTcwNTRlMjVkNzliZjkzZTU1NjdhZCZjdD1n%2FBtsDes5ZxjdJDhMiBt%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FBtsDes5ZxjdJDhMiBt%2Fgiphy-downsized-large.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ea46b5bb7b8c9efed8ab2327c223212/href">https://medium.com/media/4ea46b5bb7b8c9efed8ab2327c223212/href</a></iframe><p>LED Off Using Bluetooth</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FD4zx7TLsZ40u8J7utg%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNTc0MzI2NzY2OTgwZDg5NmM3NWYzZmJiZDA1ZjljODU5NTYyMTNiYyZjdD1n%2FD4zx7TLsZ40u8J7utg%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FD4zx7TLsZ40u8J7utg%2Fgiphy-downsized-large.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/8215b95f464e17479ddb6363d319efae/href">https://medium.com/media/8215b95f464e17479ddb6363d319efae/href</a></iframe><p>Bluetooth BLE</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FVmebu0WQs7GcvYS0I6%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNDczNzAxYjM5Y2I4ZmViNmQyMDAxM2FlZTM0ZjNlNTkxNzAxNTM0MyZjdD1n%2FVmebu0WQs7GcvYS0I6%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FVmebu0WQs7GcvYS0I6%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="940" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe1fcb9d83f0b7262bc16deb2be66027/href">https://medium.com/media/fe1fcb9d83f0b7262bc16deb2be66027/href</a></iframe><blockquote>I don’t know why the quality downgraded :) , but I hope that it’s still watchable.</blockquote><h4>Final Say</h4><p>Well, that’s all for this week’s project. I’m pretty satisfied with how it turned out. See you guys on my next project, byee !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e06ef9c43e51" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded System Project #6 : Serial Communication]]></title>
            <link>https://medium.com/@Laurensia_Audrey/embedded-system-project-6-serial-communication-e4cc2cea959e?source=rss-b128545a082------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4cc2cea959e</guid>
            <dc:creator><![CDATA[Laurensia Audrey Pramashinta]]></dc:creator>
            <pubDate>Sun, 19 Mar 2023 14:04:59 GMT</pubDate>
            <atom:updated>2023-03-19T14:04:59.342Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embedded System Project #6 : Serial Communication</h3><p>Hi all ! In this project, we’ll be combining our previous knowledge on ESP32 External Sensor (Project 4) and OLED Display (Project 5). We’ll try to get sensor reading from BMP280 sensor and displays the results on an OLED Display.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*ACeO0ZujHqYiO-A8wlXABw.jpeg" /></figure><p>For this project, I’m using this <a href="https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/">link</a> as a reference, but there are some minor changes to accommodate the tools that I used. Well, let’s get started !</p><h4>[Preparation]</h4><p>Required components :</p><ul><li>ESP32 Board</li><li>0.96 inch OLED display</li><li>BMP280 Sensor</li><li>Male to male jumper wires</li><li>Breadboard</li><li>Micro USB cable</li></ul><h4>[Steps]</h4><p><strong>Circuit</strong></p><p>For this project, we have to connect both peripherals to the ESP32 <strong>GPIO 22 (SCL)</strong> and <strong>GPIO 21 (SDA). </strong>Don’t forget to refer to each peripheral by its address in the code.</p><p>Here are the circuit that I used :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mguTp6LhFYgxjLPiKpGbbw.jpeg" /></figure><p>Next, make sure that you already have all the libraries needed which are Adafruit BMP280, Adafruit SSD1306, and Adafruit GFX</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*SbAWT5rtx9UW8LnmlhVTRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*I7-uHOBAd_kVAoAx63c4jg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*foy-6-kRCBrtnMVx9pcyGw.png" /></figure><p>For the code, I’m using <a href="https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/">this link</a> as reference. You can go ahead and copy the following code to your Arduino IDE.</p><pre><br>*********<br>#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;Adafruit_BMP280.h&gt;<br>#define SCREEN_WIDTH 128 // OLED display width, in pixels<br>#define SCREEN_HEIGHT 64 // OLED display height, in pixels<br>// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)<br>Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &amp;Wire, -1);<br>Adafruit_BMP280 bmp; // I2C<br>void setup() {<br>  Serial.begin(115200);<br>  bmp.begin(0x76); // Initialize I2C address of BMP280<br>  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {<br>    Serial.println(F(&quot;SSD1306 allocation failed&quot;));<br>    for(;;);<br>  }<br>  delay(2000);<br>  display.clearDisplay();<br>  display.setTextColor(WHITE);<br>}<br>void loop() {<br>  delay(3000);<br>  <br>  //read temperature and pressure<br>  float t = bmp.readTemperature();<br>  float p = bmp.readPressure();<br>  if (isnan(p) || isnan(t)){<br>    Serial.println(&quot;Failed to read from bmp sensor!&quot;);<br>  }<br>  <br>  // clear display<br>  display.clearDisplay();<br>  <br>  // display temperature<br>  display.setTextSize(1);<br>  display.setCursor(0,0);<br>  display.print(&quot;Temperature: &quot;);<br>  display.setTextSize(2);<br>  display.setCursor(0,10);<br>  display.print(t);<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 pressure<br>  display.setTextSize(1);<br>  display.setCursor(0, 35);<br>  display.print(&quot;Pressure: &quot;);<br>  display.setTextSize(2);<br>  display.setCursor(0, 45);<br>  display.print(p/1000);<br>  display.print(&quot; kPa&quot;); <br>  <br>  display.display(); <br>}</pre><h4>[Result]</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OSVSQZloLvlsVswiwnEkGg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*1Nuyi0HHu9OQ4O_kth021Q.jpeg" /></figure><p>It worked ! When I touched the sensor with my bare hand, the temperature displayed on the OLED changed from 25.01°C to 28.22°C.</p><p>In conclusion, we can use the same GPIO22 (SCL) and GPIO21 (SDA) without any problem because the addresses used by the BMP280 and the OLED happened to be different.</p><p>That’s all for this week’s project. I hope that this article will give you guys new insight. See you on my next project !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4cc2cea959e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded System Project #5 : ESP 32 Display (OLED)]]></title>
            <link>https://medium.com/@Laurensia_Audrey/embedded-system-project-5-esp-32-display-oled-d601a44a7438?source=rss-b128545a082------2</link>
            <guid isPermaLink="false">https://medium.com/p/d601a44a7438</guid>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[oled-display]]></category>
            <dc:creator><![CDATA[Laurensia Audrey Pramashinta]]></dc:creator>
            <pubDate>Tue, 14 Mar 2023 11:51:17 GMT</pubDate>
            <atom:updated>2023-03-14T11:51:17.605Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://medium.com/@Laurensia_Audrey/embedded-system-project-4-esp-32-external-sensor-69a3cd34992a?source=your_stories_page-------------------------------------">Embedded System Project #5 : ESP 32 Display (O</a>LED)</h3><p>Hi , back again with another ESP32 Project. If you haven’t read my <a href="https://medium.com/@Laurensia_Audrey/embedded-system-project-4-esp-32-external-sensor-69a3cd34992a"><strong>previous article</strong></a> about external sensor, kindly check it out. This time, I’m going to show you how to display text and shape using OLED. Let’s get started !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-DgBCiS24GwRIOoi0AGtdQ.jpeg" /></figure><h3>Display</h3><p>There are actually various types of display available. To make it simple, I’ll only explain 2 of the external display, which is LCD and OLED.</p><p>The first one is LCD (Liquid Crystal Display), which is a type of flat panel display that uses liquid crystals in its primary form of operation. The LCD that’s usually used in this project is the 16×2 I2C Liquid Crystal Display. LCD is heavier, having more components, and cheaper if compared to OLED.</p><p>The second one is OLED (Organic Light-Emitting Diode), which is a semiconductor that can emit light for display. OLED has wider view, lighter and more flexible, brighter color, more efficient, lower power consumption, and higher display response speed if compared to LCD.</p><p>In this project, I’ll be using OLED as my external display.</p><h3>Parts Required</h3><p>To start this project, we will need:</p><ul><li>ESP32 Board</li><li>0.96 inch OLED display</li><li>USB cable</li><li>Jumper wires (4 male to male jumper wires)</li><li>Breadboard</li></ul><h3>Steps</h3><h4>Circuit</h4><p>The circuit is pretty simple, you just need to connect 4 male-to-male jumper cables to the ESP32 towards the OLED Display. Check the following picture to better understand the circuit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*cfJO741Y2Gy3z2XfcJ7heg.jpeg" /><figcaption>Circuit used</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/0*4L_5rFQGiWr6e7e5.jpeg" /></figure><h4>Installing Libraries</h4><p>You may follow these steps below to install the library.</p><ul><li>In your Arduino IDE, Sketch &gt; Include Library &gt; Manage Libraries</li><li>Type “<strong>Adafruit SSD1306</strong>” in the search box and then install the SSD1306 library from Adafruit</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Av2OOos8pSdw44eDDF-8nA.png" /></figure><ul><li>Type “GFX Library” in the search box and install the <strong>“Adafruit GFX Library”</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LxJJpCkksT9WC1DxHhtSag.png" /></figure><h4>Code</h4><p>This time, I’ll show you 2 different output that we can display with OLED, which is texts and shapes.</p><p><strong>— Code to display texts</strong></p><pre>/*********<br>  Rui Santos<br>  Complete project details at https://randomnerdtutorials.com  <br>*********/<br><br>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_GFX.h&gt;<br>#include &lt;Adafruit_SSD1306.h&gt;<br><br>#define SCREEN_WIDTH 128 // OLED display width, in pixels<br>#define SCREEN_HEIGHT 64 // OLED display height, in pixels<br><br>// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)<br>Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &amp;Wire, -1);<br><br>void setup() {<br>  Serial.begin(115200);<br><br>  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64<br>    Serial.println(F(&quot;SSD1306 allocation failed&quot;));<br>    for(;;);<br>  }<br>  delay(2000);<br>  display.clearDisplay();<br><br>  display.setTextSize(1);<br>  display.setTextColor(WHITE);<br>  display.setCursor(0, 10);<br>  // Display static text<br>  display.println(&quot;Hello, world!&quot;);<br>  display.println(&quot;Laurensia Audrey Pramashinta&quot;);<br>  display.display(); <br>}<br><br>void loop() {<br>  <br>}</pre><p>The result that I got :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNdB8kbt-bosHWedj-jI6w.jpeg" /></figure><p><strong>— Code to display shapes</strong></p><p>In your Arduino IDE, go to File &gt; Examples &gt; Adafruit SSD1306 and then select the example for the display you’re using. I picked “ssd1306_128x64_i2c”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a5L9SD9Gu42sbxYcJT3AHg.png" /></figure><p>I wanted to display 3 shapes in my OLED, which is rectangle, circle, and triangle. Down below are the code that I used.</p><pre>#include &lt;Wire.h&gt;<br>#include &lt;Adafruit_GFX.h&gt;<br>#include &lt;Adafruit_SSD1306.h&gt;<br><br>#define SCREEN_WIDTH 128<br>#define SCREEN_HEIGHT 64<br><br>// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)<br>Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &amp;Wire, -1);<br><br>void setup() {<br>  Serial.begin(115200);<br><br>  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {<br>    Serial.println(F(&quot;SSD1306 allocation failed&quot;));<br>    for(;;);<br>  }<br>  delay(1000); // Pause for 1 seconds<br><br><br>}<br>void loop() {<br>  // Clear the buffer<br>  display.clearDisplay();<br>  // Draw a single pixel in white<br>  display.drawPixel(64, 32, WHITE);<br>  display.display();<br>  delay(500);<br>  <br>  // Draw rectangle<br>  display.clearDisplay();<br>  display.drawRect(30, 10, 50, 30, WHITE);<br>  display.display();<br>  delay(500);<br>  // Fill rectangle<br>  display.fillRect(30, 10, 50, 30, WHITE);<br>  display.display();<br>  delay(500);<br>  <br>  // Draw circle<br>  display.clearDisplay();<br>  display.drawCircle(64, 32, 10, WHITE);<br>  display.display();<br>  delay(500);<br>  // Fill circle<br>  display.fillCircle(64, 32, 10, WHITE);<br>  display.display();<br>  delay(500);<br>  <br>  // Draw triangle<br>  display.clearDisplay();<br>  display.drawTriangle(10, 10, 55, 20, 5, 40, WHITE);<br>  display.display();<br>  delay(500);<br>  // Fill triangle<br>  display.fillTriangle(10, 10, 55, 20, 5, 40, WHITE);<br>  display.display();<br>  delay(500);<br><br>  // Invert and restore display, pausing in-between<br>  display.invertDisplay(true);<br>  delay(500);<br>  display.invertDisplay(false);<br>  delay(500);<br>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FmtAEgr2I3RV1GvEJWa%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNTAyNGU4YzkwZjk1N2NiZmRhZjkyNjIzYmExODdlNTY5ZmY4ZTY0YSZjdD1n%2FmtAEgr2I3RV1GvEJWa%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FmtAEgr2I3RV1GvEJWa%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/99cb456f77957f8519588a0c2452beb8/href">https://medium.com/media/99cb456f77957f8519588a0c2452beb8/href</a></iframe><p>As you can see, the code worked as intended.</p><p>In summary, utilizing the Arduino IDE software and ESP32, the OLED display can perform tasks such as writing text, drawing shapes, and exhibiting bitmap images. It is noteworthy that the OLED display does not rely on a backlight, producing excellent contrast in low-light environments. Additionally, the OLED display consumes less power compared to other displays, as its pixels only consume energy when activated.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d601a44a7438" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded System Project #4 : ESP 32 External Sensor]]></title>
            <link>https://medium.com/@Laurensia_Audrey/embedded-system-project-4-esp-32-external-sensor-69a3cd34992a?source=rss-b128545a082------2</link>
            <guid isPermaLink="false">https://medium.com/p/69a3cd34992a</guid>
            <category><![CDATA[external-sensor]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[arduino-ide]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <dc:creator><![CDATA[Laurensia Audrey Pramashinta]]></dc:creator>
            <pubDate>Fri, 03 Mar 2023 16:37:38 GMT</pubDate>
            <atom:updated>2023-03-03T16:37:38.829Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://medium.com/@Laurensia_Audrey/embedded-system-project-3-esp-32-internal-sensor-f69e1a41a5b8?source=your_stories_page-------------------------------------">Embedded System Project #4 : ESP 32 External Sensor</a></h3><p>Hii !! It’s time for another Embedded System Project. This week, we’ll be playing with external sensor from ESP32. Go check out my previous article about internal sensor if you haven’t read it yet, you can go ahead and click the <a href="https://medium.com/@Laurensia_Audrey/embedded-system-project-3-esp-32-internal-sensor-f69e1a41a5b8">link</a> here.</p><p>In this project, I’m using the BMP280 sensor. Using this sensor, we’ll be able to identify the air pressure, temperature, and estimate the altitude. This sensor connects directly to a microcontroller via I2C or SPI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*hirs6heomsb7hLg6.png" /><figcaption>BMP280 sensor</figcaption></figure><h3>[Preparation]</h3><p><strong>Required components :</strong></p><ul><li>ESP32 Development Board</li><li>Breadboard</li><li>BMP280 sensor</li><li>Jumper wires (male to male)</li><li>Micro USB cable</li></ul><p>There are actually many external sensors compatible with ESP32. But keep in mind that if you want to use a sensor that works at a voltage level of 5 V , then extra components are needed to do voltage conversion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KPCulHR4mx-0dHbA.jpeg" /></figure><h4>Steps</h4><p>To start this project, go ahead and connect the ESP32’s pins to the sensor using the guidance provided down below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d1USN7VND0dQUXQEKnjc2Q.jpeg" /><figcaption>ESP32 and BMP280 connected circuit</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*7Ywp4_W13YYtmSXI92QY2g.png" /><figcaption>BMP280 pinout</figcaption></figure><p>Next, get the code from File &gt; Examples &gt; BMP280 Library. If you don’t find it, you need to install it first. Go to Sketch &gt; Include Library &gt; Manage Libraries. Search “Adafruit BMP280 Library” and click Install &gt; install All.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*bMk_Nza55E6U6gyqQdIg7g.png" /></figure><p>To test the sketch , go to File &gt; Examples &gt; Adafruit BMP280 Library &gt; bmp280test. As usual, don’t forget to verify and upload the sketch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*Y7Q36pfibCEUrvcdQvZEQg.png" /></figure><p>This is the bmp280 test :</p><pre>/***************************************************************************<br>  This is a library for the BMP280 humidity, temperature &amp; pressure sensor<br><br>  Designed specifically to work with the Adafruit BMP280 Breakout<br>  ----&gt; http://www.adafruit.com/products/2651<br><br>  These sensors use I2C or SPI to communicate, 2 or 4 pins are required<br>  to interface.<br><br>  Adafruit invests time and resources providing this open source code,<br>  please support Adafruit andopen-source hardware by purchasing products<br>  from Adafruit!<br><br>  Written by Limor Fried &amp; Kevin Townsend for Adafruit Industries.<br>  BSD license, all text above must be included in any redistribution<br> ***************************************************************************/<br><br>#include &lt;Wire.h&gt;<br>#include &lt;SPI.h&gt;<br>#include &lt;Adafruit_BMP280.h&gt;<br><br>#define BMP_SCK  (13)<br>#define BMP_MISO (12)<br>#define BMP_MOSI (11)<br>#define BMP_CS   (10)<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);<br><br>void setup() {<br>  Serial.begin(9600);<br>  while ( !Serial ) delay(100);   // wait for native usb<br>  Serial.println(F(&quot;BMP280 test&quot;));<br>  unsigned status;<br>  //status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);<br>  status = bmp.begin();<br>  if (!status) {<br>    Serial.println(F(&quot;Could not find a valid BMP280 sensor, check wiring or &quot;<br>                      &quot;try a different address!&quot;));<br>    Serial.print(&quot;SensorID was: 0x&quot;); Serial.println(bmp.sensorID(),16);<br>    Serial.print(&quot;        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n&quot;);<br>    Serial.print(&quot;   ID of 0x56-0x58 represents a BMP 280,\n&quot;);<br>    Serial.print(&quot;        ID of 0x60 represents a BME 280.\n&quot;);<br>    Serial.print(&quot;        ID of 0x61 represents a BME 680.\n&quot;);<br>    while (1) delay(10);<br>  }<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><br>void loop() {<br>    Serial.print(F(&quot;Temperature = &quot;));<br>    Serial.print(bmp.readTemperature());<br>    Serial.println(&quot; *C&quot;);<br><br>    Serial.print(F(&quot;Pressure = &quot;));<br>    Serial.print(bmp.readPressure());<br>    Serial.println(&quot; Pa&quot;);<br><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><br>    Serial.println();<br>    delay(2000);<br>}</pre><p>In this particular step, I encountered a small problem. When I opened the Serial Monitor, nothing showed up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gohoFS-plWmGMiSkBkWIAQ.png" /></figure><p>I eventually found out that we need to look for the I2C address of BMP280 first and then add it to the code. This is the code that I used :</p><pre>/*********<br>  Rui Santos<br>  Complete project details at https://randomnerdtutorials.com  <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><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*1npxaUjrCDBVWBW9S2xiSw.png" /></figure><p>We now know that I2C device found at address 0x76. Now, the final code will be :</p><pre>/***************************************************************************<br>  This is a library for the BMP280 humidity, temperature &amp; pressure sensor<br>Designed specifically to work with the Adafruit BMP280 Breakout<br>  ----&gt; http://www.adafruit.com/products/2651<br>These sensors use I2C or SPI to communicate, 2 or 4 pins are required<br>  to interface.<br>Adafruit invests time and resources providing this open source code,<br>  please support Adafruit andopen-source hardware by purchasing products<br>  from Adafruit!<br>Written by Limor Fried &amp; Kevin Townsend for Adafruit Industries.<br>  BSD license, all text above must be included in any redistribution<br> ***************************************************************************/<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; // 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)) {<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><h4>Let’s test it out !</h4><p>Arduino IDE will print the temperature, pressure, and approximate altitude value on the serial monitor continuously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E3szXPow9gD3YncpY8x9aQ.jpeg" /></figure><p>When left untouched, the temperature shown was 26.78 C. And it kept going up as I touched the sensor.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2Fdisfiguredcompassionatebittern&amp;display_name=Gfycat&amp;url=https%3A%2F%2Fgfycat.com%2Fdisfiguredcompassionatebittern&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FDisfiguredCompassionateBittern-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="640" height="504" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffb8767abd63b932b4462d515a7414d6/href">https://medium.com/media/ffb8767abd63b932b4462d515a7414d6/href</a></iframe><p>The result above proves that my BMP280 works as intended. Its temperature increased from 26.78 C to 29.44 C as it made contact with my hand.</p><p>This will end my experiment on external sensor using BMP280. I’m really satisfied with this week’s project and hope that this article will also give you guys new knowledge and insight. See you on my next project !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69a3cd34992a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded System Project #3 : ESP 32 Internal Sensor]]></title>
            <link>https://medium.com/@Laurensia_Audrey/embedded-system-project-3-esp-32-internal-sensor-f69e1a41a5b8?source=rss-b128545a082------2</link>
            <guid isPermaLink="false">https://medium.com/p/f69e1a41a5b8</guid>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[internal-sensor]]></category>
            <dc:creator><![CDATA[Laurensia Audrey Pramashinta]]></dc:creator>
            <pubDate>Wed, 22 Feb 2023 15:30:17 GMT</pubDate>
            <atom:updated>2023-02-22T15:30:17.781Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embedded System Project #3 : ESP 32 Internal Sensor</h3><p>Hello ! I’m back with another ESP32 project. This is my 3rd Embedded System Project and if you haven’t read my <a href="https://medium.com/@Laurensia_Audrey/embedded-system-project-2-esp32-digital-input-and-output-b7bb64dc15d5">previous article</a>, kindly check it out.</p><p>Internal sensors are generally used to determine the conditions in the ESP32 device itself, which are called proprioceptive sensors. This time, I’m going to try 2 built-in sensor in ESP32, which is touch sensor and hall effect sensor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*lF-UEevEBNPZ-r6I8lDeZQ.jpeg" /></figure><h4>Parts Required</h4><ul><li>ESP32 Development Board</li><li>Breadboard</li><li>5mm LEDs</li><li>330 Ohm resistors</li><li>Male to male jumper wires</li><li>Micro USB cable</li><li>Magnet</li></ul><h4>Touch Sensor</h4><p>The ESP32 has 10 capacitive touch GPIOs that can sense variations in anything that holds an electrical charge. These pins can be easily integrated into capacitive pads and replace mechanical buttons. Additionally, the touch pins can also be used as a wake-up source when the ESP32 is in deep sleep.</p><p>In this project, I’m using 2 LED lights. The goal is to make the first LED light up whenever I touch the sensor and the second LED to light up if the sensor is untouched.</p><p>This is the code that I used :</p><pre>// Inisiasi nomor pin<br>const int touchPin = 4; <br>const int ledPin1 = 18;<br>const int ledPin2 = 19;<br>// Nilai treshold/ toleransi sentuh<br>const int threshold = 35;<br>// Menyimpan nilai yang dibaca sensor <br>int touchValue;<br>void setup(){<br>  Serial.begin(115200);<br>  delay(1000); <br>  // Menginisiasi ledPin sebagai output<br>  pinMode (ledPin1, OUTPUT);<br>  pinMode (ledPin2, OUTPUT);<br>}<br>void loop(){<br>  // Membaca nilai sensor  <br>  touchValue = touchRead(touchPin);<br>  Serial.print(touchValue);<br>  // Memeriksa kondisi touchValue terhadap treshold<br>  // Apabila touchValue &lt; treshold (sedang disentuh) <br>  // Matikan LED 2 dan nyalakan LED 1<br>  <br>  if(touchValue &lt; threshold){<br>    digitalWrite(ledPin1, HIGH);<br>    digitalWrite(ledPin2, LOW);<br>    Serial.println(&quot; touched&quot;);<br>  }<br>  // Apabila touchValue &lt; treshold (sedang tidak disentuh), <br>  // Matikan LED 1 dan nyalakan LED 2<br>  else{<br>    digitalWrite(ledPin2, HIGH);<br>    digitalWrite(ledPin1, LOW);<br>    Serial.println(&quot; untouched&quot;);<br>  }<br>  delay(500);<br>}</pre><p>Let’s test it out !</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2Fadmirablecelebratedadamsstaghornedbeetle&amp;display_name=Gfycat&amp;url=http%3A%2F%2Fgfycat.com%2Fadmirablecelebratedadamsstaghornedbeetle&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="600" height="464" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c21efc1a62df769ceebf568ff9e582f/href">https://medium.com/media/6c21efc1a62df769ceebf568ff9e582f/href</a></iframe><p>As you can see, the green LED (2nd LED) light up when left untouched. But it will switch to the yellow LED (1st LED) as soon as I touched the sensor. When I opened the Serial Monitor (Ctrl + Shift + M) with 115200 baud rate, this is the output that I got :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i6oz_V30DXVtXAztrxdTgQ.png" /><figcaption>Serial Monitor Touch Sensor Project</figcaption></figure><p>The message “untouched” are displayed when I didn’t touch the sensor and “touched” are displayed when I touched the sensor. So, I can conclude that my simple Touch Sensor was a success !</p><h4>Hall Effect Sensor</h4><p>We can use hall effect sensor with magnet instead of touch sensor to turn on the LED. The hall effect sensor detect variations in the magnetic field in its surroundings. The greater the magnetic field, the greater the sensor’s output voltage.</p><p>For this project, I’m using the same components that I used for the touch sensor project, but I took out the pin that’s attached to the GPIO4. The goal is to make the first LED light up whenever I the magnet touched the ESP32 (negative) and the second LED to light up if the sensor is untouched (netral).</p><p>Here’s the code that I used :</p><pre>// Menginisiasi variabel nilai Hall Effect<br>int hallValue;<br>// Menginisiasi nilai pin yang terhubung<br>const int ledPin1 = 18;<br>const int ledPin2 = 19;<br>void setup() {<br>  Serial.begin(115200);<br>  delay(1000); <br>  // Menginisiasi ledPin sebagai Output<br>  pinMode (ledPin1, OUTPUT);<br>  pinMode (ledPin2, OUTPUT);<br>}<br>void loop(){<br>  // Membaca state sensor<br>  hallValue = hallRead();<br>  // Mencetak nilai bacaan sensor ke serial monitor<br>  Serial.print(hallValue);<br>  // Mengecek hasil bacaan sensor, apabila &lt; 0 berarti kutub negatif<br>  if(hallValue &lt; 0){<br>    // Menyalakan LED merah dan mematikan LED Hijau<br>    digitalWrite(ledPin1, HIGH);<br>    digitalWrite(ledPin2, LOW);<br>    // Memberikan simbol - (kutub negatif)<br>    Serial.println(&quot; -&quot;);<br>  }<br>  // apabila &gt; 50 berarti kutub positif<br>  else {<br>    Serial.println(&quot; netral&quot;);<br>    // Mematikan kedua LED<br>    digitalWrite(ledPin1, LOW);<br>    digitalWrite(ledPin2, HIGH);<br>  }<br>  delay(500);<br>}</pre><p>I made some small changes to the code. When the ESP32 detects negative pole, serial monitor will display negative number. When left untouched, it will display “netral” message. There’s also a new variable “hallValue” that contains a new function called hallRead() to read the hall effect value. Well, let’s try it out!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2Fidenticalpowerfulbarnswallow&amp;display_name=Gfycat&amp;url=https%3A%2F%2Fgfycat.com%2Fidenticalpowerfulbarnswallow&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FIdenticalPowerfulBarnswallow-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="600" height="352" frameborder="0" scrolling="no"><a href="https://medium.com/media/889ae27a45c4e00ee35637f62870d38a/href">https://medium.com/media/889ae27a45c4e00ee35637f62870d38a/href</a></iframe><p>Depends on the magnet pole that’s facing the sensor, magnet can increase or decrease the value of hallRead() . The closer the magnet to the sensor, the greater the absolute values.</p><p>Here’s the serial monitor for this project :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*_qtCWRhThrREVFtatuKPow.png" /><figcaption>Serial Monitor Hall Effect Sensor Project</figcaption></figure><p>Success! The serial monitor shows “netral” when the ESP32’s left untouched and “ -” when it’s touched by magnet.</p><p>Well, that’s all for now. See you on my next projects !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f69e1a41a5b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedded System Project #2 : ESP32 Digital Input and Output]]></title>
            <link>https://medium.com/@Laurensia_Audrey/embedded-system-project-2-esp32-digital-input-and-output-b7bb64dc15d5?source=rss-b128545a082------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7bb64dc15d5</guid>
            <category><![CDATA[digital-input-output]]></category>
            <category><![CDATA[arduino-ide]]></category>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[Laurensia Audrey Pramashinta]]></dc:creator>
            <pubDate>Sun, 12 Feb 2023 13:02:44 GMT</pubDate>
            <atom:updated>2023-02-22T04:20:13.271Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Embedded System Project #2 : ESP32 Digital Input and Output</strong></h3><p>Hey there ! In this article, I’d like to share my second Embedded System Project, Digital I/O. If you haven’t read my first post, you can access it <a href="https://medium.com/@Laurensia_Audrey/my-first-esp32-project-led-blink-134987b9e390">here</a>.</p><p>ESP32 has Input and Output pins as an interface to communicate<br>with the outside world. These pins are referred to as General Purpose Input Output (GPIO). GPIO can be used to receive digital or analog input signal and send out a digital output signal or analog. Digital signal means there are only two conditions, namely OFF and ON</p><p>Today, we’ll build a simple digital I/O using pushbutton and LED.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*GnJzg5KhlMS5N26gvZ9-ZA.jpeg" /></figure><h3><strong>Simple I/O</strong></h3><h4>Parts Required</h4><ul><li>ESP32</li><li>LED</li><li>330 Ohm resistor</li><li>Pushbutton</li><li>10k Ohm resistor</li><li>Breadboard</li><li>Jumper wires</li></ul><p><strong>Here are the simplified steps that you need to follow :</strong></p><ol><li>Connect the 3v3 pin to the positive (red) part of the breadboard and GND pin to the negative (blue) part.</li><li>Connect GPIO4 (D4) pin to the Push Button with 10k Ohm resistor.</li><li>Connect GPIO5 (D5) pin to the longer leg (anode) of the LED.</li><li>Connect the shorter LED leg (cathode) with 330 Ohm resistor.</li><li>Last, connect the other leg of the push button to the positive part of the breadboard with a jumper wire.</li></ol><p><strong>To proceed, we need to follow this schematics:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*87JiP6CRzCkASqgN" /></figure><h3>Code</h3><p>When it’s all done, we can go ahead and copy this code to our Arduino IDE :</p><pre>// set pin numbers<br>const int buttonPin = 4;  // the number of the pushbutton pin<br>const int ledPin =  5;    // the number of the LED pin<br><br>// variable for storing the pushbutton status <br>int buttonState = 0;<br><br>void setup() {<br>  Serial.begin(115200);  <br>  // initialize the pushbutton pin as an input<br>  pinMode(buttonPin, INPUT);<br>  // initialize the LED pin as an output<br>  pinMode(ledPin, OUTPUT);<br>}<br><br>void loop() {<br>  // read the state of the pushbutton value<br>  buttonState = digitalRead(buttonPin);<br>  Serial.println(buttonState);<br>  // check if the pushbutton is pressed.<br>  // if it is, the buttonState is HIGH<br>  if (buttonState == HIGH) {<br>    // turn LED on<br>    digitalWrite(ledPin, HIGH);<br>  } else {<br>    // turn LED off<br>    digitalWrite(ledPin, LOW);<br>  }<br>}</pre><p><strong>Here’s how the code works :</strong></p><p>The number of GPIO used for the LED and the button are initialized with the first two lines. It was 4 for the button and 5 for the LED. Then the push button status was set to 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*F7piyYXZ6m_gm4VvLLVPKg.png" /></figure><p>In the <em>setup() </em>there’s Serial.begin(115200), that means the baud rate is 115200 bits per second . Then we’ll set the push button as the input and the LED as the output. For that, we use the pinMode() function that accepts the pin we are referring to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*xb_G8z_4PvMr7gTlpQnlZA.png" /></figure><p>In the loop(), we’ll read the input from push button. If the buttonState is HIGH , the ledPin will be written HIGH so the LED will be on, and vice versa. We use the digitalWrite() function that accepts ledPin and the state(HIGH or LOW) as an argument</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*EwX2zaNyXu8m_C1AQP_YHw.png" /></figure><h3>Demonstration</h3><p>After following those steps, I can finally test if it all worked out.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2Frectangularscratchyinganue&amp;display_name=Gfycat&amp;url=https%3A%2F%2Fgfycat.com%2Frectangularscratchyinganue&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FRectangularScratchyInganue-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="600" height="338" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c833d5e57f3bd1f0330eaa1f7c60dbb/href">https://medium.com/media/2c833d5e57f3bd1f0330eaa1f7c60dbb/href</a></iframe><p>Success! The LED turned on when I pressed the button and turned off when I released it.</p><h3><strong>Modification</strong></h3><p>To further broaden my understanding about this project, I made some small changes. This time, I used 2 LED lights and 2 push buttons.</p><p>I wanted the first LED to be switched on when the first push button is pressed and the second LED to be switched on when the second push button is pressed. When we pressed the push buttons together, it will turn both of the LED.</p><p>This time, I added another line for the number of GPIO used for the second LED and the button. It was 19 for the button and 18 for the LED. Here’s the code that I made :</p><pre>// set pin numbers<br>const int buttonPin1 = 4;  // the number of the pushbutton pin<br>const int buttonPin2 = 19;  // the number of the pushbutton pin<br>const int ledPin1 =  5;    // the number of the LED pin<br>const int ledPin2 =  18;    // the number of the LED pin<br><br><br>// variable for storing the pushbutton status <br>int buttonState1 = 0;<br>int buttonState2 = 0;<br><br>void setup() {<br>  Serial.begin(115200);  <br>  // initialize the pushbutton pin as an input<br>  pinMode(buttonPin1, INPUT);<br>  pinMode(buttonPin2, INPUT);<br>  // initialize the LED pin as an output<br>  pinMode(ledPin1, OUTPUT);<br>  pinMode(ledPin2, OUTPUT);<br><br>}<br><br>void loop() {<br>  // read the state of the pushbutton value<br>  buttonState1 = digitalRead(buttonPin1);<br>  buttonState2 = digitalRead(buttonPin2);<br><br>  Serial.println(buttonState1);<br>  // check if the pushbutton is pressed.<br>  // if it is, the buttonState is HIGH<br>  if (buttonState1 == HIGH) {<br>    // turn LED on<br>    digitalWrite(ledPin1, HIGH);<br>  }else if(buttonState2==HIGH){<br>    digitalWrite(ledPin2, HIGH);<br>  }else{<br>    // turn LED off<br>    digitalWrite(ledPin1, LOW);<br>    digitalWrite(ledPin2, LOW);<br><br>  }<br>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2Fangelicscientificcattle&amp;display_name=Gfycat&amp;url=https%3A%2F%2Fgfycat.com%2Fangelicscientificcattle&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FAngelicScientificCattle-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="600" height="398" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0cafc328911ecbe31aadd7bffb72b3c/href">https://medium.com/media/c0cafc328911ecbe31aadd7bffb72b3c/href</a></iframe><p>It worked !</p><p>Well, that’s it for our Digital I/O Project. I had a lot of fun and can’t wait to start working on my 3rd project. See you next time :) !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7bb64dc15d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First ESP32 Project : LED Blink]]></title>
            <link>https://medium.com/@Laurensia_Audrey/my-first-esp32-project-led-blink-134987b9e390?source=rss-b128545a082------2</link>
            <guid isPermaLink="false">https://medium.com/p/134987b9e390</guid>
            <category><![CDATA[esp32]]></category>
            <dc:creator><![CDATA[Laurensia Audrey Pramashinta]]></dc:creator>
            <pubDate>Sun, 05 Feb 2023 13:52:39 GMT</pubDate>
            <atom:updated>2023-02-05T13:52:39.906Z</atom:updated>
            <content:encoded><![CDATA[<h3>My First ESP32 Project : LED Blink</h3><p>Greetings my fellow readers ! This is Audrey and I’m going to walk you through my first ever Embedded System project. This is my first time using Arduino IDE but I’m positive that it’s going to be a lot of fun. I will keep posting weekly about my journey, so stay tuned for more upcoming posts !</p><h3><strong>Required Hardware</strong></h3><ol><li>ESP32 Dev Board</li><li>USB Type A Male to Micro USB</li><li>Laptop</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*yasijMRdFb7OPg0F" /></figure><h3>Required Software</h3><p><strong>1.Download Arduino IDE</strong></p><p>To begin this project, you need to install Arduino IDE in your computer. You may get your latest Arduino IDE software from <a href="https://www.arduino.cc/en/Main/Software"><strong>arduino.cc/en/Main/Software</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7vvcrF2HyAkfK-EiucZvdA.png" /><figcaption><a href="https://www.arduino.cc/en/Main/Software">arduino.cc/en/Main/Software</a></figcaption></figure><p><strong>2. Arduino IDE Configuration</strong></p><ul><li>Copy this URL into the Additional Boards Manager URLs bar in Preferences : <a href="https://dl.espressif.com/dl/package_esp32_index.json">https://dl.espressif.com/dl/package_esp32_index.json</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hhKqT_NuzJxIFkUQkbKDBw.png" /></figure><ul><li>Find Boards Manager under Tools &gt; Boards and choose the esp32 Board</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MK6bZwtHNpseG7POwfXOQA.png" /></figure><ul><li>Choose your board. In this case, I’m using ESP32 DEVKIT V1</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*88feY-rKmuuXcy_Anq3FLA.png" /></figure><p><strong>3. Install a USB to UART Port Driver</strong></p><p>you can use this link : <a href="https://www.silabs.com/products/development-tools/software/usbto-uart-bridge-vcp-drivers">https://www.silabs.com/products/development-tools/software/usbto-uart-bridge-vcp-drivers</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5k5T8saTYYyv6MH1knbSQ.png" /></figure><ul><li>Choose the USB to UART Port under Tools &gt; Port</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*OgAPkBU67DtPn_S0m3T0mg.png" /></figure><h3>LED BLINK</h3><p>Here are the steps I do for this project :</p><ol><li>Plug ESP32 to computer</li><li>Open Examples &gt; 01.Basics &gt; Blink</li><li>Click verify</li><li>Upload program to ESP32</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0J9kStjRCzvupmPSS80lUA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZa1fIAHXLAxkrBurUIhpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tru-joVirrBFdGgsgRlrxQ.png" /></figure><ul><li>When uploading, don’t forget to keep clicking on the ‘BOOT’ button on your ESP32.</li><li>Then click on the ‘EN’ button and the blue LED will start blinking</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2Fcandidmediocreblackmamba&amp;display_name=Gfycat&amp;url=https%3A%2F%2Fgfycat.com%2Fcandidmediocreblackmamba&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FCandidMediocreBlackmamba-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="540" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f5e85bef64430f28fadaa66253c8b36/href">https://medium.com/media/0f5e85bef64430f28fadaa66253c8b36/href</a></iframe><p>And.. that’s it !! We’re basically done. The blue LED on your Development Board will light up simultaneously in an interval of 1000 ms.</p><p>I tried to change the delay value to 300 ms, and this happened :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2Fwhimsicalpastelafricanaugurbuzzard&amp;display_name=Gfycat&amp;url=https%3A%2F%2Fgfycat.com%2Fwhimsicalpastelafricanaugurbuzzard&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FWhimsicalPastelAfricanaugurbuzzard-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="360" height="640" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8182a5ccc205814f94bee9e3c0ba636/href">https://medium.com/media/b8182a5ccc205814f94bee9e3c0ba636/href</a></iframe><p>The LED blinked faster than the first one.</p><p>With this experience, I conclude that the frequency of the LED blink depends on the delay that we input. The lower the delay, the faster it blinks.</p><p>Well, that’s it ! I finished my first Embedded System Project : LED Blink. See you on the next project ! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=134987b9e390" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>