We’re excited to announce the launch of our latest library, AvantAnalogRead! Following the release of our digital input library, AvantDigitalRead, we’re taking another step forward in simplifying and enhancing your ESP32 projects. This time, we’re focusing on the often complex world of analog inputs.
Just like AvantDigitalRead made handling buttons and digital sensors a breeze, AvantAnalogRead is here to transform how you work with potentiometers, analog sensors, and variable resistors. Say goodbye to messy analog input code and hello to clean, reliable, and feature-rich data acquisition!
Why AvantAnalogRead?
If you’ve ever tried to read data from a potentiometer or an analog sensor on an ESP32, you know it can be tricky. Noise, unstable readings, and false triggers can make your project unreliable. AvantAnalogRead solves these problems by providing a powerful, yet easy-to-use library that handles the heavy lifting for you.
Whether you’re building a smart home controller, a robotics platform, or an IoT sensor node, AvantAnalogRead gives you the tools to manage analog inputs with confidence and precision.
Key Features That Make a Difference
AvantAnalogRead is packed with features designed to make analog input management as smooth as possible:
- Multi-pin Management: Dynamically add and remove pins for unified control over multiple analog inputs.
- Built-in Debouncing: Customizable debounce time to ensure stable and reliable readings.
- Smart Threshold Detection: Configurable thresholds with gap control to prevent false triggers.
- Software Filtering: Built-in moving average filter to reduce noise and smooth out your data.
- Rich Event Detection: Detects value changes, rising/falling trends, and threshold crossings.
- Non-blocking Design: Keeps your main program flow running smoothly.
- Unified Callback System: Simplifies your code with a consistent and intuitive API.
A Quick Example
Imagine you’re building a custom user interface with potentiometer to control various settings. Without AvantAnalogRead, you’d need to write complex code to handle noise, debouncing, and event detection for each pin. With AvantAnalogRead, it’s as simple as:
#include <AvantAnalogRead.h>
// Create AvantAnalogRead object to handle analog input monitoring
AvantAnalogRead analogReader;
void setup() {
// Initialize serial communication at 115200 baud rate
Serial.begin(115200);
delay(1000); // Wait for serial to stabilize
// Print example title and separator
Serial.println("AvantAnalogRead Library Example: Using onChange function");
Serial.println("=====================================");
// Initialize pin 33 for analog input monitoring
if (analogReader.addPin(33)) {
Serial.println("Pin 33 initialization successful!");
// Set debounce time to 100 milliseconds to prevent rapid successive triggers
analogReader.setDebounceTime(33, 100);
// Set threshold gap to 30 to avoid triggering events with minor fluctuations
// This means the value must change by at least 30 units to trigger an event
analogReader.setThresholdGap(33, 30);
// Enable software filtering to reduce noise (filter size of 5)
// This averages multiple readings to provide more stable values
if (analogReader.enableFilter(33, 5)) {
Serial.println("Software filtering enabled for pin 33!");
} else {
Serial.println("Failed to enable software filtering for pin 33!");
}
// Register onChange callback function to be called when pin value changes
// The callback will be triggered when the value changes beyond the threshold
if (analogReader.onChange(33, onPinChange)) {
Serial.println("onChange callback function registered successfully!");
} else {
Serial.println("onChange callback function registration failed!");
}
} else {
Serial.println("Pin 33 initialization failed!");
}
Serial.println("Starting to monitor analog input on pin 33...");
Serial.println("=====================================");
}
void loop() {
// Update all pin states and detect events
analogReader.update();
// Read and display current value once per second (for demonstration only, adjust as needed in actual applications)
// This helps visualize the current analog value but is not required for the onChange functionality
static unsigned long lastPrintTime = 0;
if (millis() - lastPrintTime >= 1000) {
int currentValue = analogReader.readPin(33);
if (currentValue >= 0) {
Serial.printf("Current pin 33 reading: %d\n", currentValue);
} else {
Serial.println("Failed to read pin 33!");
}
lastPrintTime = millis();
}
// Short delay to avoid excessive CPU usage
delay(10);
}
// Callback function: Called when pin value changes beyond the threshold
// This function is automatically triggered when the analog value changes by more than the threshold gap
// Parameters:
// pin: The pin number that triggered the event
// value: The current analog value (0-4095)
// event: The type of event that occurred
void onPinChange(int pin, int value, EventType event) {
Serial.printf("Pin %d value changed! Current value: %d", pin, value);
Serial.println();
}This code sets up a pin, handles debouncing and filtering, and detects value changes—all with minimal effort. It’s the analog counterpart to the simplicity you loved in AvantDigitalRead!
Perfect for Your Creative Projects
AvantAnalogRead is ideal for a wide range of applications:
- Interactive User Interfaces: Create smooth, responsive controls with potentiometers.
- Sensor Data Acquisition: Read analog sensors (like temperature, light, or pressure) with confidence.
- IoT Devices: Send stable, filtered data to the cloud or a local broker.
- Robotics: Read analog feedback from sensors and actuators.
- AI & Machine Learning: Provide clean data streams for edge computing projects.
Get Started Today!
Ready to elevate your ESP32 analog input game? Getting started with AvantAnalogRead is easy:
- Manual Installation: Download the ZIP from our GitHub repository and add it to your IDE.
- Direct Integration: Copy the source files into your project folder.
We’ve included a variety of example sketches to get you up and running quickly, from basic value monitoring to complex IoT integrations.
What’s Next?
AvantAnalogRead is just the beginning. We’re already working on exciting new features, including enhanced filtering options and deeper integration with our other libraries like AvantDigitalRead and AvantPinSet. Stay tuned for upcoming tutorials where we’ll showcase real-world projects, from smart home automation to AI-driven sensor networks.
We can’t wait to see what amazing projects you’ll create with AvantAnalogRead. Got ideas for new features or cool builds? Share them with us on GitHub or drop us a line!
Happy Making!











