Smart CO2-Based Fan Control Using BleuIO and Renesas RA4M2

January 29, 2025
Smart CO2-Based Fan Control Using BleuIO and Renesas RA4M2

This project showcases how to integrate the Renesas EK-RA4M2 microcontroller with a BleuIO BLE USB dongle to create a smart air ventilation system. By using HibouAir‘s CO2 parameter, an air quality monitoring device, the system continuously monitors indoor air quality and automatically controls a fan based on CO2 levels.

The BleuIO dongle scans for HibouAir’s BLE advertising data to retrieve real-time CO2 readings. When the CO2 concentration exceeds 600 ppm, the system activates the fan to improve air circulation. Once the CO2 level drops below 550 ppm, the fan is turned off to conserve energy.

This implementation demonstrates a practical IoT-based air quality control solution, making indoor environments healthier and more efficient.

The EK-RA4M2 board prints the CO2 values, as they change, on the RTTViewer.

Requirements

Setup

  • Connect a Micro USB device cable (type-A male to micro-B male) between J10 (Debug1) and a Computer USB port.
  • Plug in a BleuIO Dongle in the USB OTG Cable (type-A female to micro-B male) and connect it to J11 (USB Full Speed).
  • Make sure Jumper J12 is placed on pins 1-2
  • Remove Jumper J15 pins
  • Connect the fan power adapter to 3V3 and GND on the developer kit like this:

  • The fan power adapter will also need to be connected to GPIO pin 505 on the developer kit to turn it on and off:

Importing project

  • Open e² studio IDE
  • Choose a workspace and click ‘Launch’
  • Download or clone the example project. Place the folder ‘bleuio_ra4m2_fan_example’ in workspace.
  • Choose Import Project
  • Select ‘Existing Projects into Workspace’ under the ‘General’ tab:
  • Click the ‘Browse…’ button and open the folder where the ‘bleuio_ra4m2_fan_example’ project folder is located:
  • Finally select the project and click ‘Finish’. You have now imported the the project!

Running the example

  • Go to file ‘usb_hcdc_app.c’ under ‘src/’ and edit line 41 to the board ID of the HibouAir Sensor:
  • #define BOARD_ID_TO_SCAN “2202B3”
  • The board ID is printed on the back of the HibouAir sensor:
  • You can also threshold values to change when the fan should start and stop.

    The defines can be found on row 45 and 47 in ‘usb_hcdc_app.c’ under ‘src/’:
  • /* CO2 threshold value 1. If at this value or above, the fan will start. */
    #define CO2_FAN_ROOF 600
    /* CO2 threshold value 2. If at this value or below, the fan will stop. */
    #define CO2_FAN_FLOOR 550

Build the project by clicking the building icon:

  • Use Debug to download and run the project. The first time you need to configure the debug settings. Click down arrow to the right of the Debug icon and select ‘Debug Configurations…’


Under ‘Renesas GDB Hardware Debugging’ select ‘bleuio_ra4m2_fan_example.elf’ and click ‘Debug’

  • The debug is now configured and the ‘Debug’ icon can be used next time to run the project.
  • Open RTTViewer. Connect and use these settings:

    Connection to J-Link: USB

    Specify Target Device: R7FA4M2AD

    Target Interface & Speed: SWD 4000kHz

    RTT Control Block: Address 0x2000095c


On the debugger screen in e² studio click the ‘Resume’ icon twice to run the project.

  • The application is now running. When starting up you should notice all LEDs lighting up for one second then only the red LED will be on. It will turn off as soon as the BleuIO is configured.
  • You should now see the output on the RTTViewer. 


If CO2 value is 600ppm or above, the fan will turn on.

If CO2 value is 550ppm or below, the fan will turn off.


The LEDs will light up like the previous CO2 Monitor Example:

When the CO2 level is less than 600 ppm only the blue LED will be turned on.


If the CO2 level is over 600 ppm but below 1000 ppm then the green LED will be on.


If the CO2 level is above 1000 ppm then the red LED will be on.

Share this post on :

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow us on LinkedIn :

Order Now