Welcome to my build log for the Build Inside the Box Challenge! This is my first blog/writeup/build on here, so if you have any feedback, please leave a comment!

Here are the contents of The Box:
- Arduino MKR Zero – Neat little development board, uses a Cortex M0+ MCU, and has an SD card slot.
-  USB Power Bank – 10Ah 5V power bank, should be able to power any project that doesn’t involve large motors
- WAGO Terminal Blocks – great way to connect cables together
- MCP604 – quad opamp, 6V max supply voltage, comes in a DIP package for ease of soldering
- TCST1103TCST1103 Photointerrupter/Phototransistor – an infrared emitter and phototransistor, with a gap between them.
- 128x64 OLED Display – I2C/SPI monochrome display
- Analog Temp Sensor
- VL53L0X ToF Sensor

Ideas and planning

My first thought was that the ToF sensor could be used as a park assist on a car, so that was the first idea I started planning. My car radio is quite bad, so the MKR Zero could be used as a music player with an I2S DAC/AMP, put the OLED and some buttons on the steering wheel, power them somehow, and I’ve got a nice and handy music player controller as well. However, I had absolutely no idea what to do with the opamp, phototransistor, and power bank.


Time for another idea. The weather is starting to be good, so who doesn’t like to go on some bike trips? I hate having to mount my phone on the bike, the screen is barely visible outside, none of the tracker apps do exactly what I want, so let’s make something for my bike.

My first ideas were using the phototransistor for measuring rotational speed of the wheel. I wanted to put a small plastic circle thing on the axis of the wheel, cut part of it out, and mount the phototransistor on the side, something like this:


I didn’t want to tear my bike apart to somehow mount this, so time for plan b:  mount the phototransistor on the fork, and make something that sticks out to the side from one of the spokes that the phototransistor can detect. Not as elegant as the previous idea, but much easier to implement.

Soldered the phototransistor to a small perf board, added a resistor for the emitter side, drilled a hole for mounting, and added a 2.54mm 3pin header.

Designed a mount for this PCB, and printed it out of PETG


So that’s the speed measuring part done.

My second thought was using the ToF sensors for an anti-theft system. I’ve had bad experiences with off the shelf bike alarms, so this is the perfect opportunity to make my custom one. Mount the two ToF sensors on two sides, use one of them(user selectable at activation) to constantly measure the distance to the nearest object(wall, lamp post, etc.), and if the distance changes, the bike is being moved. I got some piezo buzzers to use as a mini siren, and the opamp can be used to amplify the Arduino’s 3.3V output to drive them.


Unfortunately, due to some issues on the part of UPS, I still don’t have my Box, so I can’t design the mounts for these parts yet. I managed to find the TCST1103TCST1103 locally at least, so I could build this part.

Most of the electronics and battery will be mounted in a custom box, however having a battery in a black box in direct sunlight for hours might not always be the best idea, so the temperature sensor comes in handy there.


Since the MKR Zero has an SD card slot, it would be perfect for logging location and writing it into a GPX file that can be later opened in Google Earth or similar programs, along with logging a bunch of other sensor info.

Logging GPS data means we need a GPS module(duh), so got one from an old project. It has a Ublox M8N chip on it which communicates using UART, has a large patch antenna built in.


I’ve found some interesting sensors at my local parts supplier that I could use, so let’s take a look at them:

- MQ135 air quality sensor – breathing in smog and all kinds of nasty stuff isn’t great, so having an indication of air quality would be useful. The module needs 5V, which we can get from the power bank. It outputs an analog voltage between 0V and 4V, so a voltage divider will be needed to not damage the 3.3v Arduino.

- DHT11 temp and humidity sensor – not the most accurate, not the fastest, but it’s cheap, and perfect for this project. Needs at least 3.5V, so this will be powered from the power bank as well, which means another voltage divider is needed for the output.

- S12SD UV sensor – No one likes getting sunburnt, so let’s add this sensor to know when UV levels are too high. Output is an analog signal between 0V and 1V, corresponding to 0-10 UV index.


- Picked up an RTC module as well, so that the GPS logs can have proper timestamps. (Edit: realized 20 minutes after I wrote this that GPS data has accurate time, so no need for this)



The main box


The Arduino, DHT11, ToF Sensors, MQ135, Opamp + Buzzer will live in this box, along with the Temp Sensor to make sure things don’t overheat.


I put the Opamp, Temp Sensor, Buzzer, and some pin sockets on a perfboard, and cut it to size



Top panel went smooth as well, just 2 cutouts and mounting holes for the Air Quality Sensor and DHT11.



All that’s left is wiring for the main box, but first, let’s design the user facing box with the OLED Screen, GPS, and UV sensor

User facing box


Mounted all the components and wired up everything



With this, hardware assembly is done:






I wrote the code in C++ using PlatformIO, used Adafruit's libraries for the OLED and DHT11, here it is.

The GPS logging code is missing from this version, as I couldn't test it(no GPS signal in my apartment), and I don't want to include potentially not working code for now. I'll update it as soon as I can.

Reading sensors


By far the most compilcated sensor in this project is the ToF sensor. It communicates using I2C, and the address is user customizable, however the default address is reverted on power loss.

The solution is to wire up the XSHUT(reset) pins to the MCU as well, keep one of the sensors in reset, set a new address on the other one, then bring the first sensor out of reset.
Adafruit has a great library for this device, with examples for using multiple sensors on one I2C bus.


DHT11 Temperature

This sensor uses a one-wire interface, which didn't seem like an issue at first. I connected the VCC pin to 5V, and the DATA pin to the MCU through a voltage divider to turn 5V signals into 3.3V (the Arduino MKR Zero is a 3.3V board). Later I realized this won't work, as the DATA pin isn't a unidirectional pin that only sends data why.
The datasheet of the DHT11 says it needs 3.5V at least, so it can't run off of 3.3V, but let's try anyways.

Turns out it does work just fine with 3.3V, so that's good, saved me from a few headaches.

Using the sensor was really simple thanks to another great library from Adafruit


MQ135 Air Quality

As this device has only an analog output pin, it's really easy to use. Connected 5V to VCC, added a voltage divider to the AO(Analog Out) pin, and connected it to analog pin 2 (A2) on the Arduino.

According to the datasheet, the highest voltage it can output is 4V, which corresponds to the most contaminated air measurable. Since I used a voltage divider, this becomes 2.64V. I used the Arduino in 12bit ADC mode, which is the default and more than enough for this purpose, so that means there are 1024 different values the ADC can return(0 = 0V, 1023 = 3.3V). I calculated the maximum output of the ADC connected to this sensor to be 818. This simple function will give an air quality reading from 0-100 where 100 is the cleanest possible air:



Even simpler to use than the MQ135, this sensor has an analog output pin as well, with the output voltage being between 0V and 1V, corresponding to the UV index scale from 0-10 (I'm not sure 0 exists on the UV index scale, but let's pretend it does).

Here's another short function, that will return the UV index:




Video of project



Unfortunately, some unrelated things that happened took away a week of my time I wanted to spend on this project, so I only had time in the last 3 days. I will update this post later with some stuff, but I'm already late, so this is it I guess. I know the wiring is absolutely horrible, and I didn't have time to test this outside on my bike, I will do that later though.


Thank you for the opportunity and the free box to everyone involved, and also thank you to danzima for helping me with shipping issues.