teachmemicrocontrollers
teachmemicrocontrollers
Microcontroller Tutorials
119 posts
Tumblr version of Teach Me Microcontrollers!
Don't wanna be here? Send us removal request.
teachmemicrocontrollers · 2 years ago
Photo
Tumblr media
Microcontroller Tutorials turned 5 today!
2 notes · View notes
teachmemicrocontrollers · 4 years ago
Text
ESP32 WiFi Manager | Dynamic SSID and Password
ESP32 WiFi Manager | Dynamic SSID and Password
If you’ve been following my tutorials on ESP32, then you’ll notice that the WiFi SSID and password are always hardcoded. This tutorial will show you a way to change the WiFi credentials without needing to edit and re-upload your sketch. Our aim is to create a simple ESP32 WiFi manager. Overview There are two scenarios where you would need a WiFi SSID and password. The first is when your ESP32 or…
Tumblr media
View On WordPress
2 notes · View notes
teachmemicrocontrollers · 5 years ago
Text
Using RESTful APIs with ESP32
Using RESTful APIs with ESP32
Tumblr media
With its WiFi capabilities, the ESP32 can connect to API services and acquire useful (and sometimes useless) information from the web. Here’s a quick tutorial on how to connect to RESTful APIs using ESP32.
(more…)
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
Getting Started with Blue Pill and STM32Cube
Getting Started with Blue Pill and STM32Cube
Arduino was made to be easy-to-use but at the expense of a lot of features, most glaring of them is speed. Hence you would rarely see an Arduino in an embedded, industrial setting. ARM Cortex-M microcontrollers are low-cost, energy-efficient 32-bit devices with up to 2 DMIPS/MHz. They are the microcontroller of choice if you are looking into image processing, machine learning or digital signal…
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
Arduino State Machine Tutorial
Arduino State Machine Tutorial
A finite state machine (FSM) is a theoretical machine that only has one action or state at a time. The machine may go from one state to another if there are inputs (or one input) that triggers the state change.
In this article, I will guide you on how to implement an Arduino state machinefor your project. Using state machines will not necessarily make your Arduino sketch execute faster; state…
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
Seeed Studio now Offering Free DFA Review for PCBA Orders
Seeed Studio now Offering Free DFA Review for PCBA Orders
This post is sponsored by Seeed Studio
With a focus on giving customers the best value for money, Seeed Fusion’s turnkey PCB assembly now offers free Design for Assembly (DFA) on all PCB assembly orders. This is supposed to be the first on a series of new offers Seeed Studio will be rolling out every month of this year and maybe, beyond.
(more…)
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
ESP8266 SPIFFs | File System for NodeMCU
ESP8266 SPIFFs | File System for NodeMCU
SPIFFS or Serial Peripheral Interface Flash File System is a system that utilizes extra flash memory on the ESP8266 and ESP32 for storing files. It’s so named because the user reads, writes or deletes files in the memory using the serial interface. In this article, I will show you how to set up SPIFFS for your NodeMCU or WeMos D1 Miniboard. Also, an example is presented on how to take advantage…
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
The MQ-4 is one of many gas sensors ready to be interfaced with microcontrollers. Just like the rest of the MQ sensors, the MQ-4 is most sensitive to a particular gas. This time, it’s methane, although the sensor can still detect other flammable gases like butane and propane.
MQ-4 Methane Sensor Overview
At the heart of the MQ-4 is a heater and electrochemical sensor. When the target gas enters the membrane and reaches the sensor, it undergoes a redox reaction which creates current. This current is stronger for sensors at specific gases. In the case of the MQ4, it’s more sensitive to methane, butane and propane.
If you are looking to buy a MQ-4 sensor, you should choose the one that comes in a breakout board like this:
#gallery-0-4 { margin: auto; } #gallery-0-4 .gallery-item { float: left; margin-top: 10px; text-align: center; width: 33%; } #gallery-0-4 img { border: 2px solid #cfcfcf; } #gallery-0-4 .gallery-caption { margin-left: 0; } /* see gallery_shortcode() in wp-includes/media.php */
This breakout board has four output pins, namely A0, D0, GND and VCC.
The power pins VCC and GND can be connected directly to an Arduino’s 5 V pin and GND respectively.
Using Digital Output
The D0 pin generates a high (equal to VCC) when in the presence of methane gas and low (equal to around 0.1 V) otherwise. You can calibrate this “digital” output through the trimmer pot on the board.
If your project only requires detection of methane then reading the D0 pin will do. Here’s a circuit diagram with an Arduino UNO:
Here, the D0 pin connects to digital pin 2 of the Arduino. The Arduino sketch below uses an interrupt so that the microcontroller always detects the MQ-4 first.
/* MQ4 Sensor - Digital Output Example * by R. Pelayo * * From TeachMeMicro (www.teachmemicro.com/arduino-mq4-methane-sensor * * Date Created: 09/11/2020 */ const byte MQ4_Pin = 2; //MQ4 D0 pin void setup() { pinMode(MQ4_Pin, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(MQ4_Pin), sensor_triggered, CHANGE); //attach interrupt on MQ4 pin Serial.begin(9600); } void loop() { // Do anything you want here } void sensor_triggered() { Serial.println("Methane detected!"); // Output to serial monitor }
If however you need to determine methane concentration, you’ll need the A0 pin.
Using Analog Output
Determining PPM Equation
The sensitivity curve of the MQ-4 is shown below:
This curve is from the device datasheet and shows the sensitivity of the MQ-4 to gases. As seen here, it’s most sensitive to CH4, the chemical name of methane. Absent in the curve are propane and butane gases although both are known components of LPG (which is second to methane in this curve).
The curve is a log-log scale and shows the relationship between RS/R0 and gas concentration in parts-per-million (PPM). RS/R0 is the ratio of sensor resistance at target gas (RS) and resistance in clean air (R0). Hence, by knowing RS/R0, we can determine the concentration of the gas in PPM.
We take two points on this graph to derive a formula. This formula will then be used in our Arduino sketch later on.
The most obvious point is when RS/R0 = 1 and PPM = 1000. The second point is when RS/R0 is somewhere around 0.58 and PPM = 5000. The equation starts with:
Here, we will assign Y1 = 1, X1 = 1000 from the first point and Y2 = 0.58 and X2 = 5000 from the second point. Substituting these values in the equation above:
Changing Y to RS/R0 and X to PPM and solving for PPM:
We can now use this formula in our sketch. But before that, we need to determine the resistance ratio RS/R0.
Methane PPM Output Arduino Sketch
As mentioned, RS is the sensor resistance in the presence of Methane while R0 is the sensor resistance in clean air. Of these two, R0 would be easier to determine. We measure the resistance of the electrodes 1-6 or 4-3 (see figure below) using an ohmmeter.
My MQ-4 electrodes give out 945 ohms of resistance for both 1-6 and 4-3 electrodes. This means my R0 is 945 ohms.
The value of RS would have to be known through a sketch. The MQ-4 breakout board uses this schematic:
As you can see, Aout connects to one of the electrodes and in parallel to a resistor RL. This means the electrode resistance creates a voltage divider with RL and the voltage at Aout is:
Here, RS is our target electrode resistance which varies depending on methane concentration.
BTW, RL is an SMD resistor with label 102. This corresponds to a resistance of 1k.
So to get RS we use this formula:
The Arduino sketch to give out methane concentration in PPM is now:
/* MQ4 Sensor - Analog Output Example * Prints out methane concentration in PPM to serial monitor * by R. Pelayo * * From TeachMeMicro (www.teachmemicro.com/arduino-mq4-methane-sensor * * Date Created: 09/11/2020 */ const byte MQ4_Pin = A0; //MQ4 A0 pin const int R_0 = 945; //Change this to your own R0 measurements void setup() { Serial.begin(9600); } void loop() { Serial.println(getMethanePPM()); } /* * getMethanePPM returns a float value in PPM of methane concentration */ float getMethanePPM(){ float a0 = analogRead(A0); // get raw reading from sensor float v_o = a0 * 5 / 1023; // convert reading to volts float R_S = (5-v_o) * 1000 / v_o; // apply formula for getting RS float PPM = pow(R_S/R_0,-2.95) * 1000; //apply formula for getting PPM return PPM; // return PPM value to calling function }
That’s two ways to use the MQ-4 methane gas sensor. Note that this sketch is for display methane concentrations only, not butane or propane. For any questions, reactions, or suggestions, kindly drop a comment below.
How to Use MQ-4 Methane Gas Sensor The MQ-4 is one of many gas sensors ready to be interfaced with microcontrollers. Just like the rest of the MQ sensors, the MQ-4 is most sensitive to a particular gas.
0 notes
teachmemicrocontrollers · 5 years ago
Text
Using the BH1750 (GY-30) Sensor with Arduino
Using the BH1750 (GY-30) Sensor with Arduino
The BH1750 is a light intensity sensor which interfaces with a microcontroller through the I2C bus. It can directly provide lux values without further processing unlike CdS cells or photodiodes.
(more…)
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
Using AD9833 Signal Generator with Arduino
Using AD9833 Signal Generator with Arduino
Have you ever wondered how you can create sine, square or triangular waves with Arduino? Apparently, there’s a way with the help of an integrated circuit package called AD9833. With it, you can now create waveforms for communications, instrumentation or other related projects. My tutorial on building your own Arduino signal generator after the jump.
(more…)
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
How to Use I2C Devices with Raspberry Pi
How to Use I2C Devices with Raspberry Pi
I2C is a popular device protocol in communicating with microcontrollers. However, this protocol is not limited to Arduino, PIC and STM32; the Raspberry Pi can also use I2C.
(more…)
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
Watchdog Timer on Arduino Tutorial
Watchdog Timer on Arduino Tutorial
In Arduino programming, we learn about functions setup() and loop(). Any code inside setup() executes once while code inside loop() executes again and again until the next reset.
Now what if while inside the loop(), something went wrong either in code or in hardware? Normally we just press the reset button. But what if we can’t press that button? You can reset the Arduino via software using the w…
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
Dot Matrix Droplets Project
Dot Matrix Droplets Project
Tumblr media
This project makes the “dots” on a dot matrix look like they are pebbles in a container. Tilt the device on one side and the dots fall toward that side. The same goes if the device tilts to the other side.
(more…)
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
How to Use TM1637 and Four Seven Segment Display Module
How to Use TM1637 and Four Seven Segment Display Module
A seven segment display has one pin for each of its seven segments. This means if directly interfaced with a microcontroller, you will need at least seven pins. Fortunately, there is a way to use four seven segment displays and using only four pins from your Arduino.
(more…)
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
How to Use Load Cell with HX711 and Arduino
How to Use Load Cell with HX711 and Arduino
Measuring an object’s weight can sometimes be part of a bigger project. And unless you have a good reason, you wouldn’t want to use an analog weighing scale. A digital weight sensor is easier to interface with, not to mention its accuracy and durability against an analog weight sensor. In this article, I will show you how to build your own weighing scale using a load cell, HX711 and Arduino.
(mo…
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
ESP32 MAX7219 WiFi Message Board
ESP32 MAX7219 WiFi Message Board
This ESP32-powered project allows you to write messages to a MAX7219 LED matrix display using your smartphone. Scaled up, this can be used as a WiFi message board for schools or signages for businesses.
(more…)
View On WordPress
0 notes
teachmemicrocontrollers · 5 years ago
Text
ESP32 Magnetometer using HMC5883L
ESP32 Magnetometer using HMC5883L
For this article, I will show you how to use an ESP32 microcontroller as a magnetometer – a device that measures the direction and strength of a nearby magnet. In the absence of a nearby magnet, the device detects the Earth’s magnetic field. Hence, a compass is a type of magnetometer.
(more…)
View On WordPress
0 notes