MyLD2410 Library
Loading...
Searching...
No Matches
MyLD2410 Class Reference

Classes

struct  SensorData
 
struct  ValuesArray
 

Public Types

enum  Response { FAIL = 0 , ACK , DATA }
 

Public Member Functions

 MyLD2410 (Stream &serial, bool debug=false)
 Construct a new MyLD2410 object.
 
bool begin ()
 Call this function in setup() to ascertain whether the device is responding.
 
void end ()
 Call this function to gracefully close the sensor. Useful for entering sleep mode.
 
void debugOn ()
 Set the debug flag.
 
void debugOff ()
 Reset the debug flag.
 
Response check ()
 Call this function in the main loop.
 
bool inConfigMode ()
 Check whether the device is in config mode (accepts commands)
 
bool inBasicMode ()
 Check whether the device is in basic mode (continuously sends basic presence data)
 
bool inEnhancedMode ()
 Check whether the device is in enhanced mode (continuously sends enhanced presence data)
 
byte getStatus ()
 Get the status of the sensor: 0 - No presence; 1 - Moving only; 2 - Stationary only; 3 - Both moving and stationary; 4 - Auto thresholds in progress; 5 - Auto thresholds successful; 6 - Auto thresholds failed; 255 - The sensor status is invalid.
 
const char * statusString ()
 Get the presence status as a c-string.
 
bool presenceDetected ()
 Check whether presence was detected in the latest frame.
 
bool stationaryTargetDetected ()
 Check whether a stationary target was detected in the latest frame.
 
unsigned long stationaryTargetDistance ()
 Get the distance to the stationary target in [cm].
 
byte stationaryTargetSignal ()
 Get the signal from the stationary target.
 
const ValuesArraygetStationarySignals ()
 Get the Stationary Signals object, if in enhanced mode.
 
bool movingTargetDetected ()
 Check whether a moving target was detected in the latest frame.
 
unsigned long movingTargetDistance ()
 Get the distance to the moving target in [cm].
 
byte movingTargetSignal ()
 Get the signal from the moving target.
 
const ValuesArraygetMovingSignals ()
 Get the Moving Signals object, if in enhanced mode.
 
unsigned long detectedDistance ()
 Get the detected distance.
 
const byte * getMAC ()
 Get the Bluetooth MAC address as an array byte[6].
 
String getMACstr ()
 Get the Bluetooth MAC address as a String.
 
String getFirmware ()
 Get the Firmware as a String.
 
byte getFirmwareMajor ()
 Get the Firmware Major.
 
byte getFirmwareMinor ()
 Get the Firmware Minor.
 
unsigned long getVersion ()
 Get the protocol version.
 
const SensorDatagetSensorData ()
 Get the SensorData object.
 
byte getResolution ()
 Get the sensor resolution (gate-width) in [cm].
 
const ValuesArraygetMovingThresholds ()
 Get the detection thresholds for moving targets.
 
const ValuesArraygetStationaryThresholds ()
 Get the detection thresholds for stationary targets.
 
byte getRange ()
 Get the maximum detection gate.
 
unsigned long getRange_cm ()
 Get the maximum detection range in [cm].
 
byte getNoOneWindow ()
 Get the time-lag of "no presence" in [s]. The sensor begins reporting "no presence" only after no motion has been detected for that many seconds.
 
bool configMode (bool enable=true)
 Request config mode.
 
bool enhancedMode (bool enable=true)
 Request enhanced mode.
 
bool requestAuxConfig ()
 Request the current auxiliary configuration.
 
bool autoThresholds (byte _timeout=10)
 Begin the automatic threshold detection routine (firmware >= 2.44)
 
AutoStatus getAutoStatus ()
 Get the status of the automatic threshold detection routine (firmware >= 2.44)
 
bool requestMAC ()
 Request the Bluetooth MAC address.
 
bool requestFirmware ()
 Request the Firmware.
 
bool requestResolution ()
 Request the resolution (gate-width)
 
bool setResolution (bool fine=false)
 Set the resolution of the sensor.
 
bool requestParameters ()
 Request the sensor parameters: range, motion thresholds, stationary thresholds, no-one window.
 
bool setGateParameters (byte gate, byte movingThreshold, byte stationaryThreshold)
 Set the gate parameters for a particular gate, or for all gates at once.
 
bool setMovingThreshold (byte gate, byte movingThreshold)
 Set the moving target threshold for a particular gate.
 
