Background
Due to the unreliable mounting of the servo motor, the smart bin was decommissioned in Jan 2025, after around 12 months of service. It has been a great experience in learning the microprocessor world through this project.
A smart bin was purchased from TaoBao in June 2022. However, after several months of operation, the open opration of the top cover was not effective due to the wear of the plastic gears of the driving motor. In order to avoid putting this bin into another rubbish bin, it was decided to replace the whole control mechanism to give it a second life!
The new control mechanism is based on ESP32C3 which is a RISC-V microprocessor.
Bin Dimesions and Original Components
Components
Most of the components used in this project were purchased from Taobao. Data sheets of these components can be found in the folders at DT16: Documents\Proj-IOT\01-SmartBin\
# Microprocessor
The processor is on the Xiao ESP32C3 development board from Seeed Studio which is costing only arund HK$40. Its architecture is based on the RISC-V.
# IR Controller
The smart bin is using Infra Red controller to detect the opening/closing of the bin cover. To meet the physical constraints, the IR emitter and receiver have to be separated from the PCB and connected via wiring.
# Servo Motor
The servo motor used is the AAS-380MAX from Alturn (made in Taiwan). This one has metal gear and more torque than the MG90S which was used in the first attempt. The MG90S failed to operate after serveral months of operation probably due to its plastic gearing.
# Switching Relay
To reduce the power consumption of the bin, the servo motor power supply is controlled by an optical relay. It is disconnected from power when the bin is idle so as to eliminate the idling current of the motor.
# Print Curcuit Board
State Machine
The smart bin is in fact run as a finite state machine (FSM). Based on the current state and a given input the machine performs state transitions and produces outputs. Below is the state diagram of the machine.
Circurit Diagram
Software Development
The development framework is the ESP-IDF which is the official framework from Expressif. The language used is mainly C and C++.
The software is developed using VS Code with the ESP-IDF plugin. Click here for more resources.
The source code can be found on DT16: Documents\Proj-IOT\01-SmartBin\80-swdev\02-dev
LED Status
| States | LED short (80ms), long (1s), very long (1.5s) |
|---|---|
| LID Closed (state 0) | 1-very long. low power: 3-short, 1-very long sleep: 2-short, 1-long |
| LID Ready (state 1) | no LED signal |
| LID Opening (state 2) | 8-short |
| LID Opened (state 3) | no LED signal |
| LID Opened Long (state 4) | 2-very long |
| LID Closing (state 5) | 8-short |
| BIN Mode Sleep (state 6) | 3-short, 1-long |
| BIN Mode Wake (state 7) | 3-short |
Points to Note
# 2023-10-18 @1246
Wasted a lot of time to debug the program and finally found that VSCode actually didn’t upload the firmward eventhough it displayed the upload was successful. This was solved after the Full Clean.
# 2023-06-30 @0230
On 30 Jun when trying to recompile the code, it was found that the IDF plugin had been updated automatically to the latest version. This has caused many files not find errors.
Adding the "REQUIRES driver" line to all CMakeLists.txt solved a few errors, but other errors are still there:
> 'gpio_pad_select_gpio' was not declared in this scope; did you mean 'esp_rom_gpio_pad_select_gpio'?
solution:
in the flashLED.cpp, added #include "esp_rom/esp_rom_gpio.h" and changed the command to esp_rom_gpio_pad_select_gpio()
> 'portTICK_RATE_MS' was not declared in this scope; did you mean 'portTICK_PERIOD_MS'?
Solution:
called up the SDK Config Editor > FreeRTOS. Enabled configENABLE_BACKWARD_COMPATIBILITY
Finally, all 'portTICK_RATE_MS' are replaced by 'portTICK_PERIOD_MS'.
> esp_timer.h: No such file or directory
solution:
this file is required in miscFuntions component. Added "REQUIRES esp_timer" in CMakeLists.txt for miscFuntions solved the problem.
This is caused by upgrading esp-idf from v4 to v5.0. Some default inclusions are removed and these components have to be included explicitly.
See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/release-5.x/5.0/build-system.html#specify-component-requirements-explicitly
> flashLED.h: No such file or directory
solution:
Added "PRIV_REQUIRES flashLED miscFunctions servoControl" to CMakeLists for main.
> #warning "legacy adc driver is deprecated, please migrate to use esp_adc/adc_oneshot.h and esp_adc/adc_continuous.h for oneshot mode and continuous mode drivers respectively" [-Wcpp]











