Automating Windows with IAQ Sensor-Driven DC Motors
Develop a Practical Solution for a Modern Problem
Aly Barakat, Mouser Electronics
The negative effects of greenhouse gases on the environment have led scientists and engineers to seek ways to reduce emissions as well as exposure. Given the amount of time that many of us spend in enclosed spaces, indoor air quality (IAQ) has emerged as an important facet of curbing exposure to greenhouse gases. An IAQ sensor that can accurately measure greenhouse gases is a crucial tool that can provide insights into the quality of air we inhale.
IAQ sensors are devices that measure and monitor the quality of the air inside a building or other enclosed space, typically measuring parameters such as temperature (T), relative humidity (RH), volatile organic compounds (VOCs), carbon dioxide (CO2), particulate matter (PM), and nitrogen oxides (NOx). IAQ sensors can help individuals and organizations identify and address air quality issues and maintain healthy and comfortable indoor environments. IAQ sensors can also be used in conjunction with other systems, such as ventilation or air purification systems, to help maintain optimal air quality in the enclosed space.
This project is a proof of concept to show how IAQ sensors can feed data to a microcontroller board, which will then send commands to a DC motor to open and close a window depending on the IAQ parameters. Because this project is just a proof of concept, we will use only the CO2 parameter. If the value of the CO2 is above or below the specific limits defined in the code, a signal will be sent to the DC motor driver to open or close the window to allow for better ventilation.
Project Materials and Resources
This project uses an Arduino MKR WIFI 1010, two Sensirion sensor modules, and an Infineon DCMOTORCONTRBTN8982TOBO motor control shield to control a Nidec Components DC motor.
Important Note: At the time of writing, the Infineon DCMOTORCONTRBTN8982TOBO1 Motor Control Shield has been superseded by the DCSHIELDBTN9970LVTOBO1
. While the principles of operation are broadly similar to its predecessor, you should validate the correct operation. Example code for the DCSHIELDBTN9970LVTOBO1 is available at https://github.com/Infineon/arduino-examples-btn9990-9970-dc-motor-control-shield.
Project Bill of Materials (BOM)
- 782-ABX00023: Arduino MKR WIFI 1010
- 403-SCD41-D-R2: Sensirion SCD41 CO2, RH, & T Sensor
- 403-SEN55-SDN-T: Sensirion SEN55 PM, NOx, VOC, RH, & T Sensor
- 726-DCMTRCONTRBTN898: Infineon Technologies DCMOTORCONTRBTN8982TOBO1 DC Motor Driver Shield)
- 229-HG37-150-AA-00: Nidec Components HG37-150-AA-00 DC Motor
- 709-GSV60E12-P1J: Mean Well Wall Mount AC Adapters 60W 12V 5A US 2 pin AC plug 2.1x5.5 DCPlug
- 485-4539: Adafruit Breadboard
- 485-4482: Adafruit Jumper Wires
- 166-USBCABLEMICRO80: Micro USB Cable
- 485-368: Adafruit Female DC Power Adapter
All of these materials are collected in the project BOM.
Software and Tools
- Arduino IDE
- Arduino Create Agent for Arduino IoT Cloud
- Hardware STL files and Arduino sketch on Github
- Sensirion Libraries
Project Technology Overview
The Arduino MKR WIFI 1010 (Figure 1) is a versatile microcontroller board featuring an ESP32-based u-blox Nina W102 module for Wi-Fi® and Bluetooth® connectivity. Its compact form factor and low power consumption make it ideal for IoT projects and battery-powered applications. With a Microchip Technology SAMD21 Arm® Cortex®-M0+ 32-bit microprocessor, it offers ample processing power and flexibility for a wide variety of tasks. The board also comes with extensive peripheral support, including I²C, SPI, UART, and analog/digital inputs, enabling easy interfacing with sensors and actuators.
Figure 1: Arduino MKR WIFI 1010 microcontroller board. (Source: Mouser Electronics)
The Sensirion SCD41 CO2 sensor (Figure 2) is a compact, low-power, high-precision CO2 sensor that provides accurate and reliable CO2 concentration measurements. This sensor is based on the photoacoustic sensing principle and offers a unique combination of performance characteristics that make it suitable for a range of applications, including IAQ monitoring, HVAC systems, and smart home devices.
Figure 2: Sensirion SCD41 CO2 sensor. (Source: Mouser Electronics)
The Sensirion SEN55 environmental sensor node (Figure 3) provides highly accurate measurements of PM, RH, T, VOC index, and NOx index. The node incorporates the Sensirion Temperature Acceleration Routine (STAR) engine to enable up to three times' faster response time to changes in the ambient temperature. Combined with the node's temperature compensation engine, this technology provides more accurate measurements.
Figure 3: Sensirion SEN55 environmental sensor node. (Source: Mouser Electronics)
The Nidec Components HG37 is a compact and efficient DC motor designed for a variety of applications that require precise motion control. It features a rated voltage of 12VDC and a no-load speed of 3700RPM, delivering reliable performance in a small form factor. This motor is equipped with an integrated gearbox, providing a gear ratio of 150:1 for increased torque and finer motion control. The HG37 (Figure 4) is suitable for use in robotics, automation systems, and other applications where space constraints and power efficiency are crucial considerations.
Figure 4: Nidec Components HG37-150-AA-00 DC motor. (Source: Mouser Electronics)
The Infineon Technologies DCMOTORCONTRBTN8982TOBO1 shield (Figure 5) is a high-performance DC motor driver designed for efficient and precise motor control applications. It is based on the BTN8982TA integrated H-bridge controller with high current capabilities that can manage up to 50A continuous current and up to 80A peak current. This motor driver board features over-temperature protection, over-voltage protection, and under-voltage protection, ensuring reliable operation in various conditions.
Figure 5: Infineon Technologies DCMOTORCONTRBTN8982TOBO1 DC motor driver shield. (Source: Mouser Electronics)
Hardware Setup
Identify the GND (ground) and VCC (voltage) pins on the underside of the Arduino board. These are essential as they will power the breadboard once connected. Then align the pins of the Arduino board with the holes in the breadboard. Ensure that the Arduino board is centered on the breadboard and that all pins align with separate rows as shown in Figure 6.
- Connect the Arduino board's 5V pin to the positive rail on the breadboard
- Connect the Arduino board's GND pin to the negative rail on the breadboard.
The Sensirion SCD41 sensor has four pins: voltage common collector (VCC), ground (GND), serial data line (SDA), and serial clock line (SCL). We will use the breadboard and jumper wires to connect the sensor with the Arduino MKR WIFI 1010 board, providing power and communication. See Figure 6 for the completed connections.
- Connect the SCD41 sensor's VCC pin to the positive rail on the breadboard.
- Connect the SCD41 sensor's GND pin to the negative rail on the breadboard.
- Connect the SCD41 sensor's SDA pin to the A4 (SDA) pin on the Arduino board
- Connect the SCD41 sensor's SCL pin to the A5 (SCL) pin on the Arduino board.
The Sensirion SEN55 has six pins: VCC, GND, SDA, SCL, interface select (SEL), and not connected (NC). Sensor fusion is required to connect this sensor to the Arduino board and the SCD41 sensor:
- Connect the SEN55 sensor's VCC pin to the positive rail on the breadboard.
- Connect the SEN55 sensor's GND pin to the negative rail on the breadboard.
Two pins on the Arduino MKR WIFI 1010 (SDA and SCL) are already being used by the SCD41 sensor. This means that there is no available port on the Arduino board to connect the SEN55 sensor's SDA and SCL pins. We will solve this problem by connecting the SEN55 sensor's SDA and SCL pins to the corresponding rows on the breadboard.
3. Connect the SEN55 sensor's SDA pin to the terminal hole on the same row as the Arduino's A4 pin.
4. Connect the SEN55 sensor's SCL pin to the terminal hole on the same row as the Arduino's A5 pin.
5. Connect the SEL pin to negative on the breadboard and leave the NC pin unconnected.
This project requires the motor to move bidirectionally to open and close the window. To enable this, we will allow the current to flow in both ways by soldering the positive and negative terminals of the Nidec motor to the OUT1 and OUT2 pins, respectively, on the Infineon motor controller shield. The shield needs an input voltage of 12V, so we will solder the positive terminal of the power supply to the VBAT pin on the shield and the negative terminal to GND using the following steps:
- Solder two jumper wires, one for ground (-) and one for power supply (+), to the terminal block of the Adafruit Female DC Power Adapter.
- Solder the other end of the power supply wire to VBAT on the motor shield.
- Solder the other end of the ground cable to GND on the motor shield.
- Connect the Mean Well Wall Mount to the Adafruit Female adapter.
Now the DC motor is connected to the shield and power supply. There are three input signals for the motor driver: IN, INH, and SR. To connect the shield to the Arduino board, we will create connections for movements in both directions for the DC motor:
The first motor controller’s connections:
- IS_1 is connected to A0 on the Arduino board.
- IN_1 is connected to pin 3 (PWM) on the Arduino board.
- INH_1 is connected to pin 14 on the Arduino board.
The second motor controller’s connections:
- IS_2 is connected to A1 on the Arduino board.
- IN_2 is connected to pin 10 (PWM) on the Arduino board.
- INH_2 is connected to pin 13 on the Arduino board
Figure 6: Full circuit connection. (Source: Author, created in Fritzing)
I used Tinkercad to create 3D models (as .stl files) of this project's mechanical parts, including the hardware for opening the window and stabilizers for the motor. These .stl files are in the Github repository linked in the Project Materials and Resources section. Because the sizes of some parts match the dimensions of the window, you may need to modify some measurements in the .stl files to match your window.
Software Setup
To program the Arduino MKR WIFI 1010 and connect it to the cloud, install the Arduino IDE and Arduino Agent for IoT Cloud according to the instructions on the respective download pages. After downloading the software, connect the Arduino board to your computer using the micro-USB cable.
Sensirion provides the libraries and code needed to program both sensors and to see the measured values on the serial monitor. However, the codes are written separately so we need to combine them to implement the fusion of both sensors. We can do this by combining the relevant functions and variables from both codes, while ensuring that they do not conflict with each other.
One way to approach this is to copy the setup and loop functions and any necessary libraries and variable declarations from each sensor's code. Next, the measurement functions from both sensors must be integrated into the loop function.
The first few lines of code include the necessary libraries and define some variables for the motor control pins.
- The window_state variable is used to track whether the window is open or closed.
- The printModuleVersions() function prints the product name, firmware, and hardware versions of the SEN55 sensor.
- The printSerialNumber() function prints the serial number of the SEN55 sensor.
- The printUint16Hex() function prints uint16_t values in hexadecimal format.
- The printSerialNumber2() function prints the serial number of the SCD41 sensor.
- In the setup() function, the serial communication is initialized, and the sensors are started by calling the begin() function of each sensor object.
- The deviceReset() function is called to reset the SEN55 sensor.
- The stopPeriodicMeasurement() function is called to stop any previously started measurement on the SCD41 sensor.
- The printSerialNumber() and printModuleVersions() functions are called to print information about the SEN55 sensor.
- The loop() function is where the sensor readings are taken.
- The sen5x.measureData() function is called to get the temperature, humidity, and VOC concentration values from the SEN55 sensor.
- The Serial.print() function is used to print these values to the serial monitor.
- The scd4x.getCarbonDioxideConcentration() function is called to get the current CO2 concentration value from the SCD41 sensor.
- If the window_state is false (meaning the window is closed) and the CO2 value is above 1300ppm (for proof-of-concept purposes), then the motor is commanded to open the window by calling the biDirectionPower() function with a negative power value. The motor runs for 5 seconds (as specified by the delay() function) and then stops by calling biDirectionPower() with a power value of zero. Finally, the window_state variable is updated to true to reflect the new state of the window (which is now open).
- If the window_state is true (meaning the window is open) and the CO2 value is below 1250ppm (for proof-of-concept purposes), then the motor is commanded to close the window by calling the biDirectionPower() function with a positive power value. The motor runs for 5 seconds and then stops by calling biDirectionPower() with a power value of zero. Finally, the window_state variable is updated to false to reflect the new state of the window (which is now closed).
- The biDirectionPower() function is responsible for controlling the direction and speed of the motor. It takes an input power value (inputBiPower) that can be positive or negative, indicating the direction of the motor.
- If inputBiPower is zero, the motor is stopped by setting the two motor pins (IN_1 and IN_2) to zero using the analogWrite() function.
- If inputBiPower is positive, then the motor is commanded to run in one direction by setting IN_1 to the input power value.
- If inputBiPower is negative, then the motor is commanded to run in the opposite direction by setting IN_2 to the absolute value of the input power value.
Cloud Communication
The Arduino IoT Cloud is a tool that provides a way to connect Arduino devices to the internet. The free version of the Arduino IoT Cloud provides a set of essential features for creating and managing IoT projects, including dashboards for controlling IoT devices, automatic generation of code, and secure communication between the cloud and your devices.
Using Arduino IoT Cloud, the data of the sensors and the window state are displayed on a single dashboard, which allows you to monitor the IAQ parameters values. Figure 7 shows the statuses of CO2 level, CO2 history, VOC, RH, temperature, PM2.5, and the window state as they appear on the dashboard. Because the CO2 level is below 1300, the window sate is "x," or closed.
Figure 7: Arduino IoT Cloud dashboard. (Source: Author)
Conclusion
This article documents a project that uses two IAQ sensors to measure the concentration of greenhouse gases in indoor air alongside a motor driver circuit that opens and closes a window to maintain the desired level of fresh air flow. The sensors are connected to an Arduino MKR WIFI 1010 microcontroller board to facilitate the measurement and logging of greenhouse gases in real time. The motor driver circuit features an H-bridge configuration that enables precise control of the motor in both directions.
The results demonstrated that the sensor and motor driver circuits were equally reliable and efficient at performing their designated tasks, enabling the accurate measurement of greenhouse gases and the regulation of the motor to keep the window in the desired position (Figure 8 and Figure 9).
Figure 8: Sensor- and motor-controlled window in closed and open states. (Source: Author)
Figure 9: The 3D-printed open/close mechanism. (Source: Author)
Overall, the project could help users enhance the quality of indoor air. The measurement of greenhouse gases and regulation of fresh air flow are essential to maintaining air quality in closed spaces. The success of this project opens the way for further explorations and investigations in this area, which could lead in the creation of more advanced systems for indoor air quality monitoring.