bool setStationaryThreshold (byte gate, byte stationaryThreshold)
 Set the stationary target threshold for a particular gate.
 
bool setGateParameters (const ValuesArray &moving_thresholds, const ValuesArray &stationary_thresholds, byte noOneWindow=5)
 Set the parameters for all gates at once, as well as the no-one window.
 
bool setMaxGate (byte movingGate, byte stationaryGate, byte noOneWindow=5)
 Set the detection range for moving targets, stationary targets, as well as the no-one window.
 
bool setNoOneWindow (byte noOneWindow)
 Set the no-one window parameter.
 
bool setMaxMovingGate (byte movingGate)
 Set the maximum moving gate.
 
bool setMaxStationaryGate (byte stationaryGate)
 Set the maximum stationary gate.
 
byte getMaxMovingGate ()
 Get the maximum moving gate.
 
byte getMaxStationaryGate ()
 Get the maximum stationary gate.
 
bool requestReset ()
 Request reset to factory default parameters.
 
bool requestReboot ()
 Request reboot.
 
bool requestBTon ()
 Turn Bluetooth ON.
 
bool requestBToff ()
 Turn Bluetooth OFF.
 
bool setBTpassword (const char *passwd)
 Set a new BT password.
 
bool setBTpassword (const String &passwd)
 Set a new BT password.
 
bool resetBTpassword ()
 Reset the BT password.
 
bool setBaud (byte baud)
 Reset the serial baud rate. The sensor reboots at the new rate on success.
 
byte getLightLevel ()
 Get the Light Level.
 
LightControl getLightControl ()
 Get the Light Control parameter.
 
bool setAuxControl (LightControl light_control, byte light_threshold, OutputControl output_control)
 Set the Auxiliary Control parameters.
 
bool resetAuxControl ()
 Reset the Auxiliary Control parameters to their default values.
 
byte getLightThreshold ()
 Get the Light Threshold.
 
OutputControl getOutputControl ()
 Get the Output Control parameter.
 
byte getOutLevel ()
 Get the Light Level.
 

Constructor & Destructor Documentation

◆ MyLD2410()

MyLD2410::MyLD2410 ( Stream & serial,
bool debug = false )

Construct a new MyLD2410 object.

Construct from a serial stream object.

Parameters
serial- a reference to a stream object (sensorSerial)
debug- a flag that controls whether debug data will be sent to Serial

Member Function Documentation

◆ autoThresholds()

bool MyLD2410::autoThresholds ( byte _timeout = 10)

Begin the automatic threshold detection routine (firmware >= 2.44)

Parameters
_timeout- allow for timeout [s] to leave the room
Returns
true on success

◆ check()

MyLD2410::Response MyLD2410::check ( )

Call this function in the main loop.

Returns
MyLD2410::DATA = (evaluates to true) if the latest frame contained data
MyLD2410::ACK = (evaluates to true) if the latest frame contained a reply to a command
MyLD2410::FAIL = (evaluates to false) if no useful info was processed

◆ configMode()

bool MyLD2410::configMode ( bool enable = true)

Request config mode.

Parameters
enable[true]/false
Returns
true on success

◆ detectedDistance()

unsigned long MyLD2410::detectedDistance ( )

Get the detected distance.

Returns
unsigned long - distance in [cm]

◆ enhancedMode()

bool MyLD2410::enhancedMode ( bool enable = true)

Request enhanced mode.

Parameters
enable[true]/false
Returns
true on success

◆ getAutoStatus()

AutoStatus MyLD2410::getAutoStatus ( )

Get the status of the automatic threshold detection routine (firmware >= 2.44)

Returns
AutoStatus

◆ getFirmware()

String MyLD2410::getFirmware ( )

Get the Firmware as a String.

Returns
String

◆ getFirmwareMajor()

byte MyLD2410::getFirmwareMajor ( )

Get the Firmware Major.

Returns
byte

◆ getFirmwareMinor()

byte MyLD2410::getFirmwareMinor ( )

Get the Firmware Minor.

Returns
byte

◆ getLightControl()

LightControl MyLD2410::getLightControl ( )

Get the Light Control parameter.

Returns
LightControl enum

◆ getLightLevel()

byte MyLD2410::getLightLevel ( )

Get the Light Level.

Returns
byte

◆ getLightThreshold()

byte MyLD2410::getLightThreshold ( )

Get the Light Threshold.

Returns
byte

◆ getMAC()

const byte * MyLD2410::getMAC ( )

