Intro to Wearables Week 6/7

Task: Turn one of the previous wearable projects into a wireless one.

I had the idea of creating some sort of messaging system to alert me when my dog pooped. I usually let my dog go off to do his business on his own, but sometimes he runs away to poop in secret or I have to get something and am unable to find where he poops. I had some ideas for which sensor to use, but I decided upon a light sensor. I had the idea that when my dog poops, the back of his garment is raised allowing there to be exposed light to the photoresistor that is underneath his garment. I decided to use an Arduino MKR WiFi 1010 because it was easily accessible. I started by connecting the circuit to get a read on the light sensor. Due to the nature of a light sensor and an FSR, I interchangeable tested them since I was unsure which I would use in the end. This was very simple, I started by connecting the light sensor and FSR to a normal Arduino in order to make sure I was getting readings and then transferred it to the MKR 1010. I’m not sure if a MKR 1010 has the internal resistor function, but that seemed to not work when I tried to do this. I tried to modify one of the other examples of a p5.js sketch in order to get information to the browser, but this was rather difficult because I was trying to just get one input into a sketch that was meant for two inputs, but I eventually used the example sketch that is on the p5.ble.js website in order to gather information from the light sensor or FSR into the browser and this worked really well. The example I was using had difficulty going through the characteristic array because there was only one object in the array.

I also went through some trouble gathering information through p5.js because the sensorValue would never change from 0 or gather information from the Arduino, this was because I was using the example that required two inputs and while manipulating the code, I must have created an error somewhere while changing variable names and commenting things out.

I tried to mockup a garment that would move upward in the back when my dog scrunched, exposing the light sensor to some light, but this proved to be a larger challenge cause of the variable amount of light and the rigidness that the garment would have to have. In the end, I just decided to utilize a flex sensor. One thing I noticed is that the values that p5.js receive were always between 0 and 255, when some of the values I was seeing on the serial monitor were way above that. In this case, I don’t know if the values are mapped between 0 and 255, or if the values are just automatically scaled and once it reaches above 255, the values are capped. I think the values were mapped, but I also wanted to make sure this was the case, so I mapped the value of the sensor on the Arduino side of things to a value between 0 and 255. I also had difficulty when making the MKR 1010 truly wireless, even when the “while (!Serial)" line of code was commented out.

Below are my documentation photos, final photos, a video of the circuit in action and the code for the circuit.

normal standing pose

normal standing pose

pose while pooping

pose while pooping

#include <ArduinoBLE.h>

const int lightPin = A2; // set buttonPin to digital pin 4

BLEService sensorService("7bfa8c8f-fa3e-4371-a9eb-6c0a4dff68a7"); // create service

BLEIntCharacteristic sensorCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);

void setup() {
  while (!Serial);

  pinMode(lightPin, INPUT_PULLUP); // use button pin as an input

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");
    while (1);

  // set the local name peripheral advertises
  BLE.setLocalName("Sensor Button");

  // set the UUID for the service this peripheral advertises:

  // add the characteristics to the service

  // add the service

  //set init value

  // start advertising

  Serial.println("Bluetooth device active, waiting for connections...");

void loop() {
  // poll for BLE events

  int sensorValue = analogRead(lightPin);
  sensorValue = map(sensorValue,0,1023,0,255);
// Copyright (c) 2018 p5ble
// This software is released under the MIT License.

// The serviceUuid must match the serviceUuid of the device you would like to connect
const serviceUuid = "7bfa8c8f-fa3e-4371-a9eb-6c0a4dff68a7";

let sensorCharacteristic;
let sensorValue = 0;
let myBLE;

function setup() {
  // Create a p5ble class
  myBLE = new p5ble();

  createCanvas(windowWidth, windowHeight);
  // Create a 'Connect and Start Notifications' button
  const connectButton = createButton('Connect and Start Notifications')

function connectAndStartNotify() {
  // 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);
  myCharacteristic = characteristics[0];
  // Read the value of the first characteristic, gotValue);
  // Start notifications on the first characteristic by passing the characteristic
  // And a callback function to handle notifications

function gotValue(error, value) {
  if (error) console.log('error: ', error);
  console.log('value: ', value);
  sensorValue = value;
  // After getting a value, call again to get the value again, gotValue);

function draw() {
  if (sensorValue < 6) {
    background(color(255, 0, 0));
    text("POOP ALERT", (width / 2) - 30, height / 2);
    fill((101, 67, 33));
    translate(random(width), random(height));
    ellipse(0, 0, 40, 20);
    ellipse(0, -10, 30, 20);
    ellipse(0, -20, 20, 20);
    ellipse(0, -30, 10, 10);
    translate(random(width), random(height));
    ellipse(0, 0, 40, 20);
    ellipse(0, -10, 30, 20);
    ellipse(0, -20, 20, 20);
    ellipse(0, -30, 10, 10);
  } else {
    background(color(0, 255, 0));
    text("No poop", (width / 2) - 30, height / 2);