AutoFuzzy is a powerful and flexible Arduino library that provides automated fuzzy logic capabilities with self-optimizing features. The library is designed to simplify the implementation of fuzzy logic controllers while offering advanced features for optimization and automation.
- Easy-to-use API for fuzzy logic implementation
- Support for multiple input and output variables
- Triangular and trapezoidal membership functions
- Automated parameter optimization using genetic algorithms
- Up to 10 variables (inputs + outputs)
- Up to 5 membership functions per variable
- Up to 50 fuzzy rules
- Memory-efficient implementation
- Built-in constraint handling
- Real-time evaluation capabilities
- Download the library as a ZIP file
- In the Arduino IDE, go to Sketch > Include Library > Add .ZIP Library
- Select the downloaded ZIP file
- Restart the Arduino IDE
#include <AutoFuzzy.h>
AutoFuzzy fuzzy;
// Add input variable (name, min value, max value)
fuzzy.addInput("temperature", 0, 100);
// Add output variable (name, min value, max value)
fuzzy.addOutput("fan_speed", 0, 255);
// Triangular membership function (variable, name, left, center, right)
fuzzy.addTriangularMF("temperature", "cold", 0, 20, 40);
fuzzy.addTriangularMF("temperature", "hot", 60, 80, 100);
// Trapezoidal membership function (variable, name, left, left-center, right-center, right)
fuzzy.addTrapezoidalMF("fan_speed", "slow", 0, 0, 50, 127);
fuzzy.addTrapezoidalMF("fan_speed", "fast", 127, 200, 255, 255);
fuzzy.addRule("temperature", "cold", "fan_speed", "slow");
fuzzy.addRule("temperature", "hot", "fan_speed", "fast");
// Optional: Run optimization (iterations)
fuzzy.autoOptimize(100);
// Evaluate input and get output
float temp = analogRead(A0) * 100.0 / 1023.0;
float fanSpeed = fuzzy.evaluate(&temp);
Controls LED brightness based on ambient light level.
// See examples/SimpleLED/SimpleLED.ino
Automated watering system based on soil moisture and temperature.
// See examples/PlantWatering/PlantWatering.ino
Advanced temperature and humidity control with energy optimization.
// See examples/HVACControl/HVACControl.ino
fuzzy.addInput("temperature", 0, 100);
fuzzy.addInput("humidity", 0, 100);
fuzzy.addOutput("fan_speed", 0, 255);
// Evaluate multiple inputs
float inputs[] = {temperature, humidity};
float fanSpeed = fuzzy.evaluate(inputs);
The autoOptimize()
function uses a genetic algorithm to optimize membership function parameters:
// Default optimization
fuzzy.autoOptimize(100); // 100 iterations
// The optimization process:
// 1. Randomly adjusts membership function parameters
// 2. Maintains valid ranges and relationships
// 3. Preserves system stability
// 4. Improves response based on built-in fitness function
- Each variable: ~32 bytes
- Each membership function: ~24 bytes
- Each rule: ~4 bytes
- Maximum memory usage with default settings: ~1KB
- Maximum 10 variables (combined inputs and outputs)
- Maximum 5 membership functions per variable
- Maximum 50 rules
- No support for custom membership function shapes
- Single output evaluation per call
- Evaluation time increases linearly with number of rules
- Optimization process can take significant time
- Consider reducing iteration count for faster optimization
- Memory usage increases with number of variables and rules
-
System not responding:
- Check if variables are within defined ranges
- Verify rule definitions
- Ensure proper connection between inputs and outputs
-
Unexpected behavior:
- Verify membership function overlap
- Check rule consistency
- Validate input scaling
-
Memory issues:
- Reduce number of variables/rules
- Optimize membership function count
- Consider using PROGMEM for constant data
-
System Design:
- Start with simple systems and gradually add complexity
- Use appropriate ranges for variables
- Ensure smooth overlap between membership functions
- Design rules to cover all possible scenarios
-
Optimization:
- Run optimization during setup if possible
- Use appropriate iteration count for your application
- Monitor system performance after optimization
- Consider periodic re-optimization for dynamic systems
-
Memory Management:
- Use minimum necessary membership functions
- Optimize rule count
- Clean up unused variables and rules
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
This library is released under the MIT License. See the LICENSE file for details.
For bugs, feature requests, and discussions:
- Open an issue on GitHub
- Contact: https://azzar.netlify.app
- 1.0.0 (2024-12-13)
- Initial release
- Basic fuzzy logic functionality
- Automated optimization features
- Example projects
- Support for custom membership function shapes
- Advanced optimization algorithms
- Multiple output evaluation
- Enhanced data logging and analysis tools