This project controls a derailleur using an ESP8266 microcontroller. The system allows for shifting gears via buttons and a web interface. The current gear and settings are saved to EEPROM to retain state between power cycles. The web interface now updates the current gear in real-time using WebSockets.
- ESP8266: The microcontroller used for Wi-Fi connectivity and control.
- Servo: Controls the derailleur position.
- Buttons: Used for shifting up and down.
- EEPROM: Stores the current gear and settings.
- Buzzer: Provides audio feedback for hotspot activation and deactivation.
- servoPin (D5): Connected to the servo motor.
- upButtonPin (D6): Connected to the button for shifting up.
- downButtonPin (D7): Connected to the button for shifting down.
- buzzerPin (D8): Connected to the buzzer.
- currentGear: Tracks the current gear.
- maxGear: Maximum gear limit. (up to 12)
- minGear: Minimum gear limit.
- currentPosition: Current servo position in degrees.
- gearCablePull: Array storing the cable pull in mm for each gear.
- ssid: Wi-Fi SSID for the hotspot.
- password: Password for the Wi-Fi hotspot.
- server: AsyncWebServer instance for handling web requests.
- webSocket: WebSocketsServer instance for real-time updates.
- hotspotActive: Boolean indicating if the hotspot is active.
The web interface allows users to:
- View the current gear position in real-time.
- Update gear cable pull settings.
- Update the maximum gear limit.
- Reset settings to default values.
- Shift gears using UP and DOWN buttons.
- Connect to the Wi-Fi hotspot: Use the SSID and password provided in the code.
- Open a web browser: Navigate to the default web server address:
http://192.168.4.1. - View current gear: The current gear position is displayed at the top of the page and updates in real-time.
- Update gear settings:
- On the main page, you will see a form with input fields for each gear.
- Enter the desired cable pull values (in mm) for each gear.
- Click the "Send" button next to each gear to save the new setting.
- The input field will turn green to indicate the setting has been sent.
- Update maximum gear limit:
- Change the value in the "Max Gear" input field.
- The new maximum gear limit will be saved automatically.
- Shift gears:
- Use the "UP" and "DOWN" buttons to shift gears.
- Reset to default settings:
- Click the "Reset to Default" link to reset all gear settings to their default values.
- Power on the device: The system initializes and moves the servo to the last saved gear position.
- Shift gears: Use the up and down buttons to shift gears.
- Activate the hotspot:
- Press both the up and down buttons for 3 seconds to activate the hotspot.
- The hotspot SSID is
DerailleurControland the password is12345678. - The buzzer will beep twice to indicate the hotspot is activated.
- Deactivate the hotspot:
- Press both the up and down buttons for 5 seconds to deactivate the hotspot.
- The buzzer will beep three times to indicate the hotspot is deactivated.
- Access the web interface: Connect to the Wi-Fi hotspot and navigate to the web server to update settings.
- Default web server address:
http://192.168.4.1
- Default web server address:
To compile and upload the code to the ESP8266, you need to install the following libraries:
- ESP8266WiFi: Provides Wi-Fi connectivity.
- ESPAsyncWebServer: Handles the web server functionality.
- EEPROM: Manages EEPROM read/write operations.
- Servo: Controls the servo motor.
- WebSocketsServer: Provides WebSocket functionality for real-time updates.
- ESP8266WiFi and EEPROM libraries are included with the ESP8266 core for Arduino. Install the ESP8266 core by following the instructions here.
- ESPAsyncWebServer:
- Install the ESPAsyncWebServer library from the Arduino Library Manager or download it from GitHub.
- Additionally, install the AsyncTCP library, which is a dependency for ESPAsyncWebServer.
- Servo:
- Install the Servo library from the Arduino Library Manager or download it from GitHub.
- WebSocketsServer:
- Install the WebSocketsServer library from the Arduino Library Manager or download it from GitHub.
Make sure to include these libraries in your Arduino IDE before compiling and uploading the code.