ModularSensors > Modules > Supported Sensors > AOSong AM2315

AOSong AM2315 module

Classes for the AOSong AM2315 encased I2C capacitive humidity and temperature sensor.

Quick Notes

  • Applies to both the AOSong AM2315 and CM2311 capacitive relative humidity and temperature sensors
  • Depends on the Adafruit AM2315 Library.
  • Communicates via I2C
    • only one address possible, 0xB8
  • Only 1 can be connected to a single I2C bus at a time
  • Requires a 3.3 - 5.5V power source

Sensor Datasheet

Datasheet

Sensor Constructors

AOSongAM2315(int8_t powerPin, uint8_t measurementsToAverage = 1) explicit

Construct a new AOSongAM2315 object using the primary hardware I2C instance.

Parameters
powerPin

The pin on the mcu controlling power to the AOSong AM2315. Use -1 if it is continuously powered.

  • The AM2315 requires a 3.3 - 5.5V power source
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

Because this is I2C and has only 1 possible address (0xB8), we only need the power pin.


AOSongAM2315(TwoWire* theI2C, int8_t powerPin, uint8_t measurementsToAverage = 1)

Construct a new AOSongAM2315 object using a secondary hardware I2C instance.

Parameters
theI2C A TwoWire instance for I2C communication. Due to the limitations of the Arduino core, only a hardware I2C instance can be used. For an AVR board, there is only one I2C instance possible and this form of the constructor should not be used. For a SAMD board, this can be used if a secondary I2C port is created on one of the extra SERCOMs.
powerPin

The pin on the mcu controlling power to the AOSong AM2315. Use -1 if it is continuously powered.

  • The AM2315 requires a 3.3 - 5.5V power source
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

This is only applicable to SAMD boards that are able to have multiple hardware I2C ports in use via SERCOMs.


Example Code

The AM2315 is used in the double logger and menu a la carte example

#include <sensors/AOSongAM2315.h>

const int8_t AM2315Power = sensorPowerPin;  // Power pin (-1 if unconnected)

// Create an AOSong AM2315 sensor object
AOSongAM2315 am2315(AM2315Power);

// Create humidity and temperature variable pointers for the AM2315
Variable* am2315Humid =
    new AOSongAM2315_Humidity(&am2315, "12345678-abcd-1234-ef00-1234567890ab");
Variable* am2315Temp =
    new AOSongAM2315_Temp(&am2315, "12345678-abcd-1234-ef00-1234567890ab");

Classes

class AOSongAM2315
The Sensor sub-class for the AOSong AM2315.
class AOSongAM2315_Humidity
The Variable sub-class used for the relative humidity output from an AOSong AM2315.
class AOSongAM2315_Temp
The Variable sub-class used for the temperature output from an AOSong AM2315.

Defines

#define AM2315_NUM_VARIABLES = 2
Sensor::_numReturnedValues; the AM2315 can report 2 values.

Sensor Timing

The sensor timing for an AOSong AM2315

#define AM2315_WARM_UP_TIME_MS = 500
Sensor::_warmUpTime_ms; AM2315 warms up in 500ms (estimated).
#define AM2315_STABILIZATION_TIME_MS = 500
Sensor::_stabilizationTime_ms; AM2315 is stable after 500ms (estimated).
#define AM2315_MEASUREMENT_TIME_MS = 2000
Sensor::_measurementTime_ms; AM2315 takes 2000ms (2s) to complete a measurement.

Humidity

The humidity variable from an AOSong AM2315

  • Range is 0 to 100% RH
  • Accuracy is ± 2 % RH at 25°C

AOSongAM2315_Humidity(AOSongAM2315* parentSense, const char* uuid = "", const char* varCode = AM2315_HUMIDITY_DEFAULT_CODE) explicit

Construct a new AOSongAM2315_Humidity object.

Parameters
parentSense The parent AOSongAM2315 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "AM2315Humidity".

#define AM2315_HUMIDITY_RESOLUTION = 1
Decimals places in string representation; humidity should have 1 (0.1 % RH for the 16 bit sensor).
#define AM2315_HUMIDITY_VAR_NUM = 0
Sensor variable number; humidity is stored in sensorValues[0].
#define AM2315_HUMIDITY_VAR_NAME = "relativeHumidity"
Variable name in ODM2 controlled vocabulary; "relativeHumidity".
#define AM2315_HUMIDITY_UNIT_NAME = "percent"
Variable unit name in ODM2 controlled vocabulary; "percent" (percent relative humidity)
#define AM2315_HUMIDITY_DEFAULT_CODE = "AM2315Humidity"
Default variable short code; "AM2315Humidity".

Temperature

The temperature variable from an AOSong AM2315

  • Range is -40°C to +125°C
  • Accuracy is ±0.1°C

AOSongAM2315_Temp(AOSongAM2315* parentSense, const char* uuid = "", const char* varCode = AM2315_TEMP_DEFAULT_CODE) explicit

Construct a new AOSongAM2315_Temp object.

Parameters
parentSense The parent AOSongAM2315 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "AM2315Temp".

#define AM2315_TEMP_RESOLUTION = 1
Decimals places in string representation; temperature should have 1. (0.1°C for the 16 bit sensor)
#define AM2315_TEMP_VAR_NUM = 1
Sensor variable number; temperature is stored in sensorValues[1].
#define AM2315_TEMP_VAR_NAME = "temperature"
Variable name in ODM2 controlled vocabulary; "temperature".
#define AM2315_TEMP_UNIT_NAME = "degreeCelsius"
Variable unit name in ODM2 controlled vocabulary; "degreeCelsius" (°C)
#define AM2315_TEMP_DEFAULT_CODE = "AM2315Temp"
Default variable short code; "AM2315Temp".