Welcome to the Candy Conveyor Belt Color Sensor project! This is a project that mashes up the use of a color sensor, associated illumination, an OLED display screen, an Arduino Nano, custom printed 3D parts, and well-known chocolate round candies that come in predictable colors. This is one of the more involved projects we've posted on about on this blog, but if you follow along carefully, you'll end up with an impressive project that looks like this:
Aside from soldering supplies, PLA for 3D printing, electrical tape (and something to cut it with), and a laptop loaded up with a code window for programming an Arduino, here are the supplies you'll need for this project:
- Arduino Nano V3.0: one Arduino Nano with pins soldered on. If your Arduino Nano didn't come with pins soldered on (most don't), there are plenty of online tutorials showing how to do that (here's a good one).
- Breadboard: just about any breadboard will do; if you don't have one, here's a good kind to buy.
- Jumper Wires: you'll need a variety of jumper wires -- enough variety to keep a rational color-coding arrangement as you assemble the circuit. You'll mostly need male-to-male jumper wires, but you'll need at least four female-to-male jumpers.
- Power: a 5V AC/DC Power Adapter that outputs to a 3.5mmx1.35mm barrel plug, and an associated female jack with a screw terminal. There is nothing special about using this particular size of barrel plug; if your power adapter and jack happen to be of a different size, that's fine.
- Capacitor: one smoothing capacitor to use with the external power supply. I'm iusing a 1000uF capacitor 16V capacitor from this kit, but your math may differ if you are using a different type of power supply.
- Machined Screws & Bolts: two #8-32 machine screws (1 inch or longer) and four #8-32 machine nuts (these are easy to procure at your local hardware store).
- LED Ring: one WS2812B LED Ring with jumper wires soldered to the leads.
- Bi-Directional Logic Level Converter (5V/3.3V): this one is very cost effective on a per-unit basis if you think you might make use of more of these in a future project.
- Color Sensor: one SparkFun ISL29125 color sensor, with pins soldered on (it typically comes with pins, but you'll need to solder them on).
- Resistor: one 470 ohm resistor
- OLED Display: one SSD1306 display
Although this materials list is more involved than the ones that we've used for prior projects on this blog, the majority of these items are ones that you'll find yourself keeping on hand for routine DIY electronics projects -- jumper wires, resistors, capacitors, breadboards, and power supplies are the bread, eggs, and milk of your electronics hobby station.
3D Printed Components
The 3D printed portion of this project is designed to suspend the color sensor and LED ring about a half-inch from a flat surface, with just enough room to slide a round piece of candy beneath it (or some similarly small object). So, the components form a "bridge" design, with enclosures that contain and position the sensors/lights to face downwards to a flat surface:
With this design in mind, here are the 3D design files for this project:
|Color Sensor Seat||Download|
|LED Ring Holder||Download|
This project is relatively complex compared to other projects on this blog, so we'll divide out the build into three steps -- Sensor/LED Enclosure, Breadboard Wiring, and Software Code.
Here's what you'll need in your workspace to complete this step:
And, here's how to assemble it:
Here's the wiring diagram for this project:
Note the cluster of Yellow, Orange, Gray, and Green wires on the Low Voltage ("LV") side of the logic level converter. Those are the I2C bus that we are connecting the OLED display and the color sensor to. In theory, we could connect a large number of additional sensors and outputs to that same bus -- the beauty of I2C in this project is that it's very extensible.
There are many great tutorials for setting up the Arduino application on your computer, so for this tutorial, I'll assume that you've already got that set up, and we'll jump straight to the code for this particular project:
You'll need to upload this code to your arduino, typically using a USB cable to connect the Arduino to your laptop.
The most delicate part of this code is the definition of aKnownColors. There, you'll likely need to do some tuning of your own, as you wrestle with the precise Red, Green, and Blue levels that your color sensor detects when it "sees" each particular type of candy. Feel free to improvise further with additional candy colors, or some other target that isn't candy at all!
If you've completed this project successfully, your candy conveyor belt color sensor should work something like this:
This project was a great learning experience, and leaves a number of possible improvements for the future. Some ideas for further improving this project include having some user interface (using additional buttons and the existing OLED display) to allow for end-user tuning of the candy colors. I'd also love to create a 3D printed enclosure for the OLED display. Lastly, I think this project would look really sharp on a PCB (instead of a breadboard), with all of the circuitry fully enclosed in some type of project case.
However, for now, I'm proud to say that I successfully #justbuiltit -- on to the next project!