I've always wanted to create a spectrometer that is so small it can fit into one's pocket and just barely larger than a cuvette itself. Working with bulky commercial spectrometers in labs, I was wondering about applications of such a small spectrometer. That's when I discovered the perfect combination – the M5StickC microcontroller and the AS7341 spectral sensor. My goal was simple: create an ultra-compact spectrometer that anyone could use.
While commercial spectrometers offer high precision, they're often expensive, bulky, and require a computer connection. I wanted something different – a standalone device that could fit in your pocket, complete with its own display and interface, without requiring external equipment such as connection to a mobile app or a computer. The kind of tool that could democratize spectroscopy for educators, students, and citizen scientists.
- 1x M5StickC (https://docs.m5stack.com/en/core/m5stickc_plus)
- 1x AS7341 spectral sensor (https://www.dfrobot.com/product-2132.html)
- 1x Grove connector (https://docs.m5stack.com/en/accessory/cable/grove_cable)
- 2x M2 screws (https://eu.mouser.com/ProductDetail/Harwin/M80-2260000B?qs=DXv0QSHKF4wN5XPxPv8mDw%3D%3D&utm_source=octopart&utm_medium=aggregator&utm_campaign=855-M80-2260000B&utm_content=Harwin)
- 2x M2 heat-set inserts (https://www.mouser.com/ProductDetail/SI/IUTFB-M2?qs=DPoM0jnrROVcA4QFWOCRzw%3D%3D&srsltid=AfmBOopUU4Yk4SA0-Q8_GQOYWdSUdiCuBDWbHyQfNmQKO6hRtp1Q_SV6)
- Black filament for 3D printing
- White reflector (Optional)
- Main body
- Cap
- 3D printer
- Soldering iron
- Screwdriver
- OpenSCAD for 3D printed parts (Optional, only required to modify the designs)
- 3D printer slicer software (I used Ultimaker’s CURA)
- Thonny IDE for programming
The AS7341 sensor is crucial for this project:
- 11 readable individual sensor elements (10 light channels plus flicker detection)
- Coverage from 350-1000 nm for comprehensive analysis
- Built-in LED control for consistent illumination
- Low power consumption for extended battery life
- Affordable price point (~$16)
The M5StickC is the perfect platform for this project because it packs incredible functionality into a tiny package:
- Built-in rechargeable battery for true portability and for on-field applications
- USB-C connector for easy charging and programming
- Seeed Grove port for simple sensor connections
- Two user-programmable buttons for interface control
- TFT display screen for displaying spectra in real-time
- Beautifully labeled breakout header for expansion
- Extra in-bulit sensors (6-axis IMU, Microphone, IR transmitter)
- Compact size (48.2 x 25.5 x 13.7mm) ideal for portable size of pocket spectrometer
- MicroPython support for easy programming
- Affordable price point (~$20)
-
Connect the Grove cable to the M5StickC
-
Flash the firmware using Thonny
-
Test the spectral sensor functionality
-
Disconnect the Grove connector
-
3D print the main body and cap (no support required)
-
Press-fit the M5StickC into the body from the top
-
Connect the Grove connector from the bottom
- Power on the M5StickC
- Quickly press the M5 button after restart (using reset/PWR button) until you see the settings screen
- Select "Switch Mode" using the M5 button
- Choose "USB Mode" from the options
- Download and install Thonny IDE
- Open Thonny
- Navigate to Tools > Options > Interpreter
- Configure settings:
- Set interpreter to "MicroPython (ESP32)"
- Select the correct COM port for your M5StickC
- Click OK and reconnect
- Once connected, you can write and test code directly in the IDE
- Best practice is to write your code in
main.py
for automatic execution on startup
The Pocket Spectrometer has numerous practical applications:
- Water Quality Testing:
- Measure water turbidity
- Test chlorine content
- Monitor pH levels
- Assess water hardness
- Analyze phosphate content
- Aquatic Habitat Monitoring:
- Track ammonia levels
- Measure nitrate and nitrite concentrations
- Monitor phosphate levels
- Ideal for both freshwater and saltwater systems
- Perfect for aquaponics monitoring
- Soil Analysis:
- Detect environmental pollutants
- Measure heavy metals like lead
- Test for oil contamination
- Monitor diesel presence
- Screen for pesticides
- Biochemical Analysis:
- Protein quantification using Bradford assay
- Colorimetric enzyme assays
- Chemical concentration measurements
- Educational demonstrations
- STEM project applications
The code is written in MicroPython for simplicity and accessibility, making it easy to modify for various applications. Most of the AI tools nowadays are good with python code, so would be handy to have the code in micropython.
- Upgrade to AS7343 as it has 14 spectral channels, compared to 10 spectral channels of AS7341
- Optimize battery life for extended field use
- Conduct comprehensive testing (Work in progress)
- Write the protocols in detail and make standard curve plots
- Add saving the spectra as a time-stamped text file
- If code doesn't execute properly, use the stop/rerun button in Thonny until you see three forward-looking arrows in the console
- Restart the device if experiencing connection issues
- Ensure proper USB mode selection before programming
- Double-check Grove connector wiring if sensor readings are incorrect