Introduction: Color Vending Machine
Have you ever thought while eating your favorite candy, which color should I pick? With the color vending machine this situation is simplified. Using the Pantone colors, you will be able to choose which you want to eat.
It’s is a small vending machine, that you can have at home, in your room, in the kitchen… wherever you want!
We have chosen three colors for our vending machine, yellow, green and blue, but feel free to use your favorites and as many as you want!
Step 1: Materials
To do the color vending machine you will need the following materials.
electronics
-Arduino One
-Wire Arduino-computer
-Color sensor TCS3200
-RGB Led
-Color leds: Green, Blue and Yellow
-3 Servomotor sg90
-Button
-Wires male-male and male-female
-7 Resistances (higher than 150Ohm)
prototype
-Wood
-Plastic transparent tubes (Ø35mm)
-Glue
-Welder
-Tin wire (for welding)
-Perforated plate
Step 2: Connecting the Color Sensor
This is the most important part of the system, as it is where everything starts. When the sensor reads the right color, the vending machine starts functioning.
Use the following diagram to carry out with the connections.
Step 3: Connecting the RGB Led
As the led is RGB, its light can have different colors depending on the code. It can have pure colors (Red, Green, and Blue) or combinations of those. As it has three colors, it requires three pins of the Arduino, to process the information of each channel. This connection requires a resistance for each channel (R, G and B), which has to be higher than 150Ohm. However, as the resistance value rises, the light intensity is reduced, so the recommended values are between 150-200Ohm. The pins that correspond to R, G and B have to be analog outputs.
This led turns on when a color is detected, and the light is the same as the Pantone card used. It will be turned on as long as the machine is functioning.
Use the following diagram to carry out with the connections.
Step 4: Connecting the Color Leds
The single color Leds connection is simpler than the RGB Led. In this case, the Leds only have two pins, one that goes to a digital output and the other connected to the GND. In this case, it is also necessary to use resistances.
The color leds will only turn on if their color is detected. Once this happen, they will blink for some seconds and then stay on while the machine is functioning.
Use the following diagram to carry out with the connections.
Step 5: Connecting the Servomotors
Connecting the servos might seem complicated but in fact is quite simple. Every motors has to be connected to the ground and the 5V channels, and it also needs to be connected to an analog output pin.
The servomotors are the ones that facilitate the droping of the candy. Each one corresponds to one color, so it will be activated when its color is detected.
Use the following diagram to carry out with the connections.
Step 6: Connecting the Button
The button is used to activate the system. The connection requires a resistance and a digital output pin.
Once te Pantone card is inserted, press the button so the vending machine can start working.
Use the following diagram to carry out with the connections.
Step 7: Prototype
The first thing we have made is the wood carcass. We have made the design using digital tools (AutoCad) and we have used a laser cut machine to carry out the pieces. The designed we have used is available in the "Laser expendedora" document, but feel free to design your own.
The next step was painting the wood parts and cutting the tubes with the desired length.
Finally, we have made the Pantone cards. The document "Pantone cards" contain the stencil we have used.
Step 8: Welding
The electronics were at first connected using a protoboard, but for the final prototype we have decided to weld them on a perforated plate to avoid that some wires get disconnected. It has been used a common welder and tin wire.
Step 9: Final Assembly
The last step was to carry out the assembly of the prototype parts with the electronics. In this stage, having clear ideas and everything organized is essential, otherwise it can turn to be a messy step. We have used regular glue for wood and silicone to join all the components.
To cover and protect all the wires, you can build a box to keep all of them in safe and hide.
Step 10: The Code
int S1 = 1;
int S2 = 2; int S3 = 8; int sensorOut = 7; int frequency = 0; int color = 0; const int LED_ROJO = 11; // Pin where we are connecting the RED leg of the RGB LED const int LED_VERDE = 9; // Pin where we are connecting the GREEN leg of the RGB LED const int LED_AZUL = 10; // Pin where we are connecting the BLUE leg of the RGB LED int Yellow = A0; // LED Yellow tube Pin int Blue = A2; // LED Blue tube Pin int Green = A1; // LED Green tube Pin #include ; Servo servo1; Servo servo2; Servo servo3; void setup() { // put your setup code here, to run once: Serial.begin(115200); pinMode(S0, OUTPUT); pinMode(S1, OUTPUT); pinMode(S2, OUTPUT); pinMode(S3, OUTPUT); pinMode(sensorOut, INPUT); //Where are the LED located pinMode(LED_ROJO, OUTPUT); pinMode(LED_VERDE, OUTPUT); pinMode(LED_AZUL, OUTPUT); servo1.attach(3); servo2.attach(5); servo3.attach(6); pinMode(Yellow, OUTPUT); pinMode(Green, OUTPUT); pinMode(Blue, OUTPUT); // Setting frequency-scaling to 20% digitalWrite(S0, HIGH); digitalWrite(S1, LOW); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: int button = digitalRead(4); if (button == LOW) { color = readColor(); //starts the function when the button is pressed delay(500); } //servos initial position on 0º servo1.write(0); servo2.write(0); servo3.write(0); Serial.println (button); } // Custom Function - readColor() //if (button == LOW) { int readColor() { // Setting red to be read digitalWrite(S2, LOW); digitalWrite(S3, LOW); // Reading the output frequency frequency = pulseIn(sensorOut, LOW); int R = frequency; // Printing the value on the serial monitor Serial.print("R= ");//printing name Serial.print(frequency);//printing RED color frequency Serial.print(" "); delay(500); // Setting Green to be read digitalWrite(S2, HIGH); digitalWrite(S3, HIGH); // Reading the output frequency frequency = pulseIn(sensorOut, LOW); int G = frequency; // Printing the value on the serial monitor Serial.print("G= ");//printing name Serial.print(frequency);//printing RED color frequency Serial.print(" "); delay(500); // Setting Blue to be read digitalWrite(S2, LOW); digitalWrite(S3, HIGH); // Reading the output frequency frequency = pulseIn(sensorOut, LOW); int B = frequency; // Printing the value on the serial monitor Serial.print("B= ");//printing name Serial.print(frequency);//printing RED color frequency Serial.println(" "); delay(500); if (R<50 & R>9 & G<20 & G>8 & B<25 & B>10) { //Adjust the ranks to your color. You can use the Monitor Serie to know the numbers the Color Sensor is reading. color = 1; // Green Serial.println("Color 1 detectat!"); analogWrite(LED_ROJO, 0); // If color == 'y' green led turns on analogWrite(LED_VERDE, 255); // analogWrite(LED_AZUL, 0); servo2.write(90); //servo moves to make the candy drop digitalWrite(Green, HIGH); //tube led blink 4 times delay(200); digitalWrite(Green, LOW); delay(200); digitalWrite(Green, HIGH); delay(200); digitalWrite(Green, LOW); delay(200); digitalWrite(Green, HIGH); delay(200); digitalWrite(Green, LOW); delay(200); digitalWrite(Green, HIGH); delay(200); digitalWrite(Green, LOW); delay(200); digitalWrite(Green, HIGH); delay(200); delay(4000); //duration of the functioning digitalWrite(Green, LOW); //tube led off analogWrite(LED_ROJO, 0);// RGB Led off analogWrite(LED_AZUL, 0); analogWrite(LED_VERDE, 0); return color; // End of the cicle, everything returns to its initial position. } else if (R<30 & R>10 & G<10 & G>0 & B<10 & B>0) { //Adjust the ranks to your color. You can use the Monitor Serie to know the numbers the Color Sensor is reading. color = 2; // Blue Serial.println("Color 2 detectat!"); analogWrite(LED_ROJO, 0); analogWrite(LED_VERDE, 0 ); analogWrite(LED_AZUL, 255); servo3.write(90); digitalWrite(Blue, HIGH); delay(200); digitalWrite(Blue, LOW); delay(200); digitalWrite(Blue, HIGH); delay(200); digitalWrite(Blue, LOW); delay(200); digitalWrite(Blue, HIGH); delay(200); digitalWrite(Blue, LOW); delay(200); digitalWrite(Blue, HIGH); delay(200); digitalWrite(Blue, LOW); delay(200); digitalWrite(Blue, HIGH); delay(1000); servo2.write(0); delay(4000); digitalWrite(Blue, LOW); analogWrite(LED_ROJO, 0); analogWrite(LED_VERDE, 0 ); analogWrite(LED_AZUL, 0); return color; } else if (R<38 & R>10 & G<20 & G>4 & B<35 & B>7) {//Adjust the ranks to your color. You can use the Monitor Serie to know the numbers the Color Sensor is reading. color = 3; // Yellow Serial.println("Color 3 detectat!"); analogWrite(LED_ROJO, 255); analogWrite(LED_VERDE, 255); analogWrite(LED_AZUL, 0); servo1.write(90); digitalWrite(Yellow, HIGH); delay(200); digitalWrite(Yellow, LOW); delay(200); digitalWrite(Yellow, HIGH); delay(200); digitalWrite(Yellow, LOW); delay(200); digitalWrite(Yellow, HIGH); delay(200); digitalWrite(Yellow, LOW); delay(200); digitalWrite(Yellow, HIGH); delay(200); digitalWrite(Yellow, LOW); delay(200); digitalWrite(Yellow, HIGH); delay(200); delay(4000); digitalWrite(Yellow, LOW); analogWrite(LED_ROJO, 0); analogWrite(LED_VERDE, 0 ); analogWrite(LED_AZUL, 0); return color; } return color; Serial.println(color); }