Hardware
Overview
The problem we set out to solve
In our project, the gene arm of the mother bacterium can undergo inversion, producing a bacterial suspension containing a mixture of multiple progeny bacteria during proliferation. Efficiently determining the abundance of different bacterial types in the suspension is a key step towards applying our system. Hardware therefore aims to build a low-cost device that can rapidly detect the ratios of different bacteria in solution.
Through communication with the Wet Lab department, we learned that by designing genes on the inversion arm, different progeny bacteria can produce pigments of different colours. So a mixed bacterial suspension with a specific ratio corresponds to a specific colour. If we can establish a mapping between solution colour and bacterial ratio, we can infer the bacterial ratio by measuring the solution colour.
We answered that with two independent devices. RATIO Pocket reads the colour with a smartphone camera; RATIO Bench reads it with a dedicated four-channel colourimeter. Each is described in its own block below.
Assumption: what the colour tells us
The whole colour-to-ratio argument rests on one assumption: the amount of pigment a cell produces is proportional to the number of cells, so that the pigment concentration in the suspension reflects the cell concentration. Under that assumption a mixed suspension at a given ratio maps to one reproducible colour, and measuring the colour is equivalent to measuring the ratio. If pigment production were to vary independently of cell number — for example between strains, growth phases or batches — the mapping would no longer hold.
For the measurements in this work, the chromoprotein-expressing cells were not yet available in the wet lab, so two food-colouring dyes were used as substitutes for the bacterial pigment: Brilliant Blue FCF (Blue No. 1, absorption peak ≈ 630 nm, mainly reducing the R channel) for the blue component, and Tartrazine (Yellow No. 5, absorption peak ≈ 427 nm, mainly reducing the B channel) for the yellow one. The dyes play the same role in the optical path — they absorb selectively and colour the solution — but they are not the same molecules and do not reproduce cell scattering or sedimentation. The calibration reported here should therefore be read as a validation of the measurement principle rather than a finished biological calibration.
RATIO Pocket
Introduction: a low-cost ratio detection platform
To realise the initial aim of a low-cost and accurate device, we turned to a common electronic device — the smartphone — hoping to use its camera and sensors for detection. After reviewing the literature, we found an app, phyphox, developed by RWTH Aachen University, Germany, which can turn a smartphone into a portable laboratory for quantitative physics experiments. Its functions meet our experimental needs. So, standing on the shoulders of giants, RATIO Pocket was born.
RATIO Pocket consists of a smartphone, the phyphox app, a data processing program we wrote, and a light-blocking housing.
The 3D-printed housing provides an operating platform that allows us to collect sample data with the smartphone. phyphox records and exports the sensor data; our program processes it. These three parts constitute a low-cost, easy-to-replicate, portable measurement platform that correlates the colour of the liquid under test with the substance ratio.
This page focuses on the smartphone optical detection method. We build on the smartphone — a device everyone owns — and design a detachable, low-cost structure to obtain biological signals.
The housing of RATIO Pocket: Voyager
The overall measurement device is cylindrical and mainly divided into three parts: a liquid chamber for holding the sample, an LED base providing illumination, and an adjustable light aperture. There is also a detachable folding phone holder for laying the smartphone. CAD modelling files and the bill of materials are listed in Materials and files.
The design is centred on light blocking, stability, portability and easy sample replacement, enabling the device to be quickly assembled and reused in a non-specialist laboratory environment.
Loading the 3D model…
Drag to rotate · pinch or Ctrl+scroll to zoom
Structure 1: the door of the liquid chamber
We designed an easy-to-open door for the liquid chamber: slide it upward to open, and it can be fixed in place, facilitating one-handed operation and shortening sample replacement time.
The liquid chamber also has a light-blocking structure to reduce light leakage, allowing convenient sample replacement while ensuring no ambient light interference after the door is closed.
Structure 2: liquid container
The liquid container is made of 3D-printed side walls and a transparent acrylic plate bonded with hot-melt adhesive. It has good sealing performance while light can pass through the liquid.
We placed the optical path vertically, so that light passes the horizontally placed liquid from below. This approach keeps the light as perpendicular to the liquid surface as possible, reducing errors caused by refraction and reflection of the liquid.
To save space and shorten the optical path, the liquid chamber is relatively narrow, making it difficult to replace the liquid container. To address this problem, we designed a slide rail that allows the liquid container to be pulled out from the side for easy replacement.
Structure 3: light source
We use an LED bead as the light source. LED beads are extremely low-cost and readily available, and our tests show that their brightness meets the experimental requirements.
To adjust light source brightness, we designed an adjustable aperture above the light source. Sliding the side slider changes the amount of light passing through the liquid.
The adjustable aperture enables the device to adapt to samples with different colour depths and exposure conditions, avoiding HSV reading distortion caused by overexposure or underexposure.
Structure 4: phone holder
To properly fix the smartphone used for measurement and data output, we designed a foldable phone holder. It is stable and can securely support the phone; the holder arm length is adjustable, allowing it to support phones of various sizes. When folded, it is compact and easy to carry. With it, we can set up an experimental measurement platform anytime, anywhere.
The photographs below show our actual device, taken during our experiments with it.
Data acquisition: a smartphone running phyphox
After several rounds of experimental results, we chose to use hue and saturation to characterise the colour of the liquid. We use a smartphone running the phyphox app to obtain this information.
Raw image data captured by a smartphone camera is a combination of red, green and blue (RGB) channels. However, the RGB colour space is not intuitive for describing colour, because the three channels are strongly correlated and can be greatly affected by illumination intensity.
The HSV colour space, on the other hand, decomposes colour into three mutually independent dimensions: hue, saturation and value, which is closer to the colour perception of the human eye. Hue is measured in degrees — red is 0°, green is 120°, and blue is 240°, covering the full colour wheel; saturation indicates how close a colour is to a spectral colour, ranging from 0.0 to 1.0; value indicates the brightness of the colour. The key advantage of HSV is that it is sensitive to changes in solution concentration but insensitive to illumination intensity, so it reduces interference from fluctuations in the light source.
The colour (HSV colour space) function in phyphox uses the smartphone camera to acquire images in real time. It then aggregates the RGB values of all pixels in a user-defined region and converts them to HSV coordinates.
Before recording begins, the phone must be fixed above the device in a fixed position; once recording starts, phyphox continuously outputs the HSV values of that region at a rate of 240 Hz. After the experiment, the data can be exported as a spreadsheet for subsequent analysis.
On the basis of the above, and of several rounds of experimental results, we chose the hue and saturation information acquired by phyphox's HSV colour space function as the raw experimental data for characterising solution colour.
Pigment ratio prediction model
Considering biosafety and data accuracy, we used food colouring to prepare blue and yellow solutions and mixed them in different ratios, to simulate the state in which two bacterial types coexist in different proportions.
With the help of RATIO Pocket, we measured the HSV values of mixed solutions with known blue–yellow ratios, obtaining 63 data points across 19 ratios.
Using these data, we established a mathematical model that calculates the pigment ratio of a mixed solution from its HSV values:
Here Hue is the hue value of the test liquid and Saturation is its saturation value; Yellow_{Hue} and Yellow_{Saturation} are the hue and saturation of the pure yellow solution; Blue_{Hue} and Blue_{Saturation} are the hue and saturation of the pure blue solution.
On the 63 dye-mixture recordings used to fit it, the endpoint-normalised model achieved an in-sample R² of 0.801 and an RMSE of 0.118. This shows that one curve can capture much of the relationship between colour and mixing fraction across the two experimental batches. Evaluating the printed equation at the pure-yellow and pure-blue endpoints, however, gives predicted blue fractions of 0.242 and 0.895 rather than 0 and 1. The remaining endpoint bias gives us a clear target for improving quantitative accuracy.
In practice, therefore, we measure pure-yellow and pure-blue solutions alongside each batch and use their HSV values to normalise the test solution before applying the curve.
The fit itself is documented on our Software page, where the CalcRatio pipeline that produces it is described.
Summary
The RATIO Pocket device is a 3D-printed experimental platform built around a smartphone camera. It uses the phyphox app to acquire solution HSV data and calculates the pigment content ratio in solution from a fitted equation.
The platform is low-cost, easy to assemble and portable, making it suitable for colour ratio detection in resource-limited environments. Future improvements may include optimising sample loading, increasing the volume of data, and evaluating additional optical components to improve detection accuracy further and extend the device to biological experiments.
Materials and fabrication files
The bill of materials below covers everything the device needs apart from the smartphone, which the user supplies.
| Material | Amount | Price | Source |
|---|---|---|---|
| LED bead | 1 | ¥0.38 | E-commerce platform |
| 3D printing filament (PETG) | 160.98 g | ¥4.02 | E-commerce platform |
| Transparent acrylic plate | One piece, 2 cm diameter | ¥2 | E-commerce platform |
| Smartphone (any model) | 1 | User-provided, not counted in the device cost | User-owned device |
| Total | ¥6.40 | Excluding the cost of the smartphone |
Table 1-1. Bill of materials for RATIO Pocket.
The housing prints as sixteen parts, in three groups.
Loading the 3D model…
Drag to rotate · pinch or Ctrl+scroll to zoom
Main body parts
Click to view 3D model
Blocks the outside light.
Lets the sample be changed.
Holds the liquid sample.
Sets the liquid vessel in place.
Holds the liquid container.
Places the LED and provides the light.
The parts of the light adjusting hole
Click to view 3D model
The top part of the hole.
The bottom part of the hole.
The adjusting plate of the hole.
The light-blocking plate of the hole.
Loading the 3D model…
Drag to rotate · pinch or Ctrl+scroll to zoom
The parts of the phone holder
Click to view 3D model
Connects the holder to the body.
One of the five phone-supporter parts.
One of the five phone-supporter parts.
One of the five phone-supporter parts.
One of the five phone-supporter parts.
One of the five phone-supporter parts.
Loading the 3D model…
Drag to rotate · pinch or Ctrl+scroll to zoom
Figure 1-17. RATIO Pocket: Voyager 3D-printed parts.
RATIO Bench
Introduction: a low-cost platform based on the TCS34725
We built RATIO Bench, a low-cost, four-channel colourimeter that quantifies the ratio of two chromoprotein-expressing cell populations in a mixed culture[3]. A TCS34725 sensing module with its own white LED sits inside a sealed, light-tight enclosure (RATIO Bench), and the liquid sample is placed in a well above the sensor[1]. Each chromoprotein selectively absorbs a specific wavelength, and the module reads the transmitted light on four channels (red / green / blue / clear). From the absorbance ratio we recover the cell fraction.
RATIO Bench consists of the TCS34725 sensing module, an STM32F103C8 microcontroller, a 0.96" OLED display and a 3D-printed light-blocking shell. It is a low-cost, easy-to-replicate platform that correlates the colour of the liquid under test with the substance ratio.
Design targets, the baseline this hardware is measured against:
| Specification | Target | Unit | Status |
|---|---|---|---|
| Resolution Δx | ≤ 5 | % (fraction) | In iteration |
| Calibration R² (rational fit) | > 0.95 | dimensionless | Achieved (0.974) |
| Signal-to-noise (R-channel drift) | < 2 | % | Pending re-test |
| Measurement time (per sample) | < 10 | s | Achieved (~7 s) |
| Output channels | 4 | R / G / B / Clear | Achieved |
| Hardware cost | ≪ spectrophotometer | CNY | Achieved |
Table 2-1. RATIO Bench design targets, the baseline this hardware is measured against.
The housing of RATIO Bench: shell
RATIO Bench: shell is a custom 3D-printed enclosure. Its job is to hold the sensing module in a fixed position and to block ambient light, so that the only light reaching the sensor comes from the module's own LED and has passed through the sample.
Structure 1: sealed enclosure
The shell is printed in opaque matte green and fully encloses the optical path. A light-tight cavity prevents any ambient light from reaching the sensor, which would otherwise add an uncontrolled offset to every reading.
Structure 2: sensor module seat
The TCS34725 module is held in a fixed seat so that its distance to the sample and its orientation do not change between measurements. Because the reading is normalised against a blank, keeping the geometry constant is what makes successive samples comparable.
Structure 3: sample well
An open well above the sensor holds the liquid sample. The sample sits directly over the sensing area so that the module's own LED illuminates it from below, and the transmitted light is read by the four channels.
Data acquisition: four-channel readout with repeated sampling
Firmware is written in C (STM32Cube HAL). Key choices:
| Feature | Setting | Reason |
|---|---|---|
| Integration time | 700 ms | More photons → lower shot noise |
| Gain | 4× | Avoids saturating the clear channel |
| Sampling | N = 10 independent readings | Outputs mean ± standard deviation |
| Display | 0.96" OLED, two pages | Page 1 = mean, page 2 = standard deviation |
| Communication | I²C (100 kHz) | Sensor on I2C2, OLED on I2C1 |
Table 2-2. Firmware data-acquisition settings and why each was chosen.
Core firmware — sensor initialisation and the repeated-sampling measurement:
uint8_t TCS_Init(void)
{
uint8_t id = TCS_ReadReg(REG_ID);
if(id != 0x44)
return 1;
TCS_WriteReg(REG_ATIME, ATIME_700MS);
TCS_WriteReg(REG_CONTROL, GAIN_4X);
TCS_WriteReg(REG_ENABLE, EN_PON | EN_AEN);
HAL_Delay(10);
return 0;
}
void TCS_Measure(uint8_t n, TCS_Stats_t *stats)
{
double sum_c = 0, sum_r = 0, sum_g = 0, sum_b = 0;
double sq_c = 0, sq_r = 0, sq_g = 0, sq_b = 0;
double mean_c, mean_r, mean_g, mean_b;
uint8_t i;
if(n == 0)
return;
for(i = 0; i < n; i++)
{
TCS_RGBData_t d;
HAL_Delay(710);
TCS_ReadAllRGB(&d);
sum_c += d.clear; sq_c += (double)d.clear * d.clear;
sum_r += d.red; sq_r += (double)d.red * d.red;
sum_g += d.green; sq_g += (double)d.green * d.green;
sum_b += d.blue; sq_b += (double)d.blue * d.blue;
}
mean_c = sum_c / n; mean_r = sum_r / n;
mean_g = sum_g / n; mean_b = sum_b / n;
stats->clear_mean = (uint16_t)mean_c;
stats->red_mean = (uint16_t)mean_r;
stats->green_mean = (uint16_t)mean_g;
stats->blue_mean = (uint16_t)mean_b;
stats->clear_std = (uint16_t)sqrt(sq_c/n - mean_c*mean_c);
stats->red_std = (uint16_t)sqrt(sq_r/n - mean_r*mean_r);
stats->green_std = (uint16_t)sqrt(sq_g/n - mean_g*mean_g);
stats->blue_std = (uint16_t)sqrt(sq_b/n - mean_b*mean_b);
}
Firmware and schematics are open-sourced on GitHub — RATIO-Bench-firmware (Keil MDK project: TCS34725 driver, OLED driver, STM32Cube HAL).
Measurement procedure
- Blank calibration — measure the pure medium and record R_0 / G_0 / B_0 / C_0.
- Sample measurement — place the sample in the well and read the mean ± standard deviation from the OLED (≈ 7 s).
- Compute — A_G = -\log_{10}(G/G_0), A_B = -\log_{10}(B/B_0), and y = A_B / A_G.
- Convert — substitute y into the calibration curve to obtain the blue fraction x.
Ratio prediction model
Lambert–Beer law. For monochromatic light through an absorbing medium[2]:
Here A is absorbance, I_0 the incident intensity, I the transmitted intensity, \varepsilon the molar absorptivity, c the concentration and L the path length.
Absorbance-ratio method. For a blue (A) + yellow (B) mixture the two channel absorbances are
Taking the ratio cancels c and L, leaving a signal that depends only on the blue fraction x:
This is a fractional-linear (rational) function of x, not a straight line. Fitting it to the pre-experiment data gives a = 15.3, b = 4.36, c = 18.2 and R^2 = 0.974 — against R^2 = 0.612 for a linear fit.
Summary
RATIO Bench provides a low-cost way to read the colour of a liquid sample and, through the absorbance ratio, to estimate the ratio of the two chromoprotein-expressing populations. The rational model explains the curvature that a linear fit misses (R² = 0.974), so the measurement principle is sound, and the whole device costs roughly ¥78.
The current results still have clear limitations. The pre-experiment used a single measurement per sample (n = 1), so the reported errors rest on five calibration points. The noise floor (13.6 %) is the same order as the signal (2.4 %–15.8 %), so the calibration cannot yet resolve the 5 % and 1 % steps, and the three concentration levels disagree by 57 %.
In future work we will raise the chromoprotein concentration so the absorbance reaches 0.2–0.8, record and normalise by the clear channel, re-test resolution and concentration independence with at least five replicates, and optionally upgrade to a dual-wavelength LED with a 16-bit ADC.
Materials and fabrication files
| Item | Unit price | Quantity | Total | Notes |
|---|---|---|---|---|
| STM32F103C8 | ~15 CNY | 1 | ~15 CNY | MCU |
| TCS34725 module | ~35 CNY | 1 | ~35 CNY | RGB sensor |
| 0.96" OLED | ~12 CNY | 1 | ~12 CNY | Display |
| White LED | ~3 CNY | 1 | ~3 CNY | Light source |
| Cuvette / tube | ~5 CNY | 1 | ~5 CNY | Sample holder |
| RATIO Bench: shell | ~8 CNY | 1 | ~8 CNY | 3D-printed enclosure, light-blocking |
| Total | ~78 CNY | Estimated |
Table 2-3. Estimated bill of materials (unit prices are approximate).
The firmware and schematics are in the RATIO-Bench-firmware repository, and the enclosure CAD is available from the team on request.
References
- ams-OSRAM. TCS34725 Color Sensor — Datasheet. ams-osram.com (accessed 2026).
- Mayerhöfer, T. G., Pahlow, S. & Popp, J. (2020). The Bouguer–Beer–Lambert Law: Shining Light on the Obscure. ChemPhysChem. DOI: 10.1002/cphc.202000464.
- Liljeruhm, J., et al. (2018). Engineering a palette of eukaryotic chromoproteins for bacterial synthetic biology. Journal of Biological Engineering. DOI: 10.1186/s13036-018-0100-0.