p5-phone library illustration
Illustration by Angela Torchio
Static No framework, no build step, GitHub Pages friendly.
Phone-first Every runnable example keeps a QR code.
Current API Reference data is checked against src/p5-phone.js.
Start

Quick Start

Use p5.js, load p5-phone, lock gestures, then enable the capability your sketch needs from a user tap.

Designed for p5.js 2.x

<script
  src="https://cdn.jsdelivr.net/npm/p5-phone@1.12.1/dist/p5-phone.min.js">
</script>
function setup() {
  createCanvas(windowWidth, windowHeight);
  lockGestures();
  enableGyroTap('Tap to enable motion sensors');
}

function draw() {
  background(245);
  textAlign(CENTER, CENTER);

  if (window.sensorsEnabled) {
    circle(width / 2 + rotationY * 3, height / 2 + rotationX * 3, 60);
  } else {
    text('Tap to enable motion sensors', width / 2, height / 2);
  }
}
Permission pattern: put code that uses phone hardware inside a positive enabled check. Write sketches as if (window.sensorsEnabled) { ... }, if (window.micEnabled) { ... }, or the matching status flag for the capability you enabled.

Motion Sensors

if (window.sensorsEnabled) {
  circle(width / 2 + rotationY * 3, height / 2 + rotationX * 3, 60);
}

Microphone

if (window.micEnabled) {
  let level = mic.getLevel();
  circle(width / 2, height / 2, level * 500);
}

Sound Output

function mousePressed() {
  if (window.soundEnabled) {
    mySound.play();
  }
  return false;
}

NFC

if (window.nfcEnabled) {
  if (isNfcTag('shirt')) {
    drawShirtEffect();
  }
}

Bluetooth (BLE)

function setup() {
  bleSetup({
    characteristics: [
      { name: 'temp', type: 'float', notify: true }
    ]
  });
  enableBleTap();
}

function bleReceive(name, value) {
  debug(name + ' = ' + value);
}

Vibration

function mousePressed() {
  if (window.vibrationEnabled) {
    vibrate(50);
  }
  return false;
}

Camera

if (cam.ready) {
  cam.draw();
}

Multiple Types

enablePermissionsTap(['sensors', 'mic'], 'Tap to enable motion + microphone');

if (window.sensorsEnabled && window.micEnabled) {
  circle(
    width / 2 + rotationY * 3,
    height / 2 + rotationX * 3,
    80 + mic.getLevel() * 400
  );
}
p5.js 2.0 note: use mousePressed(), mouseDragged(), and mouseReleased() for touch or pointer input. The older touchStarted(), touchMoved(), and touchEnded() callbacks are p5.js 1.x only.
Reference

API

Grouped by the job you are trying to do. The permission table keeps the five UI styles visible, and each category lists the p5 APIs that become practical after p5-phone handles the mobile browser setup.

Examples

Example Catalog

Reordered around starter sketches, input, output, ML5, and lower-priority comparison material. Each card has room for a full example, minimal version, Web Editor link, source link, and QR code.

Support

Compatibility

Plan mobile sketches by platform first. Browser permissions and hardware support matter more than the p5.js version for most phone behavior.

iOS Safari

  • Motion sensors, microphone, sound, speech, and camera must start from a user tap or button.
  • Motion permission uses Apple-specific sensor prompts, so the enable helpers are important.
  • Web NFC and vibration are not available in Safari on iPhone.
  • Use mousePressed(), mouseDragged(), and mouseReleased() for touch-compatible sketches.

Android Chrome

  • Motion sensors usually work without the iOS-style sensor permission prompt.
  • Microphone, sound, speech, and camera still need a user gesture and browser permission.
  • Web NFC is Android Chrome only and requires HTTPS with NDEF-formatted tags.
  • Vibration is available on many Android devices through vibrate().
CapabilityiOS SafariAndroid ChromeDesktop browsers
Motion sensorsSupported after a tap permission flow.Supported; permission request is usually a no-op.Limited or unavailable on most laptops and desktops.
Touch inputSupported through touch and pointer events.Supported through touch and pointer events.Use mouse or pointer callbacks for testing.
Microphone and soundSupported after user gesture and permission.Supported after user gesture and permission.Supported after browser permission.
Speech recognitionBrowser support varies; test on the target device.Supported in Chrome where Web Speech is available.Browser support varies.
NFCNot supported.Supported in Chrome on HTTPS.Not supported.
Camera and ML5Supported after camera permission.Supported after camera permission.Supported after camera permission.
VibrationNot supported.Supported on many phones.Limited or unavailable.