<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ESP8266 Projects | Teach Me Microcontrollers!</title>
	<atom:link href="https://www.teachmemicro.com/category/projects/esp8266-projects/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.teachmemicro.com/category/projects/esp8266-projects/</link>
	<description>Microcontroller Tutorials and Resources</description>
	<lastBuildDate>Sun, 28 Jun 2026 01:12:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>

<image>
	<url>https://www.teachmemicro.com/wp-content/uploads/2019/04/blue-icon-65x65.png</url>
	<title>ESP8266 Projects | Teach Me Microcontrollers!</title>
	<link>https://www.teachmemicro.com/category/projects/esp8266-projects/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>ESP8266 IoT Gas Leak Sensor with Arduino Cloud</title>
		<link>https://www.teachmemicro.com/esp8266-iot-gas-leak-sensor/</link>
					<comments>https://www.teachmemicro.com/esp8266-iot-gas-leak-sensor/#respond</comments>
		
		<dc:creator><![CDATA[Roland Pelayo]]></dc:creator>
		<pubDate>Fri, 08 Nov 2024 01:00:32 +0000</pubDate>
				<category><![CDATA[ESP8266 Projects]]></category>
		<category><![CDATA[Sensor Tutorial]]></category>
		<guid isPermaLink="false">https://www.teachmemicro.com/?p=2767</guid>

					<description><![CDATA[<p>In this project, we’ll use the ESP8266 to connect an MQ-135 gas sensor to the Arduino IoT Cloud. This setup will enable you to detect air quality changes and potentially dangerous gas levels, which you can monitor from anywhere in real time through the Arduino Cloud. Components Needed ESP8266 Development Board (e.g., NodeMCU or Wemos &#8230;</p>
<p>The post <a href="https://www.teachmemicro.com/esp8266-iot-gas-leak-sensor/">ESP8266 IoT Gas Leak Sensor with Arduino Cloud</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this project, we’ll use the ESP8266 to connect an MQ-135 gas sensor to the Arduino IoT Cloud. This setup will enable you to detect air quality changes and potentially dangerous gas levels, which you can monitor from anywhere in real time through the Arduino Cloud.</p>
<p><span id="more-2767"></span></p>
<h4><img decoding="async" class="aligncenter" src="https://circuit.rocks/cdn/shop/files/gas-sensor-mq135-a31153.jpg?v=1689573281&amp;width=990" /></h4>
<h4>Components Needed</h4>
<ul>
<li>ESP8266 Development Board (e.g., NodeMCU or Wemos D1 Mini)</li>
<li>MQ-135 Gas Sensor (detects gases such as ammonia, sulfide, and benzene steam)</li>
<li>Jumper wires</li>
<li>Breadboard (optional)</li>
<li>USB Cable for ESP8266</li>
</ul>
<h4>Step 1: Setting Up the Arduino IoT Cloud Account</h4>
<ol>
<li>Go to the <a target="_new" rel="noopener">Arduino IoT Cloud</a> website and create an account if you don't have one.</li>
<li>Once logged in, navigate to <strong>IoT Cloud</strong> and select <strong>Create New Thing</strong>.</li>
</ol>
<h4>Step 2: Setting Up Your IoT Thing and Variables</h4>
<ol>
<li><strong>Name the Thing</strong> as "Gas Leak Sensor".</li>
<li><strong>Add a Variable</strong>:
<ul>
<li>Name: <em>GasLevel</em></li>
<li>Type: <em>Float</em></li>
<li>Permission: <em>Read Only</em></li>
<li>Update Policy: <em>On Change</em></li>
<li>Threshold: <em>0</em></li>
</ul>
</li>
<li>This variable will hold the gas level value from the MQ-135 sensor, which will be updated on the Arduino Cloud.</li>
</ol>
<h4>Step 3: Connect the ESP8266 to Arduino IoT Cloud</h4>
<ol>
<li><strong>Go to Devices</strong> under Arduino Cloud and select <strong>Add Device</strong>.</li>
<li>Choose <strong>Set up a Third Party Device</strong> and select <strong>ESP8266</strong>.</li>
<li>You can also specify which ESP8266 board you are using. I am using WeMos Mini D1 for this example.</li>
<li>Follow the prompts to name your device and generate an <strong>API Key</strong>.</li>
<li>Once the device is registered, download the device <strong>Secret Key</strong> and store it safely; this will be needed in the code.</li>
</ol>
<h4>Step 4: Circuit Connection</h4>
<ol>
<li><strong>MQ-135 to ESP8266 Wiring</strong>:
<ul>
<li>Connect <strong>VCC</strong> of the MQ-135 to <strong>3.3V</strong> of the ESP8266.</li>
<li>Connect <strong>GND</strong> to <strong>GND</strong> on the ESP8266.</li>
<li>Connect <strong>Analog Output (AO)</strong> of the MQ-135 to the <strong>A0</strong> pin on the ESP8266 (ESP8266 has only one analog pin, A0).</li>
</ul>
</li>
</ol>
<h4>Step 5: Installing Required Libraries</h4>
<p>Open the <strong>Arduino IDE</strong> (make sure it’s the latest version).</p>
<ol>
<li>Install <strong>ArduinoIoTCloud</strong> and <strong>Arduino_ConnectionHandler</strong> libraries:
<ul>
<li>Go to <strong>Tools &gt; Manage Libraries...</strong></li>
<li>Search for and install the <strong>ArduinoIoTCloud</strong> library.</li>
<li>Repeat for the <strong>Arduino_ConnectionHandler</strong> library.</li>
</ul>
</li>
<li>If you haven’t yet installed ESP8266 board support:
<ul>
<li>Go to <strong>File &gt; Preferences</strong> and add <em>http://arduino.esp8266.com/stable/package_esp8266com_index.json</em> to the <strong>Additional Board Manager URLs</strong>.</li>
<li>Go to <strong>Tools &gt; Board &gt; Boards Manager...</strong>, search for <strong>ESP8266</strong> and install it.</li>
</ul>
</li>
</ol>
<h4><img decoding="async" class="aligncenter" src="https://circuit.rocks/cdn/shop/files/wemos-esp8266-esp-12-usb-d1-mini-wifi-1295.jpg?v=1690777327&amp;width=324" /></h4>
<h4>Step 6: Coding the ESP8266</h4>
<p>Here’s the code to set up the ESP8266 to send gas sensor readings to the Arduino IoT Cloud.</p>
<ol>
<li>Open a new sketch in Arduino IDE.</li>
<li>Replace <strong>SECRET_SSID</strong> and <strong>SECRET_PASS</strong> with your Wi-Fi credentials, and <strong>DEVICE_ID</strong> and <strong>SECRET_KEY</strong> with your Arduino Cloud device credentials.</li>
</ol>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-cpp" data-lang="C++"><code>#include "thingProperties.h"

// Analog pin for the MQ-135 sensor
const int mq135Pin = A0;
float gasLevel = 0;

void setup() {
  // Initialize serial and IoT Cloud properties
  Serial.begin(115200);
  delay(1500); 
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  // Wait for connection to the cloud
  while (!ArduinoCloud.connected()) {
    ArduinoCloud.update();
    delay(500);
  }
  Serial.println("Connected to Arduino IoT Cloud.");
}

void loop() {
  ArduinoCloud.update();

  // Read sensor value from MQ-135
  int sensorValue = analogRead(mq135Pin);

  // Convert the sensor value to a meaningful level
  gasLevel = sensorValue * (5.0 / 1023.0);

  // Log the gas level
  Serial.print("Gas Level: ");
  Serial.println(gasLevel);

  // Update cloud variable
  GasLevel = gasLevel;

  delay(1000);  // Adjust delay as needed
}
</code></pre>
</div>
<h4>Step 7: Configuring Thing Properties</h4>
<p>Before uploading, you need to configure <strong>thingProperties.h</strong> for your project:</p>
<ol>
<li>Open <strong>thingProperties.h</strong> by selecting <strong>Sketch &gt; Show Sketch Folder</strong> and finding <strong>thingProperties.h</strong>.</li>
<li>Set up your <em>setupProperties()</em> function to sync with the cloud variable:</li>
</ol>
<div class="contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950">
<div class="overflow-y-auto p-4" dir="ltr">
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-cpp" data-lang="C++"><code><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&lt;ArduinoIoTCloud.h&gt;</span></span> 
<span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&lt;Arduino_ConnectionHandler.h&gt;</span></span>

const char DEVICE_ID[] = "your_device_id";
const char SSID[] = SECRET_SSID;
const char PASS[] = SECRET_PASS;

void initProperties() {
  ArduinoCloud.setThingId(DEVICE_ID);
  ArduinoCloud.addProperty(GasLevel, READ, ON_CHANGE, NULL);
}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
</code></pre>
</div>
</div>
</div>
<h4>Step 8: Uploading the Code</h4>
<ol>
<li>Select your ESP8266 board and correct COM port in <strong>Tools</strong>.</li>
<li>Upload the code to your ESP8266.</li>
<li>Open the <strong>Serial Monitor</strong> (set it to 115200 baud rate) to confirm that your ESP8266 connects to Wi-Fi and begins sending gas level readings.</li>
</ol>
<h4>Step 9: Monitoring the Gas Levels on Arduino IoT Cloud</h4>
<ol>
<li>Return to <strong>Arduino IoT Cloud</strong> and open your <strong>Thing</strong>.</li>
<li>You should see the <strong>GasLevel</strong> variable updating in real-time.</li>
<li>Optionally, set up <strong>dashboards</strong> or <strong>notifications</strong> for specific thresholds if you want alerts.</li>
</ol>
<h4>Step 10: (Optional) Adding a Visual Dashboard</h4>
<ol>
<li>Under <strong>Arduino IoT Cloud</strong>, go to <strong>Dashboards</strong> and select <strong>Build Dashboard</strong>.</li>
<li>Add a <strong>Gauge Widget</strong> for real-time monitoring.</li>
<li>Link the <strong>GasLevel</strong> variable to the gauge.</li>
</ol>
<hr />
<h3>Summary</h3>
<p>You’ve now set up an IoT gas leak sensor with ESP8266 and MQ-135, with real-time monitoring through the Arduino IoT Cloud. This setup can serve as an effective safety tool to monitor potentially hazardous gas levels in your home or workspace.</p>
<p>The post <a href="https://www.teachmemicro.com/esp8266-iot-gas-leak-sensor/">ESP8266 IoT Gas Leak Sensor with Arduino Cloud</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.teachmemicro.com/esp8266-iot-gas-leak-sensor/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Ultrasonic Door Lock with WiFi Control</title>
		<link>https://www.teachmemicro.com/ultrasonic-door-lock-with-wifi-control/</link>
					<comments>https://www.teachmemicro.com/ultrasonic-door-lock-with-wifi-control/#respond</comments>
		
		<dc:creator><![CDATA[Roland Pelayo]]></dc:creator>
		<pubDate>Thu, 05 Aug 2021 02:24:23 +0000</pubDate>
				<category><![CDATA[ESP8266 Projects]]></category>
		<guid isPermaLink="false">https://www.teachmemicro.com/?p=5287</guid>

					<description><![CDATA[<p>For this project, I am using an HC-SR04 ultrasonic sensor for opening a solenoid door lock. Basically, the ultrasonic sensor acts as a proximity detector. A solenoid lock triggers when an object blocks the sensor at a given distance. In addition, a web app can act as WiFi remote control for the lock. Materials HC-SR04 &#8230;</p>
<p>The post <a href="https://www.teachmemicro.com/ultrasonic-door-lock-with-wifi-control/">Ultrasonic Door Lock with WiFi Control</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p class="c0"><span class="c1">For this project, I am using an <a href="https://www.win-source.net/products/detail/osepp-electronics-ltd/hc-sr04.html">HC-SR04 ultrasonic sensor</a> for opening a solenoid door lock. Basically, the ultrasonic sensor acts as a proximity detector. A solenoid lock triggers when an object blocks the sensor at a given distance. In addition, a web app can act as WiFi remote control for the lock.</span></p>
<p><span id="more-5287"></span></p>
<h3 class="c0"><strong><span class="c4">Materials</span></strong></h3>
<ul>
<li class="c0 c3 li-bullet-0"><a href="https://www.utsource.net/home/sensors?source=teachmemicro"><span class="c1">HC-SR04 Ultrasonic Sensor</span></a></li>
<li class="c0 c3 li-bullet-0"><span class="c1"><a href="https://s.click.aliexpress.com/e/_AE0hQm">WeMos D1 Mini</a> or <a href="https://s.click.aliexpress.com/e/_A5ekfc">Arduino Pro Mini (5V, 16 MHz)</a></span></li>
<li class="c0 c3 li-bullet-0"><a href="https://s.click.aliexpress.com/e/_A7s4A2"><span class="c1">Solenoid Lock</span></a></li>
<li class="c0 c3 li-bullet-0"><a href="https://www.utsource.net/itm/p/11895265.html"><span class="c1">Relay Module</span></a></li>
<li class="c0 c3 li-bullet-0"><a href="https://www.utsource.net/itm/p/11218903.html"><span class="c1">2N7000 MOSFET</span></a></li>
<li class="c0 c3 li-bullet-0"><a href="https://s.click.aliexpress.com/e/_A189vU"><span class="c1">LM2596 DC-DC Converter</span></a></li>
<li class="c0 c3 li-bullet-0"><a href="https://www.utsource.net/itm/p/11531507.html"><span class="c1">3-6 V Buzzer</span></a></li>
<li class="c0 c3 li-bullet-0"><a href="https://www.utsource.net/itm/p/11530634.html"><span class="c1">9-12 V DC Power Supply</span></a></li>
</ul>
<h3 class="c0"><strong><span class="c4">Wiring Diagram</span></strong></h3>
<p><a href="https://www.teachmemicro.com/wp-content/uploads/2021/08/ultrasonic-door-lock.jpg"><img decoding="async" class="aligncenter size-large wp-image-5289" src="https://www.teachmemicro.com/wp-content/uploads/2021/08/ultrasonic-door-lock-1024x607.jpg" alt="ultrasonic door lock wiring diagram" width="618" height="366" srcset="https://www.teachmemicro.com/wp-content/uploads/2021/08/ultrasonic-door-lock-1024x607.jpg 1024w, https://www.teachmemicro.com/wp-content/uploads/2021/08/ultrasonic-door-lock-300x178.jpg 300w, https://www.teachmemicro.com/wp-content/uploads/2021/08/ultrasonic-door-lock-768x456.jpg 768w, https://www.teachmemicro.com/wp-content/uploads/2021/08/ultrasonic-door-lock.jpg 1352w" sizes="(max-width: 618px) 100vw, 618px" /></a></p>
<h3><strong>About the Project</strong></h3>
<p class="c0"><span class="c1">The <a href="https://www.teachmemicro.com/hc-sr04-arduino-interfacing/">HC-SR04</a> produces an ultrasonic signal which bounces back to it when there’s an object in front. The distance of the object from the sensor is known through the time difference between sending the signal (trigger) and receiving back the signal (echo) then multiplying by half of the speed of sound.</span></p>
<p><img decoding="async" class="aligncenter" src="https://lh5.googleusercontent.com/u0d12jwM9b3e1kDHWODi07vm5F4mpH10EcpUI6NuqUIp5XLEb2a8x_uPNCRFm3AcutthTyUFPIoyRbZ-N-Kq91HWgbdV0qSE4R-mstun44k2OhipOn8NKNQbeXmOsyZ1U-yurULJ" /></p>
<p id="oeUVzOm">In the equation above, 0.034 is the speed of sound in centimeters (CM).</p>
<p class="c0"><span class="c1">I set the trigger distance to 10 CM, i.e., the solenoid triggers every time an object is within 10 CM from the sensor. Solenoid locks require a high current to trigger and may produce <a href="https://learn.digilentinc.com/Documents/390">unwanted flyback</a>. Thus, the solenoid and the microcontroller must be isolated. </span></p>
<p class="c0"><span class="c1">A MOSFET is used to drive the solenoid which requires 9-12 VDC and 1 A of current. The higher voltage is converted to 5 VDC using the LM2596 DC-DC converter. The MOSFET is, in turn, driven by a relay module by shorting its gate to the 5 VDC source. The MOSFET and relay combination ensures that the microcontroller is properly isolated from the solenoid. A buzzer is added to indicate that the lock has been released.</span></p>
<h3><strong>WiFi App</strong></h3>
<p class="c0"><span class="c1">If a WeMos D1 Mini is used instead of the Arduino Pro Mini, the lock can be triggered remotely using WiFi. This is done through the MQTT protocol. I created a simple web app that sends a command to the MQTT broker when a button is pushed. The broker, in turn, publishes the command to a topic where the WeMos D1 Mini is listening to. Here’s a screenshot of the web app, viewed from a smartphone:</span></p>
<p><a href="https://www.teachmemicro.com/wp-content/uploads/2021/08/web_app_ss-scaled.jpg"><img loading="lazy" decoding="async" class="size-large wp-image-5291" src="https://www.teachmemicro.com/wp-content/uploads/2021/08/web_app_ss-562x1024.jpg" alt="solenoid wifi remote control app" width="562" height="1024" srcset="https://www.teachmemicro.com/wp-content/uploads/2021/08/web_app_ss-562x1024.jpg 562w, https://www.teachmemicro.com/wp-content/uploads/2021/08/web_app_ss-165x300.jpg 165w, https://www.teachmemicro.com/wp-content/uploads/2021/08/web_app_ss-768x1400.jpg 768w, https://www.teachmemicro.com/wp-content/uploads/2021/08/web_app_ss-843x1536.jpg 843w, https://www.teachmemicro.com/wp-content/uploads/2021/08/web_app_ss-1123x2048.jpg 1123w, https://www.teachmemicro.com/wp-content/uploads/2021/08/web_app_ss-scaled.jpg 1404w" sizes="auto, (max-width: 562px) 100vw, 562px" /></a></p>
<p class="c0">The Arduino sketch and code for the web app (remote trigger) are found in <span class="c7"><a class="c9" href="https://www.google.com/url?q=https://github.com/kurimawxx00/solenoid_door_lock_wifi&amp;sa=D&amp;source=editors&amp;ust=1628132123806000&amp;usg=AOvVaw2flpUz7BezjRy_cjtfwaCB">this repository</a></span><span class="c1">.</span></p>
<h3><strong>How to Get Parts</strong></h3>
<p class="c0"><span class="c1">For those living in the US or Europe who would like to clone this project, I strongly recommend getting the parts at <a href="https://www.utsource.net/category/elec-component/transistors-1.html?source=teachmemicro">UTSource</a>. They support almost all global payment options and shipping and they have refurbished parts that are very much cheaper compared to new ones. For example, their <a href="https://www.utsource.net/itm/p/8647184.html">refurbished original Arduino UNO</a> is:</span></p>
<p><img decoding="async" src="https://lh3.googleusercontent.com/DQcRbp6SFNzC6clIV1ujp16aSr0wvhWqTatjWapIEV8tb3QSugeYDs5SJoegsMo__Gk8Xaw5iayCueEvAmIj-fsfc2kNhtaWD5zudDZH2oUGSgsl4jsW1_cwN6tAC9Q6ZOUS_MjA" /></p>
<p class="c0"><span class="c1">In comparison, here’s the price for the board from other stores:</span></p>
<p class="c0"><img decoding="async" class="aligncenter" title="" src="https://lh4.googleusercontent.com/9kxC35utmo4Fq21ezJ4cpEicf7KFdebfRlSYGtw5DYqyqtipXAqmEE5OEeSwdrXxruYR9UVezf3niV3hZaVwzon9f8dr94qvTzOszmohlaMlajhx0F19CciQtmkob6mU4-xzP_9_" alt="" /></p>
<p class="c0"><img decoding="async" class="aligncenter" title="" src="https://lh4.googleusercontent.com/BhD7h9KFn1yoK60rOjl48TbtOLCtqJ8HvnZJDKtWRX17vfhyNHDY9HKV80WbhNujVuRf1Ld1Es7_Q7BfI9fu2p0I0ZRHuH3UNnKW9YXkwv16v98GHex0gZmew9XL3QIj0AnibDNJ" alt="" /></p>
<p class="c0"><img decoding="async" title="" src="https://lh4.googleusercontent.com/5tVPxWyj1iP38qP4Qf8RCO7ltkY5xiyVEha8ZGq0XscSo-ZoIp8lANmlaLStIZ5XeP6_1lxnqWDKeOYMjGxMMkO73O6lOAhd99CQNMaNHDaWwgR_QcRWJa2_6kXCo8eQBoGsHkfr" alt="" /></p>
<p>I've experienced using refurbished Arduino's before and I can say it still performs like a new one.</p>
<p>Kindly share this project with others if you find it to be useful. Thanks for reading!</p>
<p>The post <a href="https://www.teachmemicro.com/ultrasonic-door-lock-with-wifi-control/">Ultrasonic Door Lock with WiFi Control</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.teachmemicro.com/ultrasonic-door-lock-with-wifi-control/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WiFi Servo Controller using WeMos D1 Mini</title>
		<link>https://www.teachmemicro.com/wifi-servo-controller-using-wemos-d1-mini/</link>
					<comments>https://www.teachmemicro.com/wifi-servo-controller-using-wemos-d1-mini/#respond</comments>
		
		<dc:creator><![CDATA[Roland Pelayo]]></dc:creator>
		<pubDate>Tue, 02 Jun 2020 05:34:42 +0000</pubDate>
				<category><![CDATA[ESP8266 Projects]]></category>
		<category><![CDATA[ESP8266 Tutorial]]></category>
		<guid isPermaLink="false">https://www.teachmemicro.com/?p=4380</guid>

					<description><![CDATA[<p>In this article, I will guide you to the steps on how to build a WiFi servo controller project using the WeMos D1 Mini ESP8266 breakout board. Materials WeMos D1 Mini Tower Pro SG90 Micro Servo Connecting wires, power source The WeMos D1 Mini is one of the smallest breakout boards for the ESP8266. In &#8230;</p>
<p>The post <a href="https://www.teachmemicro.com/wifi-servo-controller-using-wemos-d1-mini/">WiFi Servo Controller using WeMos D1 Mini</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, I will guide you to the steps on how to build a WiFi servo controller project using the WeMos D1 Mini <a href="https://www.win-source.net/products/detail/espressif/esp8266ex.html">ESP8266</a> breakout board.</p>
<p><span id="more-4380"></span></p>
<h3><strong>Materials</strong></h3>
<ul>
<li>WeMos D1 Mini</li>
<li>Tower Pro SG90 Micro Servo</li>
<li>Connecting wires, power source</li>
</ul>
<p>The WeMos D1 Mini is one of the smallest breakout boards for the ESP8266. In this project, I will <a href="https://www.teachmemicro.com/getting-started-wemos-d1-mini/">write the code for the WeMos D1 using the Arduino IDE</a>.</p>
<p>All digital pins of the WeMos D1 Mini support PWM so there’s a lot of options in connecting the servo motor. I will presume that you already know <a href="https://www.teachmemicro.com/arduino-servo-motor-tutorial/">how a servo motor</a> works with a microcontroller.</p>
<p>The SG90 servo motor was chosen primarily because of its lower power consumption. I haven’t tried a larger servo motor but I presume using it, with the WeMos D1 on WiFi, will strain the device.</p>
<h3>Wiring Diagram</h3>
<p>The WeMos D1 Mini connects to the servo motor as shown:</p>
<p><a href="https://www.teachmemicro.com/wp-content/uploads/2020/06/wemos-servo-controller_bb.jpg"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-4381" src="https://www.teachmemicro.com/wp-content/uploads/2020/06/wemos-servo-controller_bb.jpg" alt="WeMos D1 Mini Servo Controller Wiring" width="834" height="420" srcset="https://www.teachmemicro.com/wp-content/uploads/2020/06/wemos-servo-controller_bb.jpg 834w, https://www.teachmemicro.com/wp-content/uploads/2020/06/wemos-servo-controller_bb-300x151.jpg 300w, https://www.teachmemicro.com/wp-content/uploads/2020/06/wemos-servo-controller_bb-768x387.jpg 768w" sizes="auto, (max-width: 834px) 100vw, 834px" /></a></p>
<p>As previously mentioned, all digital pins of the WeMos D1 Mini supports PWM. I chose D4 because it’s the closest one to the power pins.</p>
<h3><strong>WiFi Servo Controller App</strong></h3>
<p>Most WiFi servo controllers I see use buttons to move the servo motor arm between positions. For this project, I decided to use a rotating wheel to move the servo motor arm.</p>
<p><a href="https://www.teachmemicro.com/wp-content/uploads/2020/06/wemos-servo-controller-app.jpg"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-4383" src="https://www.teachmemicro.com/wp-content/uploads/2020/06/wemos-servo-controller-app.jpg" alt="wemos servo controller app" width="285" height="455" srcset="https://www.teachmemicro.com/wp-content/uploads/2020/06/wemos-servo-controller-app.jpg 285w, https://www.teachmemicro.com/wp-content/uploads/2020/06/wemos-servo-controller-app-188x300.jpg 188w" sizes="auto, (max-width: 285px) 100vw, 285px" /></a></p>
<p>To achieve this, I need to use <a href="https://jqueryui.com/">JQuery UI</a> to make the wheel rotatable and then <a href="https://api.jquery.com/jquery.ajax/">AJAX</a> to send the angle of the wheel to be read by the WeMos D1 server. JQuery UI is for desktop web applications so I also needed to <a href="https://www.jqueryscript.net/other/CSS3-Rotatable-jQuery-UI.html">add a plugin</a> for the app to work on touch devices. Finally, I also used <a href="https://www.w3schools.com/bootstrap/default.asp">bootstrap</a> to position the elements on the app.</p>
<p>All in all, these were the needed Javascript libraries:</p>
<pre class="lang:arduino decode:true"><code>&lt;script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'&gt;&lt;/script&gt;
&lt;script type='text/javascript' src='https://code.jquery.com/ui/1.11.4/jquery-ui.js'&gt;&lt;/script&gt;
&lt;script type='text/javascript' src='https://www.jqueryscript.net/demo/jQuery-UI-Rotatable-Elements/jquery.ui.rotatable.js'&gt;&lt;/script&gt;
&lt;script src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js'&gt;&lt;/script&gt;
&lt;script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js'&gt;&lt;/script&gt;</code></pre>
<p>These are all in the <em>&lt;head&gt;</em> tag of the app.</p>
<p>Here’s the HTML code for the <em>&lt;body&gt;</em> of the app:</p>
<div class="container">
<div class="row">
<div class="col-xs-12">
<pre class="lang:xhtml decode:true "><code>&lt;div class='container'&gt;
  &lt;h1&gt;WeMos D1 Servo Controller&lt;/h1&gt; "
  &lt;h4&gt;Rotate wheel to rotate servo&lt;/h4&gt;"
  &lt;a href='https://www.teachmemicro.com/wifi-servo-controller-using-wemos-d1-mini'&gt;Full tutorial&lt;/a&gt;"
  &lt;div class='row'&gt;
     &lt;div class='col-xs-12'&gt;
       &lt;div id='wheel'&gt;&lt;/div&gt;
     &lt;/div&gt;
     &lt;div class='col-xs-12'&gt;
        &lt;img id='tmm-logo' src='https://i.imgur.com/G80eVhL.png' /&gt;
      &lt;/div&gt;
   &lt;/div&gt;
&lt;/div&gt;</code></pre>
<p>The wheel is the background image of the ‘wheel’ <em>&lt;div&gt;</em>. It is tied to a JQuery script and is rotatable thanks to the <a href="https://github.com/godswearhats/jquery-ui-rotatable">Rotatable library</a>. Here’s the script:</p>
</div>
</div>
</div>
<div>
<pre class="lang:js decode:true"><code>$(document).ready(function(){
            $('#wheel').draggable({handle: '.ui-rotatable-handle'}).rotatable({
               rotate: function(e, ui){
               var degrees = ui.angle.current * 180/Math.PI;
               if ( degrees &gt; 90 ) {    
                  ui.angle.current = Math.PI/2;    
               } else if ( degrees &lt; -90) {        
                  ui.angle.current = -1*Math.PI/2;  
               }
               degrees = degrees + 90;
               console.log(degrees);
               var s = String(degrees);
            $.ajax({
               type: 'POST',
               url: 'dataHandler',
               data: s,
               contentType: 'application/x-www-form-urlencoded'
            });
           },snap: true   //for the wheel to snap at discrete angles
          });
});;</code></pre>
<p>Every time the wheel rotates, the angle in radians is returned. Degrees is easier to imagine so I converted it:</p>
<pre class="lang:js decode:true "><code>$('#wheel').draggable({handle: '.ui-rotatable-handle'}).rotatable({
               rotate: function(e, ui){
               var degrees = ui.angle.current * 180/Math.PI;
               ...</code></pre>
<p>Since servo motors rotate from 0 to 180 degrees, I also needed to limit the rotation of the wheel.</p>
<pre class="lang:js decode:true"><code>  if ( degrees &gt; 90 ) {    
      ui.angle.current = Math.PI/2;    
  } else if ( degrees &lt; -90) {        
      ui.angle.current = -1*Math.PI/2;  
  }
  ...</code></pre>
<p>Then I passed the angle to the server, converting it to 0 to 180 degrees to match that of the Arduino library.</p>
<pre class="lang:arduino decode:true"><code>    ...
    degrees = degrees + 90;
    console.log(degrees);    //for debugging on the browser
    var s = String(degrees);
    $.ajax({
         type: 'POST',
         url: 'dataHandler',
         data: s,
         contentType: 'application/x-www-form-urlencoded'
    });</code></pre>
<h3><strong>Arduino Code/Sketch</strong></h3>
<p>Besides the main Arduino sketch, the project includes the headers “mainpage.h” and “jscript.h”. Both header files contain <a href="https://www.arduino.cc/reference/en/language/variables/utilities/progmem/">PROGMEM</a> constants containing the HTML and Javascript for the app. I believe it’s easier to debug if they are separated from the main Arduino code.</p>
<p>As for the Arduino sketch, I used the same code snippets for establishing a WiFi server. The relevant parts are:</p>
<pre class="lang:arduino decode:true "><code>//Home page. Contents of 'page' is in mainpage.h
server.on("/", []() {
  server.send(200, "text/html", page);
});
//JavaScript! Contents of 'javascript' is in jscript.h
server.on("/jscript.js", []() {
  server.send(200, "text/javascript", javascript);
});
//POST data handler
server.on("/dataHandler",HTTP_POST,dataHandler);
//start web server
server.begin();
//Just stating things
Serial.println("HTTP server started");
}</code></pre>
<p>When a client visits the home page (the IP address of the WeMos D1), the client sees the contents of the ‘page’ constant which is the HTML of the app. The ‘page’ constant is inside ‘mainpage.h’.</p>
<p>In the HTML, a line calls <em>jscript.js</em>:</p>
<pre class="lang:arduino decode:true "><code>&lt;script type='text/javascript' src='jscript.js'&gt;&lt;/script&gt;</code></pre>
<p>Since <em>jscript.js</em> is a file inside the server, it must pass the client to the relevant file. This is done by passing the contents of the constant ‘javascript’ which is inside ‘jscript.h’</p>
<pre class="lang:arduino decode:true "><code>//JavaScript! Contents of 'javascript' is in jscript.h
server.on("/jscript.js", []() {
  server.send(200, "text/javascript", javascript);
});</code></pre>
<p>Finally, since the AJAX call inside the script was a POST request, the server must also handle it:</p>
<pre class="lang:arduino decode:true "><code>//POST data handler
server.on("/dataHandler",HTTP_POST,dataHandler);</code></pre>
<p><em>dataHandler</em> is a function for handling the data from the POST request:</p>
<pre class="lang:arduino decode:true "><code>void dataHandler(){
  String angle = server.arg("plain");
  Serial.print("Received: ");
  Serial.println(angle);
  server.sendHeader("Location","/");
  server.send(303);
  int pos = angle.toInt();
  myservo.write(pos);
  delay(15);
}</code></pre>
<p>The angle from the AJAX POST is read through:</p>
<pre class="lang:arduino decode:true "><code>String angle = server.arg("plain");</code></pre>
<p>For debugging, I printed the received angle to the serial monitor:</p>
<pre class="lang:arduino decode:true "><code>Serial.print("Received: ");
Serial.println(angle);</code></pre>
<p>According to protocol, servers must respond to the client after a POST request, thus:</p>
<pre class="lang:arduino decode:true "><code>server.sendHeader("Location","/");
server.send(303);</code></pre>
<p>This is simply sending back the client to the home page with status 303.</p>
<p>The received angle is a string, so it’s converted to int and then used to rotate the servo motor:</p>
<pre class="lang:arduino decode:true "><code>int pos = angle.toInt();
myservo.write(pos);
delay(15);</code></pre>
<p>The full code can be downloaded in <a href="https://github.com/kurimawxx00/wemos-d1-servo-controller">my repository</a>.</p>
<h3>Output Video</h3>
<p>Once the code is uploaded to the WeMos D1 Mini, the serial monitor will give its IP address. The app is viewable through that IP address using a web browser.</p>
<p><iframe loading="lazy" width="560" height="315" src="https://www.youtube.com/embed/SD_A8o55lZE" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="allowfullscreen"></iframe></p>
<p>Honestly, I was expecting an almost real-time reaction by the servo motor but it can’t be helped; the ESP8266 has processing limitations as a web server. Using a small delay between turns seems to overwhelm the ESP8266. I presume the ESP32 will have a much better reaction time.</p>
<p>Edit: Surprisingly, using the app on a desktop computer results in a much faster reaction time. So maybe the phone is having trouble connecting through WiFi.</p>
<p>Nevertheless, I hope someone found this WiFi servo controller project useful. For questions, or suggestions, kindly drop a comment below.</p>
</div>
<p>The post <a href="https://www.teachmemicro.com/wifi-servo-controller-using-wemos-d1-mini/">WiFi Servo Controller using WeMos D1 Mini</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.teachmemicro.com/wifi-servo-controller-using-wemos-d1-mini/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Flame Sensor Project: Comprehensive Guide</title>
		<link>https://www.teachmemicro.com/flame-sensor-project-comprehensive-guide/</link>
					<comments>https://www.teachmemicro.com/flame-sensor-project-comprehensive-guide/#respond</comments>
		
		<dc:creator><![CDATA[Roland Pelayo]]></dc:creator>
		<pubDate>Thu, 23 Jan 2020 03:22:51 +0000</pubDate>
				<category><![CDATA[Arduino Projects]]></category>
		<category><![CDATA[ESP8266 Projects]]></category>
		<category><![CDATA[PIC Projects]]></category>
		<category><![CDATA[Sensor Tutorial]]></category>
		<category><![CDATA[fire detector]]></category>
		<category><![CDATA[fire sensor]]></category>
		<category><![CDATA[flame sensor for furnace]]></category>
		<category><![CDATA[iot]]></category>
		<category><![CDATA[push notification]]></category>
		<category><![CDATA[pushbullet]]></category>
		<category><![CDATA[pushingbox]]></category>
		<category><![CDATA[sensor]]></category>
		<guid isPermaLink="false">https://www.teachmemicro.com/?p=4081</guid>

					<description><![CDATA[<p>Flame sensors are found from the simplest gas stoves to huge industrial plants. There are different types of fire sensors -- some cheap, some expensive. Yet they’re all built for one single purpose: detect fire. In this article, I will guide you on how to build a flame sensor with a few extra bucks and &#8230;</p>
<p>The post <a href="https://www.teachmemicro.com/flame-sensor-project-comprehensive-guide/">Flame Sensor Project: Comprehensive Guide</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span style="font-weight: 400;">Flame sensors are found from the simplest gas stoves to huge industrial plants. There are different types of fire sensors -- some cheap, some expensive. Yet they’re all built for one single purpose: detect fire. In this article, I will guide you on how to build a flame sensor with a few extra bucks and some microcontroller programming knowledge.</span></p>
<p><span id="more-4081"></span></p>
<h3><b>What You’ll Need</b></h3>
<ul>
<li style="font-weight: 400;"><a href="http://s.click.aliexpress.com/e/_shLsn8"><span style="font-weight: 400;">Flame sensor module</span></a></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Microcontroller (<a href="http://s.click.aliexpress.com/e/_swUr9G">Arduino</a> or <a href="http://s.click.aliexpress.com/e/_sjwNOI">NodeMCU ESP8266</a> or <a href="http://s.click.aliexpress.com/e/_rwLdlk">PIC</a>)</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Power source</span></li>
<li style="font-weight: 400;"><span style="font-weight: 400;">Output device (<a href="http://s.click.aliexpress.com/e/_sJNkJ4">buzzer</a> or smartphone)</span></li>
</ul>
<h3><b>Flame Sensor Module</b></h3>
<p><span style="font-weight: 400;">The star of this project is this flame sensor module:</span></p>
<p><img loading="lazy" decoding="async" class="aligncenter" src="https://lh3.googleusercontent.com/UXqpd7DvjX9XaJgMK5vgvEzS2Xl67oAI2kZ_0juCLcn3UGK7t9laSC6FsKtlTnfCJDP7ATFQFZM8cossm01jBggvcdgcXg0uu7Zv0Y98Zdlnvg6hRWrgQNFQ6L2ZE8B58Y8OjPI8" alt="flame sensor module" width="401" height="401" /></p>
<p id="ureLAlb">This module contains a <a href="https://www.win-source.net/category/sensors-transducers/optical-sensors/optical-sensors-phototransistors">phototransistor</a> and <a href="https://en.wikipedia.org/wiki/Signal_conditioning"><i>signal conditioning</i></a> electronics. A phototransistor conducts more electrical current when exposed to light. Physics taught us that (visible) light comprises of all colors, from red to violet. By coating the phototransistor with black epoxy, it becomes more sensitive to red or even invisible <i>below red</i> or <a href="https://www.merriam-webster.com/dictionary/infra">infra</a>red. Interestingly, flame emits infrared radiation. Thus, when this sensor <i>sees</i> flame, it conducts more current.</p>
<p><a href="https://www.teachmemicro.com/wp-content/uploads/2020/01/flame-sensor-range.jpg"><img loading="lazy" decoding="async" class="aligncenter wp-image-4101 size-large" src="https://www.teachmemicro.com/wp-content/uploads/2020/01/flame-sensor-range-1024x486.jpg" alt="flame sensor range" width="640" height="304" srcset="https://www.teachmemicro.com/wp-content/uploads/2020/01/flame-sensor-range-1024x486.jpg 1024w, https://www.teachmemicro.com/wp-content/uploads/2020/01/flame-sensor-range-300x142.jpg 300w, https://www.teachmemicro.com/wp-content/uploads/2020/01/flame-sensor-range-768x365.jpg 768w, https://www.teachmemicro.com/wp-content/uploads/2020/01/flame-sensor-range.jpg 1089w" sizes="auto, (max-width: 640px) 100vw, 640px" /></a></p>
<p><span style="font-weight: 400;">Microcontrollers read voltage, not current. Thus, the signal conditioning circuit in the module converts the current into levels of voltage that is considered safe for the microcontroller (typically, the maximum voltage should be the supply voltage to the microcontroller).</span></p>
<p><span style="font-weight: 400;">The flame sensor module also contains indicator LEDs. One LED lights up (PWR-LED) when the module is powered up while another lights up (D0-LED) when the sensor detects fire.</span></p>
<p><span style="font-weight: 400;">Moreover, the voltage from the D0 pin falls to zero in the vicinity of fire and rises to the supply voltage when there is none. We use this as a trigger for the microcontroller.</span></p>
<h3><b>Arduino - Flame Sensor Interface</b></h3>
<p><span style="font-weight: 400;">I aim to use three different kinds of microcontroller for this project. First, I’ll show how to build an Arduino flame sensor with a buzzer as indicator.</span></p>
<p><span style="font-weight: 400;">Since the module only provides two values, on and off, we don’t need to use any of the </span><i><span style="font-weight: 400;">analog</span></i><span style="font-weight: 400;"> pins of the Arduino. The wiring diagram below shows that the D0 pin of the module connects to the digital pin 2 of the <a href="https://www.teachmemicro.com/arduino-uno-pinout-diagram/">Arduino UNO</a>:</span></p>
<p><img loading="lazy" decoding="async" class="aligncenter" src="https://lh6.googleusercontent.com/PranlMnwtShfCJ8lP3_YPz9tnJPyhji4pLBnISEus-tZ_0V_Hy3aY6vkLm9fjXCaEVDj8vCSHQ37fpplFfSMCBZPTthgpA34qsKnvCvS3ssqPHwZSWAe0iTB9eUBHm0drPoA82Px" alt="arduino flame sensor" width="1600" height="810" /></p>
<p id="qxiAFCd">Moreover, the VCC or + pin connects to 5V and the G pin is connected to GND. Note that the fire detector module can also run on 3.3V. Finally, the buzzer’s red wire is connected to pin 5 while its black pin is wired to GND. In this project, I am using a buzzer that can run from voltages 3 to 24 V.</p>
<p><span style="font-weight: 400;">The sketch is straightforward:</span></p>
<pre class="lang:arduino decode:true "><code>const int sensor_pin = 2;
const int buzzer = 5;

void setup() {
  pinMode(sensor_pin,INPUT_PULLUP);
  pinMode(buzzer,OUTPUT);
}

void loop() {
  if(digitalRead(sensor_pin) == LOW){
    digitalWrite(buzzer,HIGH);
  }else{
    digitalWrite(buzzer,LOW);
  }
}</code></pre>
<p><span style="font-weight: 400;">I gave pins 2 and 5 appropriate aliases:</span></p>
<pre class="lang:arduino decode:true"><code>const int sensor_pin = 2;
const int buzzer = 5;</code></pre>
<p><span style="font-weight: 400;">Inside <em>setup()</em>, we declare sensor_pin as an input pin while buzzer is an output pin:</span></p>
<pre class="lang:arduino decode:true "><code>pinMode(sensor_pin,INPUT_PULLUP);
pinMode(buzzer,OUTPUT);</code></pre>
<p>In <em>loop()</em>, we check if the sensor_pin voltage is zero. If it is, we sound the buzzer. If not, then turn off the buzzer.</p>
<pre class="lang:arduino decode:true"><code>void loop() {
  if(digitalRead(sensor_pin) == LOW){
    digitalWrite(buzzer,HIGH);
  }else{
    digitalWrite(buzzer,LOW);
  }
}</code></pre>
<p><span style="font-weight: 400;">The fire sensor can detect flame within its 60 degree capture angle. The distance of the flame varies with ambient light. In my tests, the sensor was able to detect a match’s flame from around 5 cm.</span></p>
<h3><b>Using the Flame Sensor with PIC16F877A</b></h3>
<p><span style="font-weight: 400;">The difference here is that we are using a different microcontroller and thus, a different compiler. Nevertheless, the concept is the same: the <a href="https://www.teachmemicro.com/pic16f877a-more-microcontroller-features/">PIC16F877A</a> reads the D0 pin and if its low, fire up the buzzer and so on.</span></p>
<p><span style="font-weight: 400;">Here’s the wiring diagram:</span></p>
<p><img loading="lazy" decoding="async" class="alignnone" src="https://lh4.googleusercontent.com/dUHgVWYPYGKTBkkIi98OV0o0ohNzCquUNk7_t-gBAgCKJnwVBsFRA1-RQi_3v4Ow7o5SrNTauA4MCofZkgznBr7v6YK6oa85DZ1fmmQC3dUe1EENyWSN8JwlgUMkJ4shVRYXh4ql" alt="PIC flame sensor" width="1600" height="843" /></p>
<p id="SpHuJQC">The D0 pin of the fire detector module connects to RB0 while the buzzer’s red wire is connected to RB1.</p>
<p><span style="font-weight: 400;">The C code (XC8) for the circuit above is shown below:</span></p>
<pre class="lang:arduino decode:true "><code>#define _XTAL_FREQ 4000000
#include &lt;xc.h&gt;

void main(void) {
    
    TRISBbits.TRISB0 = 1;
    TRISBbits.TRISB1 = 0;
    while(1){
        if(PORTBbits.RB0 == 0){
            PORTBbits.RB1 = 1;
        }else{
            PORTBbits.RB1 = 0;
        }
    }
    return;
}</code></pre>
<p>The pin RB0 is an input pin while RB1 is an output pin. Hence their corresponding TRIS bits should be:</p>
<pre class="lang:arduino decode:true "><code>TRISBbits.TRISB0 = 1; 
TRISBbits.TRISB1 = 0;</code></pre>
<p>We then use simple if-else statements to check if the sensor detects a fire and then turn on or off the buzzer:</p>
<pre class="lang:arduino decode:true "><code>while(1){
 if(PORTBbits.RB0 == 0){
    PORTBbits.RB1 = 1; 
 }else{ PORTBbits.RB1 = 0; 
 } 
}</code></pre>
<p>There's no <em>loop()</em> function in XC8 so we create our own infinite loop using the <em>while(1)</em> statement.</p>
<p>That's it for interfacing the flame detector with a PIC microcontroller.</p>
<h3><b>Flame Sensor and ESP8266</b></h3>
<p><span style="font-weight: 400;">Finally we are down to our last microcontroller, the <a href="https://www.teachmemicro.com/category/tutorials/esp8266-tutorial/">ESP8266</a>. Of course, we will be using the flame sensor with the ESP8266 according to the latter’s capabilities. In this version, the user will receive a push notification on his or her smartphone everytime the fire detector is triggered.</span></p>
<p><span style="font-weight: 400;">Here’s the wiring diagram:</span></p>
<p><img loading="lazy" decoding="async" class="aligncenter" src="https://lh6.googleusercontent.com/jPuaGEAok0DvjF24L3ULtL-xCwLtbK6yiYEPgqj7w-BtBtZTVdHNKBFwePp68rLr-ScEfE1tPyygRPoDe5Odc5_ZnkM3hdkdtufbeq2wCUl-6FPlcdaEfoMaAng9-CwgWTGc-EA1" alt="nodemcu esp8266 flame sensor" width="951" height="780" /></p>
<p id="XsNDRWV">This diagram is the simplest since we don’t need the buzzer anymore. Note that I am using a <a href="https://www.teachmemicro.com/nodemcu-pinout/">NodeMCU ESP8266</a> board for this project. If this is your first time using the NodeMCU, please follow the <a href="https://www.teachmemicro.com/intro-nodemcu-arduino/">instructions to program it using the Arduino IDE</a>.</p>
<p><span style="font-weight: 400;">Here is the full sketch:</span></p>
<pre class="lang:arduino decode:true "><code>/*
 *  This sketch sends push notifications via Pushbullet App through PushingBox.
 *
 *  You need to create a service and scenario at pushingbox.com to acquire
 *  a device ID. Also change lines 12 and 13 to your own WiFi SSID and password
 *
 */
#include &lt;ESP8266WiFi.h&gt;
#include &lt;WiFiClient.h&gt;
#include &lt;ESP8266WebServer.h&gt;

const char* ssid     = "&lt;your WiFi SSID&gt;";
const char* password = "&lt;your WiFi password&gt;";

const char* host = "api.pushingbox.com";
const char* devid = "vADAB279A6A4DA5A";

const int sensor_pin = 14;

void setup()
{
    pinMode(sensor_pin,INPUT_PULLUP);
    pinMode(buzzer,OUTPUT);
    
    Serial.begin(115200);
    delay(10);

    // We start by connecting to a WiFi network

    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
}

int value = 0;

void loop()
{
    delay(5000);

    if(digitalRead(sensor_pin) == LOW){  //flame sensor triggered

    Serial.print("connecting to ");
    Serial.println(host);

    // Use WiFiClient class to create TCP connections
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
        Serial.println("connection failed");
        return;
    }

    // We now create a URI for the request
    String url = "/pushingbox";
    url += "?devid=";
    url += devid;
    
    Serial.print("Requesting URL: ");
    Serial.println(url);

    // This will send the request to the server
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" +
                 "Connection: close\r\n\r\n");
    unsigned long timeout = millis();
    while (client.available() == 0) {
        if (millis() - timeout &gt; 5000) {
            Serial.println("&gt;&gt;&gt; Client Timeout !");
            client.stop();
            return;
        }
    }

    // Read all the lines of the reply from server and print them to Serial
    while(client.available()) {
        String line = client.readStringUntil('\r');
        Serial.print(line);
    }

    Serial.println();
    Serial.println("closing connection");
    }else{;}
}</code></pre>
<p><span style="font-weight: 400;">Before uploading this sketch, w</span><span style="font-weight: 400;">e need to configure <strong>Pushingbox</strong> and <strong>Pushbullet</strong> for this project to work. </span></p>
<p><span style="font-weight: 400;">First, go to <a href="http://pushingbox.com">Pushingbox</a> and signup or login to your account. You will then be redirected to the Dashboard page:</span></p>
<p><img decoding="async" class="aligncenter" src="https://lh3.googleusercontent.com/onidtVcEdB_-AD1N1hmd_U--Ugx_GuzftOOyi5w8TTPTqRhUsjVMeRMR6p6JqMimVi-vBtUCL99LkUj_blpx_Gt288EM4MFhF8tVVGvD5QDWhh2Yy0x1mbwSW7YEiX6X6BwbQBPT" /></p>
<p id="rwLevPd">Click the My Services tab and click “Add a service”:</p>
<p><img decoding="async" class="aligncenter" src="https://lh6.googleusercontent.com/7MLzXVKaxj_6xpC78ViRap8_tLodfaUrre6CDgHloPfnRW7EAc8TD2ll4DroYBgl2woBst32iE3uLW6O4W-DiVSCpasPornGV2nGZcF6J_mRErikaVSpIPdp_yre0Diq3sd2xlQ_" /></p>
<p id="WxAnCWK">Next, look for the <strong>Pushbullet</strong> service:</p>
<p><img decoding="async" class="aligncenter" src="https://lh4.googleusercontent.com/e8wWY2MwPV0Z6qqTO94GiIrpeiqaLFLR6i2fonsrNSWcGUEG8TP88ogMw3UXHsepGfd25LoU3Y2ROQGxa3ij6afPtaXdWGuhtrWf4qYVAFy88nmIth50tDN6wEzuzx1PaNeuFpdr" /></p>
<p id="RNORYDo">However, before your press the “Select this service” button, you need to have a Pushbullet account first.</p>
<p><span style="font-weight: 400;">Go to <a href="http://pushbullet.com">Pushbullet</a>:</span></p>
<p><img decoding="async" class="aligncenter" src="https://lh5.googleusercontent.com/B-9xPNHGioDovDHk7N0KuQiLvKsliBGQKHR9YeJErvbV8jZfQT1dmDbVAaTyyS2OhdwS3Mzs5Z4S9LVKkqZNY1Rp04Ih6sVb0qh-48QGJu37MaD6olFSVW674hWg7QZOOEFGO7oS" /></p>
<p id="phKrJrS">Sign up or login to your account. After that, find <i>Settings</i> on the dashboard. There you’ll find your access token:</p>
<p><img decoding="async" class="aligncenter" src="https://lh5.googleusercontent.com/9X0Yh57X6kKZTlxaA4vNpklb_VMOT9zzSohc8NYgA8y39g9zlo9in-szfwCD0b8SITQlbLAlq7jnQGn6AwTF2GIkL2EuZxjvYYfzDGhYj0DRTObwRr1UPxCtkatamWtlFxGNyono" /></p>
<p id="fPFfvEA">Go back to Pushingbox, click add a service again and this time click the “Select this service” button for pushbullet. A window appears:</p>
<p><img decoding="async" class="aligncenter" src="https://lh4.googleusercontent.com/uvIReILZSWdPHVwQvxeOUIQcJdArIZvx4IMd3VLN0HYhesHwkFISfT_kvY7N4nr5GiWaczJ1uoZmoaSYE6O1z_xx37T1_JJV6mIyl9wBlOoMy7Wvfisp5T5EDx6Nv4JYp3X7EVYG" /></p>
<p id="oQUGmGo">Give the configuration a name, paste your Pushbullet token then click submit.</p>
<p><span style="font-weight: 400;">Next, click the My Scenarios tab to add a scenario linked to the service just created:</span></p>
<p><img decoding="async" class="aligncenter" src="https://lh5.googleusercontent.com/s2ggarqvw_j8pYkbsUILpx8OwN4K79FVGl4103dIym8VyTRM-n4uQujiiDbIGxnTTnINR2qycaWjDsuKK7WqFgD_nnxZ8vtPfjINg18MPTJD--iUfR4uMUSOyWEyYghq-CbDjhAZ" /></p>
<p id="uUFvHoo">After creating the scenario, add an action:</p>
<p><img decoding="async" class="aligncenter" src="https://lh6.googleusercontent.com/LtbubUNpaf77sVNZwprFZZu1h772RvoPnsVmjWCFoHCwvCGe_QBUOKW14faxf_dFXKXKoZ_Tx-IuTegm67b9H5a0QXoMgquGU1x0ogRXWZEP6TQuYbOw2Bovxzzsow5srodB2aUw" /></p>
<p id="SqmKfkc">Make sure you select the appropriate scenario:</p>
<p><img decoding="async" class="aligncenter" src="https://lh3.googleusercontent.com/ZMtFdP_6dKMRC6ruvdydLsJjRrRRtxSam_LtvyQcoSoHrgOrDZGCTqCcRgsDSfbqbsTDaea_5ArY3gXzuYVxgBselD9w9DjguWlm9at2bS5ThenE5DhwyB8ufwYROm83hU1XXhZA" /></p>
<p id="BUFdKUn">A window appears; give the action title, push notification message and then click submit.</p>
<p><img decoding="async" class="aligncenter" src="https://lh4.googleusercontent.com/7YccBkESlKjf06DxCvKe_S4v0I_DmhCk8cO48EhPtYrC4igr5ko_39D76FE1iTBOZHXA5kFkzOPMNEt8zwqI_RzkSZaCG-x3Oz2tWm5fCS3bgB2QVV2wLgl1nDE_7Y229s0lY9Ci" /></p>
<p id="ICjEFEN">Finally, copy the d<em>evice ID</em> whose location is shown:</p>
<p><img decoding="async" class="aligncenter" src="https://lh5.googleusercontent.com/tScPkXAptG6vu4v3K3ezYKz_yn-gzTtaDO7AksWWUoISwe1xlsl_8F3aZGzyz8EsmJciGmsKTehxKaEzhmtw_zJUZzOsM8HWRG4HKtlYfG9mDSgZoNmLs0uWOhTF_KG6k6xnt5OD" /></p>
<p id="XcDpIRZ">Now on the sketch, locate line 16 and change the device ID:</p>
<pre class="lang:arduino decode:true"><code>const char* devid = "vADAB279A6A4DA5A";</code></pre>
<p><span style="font-weight: 400;">Also, don’t forget to provide your own WiFi’s SSID and password on lines 12 and 13:</span></p>
<pre class="lang:arduino decode:true"><code>const char* ssid     = "&lt;your WiFi SSID&gt;";
const char* password = "&lt;your WiFi password&gt;";</code></pre>
<p><span style="font-weight: 400;">Upload the sketch and you're good to go! Now, install the Pushbullet app on your smartphone and login to your account. Everytime the fire detector is triggered, you will receive a push notification!</span></p>
<h3><b>Conclusion</b></h3>
<p>The flame sensor project here is limited in capture angle and range. However, there's a special module that contains five phototransistors:</p>
<p><a href="https://www.teachmemicro.com/wp-content/uploads/2020/01/multi-flame-sensor.jpg"><img loading="lazy" decoding="async" class="aligncenter wp-image-4104" src="https://www.teachmemicro.com/wp-content/uploads/2020/01/multi-flame-sensor.jpg" alt="wide angle flame sensor" width="562" height="442" srcset="https://www.teachmemicro.com/wp-content/uploads/2020/01/multi-flame-sensor.jpg 905w, https://www.teachmemicro.com/wp-content/uploads/2020/01/multi-flame-sensor-300x236.jpg 300w, https://www.teachmemicro.com/wp-content/uploads/2020/01/multi-flame-sensor-768x603.jpg 768w" sizes="auto, (max-width: 562px) 100vw, 562px" /></a>This 5-way fire detector module has a capture angle of 120°. <a href="http://s.click.aliexpress.com/e/_sKoiI2">Check prices here</a>.</p>
<p id="kaAcODv">Hopefully, this article helps you in any way. For any questions, reactions or suggestions, kindly drop comments below.</p>
<p>The post <a href="https://www.teachmemicro.com/flame-sensor-project-comprehensive-guide/">Flame Sensor Project: Comprehensive Guide</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.teachmemicro.com/flame-sensor-project-comprehensive-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>NodeMCU IoT Weather Device</title>
		<link>https://www.teachmemicro.com/nodemcu-iot-weather-device/</link>
					<comments>https://www.teachmemicro.com/nodemcu-iot-weather-device/#respond</comments>
		
		<dc:creator><![CDATA[Roland Pelayo]]></dc:creator>
		<pubDate>Tue, 12 Feb 2019 02:31:24 +0000</pubDate>
				<category><![CDATA[ESP8266 Projects]]></category>
		<guid isPermaLink="false">https://www.teachmemicro.com/?p=2907</guid>

					<description><![CDATA[<p>This project demonstrates how to read data from the DHT22 temperature and humidity sensor and send that data to the web using an ESP8266 via MQTT. Setting Up As already mentioned, this project uses the DHT22 and a NodeMCU ESP8266 board. The hardware connections are straightforward: DHT22 NodeMCU Dout GPIO4 (D2) VCC 3.3V GND GND &#8230;</p>
<p>The post <a href="https://www.teachmemicro.com/nodemcu-iot-weather-device/">NodeMCU IoT Weather Device</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This project demonstrates how to read data from the DHT22 temperature and humidity sensor and send that data to the web using an <a href="https://www.win-source.net/products/detail/espressif/esp8266ex.html">ESP8266</a> via MQTT.</p>
<p><span id="more-2907"></span></p>
<h3><strong>Setting Up</strong></h3>
<p>As already mentioned, this project uses the DHT22 and a NodeMCU ESP8266 board. The hardware connections are straightforward:</p>
<table>
<tbody>
<tr>
<th>DHT22</th>
<th>NodeMCU</th>
</tr>
<tr>
<td>Dout</td>
<td>GPIO4 (D2)</td>
</tr>
<tr>
<td>VCC</td>
<td>3.3V</td>
</tr>
<tr>
<td>GND</td>
<td>GND</td>
</tr>
</tbody>
</table>
<p>Here is a photo of my actual setup:</p>
<p><a href="https://www.teachmemicro.com/wp-content/uploads/2019/02/nodemcu-weather-monitor-top.jpg"><img loading="lazy" decoding="async" class="size-large wp-image-2908 aligncenter" src="https://www.teachmemicro.com/wp-content/uploads/2019/02/nodemcu-weather-monitor-top-1024x397.jpg" alt="NodeMCU Weather Device " width="618" height="240" srcset="https://www.teachmemicro.com/wp-content/uploads/2019/02/nodemcu-weather-monitor-top-1024x397.jpg 1024w, https://www.teachmemicro.com/wp-content/uploads/2019/02/nodemcu-weather-monitor-top-300x116.jpg 300w, https://www.teachmemicro.com/wp-content/uploads/2019/02/nodemcu-weather-monitor-top-768x298.jpg 768w" sizes="auto, (max-width: 618px) 100vw, 618px" /></a></p>
<p>As for the firmware, I used the following libraries for the sketch:</p>
<ul>
<li><a href="https://github.com/winlinvip/SimpleDHT">SimpleDHT library by winlinvip </a></li>
<li><a href="https://github.com/256dpi/arduino-mqtt">MQTT library by 256dpi</a></li>
<li><a href="https://github.com/esp8266/Arduino">ESP8266 Arduino Core</a> (see Intro to NodeMCU for details)</li>
</ul>
<p>Basically, all I did was read temperature and humidity data from the DHT22 and publish that data to shiftr’s MQTT broker service. You can use shiftr’s <a href="https://shiftr.io/try">Try channel</a> if you’re short on time but I recommend creating your own account. With that, you can create your own namespace and you will be provided with a Key and Password as shown:</p>
<p><img decoding="async" title="" src="https://lh5.googleusercontent.com/6t9Mj4IADGlrQ-F606PCjXDl4Xa6JAkriW-Zk5z4wZDJTPxlg16bFshFXHExDRbmDGF2gqWPdRWoVhDK9CFWlR5pVdX6_jeGrB3M206eKZ4mrBkzmip8Ln6GW9SuSbC7fcA81MkH" alt="" /></p>
<p>Here, my Key is feceaf58 and my password is 5d0a52d449f797ca.</p>
<h3><strong>Sketch</strong></h3>
<p>Next, I modified the AdafruitHuzzahESP8266 example sketch that came with the MQTT library. I added a few lines for reading the data from the DHT22 and also inserted my own Key and password from above. Here is the full sketch:</p>
<pre class="lang:arduino decode:true"><code>#include &lt;ESP8266WiFi.h&gt;
#include &lt;MQTT.h&gt;
#include &lt;SimpleDHT.h&gt;

const char ssid[] = "&lt;Your-WiFi-SSID&gt;";
const char pass[] = "&lt;Your-WiFi-Password&gt;";
const char mqttkey[] = "&lt;Your-MQTT-Key&gt;";
const char mqttpw[] = "&lt;Your-MQTT-Password&gt;";

WiFiClient net;
MQTTClient client;

int pinDHT22 = 4;
SimpleDHT22 dht22(pinDHT22);
float temperature = 0;
float humidity = 0;
  

unsigned long lastMillis = 0;

void connect() {
  Serial.print("checking wifi...");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println("WiFi Connected!");
  Serial.print("IP address: ");
  Serial.println(net.localIP());
  delay(2000);
  Serial.println("connecting to MQTT broker...");
  while (!client.connect("DHT22-NodeMCU", mqttkey, mqttpw)) {
    Serial.print(".");
    delay(1000);
  }

  Serial.println("\nconnected!");

  client.subscribe("/DHT22");
  // client.unsubscribe("/hello");
}

void messageReceived(String &amp;topic, String &amp;payload) {
  Serial.println("incoming: " + topic + " - " + payload);
}

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, pass);

  // Note: Local domain names (e.g. "Computer.local" on OSX) are not supported by Arduino.
  // You need to set the IP address directly.
  client.begin("broker.shiftr.io",net);
  client.onMessage(messageReceived);

  connect();
}

void loop() {
  client.loop();
  delay(10);  // &lt;- fixes some issues with WiFi stability
  int err = SimpleDHTErrSuccess;
  if ((err = dht22.read2(&amp;temperature, &amp;humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
    return;
  }

  Serial.print((float)temperature); Serial.print(" *C, ");
  Serial.print((float)humidity); Serial.println(" RH%");
  delay(2000);
  if (!client.connected()) {
    connect();
  }

  // publish a message roughly every second.
  if (millis() - lastMillis &gt; 1000) {
    lastMillis = millis();
    client.publish("DHT22-NodeMCU/temperature", (String)temperature);
    client.publish("DHT22-NodeMCU/humidity", (String)humidity);
  }
}</code></pre>
<p>Don’t forget to insert your own credentials on the sketch above!</p>
<p>If the sketch is uploaded successfully to the NodeMCU, the Shiftr channel should now show the sent temperature and humidity data:</p>
<p><img decoding="async" title="" src="https://lh6.googleusercontent.com/rS_fmFZV7XsjQtuV5z1FkGIYk0A-9fUW2YiInCnLq2miIVibgmQv8AJh6QvYN7aKaC_ppx4U-Bqh6s5cimCOyS3mP3LqnqJPzvh8V9KFcYAxt3wuVdnXUNGZql_r-mQ2gxJuAbzB" alt="" /></p>
<h3><strong>Embedding Data to Web Page</strong></h3>
<p>I’m not done yet! I want to embed the temperature and humidity data to my own web page and add a graph with the values vs. time.</p>
<p>Shiftr provides an example Javascript code for embedding MQTT data. What I did is modify that code so that it displays two messages from two topics:</p>
<pre class="lang:default decode:true"><code>$(function(){
  var client = mqtt.connect('mqtt://feceaf58:5d0a52d449f79c7a@broker.shiftr.io', {
    clientId: 'browser-client'
  });
    
  var temperature;
  var humidity;
 
 
  client.on('connect', function(){
    console.log('client has connected!');
  });
 
  client.subscribe('DHT22-NodeMCU/temperature');
  client.subscribe('DHT22-NodeMCU/humidity');

  client.on('message', function(topic, message) {
      if(topic === 'DHT22-NodeMCU/temperature'){
        temperature = message;
      }else if(topic === 'DHT22-NodeMCU/humidity'){
        humidity = message;
      }else{;}
   if(temperature &amp;&amp; humidity){
    $('#temperature').text(temperature.toString());
    $('#humidity').text(humidity.toString());
    temperature =  undefined;
    humidity = undefined;
   }

   
  });

})
</code></pre>
<p>Then I used Dygraph for plotting the data against time. This library requires a Dygraph object with given properties.</p>
<pre class="lang:default decode:true"><code>var g = new Dygraph(document.getElementById("div_g"), data,
            {
                drawPoints: true,
                showRoller: true,
                valueRange: [0.0, 100, 100],
                labels: ['Time', 'Temperature', 'Humidity']
            });
  
</code></pre>
<p>Here, I created <em>div_g</em> HTML div element where the graph is located.</p>
<p>Here’s my full Javascript code:</p>
<pre class="lang:js decode:true"><code>$(function(){
  var client = mqtt.connect('mqtt://feceaf58:5d0a52d449f79c7a@broker.shiftr.io', {
    clientId: 'browser-client'
  });
    
  var temperature;
  var humidity;
 
  var data = [];
  var y;
  var z;
   
  var g = new Dygraph(document.getElementById("div_g"), data,
            {
                drawPoints: true,
                showRoller: true,
                valueRange: [0.0, 100, 100],
                labels: ['Time', 'Temperature', 'Humidity']
            });
   
  client.on('connect', function(){
    console.log('client has connected!');
  });
 
  client.subscribe('DHT22-NodeMCU/temperature');
  client.subscribe('DHT22-NodeMCU/humidity');

  client.on('message', function(topic, message) {
      if(topic === 'DHT22-NodeMCU/temperature'){
        temperature = message;
      }else if(topic === 'DHT22-NodeMCU/humidity'){
        humidity = message;
      }else{;}
   if(temperature &amp;&amp; humidity){
    $('#temperature').text(temperature.toString());
    $('#humidity').text(humidity.toString());
    y = temperature.toString();
    z = humidity.toString();
    temperature =  undefined;
    humidity = undefined;
   }

    var x = new Date();  // current time
     console.log(y);
    console.log(z);
    data.push([x, y, z]);
    g.updateOptions( { 'file': data } );
 
  });

})
</code></pre>
<p>I saved this Javascript code as mqtt.js.</p>
<p>And here’s the HTML as well:</p>
<pre class="lang:xhtml decode:true"><code>&lt;html&gt;
 &lt;title&gt;NodeMCU Weather Monitor&lt;/title&gt;
&lt;head&gt;
    &lt;script src="https://code.jquery.com/jquery-2.2.3.min.js"&gt;&lt;/script&gt;
    &lt;script src="https://assets.shiftr.io/js/mqtt-2.9.0.js"&gt;&lt;/script&gt;
      &lt;script src="https://dygraphs.com/dist/dygraph.js"&gt;&lt;/script&gt;
    &lt;script src="mqtt.js" charset="utf-8"&gt;&lt;/script&gt;
    
&lt;/head&gt;
  &lt;body&gt;
    &lt;div id="temp"&gt;&lt;p&gt;&lt;h3&gt;Temperature (&amp;#176;C): &lt;/h3&gt;&lt;p id="temperature"&gt;&lt;/p&gt;&lt;/p&gt;&lt;/div&gt;
    &lt;div id="humid"&gt;&lt;p&gt;&lt;h3&gt;Humidity (%RH): &lt;/h3&gt;&lt;p id="humidity"&gt;&lt;/p&gt;&lt;/p&gt;&lt;/div&gt;
    &lt;div id="div_g" style="width:600px; height:300px;"&gt;&lt;/div
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p><img decoding="async" title="" src="https://lh4.googleusercontent.com/1in5T-Ru8R0jhyDnX04Teq0Eh3UGwKxBCFRnNpGTvR1g7nbLaq2h2AF2v8rj7I_NkKWN50vFJRT08fX0EPR-1PehU_6Q4i96kTAUQM_8RgLXjXHfDL51JbVM-5K5vBcRZdTrME7S" alt="" /></p>
<p>&nbsp;</p>
<p>The web page lacks CSS so it’s kinda ugly. But it works!</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.teachmemicro.com/nodemcu-iot-weather-device/">NodeMCU IoT Weather Device</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.teachmemicro.com/nodemcu-iot-weather-device/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>NodeMCU IoT Environment Monitor</title>
		<link>https://www.teachmemicro.com/nodemcu-iot-environment-monitor/</link>
					<comments>https://www.teachmemicro.com/nodemcu-iot-environment-monitor/#respond</comments>
		
		<dc:creator><![CDATA[Roland Pelayo]]></dc:creator>
		<pubDate>Wed, 09 May 2018 07:32:19 +0000</pubDate>
				<category><![CDATA[ESP8266 Projects]]></category>
		<guid isPermaLink="false">https://www.teachmemicro.com/?p=2287</guid>

					<description><![CDATA[<p>Project Overview This NodeMCU IoT project is a simple demonstration on how to send sensor data to the Internet. Powered by a NodeMCU ESP8266 microcontroller, this project is able to show temperature, humidity and atmospheric pressure to any MQTT subscriber. Introduction Using MQTT is much faster than using HTTP because of reduced overhead. In fact, &#8230;</p>
<p>The post <a href="https://www.teachmemicro.com/nodemcu-iot-environment-monitor/">NodeMCU IoT Environment Monitor</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h3><strong>Project Overview</strong></h3>
<p>This NodeMCU IoT project is a simple demonstration on how to send sensor data to the Internet. Powered by a NodeMCU <a href="https://www.win-source.net/products/detail/espressif/esp8266ex.html">ESP8266</a> microcontroller, this project is able to show temperature, humidity and atmospheric pressure to any MQTT subscriber.</p>
<p><span id="more-2287"></span></p>
<h3><strong>Introduction</strong></h3>
<p>Using MQTT is much faster than using HTTP because of <a href="http://stephendnicholas.com/posts/power-profiling-mqtt-vs-https">reduced overhead</a>. In fact, MQTT is one of the preferred protocols for Internet of Things.</p>
<p>To use MQTT, we need a broker and there are lots of them! For this project, I used <a href="https://shiftr.io">Shiftr.IO</a>. I already detailed <a href="https://www.teachmemicro.com/nodemcu-mqtt-tutorial/">how to use the MQTT protocol with the NodeMCU</a> so kindly check that out first.</p>
<h3><strong>Materials</strong></h3>
<p>For temperature and humidity, I used <a href="https://www.dfrobot.com/product-80.html">SHT1x from DFRobot</a>. For the atmospheric sensor, I used the old reliable BMP085. My <a href="https://www.teachmemicro.com/arduino-bmp085-tutorial/">Arduino BMP085 tutorial</a> covers how to use this sensor with the Arduino. The <a href="https://www.teachmemicro.com/intro-nodemcu-arduino/">NodeMCU uses the same Arduino IDE</a> and code as long as the ESP8266 core is installed.</p>
<ul>
<li><a href="https://amzn.to/2FZbWuJ">NodeMCU</a></li>
<li><a href="https://www.dfrobot.com/product-80.html">SHT1X Temperature and Humidity Sensor</a></li>
<li><a href="https://www.dfrobot.com/product-822.html">BMP085 Atmospheric Pressure Sensor</a></li>
</ul>
<p>Another requirement for this project is a free account in <a href="https://shiftr.io">Shiftr.IO</a>. I’ve created an “<em>environment-monitor</em>” channel in Shiftr and was promptly given username and passwords which is needed when connecting to the broker.</p>
<p>Also, the MQTT library is required and is downloadable <a href="https://github.com/256dpi/arduino-mqtt">here</a>. Finally, you’ll be needing the <a href="https://github.com/practicalarduino/SHT1x">SHT1X library</a> and the <a href="https://github.com/adafruit/Adafruit-BMP085-Library">BMP085 library</a>, both of which (thankfully) are NodeMCU-compatible.</p>
<h3><strong>Wiring Diagram</strong></h3>
<p>The SHT1X library uses software <a href="https://www.teachmemicro.com/spi-primer/">SPI</a> while the BMP085 uses <a href="https://www.teachmemicro.com/i2c-primer/">I2C</a>.</p>
<p>The default I2C pins of the NodeMCU are D1 (SCL) and D2 (SDA) or GPIO5 and GPIO4. Naturally, the BMP085’s SDA and SCL pins should be connected to those pins. As for the the SHT1X, I decided to use the D3 and D4 pins for clock and data respectively.</p>
<p>Here is the Fritzing diagram:</p>
<p><a href="https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_environment_monitor_bb.jpg"><img loading="lazy" decoding="async" class="aligncenter wp-image-2289 size-large" src="https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_environment_monitor_bb-1024x515.jpg" alt="NodeMCU IoT Environment Monitor Wiring Diagram" width="1024" height="515" srcset="https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_environment_monitor_bb-1024x515.jpg 1024w, https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_environment_monitor_bb-300x151.jpg 300w, https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_environment_monitor_bb-768x386.jpg 768w, https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_environment_monitor_bb.jpg 1755w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h3><strong>Arduino Sketch</strong></h3>
<p>The sketch is similar to that in my <a href="https://www.teachmemicro.com/nodemcu-mqtt-tutorial/">MQTT tutorial</a>. The first part of the sketch is establishing the WiFi connection. Then, we connect to the MQTT broker through</p>
<pre class="">client.begin("broker.shiftr.io", WiFiclient);</pre>
<p>Next, I connected to the MQTT channel using</p>
<pre class="">client.connect("environment-monitor", "&lt;username&gt;", "&lt;password&gt;")</pre>
<p>The username and password is found on the URL of the MQTT channel. For example, if this is your URL: <em>mqtt://7fb2fd2f:b9f1e26ae8d3dac8@broker.shiftr.io</em> ( found in <em>namespace settings</em>). Your username is 7fb2fd2f and the password is b9f1e26ae8d3dac8.</p>
<p>To publish data, I used</p>
<pre class="">client.publish("environment-monitor/temperature", (String)temp_c);</pre>
<p>There is no need to create the /temperature topic as it’s automatically created once you call the function above. Of course, you can publish multiple topics:</p>
<pre class="">client.publish("environment-monitor/temperature", (String)temp_c);
client.publish("environment-monitor/humidity", (String)humidity);
client.publish("environment-monitor/pressure", (String)pressure);</pre>
<p>Anyway, here’s the full sketch:</p>
<pre class="lang:arduino decode:true"><code>/*NodeMCU IoT Environment Monitor
 * 
 * By Roland
 * 
 * From https://www.teachmemicro.com/nodemcu-iot-environment-monitor
 */

#include &lt;SHT1x.h&gt;
#include &lt;Wire.h&gt;
#include &lt;Adafruit_BMP085.h&gt;
#include &lt;ESP8266WiFi.h&gt;
#include &lt;MQTTClient.h&gt;
 
// Replace with your network credentials
const char* ssid = "Les Boise Engr. Innovations";
const char* password = "tingkarol";

WiFiClient WiFiclient;
MQTTClient client;

unsigned long lastMillis = 0;

String page = "";
String text = "";
String data;

// Specify data and clock connections and instantiate SHT1x object
#define dataPin  2 //D4
#define clockPin 0 //D3
SHT1x sht1x(dataPin, clockPin);

Adafruit_BMP085 bmp;

float temp_c;
float humidity;
float pressure;

void setup()
{
   Serial.begin(115200); // Open serial connection to report values to host
   Serial.println("Starting up");
   if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP085 sensor, check wiring!");
    while (1) {}
   }

   WiFi.begin(ssid, password); //begin WiFi connection

   // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print("."); 
}

 Serial.println("");
 Serial.print("Connected to ");
 Serial.println(ssid);
 Serial.print("IP address: ");
 Serial.println(WiFi.localIP());
 Serial.print("connecting to MQTT broker...");
 client.begin("broker.shiftr.io", WiFiclient);
 connect();

}

void connect() {
 while (!client.connect("environment-monitor", "7fb2fd2f", "b9f1e26ae8d3dac8")) {
   Serial.print(".");
 }

 Serial.println("\nconnected!");
 client.subscribe("environment-data");
}

void loop()
{
  
  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  humidity = sht1x.readHumidity();
  pressure = bmp.readPressure();
  
  client.loop();
  if(!client.connected()) {
   connect();
  }

  if(millis() - lastMillis &gt; 1000) {
   lastMillis = millis();
   client.publish("environment-monitor/temperature", (String)temp_c);
   client.publish("environment-monitor/humidity", (String)humidity);
   client.publish("environment-monitor/pressure", (String)pressure);
  }
}</code></pre>
<p class="">The sensor data is published every second.</p>
<h3><strong>Images</strong></h3>
<p>Here’s some pictures of my actual setup:</p>

<a href='https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_1.jpg'><img loading="lazy" decoding="async" width="150" height="150" src="https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_1-150x150.jpg" class="attachment-thumbnail size-thumbnail" alt="" srcset="https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_1-150x150.jpg 150w, https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_1-65x65.jpg 65w, https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_1-120x120.jpg 120w" sizes="auto, (max-width: 150px) 100vw, 150px" /></a>
<a href='https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_2.jpg'><img loading="lazy" decoding="async" width="150" height="150" src="https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_2-150x150.jpg" class="attachment-thumbnail size-thumbnail" alt="" srcset="https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_2-150x150.jpg 150w, https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_2-65x65.jpg 65w, https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_2-120x120.jpg 120w" sizes="auto, (max-width: 150px) 100vw, 150px" /></a>
<a href='https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_3.jpg'><img loading="lazy" decoding="async" width="150" height="150" src="https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_3-150x150.jpg" class="attachment-thumbnail size-thumbnail" alt="" srcset="https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_3-150x150.jpg 150w, https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_3-65x65.jpg 65w, https://www.teachmemicro.com/wp-content/uploads/2018/05/nodemcu_iot_environment_monitor_3-120x120.jpg 120w" sizes="auto, (max-width: 150px) 100vw, 150px" /></a>

<p>I had to go from the computer to take better pictures, hence the project is powered by a small power bank. It will still run drawing power from a computer.</p>
<h3><strong>Video</strong></h3>
<p><iframe loading="lazy" width="560" height="315" src="https://www.youtube.com/embed/TPVs6SElyyc" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen="allowfullscreen"></iframe></p>
<p>The post <a href="https://www.teachmemicro.com/nodemcu-iot-environment-monitor/">NodeMCU IoT Environment Monitor</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.teachmemicro.com/nodemcu-iot-environment-monitor/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>NodeMCU WiFi Jammer</title>
		<link>https://www.teachmemicro.com/nodemcu-wifi-jammer/</link>
					<comments>https://www.teachmemicro.com/nodemcu-wifi-jammer/#comments</comments>
		
		<dc:creator><![CDATA[Roland Pelayo]]></dc:creator>
		<pubDate>Thu, 26 Apr 2018 07:13:53 +0000</pubDate>
				<category><![CDATA[ESP8266 Projects]]></category>
		<category><![CDATA[esp8266]]></category>
		<category><![CDATA[iot]]></category>
		<guid isPermaLink="false">https://www.teachmemicro.com/?p=2190</guid>

					<description><![CDATA[<p>There is, in fact, a way to create a NodeMCU ESP8266 WiFi jammer although technically, this is a deauther and not really a jammer. A jammer sends out noise on the WiFi frequency spectrum (2.4 GHz) while the program in this tutorial sends packets that disrupt the normal functions of your WiFi router. So if &#8230;</p>
<p>The post <a href="https://www.teachmemicro.com/nodemcu-wifi-jammer/">NodeMCU WiFi Jammer</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>There is, in fact, a way to create a NodeMCU <a href="https://www.win-source.net/products/detail/espressif/esp8266ex.html">ESP8266</a> WiFi jammer although technically, this is a deauther and not really a jammer. A jammer sends out noise on the WiFi frequency spectrum (2.4 GHz) while the program in this tutorial sends packets that disrupt the normal functions of your WiFi router. So if the aim is to block WiFi to users, this will do.</p>
<p><span id="more-2190"></span></p>
<p><strong>Disclaimer: This tutorial aims to bring awareness to security vulnerabilities of the 802.11 WiFi standard and not to promote mischievousness. The author doesn’t take responsibility for whatever further application this tutorial may result in.</strong></p>
<h3><strong>Install the ESP Core for Arduino and Edit A File</strong></h3>
<p>We will be using the ESP8266 core for Arduino IDE in this tutorial. If you haven’t installed this already, go over to my Introduction to NodeMCU tutorial to show you how.</p>
<p>Once you have the core installed, go to File &gt; Preferences. Click on the preferences path:</p>
<p><img decoding="async" src="https://lh5.googleusercontent.com/5FUy7BRoGVAdMvR4Yqd5ZvAqDWe5OIxwySTc6SNW3Nocv0YleeaELSIYRCxNrdQnXd2Vs5Lt5dYodAX1uayUptCeFnFJPK2flB0H-I6E4I2xegfeZxn2Jb-9Mm0gpZCAhY0CjQwm" /></p>
<p id="BhglJKG">This will open a file dialog window. Go to <em>packages &gt; esp8266 &gt; hardware &gt; esp8266 &gt; 2.3.0 &gt; tools &gt; sdk &gt; include</em> and open the <em>user_interface.h</em> file. Scroll to the bottom of the file and just before the #endif, add these lines:</p>
<pre class="">typedef void (*freedom_outside_cb_t)(uint8 status);int wifi_register_send_pkt_freedom_cb(freedom_outside_cb_t cb);void wifi_unregister_send_pkt_freedom_cb(void);int wifi_send_pkt_freedom(uint8 *buf, int len, bool sys_seq);</pre>
<p>Save the file and close the Arduino IDE.</p>
<h3><strong>Download the Deauther Project</strong></h3>
<p>Next, download the deauther project from Stefan Kremser’s (<em>spacehuhn</em>) <a href="https://github.com/spacehuhn/esp8266_deauther">Github repository</a>.</p>
<p>Open the sketch found at<em> esp8266_deauther-master\esp8266_deauther\</em>.</p>
<p>Note that the sketch contains a lot of headers so don’t just copy this. Download the entire library! Also, Stefan has made his own board with a lot of features not found on a NodeMCU. This causes the sketch to have errors when uploaded. The solution is to add these libraries:</p>
<ul>
<li><a href="https://github.com/bblanchon/ArduinoJson">ArduinoJson</a></li>
<li><a href="https://github.com/ThingPulse/esp8266-oled-ssd1306">ESP8266 OLED SSD1306</a></li>
<li><a href="https://github.com/adafruit/Adafruit_NeoPixel">Adafruit NeoPixel</a></li>
<li><a href="https://github.com/ivanseidel/LinkedList">LinkedList</a></li>
</ul>
<p>Upload the sketch, selecting the correct NodeMCU board beforehand.</p>
<h3><strong>Running the NodeMCU WiFi Jammer</strong></h3>
<p>Open the serial monitor and this should show up:</p>
<pre class="">Mounting SPIFFS...OK
Switched to Channel 1
Settings loaded from /settings.json
Settings saved in /settings.json
Device names loaded from /names.json
SSIDs loaded from /ssids.json
Scan results saved in /scan.json
Serial interface enabled
Started AP
[WiFi] Path: '/web', Mode: 'AP', SSID: 'pwned', password: 'deauther', channel: '1', hidden: false, captive-portal: true
STARTED! \o/
v2.0.5
Executing /autostart.txt
Done executing script</pre>
<p>Now, use your smartphone or computer and connect to the NodeMCU AP showed above (<em>SSID: pwned, password: deauther</em>)</p>
<p>Now, go to <strong>192.168.4.1</strong> using the smartphone or computer connected to the NodeMCU. Click the “Attacks” tab:</p>
<p><img decoding="async" class="aligncenter" src="https://lh5.googleusercontent.com/EMJbHdsMsu4cSheNmXgB6PBIV4h0idqpHmPdxyyCs_mD9P5mgZiYk_Wa-5Vnja2VZpcx3xQtdOoF22yH9-lkc1ZlT74Av94i00MpF3Q7N04iUZnNOsmRVJcF4ZTglDD1-dYcykNj" /></p>
<p>Click the start button on the Deauth row to start the attack. Note that the AP stops so you may end up losing this user interface. Nevertheless, all the WiFi devices connected to the chosen SSID should now be disconnected.</p>
<p>The post <a href="https://www.teachmemicro.com/nodemcu-wifi-jammer/">NodeMCU WiFi Jammer</a> appeared first on <a href="https://www.teachmemicro.com">Teach Me Microcontrollers!</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.teachmemicro.com/nodemcu-wifi-jammer/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: www.teachmemicro.com @ 2026-10-20 21:44:36 by W3 Total Cache
-->