Skip to the content
2 layers102.7 × 44.5 mmPowerLayer, the printed circuit board in 3D

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
102.7 × 44.5 mm
Copper layers
2
Thickness
1.6 mm
Parts
7
Nets
2
Pads
14
Tracks, vias
15, 0
Routed
Yes
KiCad
KiCad 5 (file 20171130)
Created
7 Mar 2020
Updated
3 Oct 2026

Overview

PowerLayer 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 102.7 × 44.5 mm with 7 parts on 2 nets, routed with 15 tracks and 0 vias.

It belongs with the radio and wireless boards of this library.

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

7
QtyValueFootprintReferences
2LOGOGraphicsLib:ZueriTrailsLogo_smallG***, G***
1Keystone_1049General_TM:BatteryHolder_Keystone_1049_2x18650B1
1Logic layer connectionConnector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_VerticalJ1

The 4 most common of 7 parts.

More from guidosch/bikecounter

2
  • 2 layers122 × 122 mmBikeCounter SingleBoard, the printed circuit board in 3D

    BikeCounter SingleBoard

    guidosch/bikecounter

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

    23 parts6CC0-1.0
  • 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

Similar boards

  • 2 layersEncoder, the printed circuit board in 3D

    Encoder

    byrantech/laptop

    anyon_e, a highly integrated, high end, open source laptop. Attempt the impossible.

    7 parts4.3kMIT
  • 2 layers40 × 20 mmSensor smd, the printed circuit board in 3D

    Sensor smd

    scottbez1/splitflap

    DIY split-flap display

    7 parts4.2k
  • 2 layers19.8 × 30 mmZ limit, the printed circuit board in 3D

    Z limit

    opulo-inc/lumenpnp

    The LumenPnP is an open source pick and place machine.

    7 parts3.7k
  • 2 layers35.6 × 58.2 mmDisplay Carrier, the printed circuit board in 3D

    Display Carrier

    AxxAxx/AxxSolder

    STM32 Based soldering station for JBC cartridges, 9-24 VDC and USB-PD power

    7 parts1.7kGPL-3.0
  • 2 layers20.3 × 16.3 mmMap MPX, the printed circuit board in 3D

    Map MPX

    rusefi/rusefi

    rusefi - GPL internal combustion engine control unit

    7 parts1.2k
  • 2 layers26 × 44 mmCompact carrier board, the printed circuit board in 3D

    Compact carrier board

    jamro/tiny-engineer

    A small desktop robot that brings an AI coding assistant to life, physically acting out when it reads files, thinks, writes code, and finishes work.

    7 parts1.1k
  • 2 layers26.4 × 53.8 mmAtari pickup, the printed circuit board in 3D

    Atari pickup

    hoglet67/RGBtoHDMI

    Bare-metal Raspberry Pi project that provides pixel-perfect sampling of Retro Computer RGB/YUV video and conversion to HDMI

    7 parts1kGPL-3.0
  • 2 layersRj45 breakout, the printed circuit board in 3D

    Rj45 breakout

    rene-dev/stmbl

    AC Servo Driver for STM32F4

    7 parts990GPL-3.0

Questions

How big is the PowerLayer PCB?

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

What parts does the PowerLayer use?

7 parts. 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 PowerLayer KiCad files?

From the guidosch/bikecounter repository on GitHub, at the commit this page was made from: the board is hardware/PCB/PowerLayer/PowerLayer/PowerLayer.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 PowerLayer 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).