Cujo the turtle loves to dance. She also likes to sleep. What if we want to know when she does each of her activities? With a passing-by visual observation, it’s not always obvious. What if we could track her movement day and night and see for ourselves? Now, what if we could do all of that without writing a single line of code? We can with WipperSnapper!

Using an Adafruit Funhouse and a PIR motion sensor, we’ll track the movement of Cujo the turtle. Then we’ll analyze and visualize the data we’ve gathered to try and make sense of the results!

Wanna see what times of the day Cujo moved the most over the course of a week? Spoiler alert! The results are below.

No turtles were harmed in the making of this guide. Additionally, Cujo gets ample time out of her habitat to play around in the apartment :)

Prerequisite Guide:

WipperSnapper is an interface for Adafruit IO, our incredibly easy-to-use IoT platform, designed to turn any WiFi-capable board into an IoT device without programming a single line of code.

If you've never used WipperSnapper, click below to read through the Quickstart WipperSnapper guide before continuing.

Project materials

Adafruit products:

Home is where the heart is...it's also where we keep all our electronic bits. So why not wire it up with sensors and actuators to turn our house into an electronic wonderland....
$34.95
In Stock
PIR sensors are used to detect motion from pets/humanoids from about 5 meters away (possibly works on zombies, not guaranteed). This sensor is much smaller than most PIR modules, which...
$3.95
In Stock
As technology changes and adapts, so does Adafruit. This  USB Type A to Type C cable will help you with the transition to USB C, even if you're still...
$4.95
In Stock
Our 5V 2A USB power adapter is the perfect choice for powering single-board computers like Raspberry Pi, BeagleBone, or anything else that's power-hungry!This adapter was...
$7.95
In Stock
These Female/Male 'extension' jumper wires for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 3" (75mm) long and come...
$1.95
In Stock

Other materials:

  • Wooden skewers (found at the dollar store)
  • Tape

Align the Polarity

Adding the mini PIR sensor to the FunHouse is pretty simple, you just need to check the polarity.

Look for the + symbol on the PIR sensor's PCB and match it up with the + symbol on the front side of the FunHouse board's PIR row.

Insert Sensor

Align the pins with the socket holes on the front side of the board.

The first time you insert the sensor the fit is tight, but just apply firm down ward pressure while wiggling the board a little bit and it will go in just fine.

Step 1 is to get your Funhouse set up in the Adafruit IO WipperSnapper page. Follow the instructions in the previously mentioned Quickstart guide to do this. 

Set up the PIR sensor

In addition to the built-in LED that we set up from the Quickstart guide, we'll also want to get the PIR motion sensor set up within WipperSnapper.

  • From the WipperSnapper page, click "New Component"
  • Select "PIR Sensor"
  • Name the sensor
  • Select "PIR Sensor" for the PIR Sensor pin
  • choose the "On Change" option for the return interval. This means that the sensor will ping out data only when it is triggered (aka when Cujo the turtle moves)
  • Your WipperSnapper page should now look something like this (click on image to enlarge)
  • Ignore the "triggers" and "dashboard" for now, we'll create those next!

Create a Feed for the PIR sensor

Now that the FunHouse is connected to WipperSnapper and the PIR sensor and LED are set up, it's time to create a feed. Why? The sensor data needs a home. When the sensor is tripped, we want to send a message to this new feed documenting that movement was detected at a given time.

  • In the top pane, click "Feeds"
  • Then click "view all"
  • Create a new feed group and call it "WipperSnapper" or whatever you'd like
  • Within the new feed group, click "new feed" and enter the details about the feed.
  • Click "create"

Set up the Triggers

Now that we have a home for our data, we need to point the data to that home when certain events happen. Now it's time to define those events with triggers. Here are the triggers we'll create:

  • Send a message "Turtle moved!" to the motion sensor feed each time the sensor has been activated.
  • Send a message "Turtle is still" to the motion sensor feed when there is no longer any movement.
  • Set the LED to ON when the sensor is triggered
  • Set the LED to OFF when the sensor is not triggered.
  • In the top pane, click "Triggers"
  • Then click "view all"
  • Click "New Trigger" in the top left of the page
  • Choose "Reactive Trigger"

