This is an old revision of the document!
As an Arduino enthusiast, I find this project to be both challenging and rewarding. Not only do you get to create a useful device, but you also gain a deeper understanding of Arduino programming and electronics. Building Sweet Sort is a great way to expand your skillset and showcase your creativity.
With just one TCS230 color sensor and two SG90 servomotors, you can easily sort candies based on their color. The machine operates by moving the candy from the main container to the sensor and then to its designated container based on its color. To make the sorting process even more seamless, the machine comes equipped with an LCD screen with I2C Interface that displays the color of each candy. Additionally, an auditory alert system in the form of a buzzer will notify you when a candy has been successfully sorted. The project also features RGB LEDs that illuminate to display the color of the candy.
For the box I used a 2.5mm thick MDF board
The code is an Arduino sketch that controls a candy sorting machine using a color sensor, servomotors, and an LCD display. Here's an explanation of the code:
1. Libraries: The code includes two libraries: Servo.h for controlling the servomotors and LiquidCrystal_I2C.h for interfacing with the LCD display.
2. Pin Definitions: Various pins are defined using the #define directive for easy reference throughout the code. These pins are used to connect the color sensor, servomotors, RGB LED, buzzer, and LCD display.
3. Global Variables: The code defines several global variables to store calibration values, pulse width measurements, and the number of candies sorted for each color.
4. Setup Function: The setup() function is executed once at the beginning of the program. It initializes the serial communication, attaches the servomotors, sets pin modes, initializes the LCD, and sets the initial position for the top servomotor.
5. Loop Function: The loop() function is executed repeatedly after the setup() function. It controls the main operation of the candy sorting machine. The loop consists of the following steps:
a. Removing Candies: The top servomotor rotates from position 10 to 100, causing the candies to fall out of the tube. The delay of 15 ms after each position change allows the servomotor to reach the desired position.
b. Color Sensing: The top servomotor rotates from the maximum position (TOP_MAX) to the minimum position (TOP_MIN) while checking the color of the candy in front of the color sensor. When the servomotor reaches the position (SENSOR_POS) in front of the color sensor, it stabilizes for 1 second and reads the pulse widths of the red, green, and blue components using the color sensor.
c. Color Classification: The pulse width values are compared with the calibrated minimum and maximum values for each color (red, green, and blue). If a candy matches the color criteria, the corresponding RGB LED values, sound tone, and position for the bottom servomotors are set, and the count for that color is incremented.
d. LCD Display: The LCD is updated with the count of candies for each color.
e. RGB LED Control: The RGB LED is controlled by analogWrite() function, setting the appropriate values for the red, green, and blue pins based on the color of the candy being sorted.
6. Helper Functions: The code includes several helper functions:
getRedPW(), getGreenPW(), getBluePW(): These functions configure the color sensor to read the pulse width of a specific color (red, green, or blue) and return the measured pulse width value.
playTone(unsigned int frequency, unsigned long duration): This function plays a tone on the connected buzzer for a specific frequency and duration.
The code continuously repeats the loop, allowing the candy sorting machine to sort candies based on their colors and display the count on the LCD.
Fişierele se încarcă pe wiki folosind facilitatea Add Images or other files. Namespace-ul în care se încarcă fişierele este de tipul :pm:prj20??:c? sau :pm:prj20??:c?:nume_student (dacă este cazul). Exemplu: Dumitru Alin, 331CC → :pm:prj2009:cc:dumitru_alin.