Skip to the content
2 layers122 × 122 mmBikeCounter SingleBoard, the printed circuit board in 3D

BikeCounter SingleBoard

guidosch/bikecounter6

This repository contains the hardware and software components of a PIR based tracking device to monitor the usage of local bike trails. The data is sent over LoRaWAN to TTN and from there to a Google Cloud backend which stores the data and provides api endpoints for the data visualization web UI.

Size
122 × 122 mm
Copper layers
2
Thickness
1.6 mm
Parts
23
Nets
33
Pads
83
Tracks, vias
94, 158
Pours
1
Routed
Yes
KiCad
KiCad 8.0 (file 20240108)
Created
7 Mar 2020
Updated
3 Oct 2026

Overview

BikeCounter SingleBoard is an open-source printed circuit board by guidosch, from the guidosch/bikecounter repository on GitHub, published under the CC0-1.0 licence. It is a 2-layer board of 122 × 122 mm with 23 parts on 33 nets, routed with 94 tracks and 158 vias.

It is built around the AM2320. Its parts include 7 resistors, 4 connectors, 2 switches and 1 capacitor. It belongs with the radio and wireless boards of this library.

Main components

1

README

README.md

BikeCounter

action status

This repository contains the hardware and software components of a PIR based tracking device to monitor the usage of local bike trails. The data is sent over LoRaWAN to TTN and from there to a Google Cloud backend which stores the data and provides api endpoints for the data visualization web UI (bikeCounterUI).

The repository is divided into two main sections. The first one contains all the data regarding the hardware components and the second one holds the software code.

Hardware

The core component of the device is an Arduino MRKWAN 1310 which sits on the "logic layer" PCB. This PCB connects the micro controller to the sensors, the dip switches and the "power layer" PCB.

To detect the movement a PIR sensor from Seeed Studio is used and to monitor the internal environment of the device a temperature and humidity sensor from Adafruit was chosen.

The "power layer" PCB holds two rechargeable lithium-ion batteries (18650). This allows the device to run up to one year without exchanging the batteries.

The schematics and layout files of the PCBs as well as the BOM of the whole device can be found in the corresponding subfolder.

Software

This Repository contains the code for the tracking device as well as the scripts running on the backend.

Overview

mermaid
flowchart LR;
  subgraph BikeCounter;
    Biker(Round) -->|infrared radiation| PIR-sensor;
    PIR-sensor -->|DIO| Arduino-MKRWAN-1310;
    Temp&Hum-sensor -->|I2C| Arduino-MKRWAN-1310;
    DIP-switches -->|DIO| Arduino-MKRWAN-1310;
  end; 
  subgraph TTN;   
    Arduino-MKRWAN-1310 -->|LoRaWAN| PayloadFormatter;
  end;  
  subgraph Google Cloud;
    PayloadFormatter -->|webhook| Cloud-function;
    Cloud-function --> firebase;
  end;

BikeCounter

There are two versions of the main BikeCounter software. The light version is a simple and basic implementation of the needed functionality. The pro version has extended features that allow it to take track of time as well as its environnement conditions.

(Due to the fact that the light version is almost obsolete only the pro version will be explained in more detail.)

Overall state machine

