Color Sensor Escape Room Tech Puzzle Tutorial (Patreon)
Content
Hi folks, hope you're all well!
As requested by several people, this month's puzzle tutorial demonstrates how you can create an escape room puzzle using colour sensors: either the common TCS3200 (or its predecessor, the TCS230), or the more advanced TCS34725. These sensors contain an array of filtered photodiodes which can be used to measure the intensity of separate RGB components of light hitting the sensor - either from a light source such as a coloured spotlight, or simply reflected off the surface of an object held in front of the sensor. This can be used as an input for an escape room puzzle in which players need to present a certain-coloured object, or mix light sources or transparent liquids or overlays, in order to create a specific target colour to solve the puzzle.
The TCS34725 is a more recent and advanced sensor than the TCS3200 - it uses an I2C interface that requires less GPIO pins on the Arduino, it has built in IR filters which make the diodes capture color more similar to the human eye would perceive it, and it has a small MCU that does some pre-processing on the sensor itself, meaning that the Arduino code can retrieve a corrected colour value more simply than using the TCS3200, which requires some calibration. But the functionality here can be achieved either sensor, and I'll demonstrate the Arduino code required for both.
It's worth mentioning that with *any* colour sensors, you'll always have to do some calibration to account for factors such as the ambient lighting in a room, the distance from the object to the sensor etc. Colours appear differently in sunlight than under an incandescent room light, for example - that's because different light sources have different colour temperatures, and if you want to, say, compare whether a color is equal that's something you'll need to account for in the code. But with a combination of initial calibration and a tolerance value when comparing the Euclidean distance between colours as shown in the code, this approach should be robust enough for most purposes.
Hardware used:
TCS3200 Color Sensor Module, ~5 from e.g. https://www.banggood.com/custlink/KKmvTRuGGW
TCS34725 Color Sensor Module, ~$5 from, e.g. https://www.banggood.com/custlink/mmmvfETvDy
Arduino Nano, ~$2 from, e.g. https://www.banggood.com/custlink/mGGmwdTDmU
WS2812B (Neopixel) LED ring, ~$7 from, e.g. https://www.banggood.com/custlink/GK3G7RuGdv
Timings:
00:00-05:14 Intro and Demonstration
05:15-13:51 Hardware and wiring for TCS3200(TCS230) sensor
13:52-16:23 Hardware and wiring for TCS34725 sensor
16:24-36:36 Arduino code for TCS3200(TCS230) sensor
36:37-42:49 Arduino code for TCS34725 sensor
42:50-45:55 Wrapup
I'll be posting up a separate post shortly for Patreons-only containing links to download the Arduino code listing(s), the Fritzing project, and wiring diagram. As always, please ask if you have any questions, and I'll do my best to answer them!