First up we want to send a message "Turtle moved!" to the motion sensor feed each time the sensor has been activated.

  • If motion sensor is greater than Comparison Value 0
  • Then publish a message to Motion sensor activated? feed with Turtle moved!
  • Hit save

Create another reactive trigger for when the turtle is still:

  • If motion sensor is less than Comparison Value 1
  • Then publish a message to Motion sensor activated? feed with Turtle is still.
  • Hit save

Create two more reactive triggers for the LED:

  • New trigger: If motion sensor is greater than Comparison Value 0
  • Then publish a message to built in led feed with 1
  • Hit save
  • New trigger: If motion sensor is less than Comparison Value 1
  • Then publish a message to built in led feed with 0
  • Hit save

Why create LED triggers?

This lets us know if the motion sensor is properly working when in the calibration step which is coming up soon.

Next up we'll set up the dashboard so we can get some visual feedback on the data.

To visualize and keep tabs on Cujo, we'll need to create a dashboard. This will be an easy way to access the results from the feed and triggers we just set up.

  • In the top pane, click "Dashboards"
  • Next click "view all"
  • Click "New Dashboard"
  • Enter the title and description for the dashboard

Now we're in the Dashboard creator!

  • Click the gear icon then click the "create new block" option
  • These are all the different blocks available.

Create a line chart graph

This is helpful for seeing Cujo's movement patterns over time.

  • From the different blocks, click on the one entitled "Line Chart"
  • From your FunHouse feeds, select "motion sensor" for the chart feed
  • Name the chart
  • Create a time range for the data we would like to see.
  • Label the axes
  • Set the min and max value for the Y-axis
  • Click "Create block"
  • Hit "Save Layout"

Create a stream for the data feed

This is helpful for seeing exact data points. Aka what time exactly did Cujo move?

  • Create another new block from the gear icon.
  • Select the "Stream" block
  • For the feed, choose the feed we manually created earlier from the WipperSnapper feed group called "Motion sensor activated"?
  • Create a name for the block as well as a time range for the data we would like to see.
  • Click "Create block" and save the layout

And voila! There's our gorgeous dashboard. We can change the layout of the blocks by hitting the gear icon and dragging the blocks around, then saving the layout.

Don't see any data?

That's ok, try refreshing the page. If there's still nothing that's probably because we haven't collected any data yet! (These screenshots are showing data that's been collected over the last couple of days of this writing).

Now it's time to place the sensor near Cujo's habitat and start collecting some delicious data!

One fun fact about PIR motion sensors, they are infrared-based and are not able to see or detect movement through glass. How do we solve this problem? By placing the sensor over the tank. This works quite well because the glass blocks all other movements when pesky humans walk by or come to observe Cujo. 

Using some wooden skewers from the dollar store and some Scotch tape, I was able to easily hang the FunHouse and PIR sensor over Cujo's tank.

Calibration

The next obstacle? I noticed the sensor wasn't picking up Cujo's movements at the very top of the tank. The sensor needed to be closer to Cujo. 

(Note, I was using a toaster oven rack at first to hold up the FunHouse before switching to the much more ideal wooden skewers. Now I can use my toaster oven again!)

That's more like it! Now it able to register Cujo's movement more frequently. 

Testing...Testing

Next, let's double-check the sensor and the dashboard are set up correctly. Power on the Funhouse using a 5V 2A power supply with a USB C cable. Now wave your hand in front of the motion sensor. The onboard red led should blink on and off. Additionally, the dashboard should have recorded the hand wave as turtle movement.

If the LED is not blinking or the data isn't showing up on the dashboard, double-check the FunHouse feeds, triggers and dashboard were all set up properly in the earlier sections of this guide. Do not move on until the led blinks properly and the dashboard is collecting accurate data otherwise the project won't be collecting anything useful.

Just walk away

Ok now that everything is in working order, place the sensor in an ideal space above the tank and go away. It's time to let Cujo do her thing! The next step is to monitor, analyze and visualize the data. It's time to be a scientist and watch Cujo... from a computer.

sensors_turtle_annotation.png
note: LED I/O block is not necessary

It will be tempting to watch the dashboard in the first day or two but after a couple of days of data collection, we can start to see a bigger picture of Cujo's movement patterns. Make sure to distinguish the data recorded from the setup and calibration as opposed to the data from when the sensor was all set up and you walked away.

And it worked! Look at that wonderful turtle data! What does it mean? A couple of days is neat and all but how about waiting a whole week? You can stop here but going further into this bonus section will unlock some great turtle mysteries. Slow and steady wins the race...

Bonus section: use Google Sheets to analyze a week of turtle data

Ok, it's been a week. Suppose we'd like to see more than just the times that Cujo moved? Let's inquire about:

  • What times of the day did Cujo move the most?
  • What days did Cujo move more than other days?

These questions may give us more insight into her movement patterns than the simple line chart. 

We can export the data from Adafruit.io and import it into Google Sheets to do some analysis and answer these questions.

Download feed data

  • Go to your feeds and select the "Motion sensor activated" feed we set up earlier.
  • Click the "Download All Data" button 
  • Click "Download as CSV"
  • Next hit "click to refresh"
  • Now click "Link" to download the file.

Import feed data into Google Sheets

  • Go to https://drive.google.com/
  • You may have to create a free Gmail account if you don't already have one.
  • Create a new Google Sheets document and name it
  • Go to File > Import
  • Upload the CSV file we just downloaded from Adafruit.io
  • Select the file
  • Choose the option "Append to current sheet" for the import location.
  • Hit import data.
  • Watch as the turtle data floods your spreadsheet. Huzzah!

Separating the day and time into separate columns 

You may notice the time stamp for each data point includes both day and time. To analyze the data in the way that we'd like, it will be helpful to have separate columns for the day and the time. The day column will come in handy when we want to analyze which days Cujo moved the most. We don't so much care for the times she moved in this data set. The same goes for when we want to analyze which times of the day Cujo moved the most (we don't care which day it was).

  • Click on column d to highlight the entire date/time column.
  • In the toolbar go to Data > Split text to columns
  • Now the time/date data is split into 3 columns: date, time, and time zone. (Time zone is not important for this project)

Data Analysis Chart #1: Which times of the day did Cujo move the most during the week?

For this data visualization, let's split the day up into 4 equal parts (in military time)

  • 00:00 - 05:59
  • 06:00 - 11:59
  • 12:00 - 17:59
  • 18:00 - 23:59
  • In a new column called "time portion" manually fill out 4 rows with each of these time segments.
  • The next column should be called "times moved"
  • Now enter this formula into the cell next to 00:00 - 05:59: =countifs(E2:E758,">= 0:00:00", E2:E758, "<= 05:59:59")/2
  • This formula counts the times in column E that are between 00:00 - 05:59 then divides the resulting value by 2 (to remove the times that the sensor reset to the still state)
  • Replace E758 with the location of the last cell in this column for you.
  • Now continue this process for the other three cells.

Pie time

Now that we know how many times Cujo moved during the 4 parts of the day, let's make a pie chart!

  • Now highlight both columns we just created.
  • In the toolbar, click insert > chart
  • Select one of the pie chart options (I like the 3D one)
  • The pie should fill with the selected data.
  • Feel free to add a title and rename any labels.
  • I decided to rename column G with each time frame's colloquial name for easier reference on the chart (morning, night etc.)

That's one pretty pie!

You can adjust the font and text settings in the graph editor.

Data Analysis Chart #2: Which days did Cujo move the most during the week?

Following the same method as above, we can create a bar graph to show the days that Cujo moved the most.

The formula used is slightly differnt this time:

=countifs(D2:D758,"2021-09-29") / 2

This spits out the number of times Cujo moved on the specified day

For each cell, replace 2021-09-29 with the day you'd like to collect data for.

Chart it up with a bar graph and badda bing!

Takeaways

What patterns did you notice? 

  • Cujo liked to dance at night and sleep in the day.
  • She had a busy week to start, then got quite relaxed.
  • After feeding her, she seemed to calm down quite a bit.

You can recreate this project for your own pet(s). Some ideas include:

  • Birds
  • Reptiles
  • Hampsters and gerbils
  • Guinea pigs
  • Dogs: could put a sensor in the kennel or crate if they sleep in there.

Good luck uncovering something you didn't expect to discover about your pet with the power of WipperSnapper!

 

This guide was first published on Oct 12, 2021. It was last updated on 2021-10-12 11:59:45 -0400.