Get the Bluetooth MAC address as an array byte[6].

Returns
const byte*

◆ getMACstr()

String MyLD2410::getMACstr ( )

Get the Bluetooth MAC address as a String.

Returns
String

◆ getMaxMovingGate()

byte MyLD2410::getMaxMovingGate ( )

Get the maximum moving gate.

Returns
the maximum moving-target gate

◆ getMaxStationaryGate()

byte MyLD2410::getMaxStationaryGate ( )

Get the maximum stationary gate.

Returns
the maximum stationary-target gate

◆ getMovingSignals()

const MyLD2410::ValuesArray & MyLD2410::getMovingSignals ( )

Get the Moving Signals object, if in enhanced mode.

Returns
const MyLD2410::ValuesArray& - the signals for each detection gate

◆ getMovingThresholds()

const MyLD2410::ValuesArray & MyLD2410::getMovingThresholds ( )

Get the detection thresholds for moving targets.

Returns
const ValuesArray&

◆ getNoOneWindow()

byte MyLD2410::getNoOneWindow ( )

Get the time-lag of "no presence" in [s]. The sensor begins reporting "no presence" only after no motion has been detected for that many seconds.

Returns
byte

◆ getOutLevel()

byte MyLD2410::getOutLevel ( )

Get the Light Level.

Returns
byte

◆ getOutputControl()

OutputControl MyLD2410::getOutputControl ( )

Get the Output Control parameter.

Returns
OutputControl enum

◆ getRange()

byte MyLD2410::getRange ( )

Get the maximum detection gate.

Returns
byte

◆ getRange_cm()

unsigned long MyLD2410::getRange_cm ( )

Get the maximum detection range in [cm].

Returns
unsigned long

◆ getResolution()

byte MyLD2410::getResolution ( )

Get the sensor resolution (gate-width) in [cm].

Returns
byte either 20 or 75 on success, 0 on failure

◆ getSensorData()

const MyLD2410::SensorData & MyLD2410::getSensorData ( )

Get the SensorData object.

Returns
const SensorData&

◆ getStationarySignals()

const MyLD2410::ValuesArray & MyLD2410::getStationarySignals ( )

Get the Stationary Signals object, if in enhanced mode.

Returns
const MyLD2410::ValuesArray& - the signals for each detection gate

◆ getStationaryThresholds()

const MyLD2410::ValuesArray & MyLD2410::getStationaryThresholds ( )

Get the detection thresholds for stationary targets.

Returns
const ValuesArray&

◆ getStatus()

byte MyLD2410::getStatus ( )

Get the status of the sensor: 0 - No presence; 1 - Moving only; 2 - Stationary only; 3 - Both moving and stationary; 4 - Auto thresholds in progress; 5 - Auto thresholds successful; 6 - Auto thresholds failed; 255 - The sensor status is invalid.

Returns
byte

◆ getVersion()

unsigned long MyLD2410::getVersion ( )

Get the protocol version.

Returns
unsigned long

◆ movingTargetDistance()

unsigned long MyLD2410::movingTargetDistance ( )

Get the distance to the moving target in [cm].

Returns
unsigned long - distance in [cm]

◆ movingTargetSignal()

byte MyLD2410::movingTargetSignal ( )

Get the signal from the moving target.

Returns
byte - signal value [0 - 100]

◆ requestAuxConfig()

bool MyLD2410::requestAuxConfig ( )

Request the current auxiliary configuration.

Returns
true on success

◆ requestBToff()

bool MyLD2410::requestBToff ( )

Turn Bluetooth OFF.

Returns
true on success

◆ requestBTon()

bool MyLD2410::requestBTon ( )

Turn Bluetooth ON.

Returns
true on success

◆ requestFirmware()

bool MyLD2410::requestFirmware ( )

Request the Firmware.

Returns
true on success

◆ requestMAC()

bool MyLD2410::requestMAC ( )

Request the Bluetooth MAC address.

Returns
true on success

◆ requestParameters()

bool MyLD2410::requestParameters ( )

Request the sensor parameters: range, motion thresholds, stationary thresholds, no-one window.

Returns
true on success

◆ requestReboot()

bool MyLD2410::requestReboot ( )

Request reboot.

Returns
true on success

◆ requestReset()

bool MyLD2410::requestReset ( )

Request reset to factory default parameters.

Returns
true on success

◆ requestResolution()

bool MyLD2410::requestResolution ( )

Request the resolution (gate-width)

Returns
true on success