mermaid
stateDiagram-v2
    m1: main loop
    [*] --> Setup
    Setup --> m1
    state m1 {
      state if_motion <<choice>>
      s0: motion detected ?
      s1: store information in variable      
      s2: timer called
      s3: threshold reached ?
      state if_threshold <<choice>>
      s4: send data
      state if_downlink <<choice>>
      s5: downlink received ?
      s6: correct rtc drift
      
      [*] --> s0
      s0 --> if_motion
      if_motion --> s1: true
      if_motion --> s2: false
      s2 --> s4
      s1 --> s3
      s3 --> if_threshold
      if_threshold --> deepSleep: false

After the main loop finishes the device goes into a deepSleep mode. From there the PIR sensor or the rtc timer can wake it back up and trigger the main loop again.

Data package

The payload size of one single LoRaWAN data package is restricted to 51 bytes. To avoid multi-package messages and to reduce transmission time an optimized information transmission protocol was developed.

The dataPackage class handles all the information conversion and encoding. A detailed documentation of the protocol can be found in the dataPackage.xlsx file.

Payload encoding

address
bits
0-7
[8]
8-11
[4]
12-15
[4]
16-18
[3]
19-23
[5]
24-27
[5]
28-30
[3]
31-54
[24]
55-57
[3]
58-62
[5]
63-408
[6/7/8/9/10]
contentcountsoftware versionhardware versionstatus indexbattery voltagetemperaturehumiditydevice timeinterval indexhour of the dayoffset minutes array

The data type size of the offset array depends on the selected interval.

Time scheduler

During the night as well as the cold seasons of the year the data transmission interval can be adjusted to save energy and transmission time. The timeScheduler class provides all the necessary methods to accomplish such a dynamic behavior.

Device configuration

The configuration information to establish a connection to the TTN (AppEUI and AppKey) is saved to the flash memory of the Arduino MKRWAN 1310. The writeConfigToFlash.ino script saves a new configuration to the memory.

Unit tests

This repository contains serval unit tests for the dataPackage and the timeScheduler class. The tests are written using the Google Test framework. A cMake configuration for local testing is provided as well as an automated CI pipeline for the master branch. The runTestsLocal.sh script executes all the commands needed to run the unit tests locally.

To be aware of

  • The LoRa module is very timing sensitive. That is the reason there are so many delays in the code to give it enough time to wait for messages and to response.

  • The first time the (deep)sleep method is called, it re-initializes the RTC to a wrong value. To fix this issue the first iteration of the main loop puts the device into the sleep mode for a short period of time and resets the RTC in the next loop.

TTN

The message from the device gets over LoRaWAN to the TTN server where a uplink payload formatter parses the data bytes to a human readable JavaScript object. The server then triggers a webhook and passes the data object to the Google Cloud function API endpoint.

The downlink message with the time drift information will also be parsed by the payload formatter defined in TTN.

The up/down-link payload formatter scripts are stored in the TTN subfolder.

Google Cloud

The triggered cloud function evaluates the data object sent from TTN and saves it to the Firebase database. Depending on the difference between the local time of the device and the server time it schedules a downlink message to correct the internal device time.

There are also cloud functions that provide an API endpoint for the web UI (bikeCounterUI) to visualize the stored data.

Setup IDE and compile code

Download and install: arduino-cli which is available for brew or apt-get. Install the arduino extension for VSCode and adjust the arduino.path in the extension settings and point to your arduino-cli installation folder.

Add the following libraries to your installation: arduino-cli lib install [libName]

  • Needed libraries:
    • MKRWAN@1.1.0
    • RTCZero@1.6.0
    • SPI.h --> already preinstalled
    • SparkFun SPI SerialFlash Arduino Library@1.0.3
    • Arduino Low Power@1.2.2
    • Adafruit Unified Sensor@1.1.6

Copy and adjust the .vscode/c_cpp_properties.json_example for your platform. You have to adjust the place where arduino-cli downloads the libraries as they are needed by the IDE

Compile: arduino-cli compile --fqbn arduino:samd:mkrwan1310 BikeCounterPro.ino

Deploy: arduino-cli upload -p [/dev/yourdevice] --fqbn arduino:samd:mkrwan1310 BikeCounterPro.ino

Hint: arduino-cli board list will show the USB port, where the device is connected

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update the tests as appropriate.

License

This project is licensed under CC0-1.0

Parts

23
QtyValueFootprintReferences
510kResistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolderR1, R4, R5, R6, R7
2Keystone_1043General_TM:BatteryHolder_Keystone_1043_1x18650B1, B2
10.1uFCapacitor_SMD:C_0805_2012Metric_Pad1.18x1.45mm_HandSolderC1
11.2MResistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolderR3
1330kResistor_SMD:R_1206_3216Metric_Pad1.30x1.75mm_HandSolderR2
1AM2320Connector_PinSocket_2.54mm:PinSocket_1x04_P2.54mm_VerticalJ4
1Arduino_MKR_WAN_1310General_TM:Arduino_MKR_WAN_1310A1
1Conn_01x02_SocketConnector_PinSocket_2.54mm:PinSocket_1x02_P2.54mm_VerticalJ3
1LOGOZueriTrailsLogo:ZueriTrailsLogo_smallG***
1LOGOZueriTrailsLogo:ZueriTrailsLogoG***
1PIR SensorConnector_PinSocket_2.00mm:PinSocket_1x04_P2.00mm_VerticalJ1
1PIR Sensor 2Connector_PinSocket_2.00mm:PinSocket_1x04_P2.00mm_VerticalJ2
1SW_DIP_x03Button_Switch_SMD:SW_DIP_SPSTx03_Slide_6.7x9.18mm_W8.61mm_P2.54mm_LowProfileSW2
1SW_SPSTGeneral_TM:Switch_MHS12204SW1

The 19 most common of 23 parts.

More from guidosch/bikecounter

2
  • 2 layers110.5 × 52.8 mmBikeCounter, the printed circuit board in 3D

    BikeCounter

    guidosch/bikecounter

    This repository contains the hardware and software components of a PIR based tracking device to monitor the usage of local bike trails.

    21 parts6CC0-1.0
  • 2 layers102.7 × 44.5 mmPowerLayer, the printed circuit board in 3D

    PowerLayer

    guidosch/bikecounter

    This repository contains the hardware and software components of a PIR based tracking device to monitor the usage of local bike trails.

    7 parts6CC0-1.0

Similar boards

  • 2 layers118 × 105 mmFilamentStorage, the printed circuit board in 3D

    FilamentStorage

    LilisProtoLab/FDM-print-station

    The FDM print station of Lili's Proto Lab contains six printers, three printer enclosures and a dry-air filament drawer

    84 partsMIT
  • 4 layers66 × 57 mmA1-External ESP8266-Cooling Fan Module, the printed circuit board in 3D

    A1-External ESP8266-Cooling Fan Module

    potpurri/A1-External-ESP8266-Cooling-Fan-Module

    ESP8266-board driving an external fan for improved cooling of nozzle and prints

    74 partsApache-2.0
  • 2 layers93 × 61 mmMainPcb v 1 0, the printed circuit board in 3D

    MainPcb v 1 0

    powermosfet/mqtt-button

    A generic IoT device with two buttons, two LED's and a temperature/humidity sensor

    22 parts
  • 2 layers110 × 100 mmHydroponics, the printed circuit board in 3D

    Hydroponics

    imagestream/kicad

    Kicad designs and libraries

    88 parts1MIT
  • 2 layers65 × 56 mmPi servo hat, the printed circuit board in 3D

    Pi servo hat

    earthtojake/text-to-cad

    Design physical products with AI

    23 parts26kMIT
  • 2 layers14 × 100 mmYunomi, the printed circuit board in 3D

    Yunomi

    google/mozc-devices

    Circuit diagrams and firmware source code for Gboard DIY keyboards

    23 parts3kApache-2.0
  • 2 layers50.8 × 52.2 mmFuhhni, the printed circuit board in 3D

    Fuhhni

    hackclub/OnBoard

    💡 Join 1,000 teenagers and make your first PCB with a $100 grant!

    23 parts915
  • 2 layers138.8 × 89.8 mmKeyboard pcb, the printed circuit board in 3D

    Keyboard pcb

    diepala/cantor

    Cantor keyboard, a 42 key diodeless split keyboard.

    23 parts756GPL-3.0

Questions

How big is the BikeCounter SingleBoard PCB?

It measures 122 × 122 mm and has 2 copper layers, 1.6 mm thick.

What parts does the BikeCounter SingleBoard use?

23 parts, built around the AM2320. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the BikeCounter SingleBoard KiCad files?

From the guidosch/bikecounter repository on GitHub, at the commit this page was made from: the board is hardware/PCB/SingleBoard/BikeCounter_SingleBoard/BikeCounter_SingleBoard.kicad_pcb and its schematic hardware/PCB/LogicLayer/BikeCounter/BikeCounter.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the BikeCounter SingleBoard design in my own project?

Its repository publishes it under the CC0-1.0 licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).