中级
30 分钟

使用MQ-137和STM32L496AG简化NH3监测

纯净守护者:创新的氨气传感解决方案

Ammonia Click with Discovery kit with STM32L496AG MCU

已发布 7月 22, 2025

点击板

Ammonia Click

开发板

Discovery kit with STM32L496AG MCU

编译器

NECTO Studio

微控制器单元

STM32L496AG

我们的氨气传感解决方案提供准确及时的信息,使各行业和社区能够管理氨气水平并维持安全、可呼吸的空气。

A

A

硬件概览

它是如何工作的?

Ammonia Click 基于 Winsen 的 MQ-137 气体传感器,它使用 SnO2(氧化锡)合金,在暴露于 NH3 气体时其电阻会降低。NH3 浓度越高,这种材料的导电性就越强。这可以用于获取 NH3 浓度读数。传感器包含一个小型加热元件,连接到 5V 电源。加热元件可以通过连接到 mikroBUS™ 插座上的 PWM 引脚的 MOSFET 电源开关来控制,以降低功耗。需要预热至少 24 小时才能达到指定性能。一个不锈钢网保护传感器免受颗粒物和机械损伤,但暴露于过多的湿气和腐蚀性气体会损坏内部结构。测量电路包括 MQ-137 传感器、电源和输出引脚与接地之间的负载电阻 (RL)。传感器与负载电阻形成电压分压器。RL 被设计为可变电

阻器,允许将输出电压调整到所需值。校准应在受控条件下进行,因为环境温度和湿度会影响传感器的电阻。传感器可以在不精确校准的情况下测量相对 NH3 浓度变化,这对于构建可用作警告系统的应用很有用。传感器 RL 电压分压器的中间抽头连接到标记为 ADC SEL 的 SMD 跳线。此跳线可以将测量电压重定向到 ADC 进行采样或 AN 引脚,以便在外部电路(外部 ADC 或其他形式的测量信号调理)中使用。当由 ADC SEL 跳线选择时,Microchip 的 22 位 sigma-delta ADC MCP3551 用于采样传感器输出。此 ADC 将输入电压转换为 22 位高分辨率和低噪声的数字数据,可以通过 Click board™ 的 SPI 接口获得。此 ADC 使用

与电源电压相同的参考电压,在本例中,由 mikroBUS™ 电源轨提供 5V 电源。如前所述,ADC 使用 5V 电源。因此,该板需要一个电平转换电路与 3.3V MCU 接口。此 Click board™ 使用德州仪器的 6 位双向电平转换 IC TXB0106,用于将通信逻辑电压水平从 5V 转换为 3.3V。此 Click board™ 可以在 3.3V 或 5V 逻辑电压水平下工作,通过 VCC SEL 跳线选择。这样,3.3V 和 5V 的 MCU 都可以正确使用通信线路。此外,此 Click board™ 配备了一个包含易于使用的功能和示例代码的库,可以用作进一步开发的参考。

Ammonia Click top side image
Ammonia Click bottom side image

功能概述

开发板

32L496GDISCOVERY Discovery 套件是一款功能全面的演示和开发平台,专为搭载 Arm® Cortex®-M4 内核的 STM32L496AG 微控制器设计。该套件适用于需要在高性能、先进图形处理和超低功耗之间取得平衡的应用,支持无缝原型开发,适用于各种嵌入式解决方案。STM32L496AG 采用创新的节能架构,集成

了扩展 RAM 和 Chrom-ART 图形加速器,在提升图形性能的同时保持低功耗,使其特别适用于音频处理、图形用户界面和实时数据采集等对能效要求较高的应用。为了简化开发流程,该开发板配备了板载 ST-LINK/V2-1 调试器/编程器,提供即插即用的调试和编程体验,使用户无需额外硬件即可轻松加载、调

试和测试应用程序。凭借低功耗特性、增强的内存能力以及内置调试工具,32L496GDISCOVERY 套件是开发先进嵌入式系统、实现高效能解决方案的理想选择。

Discovery kit with STM32L496AG MCU double side image

微控制器概述 

MCU卡片 / MCU

STM32L496AG Image

建筑

ARM Cortex-M4

MCU 内存 (KB)

1024

硅供应商

STMicroelectronics

引脚数

169

RAM (字节)

327680

使用的MCU引脚

mikroBUS™映射器

Analog Output
PA4
AN
NC
NC
RST
SPI Chip Select
PG11
CS
SPI Clock
PI1
SCK
SPI Data OUT
PD3
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Sensor Heater Enable
PA0
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Ammonia Click Schematic schematic

一步一步来

项目组装

Discovery kit with STM32H750XB MCU front image hardware assembly

从选择您的开发板和Click板™开始。以Discovery kit with STM32L496AG MCU作为您的开发板开始。

Discovery kit with STM32H750XB MCU front image hardware assembly
Thermo 21 Click front image hardware assembly
Prog-cut hardware assembly
Thermo 21 Click complete accessories setup image hardware assembly
Board mapper by product7 hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Discovery kit with STM32H750XB MCU NECTO MCU Selection Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto image step 11 hardware assembly

软件支持

库描述

该库包含 Ammonia Click 驱动程序的 API。

关键功能:

  • ammonia_heater - 传感器加热功能

  • ammonia_data_read - 读取数据功能

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * \file
 * \brief Ammonia Click example
 *
 * # Description
 * This example shows the value of ammonia measurement aquired from Ammonia Click board.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Calls functions for driver initializaton used for data conversion and results reading.
 *
 * ## Application Task
 * Reads the level of ammonia in the air every with repetition of 1 second.
 * This driver is able to get the level of ammonia gas in the range from 5 to 200 ppm.
 * #note#
 * Be sure that you correctly set the AD convertor which you want to use.
 *
 * \author Nemanja Medakovic
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "ammonia.h"

// ------------------------------------------------------------------ VARIABLES

static ammonia_t ammonia;
static log_t logger;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init... ----" );

    ammonia_cfg_t ammonia_cfg;

    //  Click initialization.

    ammonia_cfg_setup( &ammonia_cfg );
    AMMONIA_MAP_MIKROBUS( ammonia_cfg, MIKROBUS_1 );

    if ( ammonia_init( &ammonia, &ammonia_cfg ) == AMMONIA_INIT_ERROR )
    {
        log_info( &logger, "---- Application Init Error. ----" );
        log_info( &logger, "---- Please, run program again... ----" );

        for ( ; ; );
    }

    log_info( &logger, "---- Application Init Done. ----\n" );
}

void application_task ( void )
{
    uint16_t nh3_ppm;

    if ( ammonia_read_measurement( &ammonia, &nh3_ppm ) == AMMONIA_OK )
    {
        log_printf( &logger, "  NH3 [ppm] : %u\r\n", nh3_ppm );
        Delay_ms ( 1000 );
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。