element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
element14 presents
  • Challenges & Projects
  • More
element14 presents
Blog Build Inside The Box - Advanced Bike Computer
  • Blog
  • Forum
  • Documents
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: greenmate
  • Date Created: 7 May 2021 10:15 PM Date Created
  • Views 1019 views
  • Likes 7 likes
  • Comments 5 comments
  • build inside the box
  • bitb
Related
Recommended

Build Inside The Box - Advanced Bike Computer

greenmate
greenmate
7 May 2021

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:

 
 
 
Software
 
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

VL53L0X ToF
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:
 
S12SD UV
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
You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview
 
 
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.
Anonymous

Top Comments

  • easyejl
    easyejl over 1 year ago +4

    That is some seriously nice 3d design + printing work. When I try to do something like that, I end up having to make tweaks + reprint 4 or 5 times to get it right.

  • greenmate
    greenmate over 1 year ago in reply to easyejl +3

    Thank you! I did have to reprint the main box once, as things just *barely* didn't fit, I was so close to grabbing a drill and making the walls a bit thinner with a sanding drum, but I decided to print…

  • mayermakes
    mayermakes over 1 year ago +2

    A really cool application, I would nopt have come up with this idea! Great execution! I especially like the intricate 3d Design of your enclosure!

  • mayermakes
    mayermakes over 1 year ago

    A really cool application, I would nopt have come up with this idea! Great execution! I especially like the intricate 3d Design of your enclosure!

    • Cancel
    • Vote Up +2 Vote Down
    • Reply
    • More
    • Cancel
  • greenmate
    greenmate over 1 year ago in reply to kmikemoo

    Thanks! I thought a lot about how to make that anti-theft thing work, originally I wanted to add some kind of input for enabling and disabling the alarm and picking the side, but I forgot about it and later I was lazy to disassemble everything and put a few buttons in it, so ended up with this method.

    • Cancel
    • Vote Up +1 Vote Down
    • Reply
    • More
    • Cancel
  • kmikemoo
    kmikemoo over 1 year ago

    greenmate  Nice build.  I like your anti-theft solution.  I'm with Eric, nice printing.

    • Cancel
    • Vote Up +1 Vote Down
    • Reply
    • More
    • Cancel
  • greenmate
    greenmate over 1 year ago in reply to easyejl

    Thank you! I did have to reprint the main box once, as things just *barely* didn't fit, I was so close to grabbing a drill and making the walls a bit thinner with a sanding drum, but I decided to print it again overnight instead

    • Cancel
    • Vote Up +3 Vote Down
    • Reply
    • More
    • Cancel
  • easyejl
    easyejl over 1 year ago

    That is some seriously nice 3d design + printing work. When I try to do something like that, I end up having to make tweaks + reprint 4 or 5 times to get it right.

    • Cancel
    • Vote Up +4 Vote Down
    • Reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube