The Problem

At Adafruit, we have a tester for virtually every product we manufacture. With hundreds of fab-made products in our catalog, that’s a lot of testers! When a tester has finished its job and there are no more boards to test, for the time being, it needs to go back home to the tester library. When the bin gets too full, I empty it and return the testers home after their long adventure. Sometimes, I forget to check the bin, and all of the sudden, the bin is brimming with testers.

The Solution

What if I could have someone else (like a robot) keep track of the testers and tell me when the bin is full? That’s exactly what this project will do. Using a FunHouse and an IR (infra-red) sensor, The project will track each time a tester gets placed in the bin with WipperSnapper and AdafruitIO. From there, a service called IFTTT will count the testers and send me an email when the bin has nearly reached its capacity.

While this is a specific project from the Adafruit factory, the method used to count actions is applicable to many aspects of everyday life such as filling a laundry bin.

Prerequisite Guide:

WipperSnapper is an interface for Adafruit IO, Adafruit's 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 Parts:

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
Infrared (IR) break-beam sensors are a simple way to detect motion. They work by having an emitter side that sends out a beam of human-invisible IR light, then a receiver across the...
$5.95
In Stock
These Female/Male 'Extension' Jumper Wires are handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 12" (300mm) long...
$3.95
In Stock
Got a glorious RGB Matrix project you want to mount and display in your workspace or home? If you have one of the matrix panels listed below, you'll need a pack of these...
$2.50
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

X2 Stemma JST cables

This cable will let you turn a JST PH 3-pin cable port into 3 individual wires with high-quality 0.1" female header sockets on the end. We're carrying these to match up with...
$1.25
In Stock

Other materials:

  • Scotch tape or similar
  • Power extension cable
  • Zip ties
  • Wooden skewer(s) (found at the dollar store)

Q: How does the IR sensor work?

Infrared (IR) break-beam sensors are a simple way to detect motion. They work by having an emitter side that sends out a beam of human-invisible IR light, with a receiver across the way which is sensitive to that same light. When something passes between the two, and it's not transparent to IR, then the 'beam is broken' and the receiver will let you know.

This is perfect for the kind of motion we want to detect, which must be accurate and specific.

Wiring

  • With the x2 stemma JST connectors, plug them into A1 and A2 of the FunHouse.
  • Next, take the IR sensor and look for the end of the sensor that has 3 cables.
  • From A2, plug the cables into the sensor matching red to red (Power), black to black (GND), and white to yellow (DATA).
  • From A1, plug the black and red cables into the sensor's black and red ends. (white will not be used for this side)

This is how the IR sensor will work in practice:

visualizing the IR beam
Visualizing the IR beam

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

Set Up the IR Sensor

  • From the WipperSnapper page, click "New Component"
  • Select "Beam Sensor"
  • Name the sensor
  • Choose A2 from the drop-down list

Test the IR Sensor

Next, test out the water sensor to verify it's working properly.

  • Position the ends of the sensor to face each other with some tape.
  • Now place your hand inbetween both sides of the sensor to "break" the beam.
  • Check the WipperSnapper device page to see if the value changes from "unbroken" to "broken" for your sensor.

Troubleshooting the Sensor

If you are not receiving feedback from the sensor, verify the following:

  • The sensor is correctly wired according to the directions on the "Add the IR Sensor" page
  • The Stemma cable is connected to the A2 pin on the FunHouse
  • The sensor ends are not more than 20" or 50cm from each other.

Now that we have the sensor set up, it's time to set up a counter to count each time the beam is broken. Then when that number reaches 25 (the capacity of a bin), I want to send an email notification that the bin is full.

What is IFTTT?

From the IFTTT site:

IFTTT is short for "If This Then That" and allows you to do more with hundreds of the apps and devices you love, including TwitterDropboxEvernoteNestFitbitAmazon Alexa, and Google Assistant.

Basically, the data feed from the IR sensor may be connected to Google Sheets to record the count of beam breaks. Then when 25 beam breaks are reached, that data from the spreadsheet may be used to send an email notification. Handy!

Create an IFTTT Account

If you don't have one already, head to the IFTTT website and create an account. It's free to create a basic account.

Create a new Google Sheet

If you don't already have a Gmail account, set one up now to access Google Sheets.

Then head to https://drive.google.com/ and open a new spreadsheet.

  • Once in Google Drive, click the "New" button on the top left of the screen
  • Then select "Google Sheets"

Step #1: Record and count each time the beam is broken

Create a New IFTTT Applet

From the IFTTT home page, click the "create" button in the top right corner of the screen. 

  • First, add the conditional "if". We want to record each time the beam is broken.
  • Click the "Add" button.
  • Search "Adafruit" from this list of services.
  • Choose the "Monitor a feed on AdafruitIO" option.
  • Next, select the feed created automatically from WipperSnapper. It should show up as whatever you named your board in WipperSnapper earlier.
  • The relationship should be "equal to" the value 0.
  • This means that each time the value of the IR sensor is 0 (which happens when the beam is broken), then do the next thing (which we'll add next).
  • Click "create trigger"
  • Now click "Add" next to "Then That"
  • Do a search for "sheets" and select the Google Sheets service.
  • Then select the "add row to spreadsheet option"
  • Enter the name of your spreadsheet
  • Detail how you'd like to format each row. We'll record a 1 (so we can add up the actions) as well as a timestamp for each row.
  • Click "Add an ingredient" and select the "created at" option.
  • Detail the Drive folder path where the spreadsheet is located. If your file is not located in a folder, create one and add the name of it here.
  • Click "create action"

Before this page gets too long, the mechanism for counting the beam breaks and sending the email notification will be discussed on the next page.

Step #2: Send an email when 25 beam breaks have been counted

  • Open your spreadsheet in a new tab
  • Label column A "Triggered" or whatever you'd like to show. It represents that the beam has been broken
  • Label column B "Time"
  • Label column E "testers counted"
  • And lastly, label column G "Collect testers?"
  • In column E, the second cell in the column is going to be used to count all the beam breaks in column A
  • Write in the formula =SUM(A2:A500) The range can vary as long or short as you'd like but should be at least a length of 26 or whatever threshold you pick.
  • In the second cell in column G, the formula is =IF(E2 > 25,1,0)
  • This means that if E2 (the sum of all testers), is greater than 25, change the value of the cell to 1, otherwise the value is 0. This will make more sense in the next section below.

Applet #2

Go back to the home page of IFTTT and create a new applet by clicking the create button again like before.

  • Click "Add" next to "If This"
  • Search for "sheets" and select the Google Sheets service.
  • Select the "Cell updated in spreadsheet" option.
  • Once again, detail the path where the spreadsheet is located in your Google Drive files.
  • Type G2 for the cell to monitor.
  • Click "create trigger"
  • Add a "Then That"
  • Search "email" and select the "Email" service
  • Select the available option "Send me an email"
  • Add the subject line and email body text you'd like to see when you receive the notification.
  • Click "create action"

Yay now it's all set up! Try triggering the sensor and watch the data flood into the spreadsheet.

There may be a bit of a lag of about a minute or so to see the data come into the spreadsheet.

How does it work?

The "collect testers?" cell monitors the sum of all testers (cell E2) and changes to 1 when that value goes above 25. When the "collect testers?" value changes, the email notification is sent.

  • When the tester count is greater than 25, set the "collect testers?" value to be 1
  • Otherwise set the "collect testers?" value to be 0.

Last but not least: to set up and configure the IR sensor where it will actually be handy.

First, pick a spot where you'd like to monitor. This is the tester bin area at Adafruit.

Then make sure you have access to a power outlet. If you do not, run an extension cable to the place where you will need it.

Next, attach the magnetic feet to the FunHouse. Place the FunHouse where you would like.

Add jumper extensions to the sensor ends so that they can be placed at an appropriate distance apart. Make sure that the POWER, GND, and DATA lines do not get mixed up.

Align and Place the Sensor

I used a wooden skewer (the pointy end removed) and some tape to align one side of the sensor with the other.

The range of the sensor ends at 20" or 50cm so make sure the ends of the sensor do not exceed this length.

Next, align the sensor ends so they are directly pointed at each other. The WipperSnapper dashboard will be useful to monitor from a mobile device to see if the beam is aligned correctly. It may take some adjusting.

Once you get a continuous "unbroken" message, test it out by waiving your hand through the beam to see if you can break it and that it can reset after your hand passes through.

After you've checked that the spreadsheet is correctly logging the beam breaks and that you're getting emails when you should be, that's it! You are set up for success :)

Fill 'er up, then ding!

Going Further

Q: What do you do when the bin is full and you've emptied it?

Time to empty the bin and start over. Once you've emptied the bin, you must also delete the recorded spreadsheet data. We're working on a better solution for resetting the bin data but that's what works for now.

Once you've emptied the bin, you must also delete the recorded spreadsheet data.

Other Applications

There are many possible ways to integrate this method of counting with a "limit reached" notification in everyday life. Here are a couple of ideas for your next project:

IR sensor input

  • You have a pile of laundry and when it gets too high send an email notification to do laundry.
  • You have a pile of books or clothes to donate and when it gets too high send an email to go donate.
  • Your dog or other pet has tripped a sensor near the back door more than normal. Send an email when the sensor is tripped X number of times (i.e your dog wants to go outside and take care of business).

Button input

  • Water cup counter: Track the number of cups of water you drink with a button press. Send yourself an email when you get to 8 cups.
  • Coffee cup counter: limit the number of cups you drink by tracking each cup with a button press. Send an email when you've reached your limit.
  • Track your focus: Press a button each time you leave your desk. Send an email when you've reached your limit.

If you can count it, you can WipperSnapper it :D

This guide was first published on Nov 10, 2021. It was last updated on 2021-11-10 12:22:31 -0500.