Overview
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.
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.
Other materials:
- Wooden skewers (found at the dollar store)
- Tape
Page last edited March 08, 2024
Text editor powered by tinymce.
Add the Mini PIR Sensor
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.
Page last edited March 08, 2024
Text editor powered by tinymce.
Set up FunHouse, Feeds and Actions
Step 1 is to get your Funhouse set up and online in the Adafruit IO WipperSnapper Devices page. Follow the instructions in the FunHouse product learn guide, on the WipperSnapper Setup page.
We'll get then PIR motion sensor setup within WipperSnapper, and then add the DotStar LED lights for output.
- From the WipperSnapper page, click "New Component"
- Search for "PIR Sensor" then select the PIR sensor component
- 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)
- Next we'll add the DotStar LEDs. Click the New Component button again.
- Search for DotStar and select the component.
- On the configuration page leave the default pins selected, but change the Number of Pixels from 1 to 5. The Color Order should be BRG.
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 "New Group"
- Create a new feed group and call it "WipperSnapper" or whatever you'd like
- Click the group name in the feeds list page to go there before creating a feed, but in future you can use the + button at the end of the row to directly add a feed to the group.
- Within the new feed group, click "new feed" and enter the details about the feed.
- Click "create"
Set up the Actions
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 actions. Here are the actions 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 navigation pane, click "Actions"
- A searchable list of actions appears, with status information at the end of each row.
- Click "New Action" in the top left of the page
- Choose a name and optional description then click Create.
First up we want to send a message "Turtle moved!" to the motion sensor feed each time the sensor has been activated.
Drag a trigger block, the one which says "When gets data matching = 0", from the toolbox and into the Triggers: section of the workspace. Update the feed dropdown to select the motion sensor, and change the operator from equals (=) to instead be "greater than" (>).
Next add a Set Feed block to the Actions: section of the root block on the diagram. Alter the feed to point to the "Motion Sensor Activated?" feed, and the value to be Turtle Moved!.
Your diagram should now look like this:
-
Triggers: When
motion sensorgets data matchinggreater than0 -
Actions:
Set FeedMotion sensor activated?to valueTurtle moved! - Hit save, and choose Enable and Save (asked the first time, or if the action is disabled when saving).
Create another action for when the turtle is still:
-
Triggers: When
motion sensorgets data matchingequals0 -
Actions:
Set FeedMotion sensor activated?to valueTurtle is still - Hit save, and choose Enable and Save (asked the first time, or if the action is disabled when saving).
Create two more reactive triggers for the LED:
- Create a new action for turning the LEDs on, almost duplicating the previous action.
-
Triggers: When
motion sensorgets data matchinggreater than0 -
Actions:
Set FeedFunHouse DotStarsto value#FFFFFF - Hit save (and choose enable if asked)
- Create the new "LED off" action
-
Triggers: When
motion sensorgets data matchingequals0 -
Actions:
Set FeedFunHouse DotStarsto value#000000 - Hit save (and enable if asked)
Why create LED actions?
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.
Page last edited March 08, 2024
Text editor powered by tinymce.
Set up the Dashboard
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.
- 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!
Page last edited March 08, 2024
Text editor powered by tinymce.
Sensor Placement and Calibration
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.
- With some short extension jumper cables, we can extend the sensor long enough to register Cujo's movement.
(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.
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.
Page last edited March 08, 2024
Text editor powered by tinymce.
Data Monitoring, Analysis and Visualization
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.
- 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.
- 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)
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:59then divides the resulting value by 2 (to remove the times that the sensor reset to the still state) - Replace
E758with 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.
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!
Page last edited March 08, 2024
Text editor powered by tinymce.