Easily read and calibrate analog sensor values with custom intervals and callbacks.
UltiBlox on GitHub | UltiBlox Home
The SensorAnalog library enables straightforward reading and calibration of analog sensors connected to Arduino boards. It includes customizable calibration ranges, periodic reading with user-defined intervals, and callbacks for handling data, with optional storage of calibration data in EEPROM for persistence.
- Custom Calibration Range: Define low and high calibration values to map sensor readings.
- Periodic Reading with Callbacks: Set an interval for automated sensor polling, with callback support.
- EEPROM Storage: Optionally store calibration values and intervals in EEPROM.
- Flexible Data Access: Read raw or calibrated sensor values as needed.
- Open the Arduino IDE.
- Go to Tools > Manage Libraries.
- Search for UltiBlox-SensorAnalog and click Install.
- Access example sketches under File > Examples > UltiBlox-SensorAnalog.
-
Clone the Repository:
git clone git@github.com:UltiBlox/SensorAnalog.git ~/workspace/SensorAnalog cd ~/workspace/SensorAnalog
-
Prepare the Environment: Run the
prepare.shscript to set up dependencies:bash prepare.sh
-
Install the Library:
- Copy Installation:
bash install.sh
- Symlink Installation (for active development):
bash install-symlink.sh
- Copy Installation:
-
Build Examples: Compile example sketches with:
bash build.sh
- EEPROM Library: Required for storing calibration data.
- Arduino Core Library
- SerialLogger: Enables serial output for logging sensor values.
- CallbackSensorReading.ino: Sets up periodic sensor reading with a callback function to log calibrated and raw values.
- ManualSensorReading.ino: Manually reads and logs both raw and calibrated sensor values.
init()Initializes the sensor, including setting the pin mode and loading any stored calibration values.
setCalibrationDefaultLow(int low)
setCalibrationDefaultHigh(int high)Sets default calibration values for the sensor. These values are loaded at startup if EEPROM does not contain stored calibration values.
setCalibrationLow(int low)
setCalibrationHigh(int high)Defines the low and high values for calibration mapping, saving these values to EEPROM for persistence.
loadCalibration()Loads calibration values from EEPROM if available.
setInterval(unsigned long interval)Sets the interval for periodic sensor reads, in milliseconds. The sensor will automatically read values at this interval.
onDataReceived(void (*callback)(int))Defines a callback function to be executed after each periodic sensor read. The callback receives the latest sensor reading as an argument.
setSampleSize(int size)Specifies the number of samples used in the smoothing algorithm. Larger sample sizes provide smoother outputs but reduce responsiveness to rapid changes. Smaller sample sizes result in less smoothing but greater responsiveness.
readRaw()Returns the raw sensor reading directly from the analog pin.
read()Returns the calibrated sensor reading, mapped to a scale from 0 to 100.