◆ resetAuxControl()

bool MyLD2410::resetAuxControl ( )

Reset the Auxiliary Control parameters to their default values.

Returns
true on success

◆ resetBTpassword()

bool MyLD2410::resetBTpassword ( )

Reset the BT password.

Returns
true on success

◆ setAuxControl()

bool MyLD2410::setAuxControl ( LightControl light_control,
byte light_threshold,
OutputControl output_control )

Set the Auxiliary Control parameters.

Parameters
light_control
light_threshold
output_control
Returns
true on success

◆ setBaud()

bool MyLD2410::setBaud ( byte baud)

Reset the serial baud rate. The sensor reboots at the new rate on success.

Returns
true on success

◆ setBTpassword() [1/2]

bool MyLD2410::setBTpassword ( const char * passwd)

Set a new BT password.

The BT password must be 6 characters long. If the string is shorter, it will be padded with spaces '\20'. If it is longer, only the first 6 characters will be used.

Parameters
passwdc-string
Returns
true on success

◆ setBTpassword() [2/2]

bool MyLD2410::setBTpassword ( const String & passwd)

Set a new BT password.

The BT password must be 6 characters long. If the string is shorter, it will be padded with spaces '\20'. If it is longer, only the first 6 characters will be used.

Parameters
passwdArduino String
Returns
true on success

◆ setGateParameters() [1/2]

bool MyLD2410::setGateParameters ( byte gate,
byte movingThreshold,
byte stationaryThreshold )

Set the gate parameters for a particular gate, or for all gates at once.

Parameters
gatethe gate to configure; pass a value greater than 8 (e.g 0xFF) to apply the same thresholds to all gates
movingThreshold[0 - 100]
stationaryThreshold[0 - 100]
Returns
true on success

◆ setGateParameters() [2/2]

bool MyLD2410::setGateParameters ( const ValuesArray & moving_thresholds,
const ValuesArray & stationary_thresholds,
byte noOneWindow = 5 )

Set the parameters for all gates at once, as well as the no-one window.

Parameters
moving_thresholdsas a ValueArray
stationary_thresholdsas a ValueArray
noOneWindow
Returns
true on success

◆ setMaxGate()

bool MyLD2410::setMaxGate ( byte movingGate,
byte stationaryGate,
byte noOneWindow = 5 )

Set the detection range for moving targets, stationary targets, as well as the no-one window.

Parameters
movingGate
stationaryGate
noOneWindow
Returns
true on success

◆ setMaxMovingGate()

bool MyLD2410::setMaxMovingGate ( byte movingGate)

Set the maximum moving gate.

Parameters
movingGate
Returns
true on success

◆ setMaxStationaryGate()

bool MyLD2410::setMaxStationaryGate ( byte stationaryGate)

Set the maximum stationary gate.

Parameters
stationaryGate
Returns
true on success

◆ setMovingThreshold()

bool MyLD2410::setMovingThreshold ( byte gate,
byte movingThreshold )

Set the moving target threshold for a particular gate.

Parameters
gatethe gate to configure [0 - 8]
movingThreshold[0 - 100]
Returns
true on success

◆ setNoOneWindow()

bool MyLD2410::setNoOneWindow ( byte noOneWindow)

Set the no-one window parameter.

Parameters
noOneWindowin [s]
Returns
true on success

◆ setResolution()

bool MyLD2410::setResolution ( bool fine = false)

Set the resolution of the sensor.

Parameters
finetrue=20cm; [false]=75cm
Returns
true on success

◆ setStationaryThreshold()

bool MyLD2410::setStationaryThreshold ( byte gate,
byte stationaryThreshold )

Set the stationary target threshold for a particular gate.

Parameters
gatethe gate to configure [0 - 8]
stationaryhreshold[0 - 100]
Returns
true on success

◆ stationaryTargetDistance()

unsigned long MyLD2410::stationaryTargetDistance ( )

Get the distance to the stationary target in [cm].

Returns
unsigned long - distance in [cm]

◆ stationaryTargetSignal()

byte MyLD2410::stationaryTargetSignal ( )

Get the signal from the stationary target.

Returns
byte - signal value [0 - 100]

◆ statusString()

const char * MyLD2410::statusString ( )

Get the presence status as a c-string.

Returns
const char* : "No target", "Moving only", "Stationary only", "Both moving and stationary", "Auto thresholds in progress", "Auto thresholds successful", "Auto thresholds failed".

The documentation for this class was generated from the following files: