Hug-sensing IoT Parihug toy (w Xyla Foxlin)

Here’s how to make your own telepresence hug toy. Each circuit connects to the Arduino IoT Cloud and translates your hug into a soothing vibration on the other toy. Xyla Foxlin originally developed this project as a crowdfunded product, and we collaborated to bring this DIY version to life.

To make this project, you will need 2x of each:

Plus these tools:

  • Soldering tools and supplies
  • Silicone adhesive
  • Hot glue gun with glue sticks

Circuit Diagram

Assemble your circuit as shown. We used a solderless breadboard to prototype before soldering the components to a more permanent solder-type proto board.

Test Components Individually

Follow these instructions to Install board support for ESP8266 and the SiLabs CP2104 driver so that your computer and Arduino software can communicate with the microcontroller.

Install the MPRLS pressure sensor Arduino library and test its included demo sketch. Do not proceed until you are getting pressure readings in the serial monitor.

Use Arduino’s included Blink sketch, modified to pin 12, to test out the motor.

Once the pressure sensor and motor are each working independently, then you know the wiring is correct and we can move on to the more complex internet-connected code. It’s important not to skip this step.

Attach Tubing to Sensor

Use silicone adhesive to affix the tubing to the port on the sensor, and glue the other end into the opening of the dog toy squeaker (after the squeaky part has been removed). Hot glue works in a pinch or for testing but doesn’t really stick to the tubing.

Connect to Arduino IoT Cloud

You’ll need to set up a (free) account with Arduino to use their IoT Cloud service. Then plug in your wifi devices, one at a time, and register them within your account. Save the credentials for your device, you’ll need them for the Arduino sketch.

Create a new variable on Arduino IoT Cloud called “hug”.

Here’s our code for this project. You’ll have to update several bits of info within it to make it work with your account and wifi network.

// Parihug IoT Hug project by Xyla Foxlin, adapted 2023 by Becky Stern
// Watch the video: https://youtu.be/u6gj8VzrHBo
// Tutorial: https://beckystern.com/2023/11/27/hug-sensing-iot-parihug-toy-w-xyla-foxlin/
// This code is in the Public Domain

#define SECRET_SSID "Your Network Name"
#define SECRET_OPTIONAL_PASS "yourpassword"
#define SECRET_DEVICE_KEY "PSyourdevicekeyHSK"

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char DEVICE_LOGIN_NAME[] = "431f9c0e-your-device-name-f08c993f9c8b";

const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_OPTIONAL_PASS; // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[] = SECRET_DEVICE_KEY; // Secret device password

void onHugChange();

bool hug;

void initProperties(){

ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(hug, READWRITE, ON_CHANGE, onHugChange);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

#include <Wire.h>
#include "Adafruit_MPRLS.h"

// You dont *need* a reset and EOC pin for most uses, so we set to -1 and don't connect
#define RESET_PIN -1 // set to any GPIO pin # to hard-reset on begin()
#define EOC_PIN -1 // set to any GPIO pin to read end-of-conversion by pin
Adafruit_MPRLS mpr = Adafruit_MPRLS(RESET_PIN, EOC_PIN);

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
pinMode(12, OUTPUT);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);

// Defined in thingProperties.h
initProperties();

// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);

/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();

Serial.println("MPRLS Simple Test");
if (! mpr.begin()) {
Serial.println("Failed to communicate with MPRLS sensor, check wiring?");
while (1) {
delay(10);
}
}
Serial.println("Found MPRLS sensor");
}

void loop() {
ArduinoCloud.update();

float pressure_hPa = mpr.readPressure();
Serial.print("Pressure (hPa): "); Serial.println(pressure_hPa);
Serial.print("Pressure (PSI): "); Serial.println(pressure_hPa / 68.947572932);
if (pressure_hPa > 1100){
hug=true;
Serial.println("Hug = true");
Serial.println("buzz buzz loop");
digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
}else{
hug=false;
Serial.println("Hug = false");
}
delay(1000);


}

/*
Since Hug is READ_WRITE variable, onHugChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHugChange() {
if(hug==true){
Serial.println("buzz buzz onHugChange");
digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
}

}

Program each circuit with the code customized for its wifi device, using your device’s ID, private key, and your wifi network name and password. Squeezing the air bladder triggers the “hug” variable to change from FALSE to TRUE, and both circuits will buzz in response.

5 thoughts on “Hug-sensing IoT Parihug toy (w Xyla Foxlin)

  1. I love this project! Would you be open to putting the code up on a site like GitHub with an open source license so it is more browseable and easier for people to fork and share?

    1. Is there another site besides Github that you would recommend? I don’t particularly like it, for lots of reasons. I updated the post to add the code as a snippet and not just a zip, so you can read before you download, and added a Public Domain message.

      1. Sourceforge.net is another favorite of the opensource community, although I personally prefer Github. You could upload the source code there. The code is in C right?

  2. I think the only thing I would change is to find a bigger, (more area), bladder to squeeze. You two are full grown adults and found it hard to locate the squeak toy to squeeze, a child won’t understand to search for it and could lead to disappointment. Maybe an inflatable ball, partially filled. Or even a whoopie cushion might be easier. (Without the farts, silly!)

Comments are closed.