Drive 8-Channel Relay Module with Bus Expander

 Posted by:   Posted on:    No comments

In automation projects it is often needed to drive multiple outputs. Combine this with the reduced number of pins of a microcontroller, such as ESP8266, and you got a problem. In this post we'll explore the methods of converting the parallel inputs of a relay module to some kind of serial protocol, which allows connecting even more relays, without the need of additional control pins. I will use for exemplification an 8-channel relay module, however the methods I will show will allow you to connect more than 8 relays to the same bus.

To achieve this purpose, I have to use some kind of bus expander IC. There are a few available options here. However, as we will see, both communication protocol and output port capability are different. And even the common relay modules use a rather unusual method of turning on the relay driver transistor. I already discussed the difference between current sink and current source in the previous post. Let's use that knowledge.

8 Relay module with PCF8574 bus expander
8 Relay module with PCF8574 bus expander

I/O Interfacing with current source and sink pins

 Posted by:   Posted on:    No comments

Current source and current sink are two commonly used terms that you will find in datasheets of microcontrollers and digital circuits. Even though most input pins of an IC nowadays are internally connected to the gate of MOSFET transistors which are voltage driven, there are situations when you have to take into account current capabilities (i.e. high speed switching or something else than a CMOS input is connected to an output pin). I'm thinking about LEDs and bipolar transistor driven devices, such as relay modules.

These inputs are current driven and need to source or sink currents to change state. Fortunately, most output pins of contemporary microcontrollers are push-pull type and can source and sink currents. This means you don't have to worry too much about the way you are connecting an LED to a digital output. But there are still in use circuits which can only sink or source currents. And if you're not paying attention to datasheet, you might very well fail to design a working circuit.

I/O Interfacing with current source and sink pins

Gas detector based on MQ-2 without microcontroller

 Posted by:   Posted on:    No comments

Nowadays people are using microcontrollers even for blinking an LED. And that is no problem, since they are cheap enough, have low power consumption and are easy to program. But there was a time when microcontrollers were expensive and hard to find. And even then, engineers were building working devices, just smart enough to do the job they were designed for. Let's try to build a "microcontroller-less" gas detector using one of the MQ sensors.

Gas sensors from MQ family are analog tin dioxide detectors which change their resistance in the presence of volatile compounds like gases or smoke. Except MQ-7 and MQ-9 which are designed for carbon monoxide detection and require alternating heater voltage, with analog output being read at the end of each heater voltage cycle, every other sensor may be used in the following circuit.

Gas detector based on MQ-2 without microcontroller
Gas detector with MQ-2 module on breadboard

I/O voltage level shifting: passive down-converters

 Posted by:   Posted on:    No comments

When interfacing various devices to a microcontroller, some kind of voltage conversion is often needed. The most common voltage levels of development boards and modules are 3.3 V and 5 V, yet it is not out of the ordinary to find devices using 2.5 V or even 1.8 V I/O levels. This post will explore some of the available methods of converting I/O voltage levels to ensure compatibility between electronic modules and ICs. When I say compatibility I mean the devices connected together through a level shifter should work as expected and not cause damage to each other.

I began searching information about level shifting after a failed attempt to interface an ESP8266 board (3.3 V I/O) to an array of 74HC595-74HC165 shift registers which were required to be powered at 5 V (therefore they expect 5 V I/O). Without documenting too much, I considered 74HC would recognize high 3.3 V output from microcontroller. But that was not the case as I would soon discover. The next step was to add a MOSFET bidirectional level shifter (the ones which are commonly used for I2C), however strange behavior occurred.

I/O voltage level shifting: passive down-converters

CO and LPG gas sensor with Arduino and LCD

 Posted by:   Posted on:    No comments

In a previous post I looked at a MQ-9 sensor module. Unfortunately, although the sensor can detect CO and LPG, it cannot be used as it is wired in the module. After analyzing the datasheet I figured the best thing to do is remove it from existing PCB and build my own. In short, like other sensors from MQ family, MQ-9 has a heater resistor inside. In order to get any useful reading from it, this resistor must be heated at 5 V for 60 seconds, then cooled at 1.4 V for 90 seconds. The same is true for MQ-7. The issue with modules is that all sensors from MQ family are fitted on the same PCB design.

In this post, I'll share two other methods of powering the heater resistor and I will design a PCB. Sensor readings will be displayed on an alphanumeric LCD powered by Arduino. Since real ppm is temperature and humidity dependent, I will provide a PCB header for DHT sensor. I already tested the sensor with the LM317 power supply I built in the previous post, and I did some measurements.

CO and LPG gas sensor with Arduino and LCD

Influence of temperature and humidity on MQ gas sensors

 Posted by:   Posted on:    No comments

I dedicated some of my previous posts to MQ gas sensors. These devices are cheap and can be bought on PCB modules, which implement a simple comparator circuit in order to provide a digital output. However, the usability of these modules is rather limited, knowing that some of the sensors from MQ family require variable heater voltage. More than this, at power-up the resistance of the sensor is low until the heater reaches working temperature, therefore the comparator output of a sensor module will trigger a false alarm.

Although this is not an important limitation, the modules do not take into account the variation of sensor resistance based on environment temperature and humidity. To do this, a microcontroller must sample the sensor resistance through an ADC and estimate gas concentration. This post continues a previous one in which I estimated gas ppm after extracting sensitivity data from datasheet graphs. However...

Influence of temperature and humidity on MQ gas sensors