HTML connect to BLE using p5.ble.js and p5.js

Just want to share a bit of webpage code that seems to work with the LED Control example code at


ISSUE: because the above example waits for the serial monitor, you must load the serial monitor before the web page will work.

If you have the above with serial monitor loaded, try this web page at

The github with code is at

If you don’t want to have to start the serial monitor, use my


The web page code is at


My version of the central program is (you must send a “1” to connect and a “2” to scan. My version works with anything that has LED in it’s BLE local name. It connects to the latest BLE found)


The actual webpage code is fairly simple, and can be edited with a simple text editor. Seems to work for me using both Chrome and my Android cell phone, although the cell phone took a while to connect to the Arduino.


<title>Simple LED, Rocksetta and p5.ble.js</title>

<script src=""></script>
<script src=""></script>


// Global variables and constants

// The serviceUuid must match the serviceUuid of the device you would like to connect
const serviceUuid = "19b10010-e8f2-537e-4f6c-d104768a1214";

let myCharacteristic;
let input;
let myBLE;

function setup() {
  myBLE = new p5ble();

function connectToBle() {
  // Connect to a device by passing the service UUID
  myBLE.connect(serviceUuid, gotCharacteristics);

function gotCharacteristics(error, characteristics) {
  if (error) console.log('error: ', error);
  console.log('characteristics: ', characteristics);
  // Set the first characteristic as myCharacteristic
  myCharacteristic = characteristics[0];

function myWriteToBle(myIn) {
  myBLE.write(myCharacteristic, myIn);



<H1>Simple LED, Rocksetta and p5.ble.js</H1>
<h6>By <a href="">Jeremy Ellis</a> Twitter <a href="">@rocksetta</a></h6>

<input type=button value="Connect to Simple-LED" onclick="{

<input type=button value="Led On" onclick="{

<input type=button value="Led Off" onclick="{