Leaf Angle App in the Field
Testing the Leaf Angle App in the field alongside traditional measurement tools.

Leaf angle, the inclination of a leaf from vertical or horizontal, affects light interception and canopy photosynthesis and is used in crop models. Measuring it by hand in the field is slow and error-prone.

Project Development Roadmap
Prototype
UX Feedback
v1 Release
2026 Refresh
Apr 23 May 23 Nov 23 Mar 26

I built a browser app that reads a phone’s IMU to measure leaf angle and export the data as CSV, and changed it based on feedback from people using it in the field.


The GEMINI Project needed to record leaf angles across many plots, with the crop name, plot number, and time for each measurement. Dedicated inclinometers are expensive, paper datasheets are slow to digitize, and generic sensor apps did not export structured CSV. I wanted a free tool that opens in a phone browser with nothing to install.


Initial Design Plans

Before writing code, I sketched the UI and data flow: a large Record button and a readout of the current angle.

Initial Hand Sketch Initial Wireframe
Early sketches and wireframes for the Field Data Collector interface.

Idea

Smartphones already contain 3-axis accelerometers and gyroscopes. Web browsers expose these through the DeviceOrientationEvent API, which gives real-time pitch (β), roll (γ), and yaw (α) angles. A simple calculation converts these into a leaf angle value with respect to vertical.

The idea is to hold the phone flat against a leaf and press Record.

Requirements:
  • Works in any mobile browser (no app install)
  • Customizable crop name and plot number
  • Log timestamped measurements in a table
  • Export data as a downloadable CSV file
  • Usable one-handed in the field

First Draft

The first version was built as a vanilla JavaScript / HTML Progressive Web App (PWA). It subscribed to deviceorientation events and computed the leaf angle from the gravity vector components. A simple table below the sensor readout accumulated each recorded measurement.

The first draft worked like this:

  1. Register a deviceorientationabsolute event listener
  2. Compute the leaf angle: leafAngle = Math.acos(Math.cos(beta * Math.PI/180) * Math.cos(gamma * Math.PI/180)) * (180/Math.PI)
  3. Render live X (β), Y (γ), Z (α), and computed leaf angle values
  4. On Record, push a row {time, crop, plot, count, x, y, z, leafAngle} to an in-memory array and render the table
  5. On Download, serialize the array to CSV using FileSaver.js

The Start, Record, Undo, and Download buttons were at the top of the screen.


Design Suggestion from Ismael

I shared the first draft with the field team, and Ismael Mayanja, a plant scientist who uses the app in field trials, sent feedback on Slack (May 2023):

“Can we have the buttons (Start/Record/Undo) at the bottom of the screen instead of the top, it is easier to press them that way especially in the field.” “Can we also have both volume buttons to also record if I press them.” “Can we make both the crop ID and the plot number customizable so that a user is prompted with a keyboard.” “Digital clock showing at the top. A compass.”

He also sent a hand-drawn sketch of the layout he wanted:

Ismael's hand-drawn wireframe: buttons at bottom, compass top-right, customizable crop and plot fields
Ismael's hand-drawn UI wireframe: buttons moved to the bottom, compass indicator added top-right, text-entry fields for crop and plot ID.

A follow-up message listed three more issues:

  1. Pressing Download CSV wasn’t working.
  2. The latest recorded data should appear at the top of the table, not the bottom.
  3. Replace “Num. of data points” with “Count” so users can quickly see how many measurements they’ve taken.

Final Design

After Ismael’s feedback and more field testing, there have been two versions: the 2023 release (v1) and a 2026 UI refresh (v2).

Leaf Angle App v1 (2023)
v1 (2023), with the controls at the bottom.
Leaf Angle App v2 (2026)
v2 (2026), with larger type and higher contrast.

Changes between versions:

Feature Before After
Button placement Top Bottom (thumb-friendly)
Volume buttons as record ✗ ✓ (both volume keys)
Crop / Plot ID Fixed dropdown Free-text input (keyboard prompt)
Digital clock ✗ ✓ (top center)
Compass ✗ ✓ (top right, if API available)
CSV download Broken Fixed via FileSaver.js
Data order in table Oldest first Newest first
Data count label “Num. of data points” “Count”

Tools and steps

Tool Purpose
HTML / CSS / JavaScript Core app structure, styling, and logic
DeviceOrientationEvent API Real-time IMU sensor data from the phone
DeviceMotionEvent API Hardware volume button detection
Vue.js Reactive UI framework for live data binding and component structure
@vueuse/core Vue composables for device orientation (useDeviceOrientation)
FileSaver.js Client-side CSV file download
GitHub Pages Free static hosting for the PWA
Vite Build toolchain for the Vue project

The steps were:

  1. A vanilla JavaScript prototype to check that deviceorientationabsolute gives usable angles on Android and iOS.
  2. A rewrite in Vue.js to clean up the reactive state (sensor readings → computed leaf angle → table rows).
  3. @vueuse/core for the device orientation hooks:
    npm i @vueuse/core
    
  4. A new layout with the controls in a fixed bottom bar, a clock at the top, and free-text Crop and Plot inputs.
  5. FileSaver.js to fix the CSV download:
    npm i file-saver
    
  6. unshift() instead of push() so the latest reading appears first.
  7. A Vite build deployed to GitHub Pages:
    npm run build
    # deploy dist/ to the gh-pages branch
    

The app can be saved to a phone’s home screen, where it opens like a native app:

Open Leaf Angle App

On iPhone: Share → Add to Home Screen
On Android: browser menu → Add to Home Screen


References