I Love You Pillow with the Arduino IoT Bundle

Open source is love, and so are hugs!

Components and Supplies

Apps and Online Services

About This Project

Create a pillow that sends your love with the help of the Arduino Cloud!

We all know that being without that special person in your life can be difficult, but what if you could send love and affection remotely over the Internet by just hugging a pillow?

Now, we can't really send hugs... but what we can send is a sweet emoji through a messaging app, triggered by you giving a pillow a hug.

When you hug the I Love You Pillow you will hear the sound of a heartbeat coming from the buzzer inside. Depending on the length of your hug, a different emoji will be sent to a chat box in the Arduino IoT Cloud Remote app.

Stay in touch with your loved one with this huggable device!

In a Nutshell

In this experiment, we will use aluminium foil to create a DIY capacitive sensor that will be used to detect hugs. By hugging the pillow you can send loving emojis to your beloved.

Components

  • Buzzer
  • Aluminium foil
  • 1 resistor 5M ohm
Show your love with a hug!
Show your love with a hug!

Show your love with a hug!

Learning Goals

  • Introducing the Arduino Cloud
  • Introducing the Arduino IoT Remote app
  • Managing capacitive sensors
  • Creating an Arduino Cloud Dashboard
  • Sharing dashboards #ProTips

Pro Tips are useful but not strictly necessary steps that add a layer of complexity to the project.

Want to Know More?

This tutorial is part of a series of experiments that familiarize you with the Arduino RP2040 and IoT. All experiments can be built using the components contained in the IoT Bundle.

Circuit

In this project, we will be using the following circuit. In it, we have a piezo speaker connected to pin 8, a 5M ohm resistor connected between A0 and A1, with jumper wires connected to the tin foil.

Show your love with a hug!
Show your love with a hug!

Setting up the Arduino Cloud

If you are new to the Arduino Cloud, check out our Getting Started Guide.

Template

To connect your board to the Arduino Cloud, we will use the I Love You Pillow Template. This template installs a specific sketch on your board and creates a dashboard that allows you to interact with your board: you don't need to write any code at all!

See the image below to understand how to set it up.

Thing overview
Thing overview

We will start by setting up the Arduino Cloud by following the steps below:

  • Login to your Arduino Create account
  • Creating a Thing
  • Attaching a Device
  • Adding the following Variables
  • Adding Network credentials
Arduino IoT Bundle

Variables

We will start by adding these variables:

Arduino IoT Bundle
Arduino IoT Bundle

Programming Overview

We will gradually build the code for the project. There are three steps to this:

  • Testing the chat function.
  • Sending hugs to the Cloud.
  • The heartbeat (Final Sketch)

In each of the sections, a separate code is provided. If you have created the variables in the Thing interface correctly, the code presented can simply be copy and pasted into the Cloud editor, and be uploaded to your board.

If you want to skip ahead to the final part, go to the The Heartbeat section which has the final sketch.

Testing the Chat Function

The first part in this project is to test out the chat functionality. The sketch below checks for whenever the string

<3
is received via the Arduino messenger widget, and sends back a heart emoji.

In order to send an emoji we will need to use UNICODE characters.For instance to send an heart emoji we will use “\U00002764”. You can see the full list of unicode emoji codes here.

1#include "thingProperties.h"
2void setup() {
3 // Initialize serial and wait for port to open:
4 Serial.begin(9600);
5 delay(1500);
6 // Defined in thingProperties.h
7 initProperties();
8 // Connect to Arduino Cloud
9 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
10 setDebugMessageLevel(2);
11 ArduinoCloud.printDebugInfo();
12}
13void loop() {
14 ArduinoCloud.update();
15 if (chat ==
16"
17 <3
18"
19) {
20 chat = "\U00002764";
21 }
22}
23void onChatChange() {
24//this function is automatically generated
25}
26void onHeartBeatChange() {
27//this function is automatically generated
28}
29void onPressedChange() {
30//this function is automatically generated
31}

After uploading the sketch above to your Nano RP2040 Connect board, you need to create a messenger widget where you can send and receive messages. To achieve that, navigate to Arduino Cloud -> Dashboards -> Create Dashboard -> Add -> Messenger Widget.

Now, you can try it out! Send

<3
via the messenger chat, and you should receive a heart. The "heart response" is sent from the physical Arduino board, and if it works, we know the connection between the Arduino Cloud and your Arduino is working!

Arduino IoT Bundle
Arduino IoT Bundle

Sending Hugs to the Cloud

We also want to be able to "send hugs" from the Arduino to the Arduino Cloud, and we will do so by measuring capacitance. In a nutshell, we will build a simple capacitance meter, using tinfoil&jumperwires connected to analog inputs.

The tinfoil will be placed inside a pillow, and when we squeeze the pillow, the capacitance will change. When the capacitance change, we will change a boolean (pressed) to true, which will be visible in a dashboard.

Upload the example sketch, connect the wires and see the result on the console:

