The project idea came from this tongue-in-cheek twitter post. But hey, why not try to make one? I read somewhere that the world needs more ridiculous smart devices.
I’ve (we’ve) only ever used the non-digital pregnancy tests where you read the strip. So to gauge how easy it is to hack the digital pregnancy tests, I googled the customer service number for one and proceeded to quiz the nice English lady on the other end of the phone.
Does your test have an ON button? What kind of battery does it use? Do the different characters on the LCD overlap, or are they separated? Well, I mean, is “Pregnant” the same as “Not Pregnant”, but just without the “Not”? You need a serial number? No, I don’t have a serial number, I haven’t purchased it yet. Oh...well, I like to be prepared.
So that didn't work, but it turns out you can learn a lot about pregnancy tests from youtube. There are lots of youtube videos of “live pregnancy tests”. Go ahead, youtube it, I’ll wait.
Now that we’ve all re-calibrated for what’s normal, this project doesn't seem weird at all. It's interesting to take apart a pregnancy test to see how it works.
- Sample Transport Media - absorbs the sample and transports it up to the rest of the device.
- Metal Gap of Turning On - the sample travels upwards from the transport media, and it bridges this gap. The ions in the sample creates an electrically conductive path across this gap, and wakes the pregnancy test microcontroller.
- Chemical Test Strip - reacts with pregnancy hormones to create visible color lines.
- Vitamin - reward for those who take the thing apart.
- Two Photodiodes - light sensor that reads the test strip to determine if lines indicate pregnancy. Each photodiode has a red LED associated with it. Interesting that there’s actually a third LED in the middle that's not associated with a light sensor. The plastic shell creates an isolated cavity so each sensor sees only a certain portion of the strip. Perhaps the design is for more expensive 3-photo cell models?
- LCD display - displays the results “Pregnant”, “Not Pregnant”, “book”, and “hourglass”
These tests are one-time use products. The chemical strip isn't reusable, so once the device is activated, it won't ever work again. Removing and replacing the battery puts it into an unrecoverable disco mode, even if it has never been activated.
This was pretty handy for figuring out which pin on the LCD displays which icon. I was kind of naive thinking that a high level on a particular LCD pin turns on a particular icon. I learned that LCDs don't work like LEDs, they need to be driven by an AC signal.
The pins that are easily accessible on the pregnancy test LCD are on the output of the XOR. So when the icon is on, that pin sees the half cycle phase shifted output relative to the regular "clock" waveform. With the unit in disco mode, it was easy to identify the clock pin (A) as well as the individual icon pins (C).
Since I only intend to monitor the "Not" and the "Pregnant" icons, I only need 4 wires: Not, Pregnant, Clock, and Ground.
The modifications to the pregnancy test involves adding headers and soldering the wires to the LCD pin. See image series below.
The Light Blue Bean provides the real world I/O and Bluetooth connectivity. The digital I/O monitors the "Not" and "Pregnant" pins on the LCD and compares them with the "clock". When they don't match, it means the corresponding icon is being displayed.
To preserve power, the Bean is sleeping most of the time. Pin 0 on the Bean (connected to the clock pin on the LCD) is set as the interrupt to wake the Bean from sleep. When the test is not being used, there is no signal on the clock pin. When the test is activated, the LCD starts displaying the hourglass icon, and the clock pin is driven with the 40Hz square wave. This wakes it up.
The Bean also has a tri-color LED and accelerometer. I used the LED to indicate state:
- (1) Wake-up blink: Upon wake-up, the Bean LED blinks green if Bluetooth connection has been established, and red if not.
- (2) Testing: displays the "breathing" blue pattern. This phase lasts 1 to 3 minutes, depending on whether it's a positive or negative sample. The manual for the pregnancy test also indicates that the tester should not be place upside down. The accelerometer is used to check the direction of gravity during the testing phase. If the test is held upside down, the breathing blue pattern changes to a solid blue as a warning to the user that something is wrong, and perhaps qualify the test results. But mostly because I wanted to use what's available on the board.
- (3) Result: Once the result is read, the data is sent via the Bean Serial to the Raspberry Pi for social media consumption. The LED also changes state. A solid red means not pregnant, solid green means pregnant.
- (4) Sleep: The Bean goes to sleep 8 seconds after it's unplugged. LED goes dark.
The Bean module can be removed and snapped onto another test over and over again.
The circuit fits snugly on the prototype area of the Bean, with the headers pointing out the back side and components in front.
The Raspberry Pi uses a Bluetooth USB adapter. It's running Node-RED, and uses the Bean node to receive serial data from the Bean. Once we have the data on the Pi, Node-RED makes it easy to tweet, send text messages via Twilio, or send email. Pretty much anything is possible from here. Scroll right to see the flows.
I happen to have some lights that are controlled via MQTT and OpenHAB. In the demo video, you can see the table lamp turn on when the result is "Pregnant". The lamp turns off when it's "Not Pregnant". The <convert_mqtt> function looks like it's not doing anything, but it is necessary due to some oddities with OpenHAB not catching MQTT publishes without \n. The arrangement of <decode_msg> makes it easy to visually exclude messages from different services.
The result is this pluggable IoT module that is energy efficient and preserves the accuracy of the original off-the-shelf pregnancy test. The module isn't limited to pregnancy tests of course. It can be used on other direct drive LCD devices.
After thinking about how this would work in real life, it seems like Twitter could use a feature where pre-authenticated (“verified”) Twitter accounts get permission to tweet under your name, but with their credentials. So, TotallyInvasivePregnancyTestCompany can tweet to your followers, but under their authorship. It’s better than a retweet, and better than just a tweet from you. The “I’m Pregnant” data would have a trusted chain of custody beginning at their device, through their phone app, all the way to the their authoritative tweet. Similarly, those Fitbit tweets about how many miles you ran aren't very trustworthy since anyone can just type that in.
Platforms like the Bean make it easy to add connectivity to products. Whether or not you should is a question best not left to the engineering department. My wife pointed out that pregnancy tests are kind of a sensitive subject. So, I hope this project comes off as making fun of IoT, not pregnancy tests.
In other news, we're really excited to be expecting our second child later this year!
Long version of demo video:
Bean Pregnancy Test
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!