ModularSensors > Classes > Sensor > MaxBotixSonar
ModularSensors > Modules > MaxBotix MaxSonar > MaxBotixSonar


MaxBotixSonar class

The Sensor sub-class for the MaxBotix ultrasonic range finders.

Base classes

class Sensor
The "Sensor" class is used for all sensor-level operations - waking, sleeping, and taking measurements.

Constructors, destructors, conversion operators

MaxBotixSonar(Stream* stream, int8_t powerPin, int8_t triggerPin = -1, uint8_t measurementsToAverage = 1)
Construct a new MaxBotix Sonar object.
MaxBotixSonar(Stream& stream, int8_t powerPin, int8_t triggerPin = -1, uint8_t measurementsToAverage = 1)
Construct a new MaxBotix Sonar object.
~MaxBotixSonar()
Destroy the MaxBotix Sonar object.

Public functions

String getSensorLocation(void ) override
Get the pin or connection location between the mcu and the sensor.
bool setup(void ) override
Do any one-time preparations needed before the sensor will be able to take readings.
bool wake(void ) override
Wake the sensor up, if necessary. Do whatever it takes to get a sensor in the proper state to begin a measurement.
bool addSingleMeasurementResult(void ) override
Get the results from a single measurement.

Function documentation

MaxBotixSonar(Stream* stream, int8_t powerPin, int8_t triggerPin = -1, uint8_t measurementsToAverage = 1)

Construct a new MaxBotix Sonar object.

Parameters
stream An Arduino data stream for TTL or RS232 communication. See notes for more information on what streams can be used.
powerPin

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

  • The MaxSonar requires a 2.7V - 5.5V power supply.
triggerPin The pin on the mcu controlling the "trigger" for the MaxSonar. Use -1 or omit for continuous ranging.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

MaxBotixSonar(Stream& stream, int8_t powerPin, int8_t triggerPin = -1, uint8_t measurementsToAverage = 1)

Construct a new MaxBotix Sonar object.

Parameters
stream An Arduino data stream for TTL or RS232 communication. See notes for more information on what streams can be used.
powerPin

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

  • The MaxSonar requires a 2.7V - 5.5V power supply.
triggerPin The pin on the mcu controlling the "trigger" for the MaxSonar. Use -1 or omit for continuous ranging.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

String getSensorLocation(void ) override

Get the pin or connection location between the mcu and the sensor.

Returns String Text describing how the sensor is attached to the mcu.

bool setup(void ) override

Do any one-time preparations needed before the sensor will be able to take readings.

Returns bool True if the setup was successful.

This sets pin mode on the trigger pin. It also sets the expected stream timeout for modbus and updates the _sensorStatus. No sensor power is required. This will always return true.


bool wake(void ) override

Wake the sensor up, if necessary. Do whatever it takes to get a sensor in the proper state to begin a measurement.

Returns bool True if the wake function completed successfully.

Verifies that the power is on and updates the _sensorStatus. This also sets the _millisSensorActivated timestamp.

For the MaxSonar, this also reads and dumps any returned "header" lines from the sensor.


bool addSingleMeasurementResult(void ) override

Get the results from a single measurement.

Returns bool True if the function completed successfully.

This asks the sensor for a new result, verifies that it passes sanity range checks, and then adds the value to the result array.

This also un-sets the _millisMeasurementRequested timestamp (sets _millisMeasurementRequested to 0) and updates the _sensorStatus.