1#include "thingProperties.h"
2void setup() {
3 // Initialize serial and wait for port to open:
4 Serial.begin(9600);
5 delay(1500);
6 // Defined in thingProperties.h
7 initProperties();
8 // Connect to Arduino Cloud
9 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
10 setDebugMessageLevel(2);
11 ArduinoCloud.printDebugInfo();
12}
13void loop() {
14 ArduinoCloud.update();
15 if (chat ==
16"
17 <3
18"
19) {
20 chat = "\U00002764";
21 }
22
23 int reading = analogRead(A0);
24
25 //threshold set to 500, this can be adjusted to your liking
26 if(reading > 500){
27 pressed = true;
28}
29else{
30 pressed = false;
31}
32}
33void onChatChange() {
34//this function is automatically generated
35}
36void onHeartBeatChange() {
37//this function is automatically generated
38}
39void onPressedChange() {
40//this function is automatically generated
41}

The Heartbeat (and Final Sketch)

The longer you hug, the more heartbeats you hear. The more the heart beats the more love you send (and different emoji, as well).

We will emulate the sound of a heartbeat using a buzzer and a few simple lines of code.

1#include "thingProperties.h"
2int Buzzer = 8;
3void setup() {
4 // Initialize serial and wait for port to open:
5 Serial.begin(9600);
6 delay(1500);
7 // Defined in thingProperties.h
8 initProperties();
9 // Connect to Arduino Cloud
10 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
11 setDebugMessageLevel(2);
12 ArduinoCloud.printDebugInfo();
13}
14void loop() {
15 ArduinoCloud.update();
16 if (chat ==
17"
18 <3
19"
20) {
21 chat = "\U00002764";
22 }
23
24 int reading = analogRead(A0);
25
26 //threshold set to 500, this can be adjusted to your liking
27 if(reading > 500){
28 pressed = true;
29
30 //execute the activateBuzzer() function when threshold is being met.
31 activateBuzzer();
32 heart_beat +=1; //increase heart_beat value for every "heart beat".
33}
34else{
35 pressed = false;
36}
37}
38void activateBuzzer() {
39 tone(Buzzer, 31, 200); // tone(Pin, Note, Duration);
40 delay(200);
41 tone(Buzzer, 31, 400);
42 delay(200);
43 noTone(Buzzer);
44 delay(1000);
45}
46void onChatChange() {
47//this function is automatically generated
48}
49void onHeartBeatChange() {
50//this function is automatically generated
51}
52void onPressedChange() {
53//this function is automatically generated
54}

Dashboard

Finally, we need to build a dashboard to communicate with our loved one. In addition to the messenger widget we added to our dashboard, we will add two more widgets:

  • A Gauge widget linked to the “heart_beat” variable
  • A LED widget linked to the “pressed” variable
Arduino IoT Bundle

Next, you need to download the Arduino IoT Cloud Remote app. Both iOS and Android versions are available and can be downloaded for free from the App Store and Google Play. The app can be used to display and interact with your Dashboards.

After downloading the app on the device of your loved one, you can login with your Arduino Create account and open your “love-you-pillow” dashboard. Now your loved one can use the app to send and receive hugs from you virtually, via the Love You Pillow!

#ProTip: Shareable Dashboards

Instead of logging into your account on the Arduino IoT Cloud Remote app, you can share your dashboards with any number with friends. This feature is only available if you have the Arduino Maker subscription.

Want to Know More?

This tutorial is part of a series of experiments that familiarize you with the Arduino RP2040 and IoT. All experiments can be built using the components contained in the IoT Bundle.

Full Code

1#include "thingProperties.h"
2int Buzzer = 8;
3void setup() {
4 // Initialize serial and wait for port to open:
5 Serial.begin(9600);
6 delay(1500);
7 // Defined in thingProperties.h
8 initProperties();
9 // Connect to Arduino Cloud
10 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
11 setDebugMessageLevel(2);
12 ArduinoCloud.printDebugInfo();
13}
14void loop() {
15 ArduinoCloud.update();
16 if (chat ==
17"
18 <3
19"
20) {
21 chat = "\U00002764";
22 }
23
24 int reading = analogRead(A0);
25
26 //threshold set to 500, this can be adjusted to your liking
27 if(reading > 500){
28 pressed = true;
29
30 //execute the activateBuzzer() function when threshold is being met.
31 activateBuzzer();
32 heart_beat +=1; //increase heart_beat value for every "heart beat".
33}
34else{
35 pressed = false;
36}
37}
38void activateBuzzer() {
39 tone(Buzzer, 31, 200); // tone(Pin, Note, Duration);
40 delay(200);
41 tone(Buzzer, 31, 400);
42 delay(200);
43 noTone(Buzzer);
44 delay(1000);
45}
46void onChatChange() {
47//this function is automatically generated
48}
49void onHeartBeatChange() {
50//this function is automatically generated
51}
52void onPressedChange() {
53//this function is automatically generated
54}

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.