If you’re reading this, you’ve probably grappled with impostor syndrome at one time or another.
Experience doesn’t always help, either. As our skills grow, we tackle harder problems. Technologists are always working at the edge of our knowledge.
What can we do to fight impostor syndrome? Studies have shown that self-affirmation can counteract negative ruminations and increase achievement. So I decided to build an Internet of Things button that delivers an SMS affirmation when pressed.
Physical responses to negative thoughts
This project could totally be a web application. But – taking a physical action in response to negative thoughts helps ground me emotionally.
Using SMS lets me receive the affirmation without the cognitive load of opening another browser tab. Twilio’s IoT capabilities let me take the button anywhere with cell service. No WiFi configuration required!
The imposter syndrome button was my first hardware project. It was a bit challenging at times. However, with support from my community, I managed to get it working eventually.
I’m excited to walk you through this build – there’s no hardware experience required to follow along.
IoT Imposter Syndrome Button: Prerequisites
- Raspberry Pi. I used a Pi 3 Model B, but any version later than 1 Model B+ should work
- LTE Cat 1 Pi HAT
- A button with these wires
- Twilio SIM card
- Twilio account - sign up for a free one here
- SD card
- USB to Ethernet adapter. Make and model depends on what kind of USB ports your laptop has. We had good results using this model
- (optional) buy or make a box to encase the project
Getting Started with Twilio IoT
First, register your Twilio SIM card. Then create a rate plan. Finally, buy a Twilio phone number with SMS capability.
Now, we’re going to set up the Pi’s operating system. We’re using a special Raspbian disk image that drives the LTE Cat 1 Pi HAT. Download Balena Etcher and follow its instructions to burn the operating system image on to the SD card.
Assemble the hardware
Pop the Twilio sim card in the HAT and gently attach the antennas.
Attach the hat to the Pi with a USB to micro USB cable. The large side goes into the Pi.
Next, put the burned SD card in to the bottom slot on the Pi.
Plug the USB to ethernet adapter into your desktop. Connect the ethernet cable between the ethernet jacks on the adapter and Raspberry Pi.
Finally, plug the Pi in to a USB power source. Don’t use your laptop: it doesn’t consistently supply as much power as the Pi needs.
If you see blinking green lights on the Raspberry Pi, you did it right! Next I’ll show you how to set up your development environment.
Set up your Development Environment
From a terminal on your desktop or laptop, SSH to pi@192.168.253.100
. You’ll be prompted to enter a password, which is build19
.
Run the following command to install pip
, the python package manager:
sudo apt-get install python3-pip
Then use pip to install the Twilio Python SDK:
sudo pip3 install twilio
Add Twilio credentials as Environment Variables on the Pi.
You need to set TWILIO_ACCOUNT_SID
and TWILIO_AUTH_TOKEN
. You can find them in the console.
Storing your credentials on a device is only acceptable if you plan to keep the device physically in your possession at all times. If that’s not the case, use another authentication solution you can disable remotely such as Trust Onboard or API Keys.
Configure your text editor
Time to configure your code editor. You have two options to enter the code you’ll need:
- You can use an editor directly on the Pi such as
nano
,vim
, oremacs
. - Alternately, you can use an editor on your laptop and configure an editor extension to copy the code over to the Pi.
When I built my button, I used atom with the remote sync extension and it worked like a charm.
Hook up the button
The Raspberry Pi has pins for general purpose input and output, aka GPIO.
If you connect the wrong pins you can brick your Pi. I did that during my first build -- guess I'm a real hardware hacker now. 😂 Use a pinout diagram to double check your pins and avoid my mistake.
Confusingly, the GPIO pins have several numbering schemes. It doesn’t matter which scheme you pick, as long as you use a consistent scheme throughout your project to avoid mixups. For this project we’ll use the BCM numbering scheme.
When the button is pushed, we want to complete a circuit.
A circuit is an unbroken path which electric current can flow along. Ground is a reasonably consistent reference point that other levels of current can be measured against.
We measure the voltage difference between the signal and ground to determine if a button is depressed. Circuits can pick up random electromagnetic energy and static, which makes it difficult to set a threshold for exactly how much of a voltage difference matters.
Resistors: what they are, why you need them
Resistors to the rescue! Resistors impede the flow of electrical current in a circuit.
For a switch that connects to ground, a pull-up resistor ensures a defined voltage (“logical high”) across the remainder of the circuit when the switch is open. Conversely, a pull-down resistor ensures a defined ground voltage (“logical low”) when the switch is open.
It doesn’t matter whether you use pull-up or pull-down resistors for this project – so let’s go with pull-up. The Pi GPIO pins have internal pull-up and pull-down resistors, which we’ll configure in our Python code.
Attach the button to the Pi
Plug the metal side of the button wires into the button. (It doesn’t matter which wire is which, they’re interchangeable.)
Plug the plastic side of the connectors in to BCM pin 18, as well as GND. You can solder these wires instead of using the connectors if you’d prefer.
Enter the Code
Copy the following code into a new file sms_button.py
on your Raspberry Pi. (Use your choice of editor from above).
Replace the from_number
with your Twilio phone number, and the to_number
with the number you want to send the affirmations to.
import RPi.GPIO as GPIO
import time
from twilio.rest import Client
import requests
client = Client()
from_number = "" # put your Twilio number here
to_number = "" # put your cell phone number here
# specify which GPIO numbering scheme we are using
GPIO.setmode(GPIO.BCM)
pin_number = 18
# configure the pin for input and set up pull-up resistor
GPIO.setup(pin_number, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def get_affirmation():
try:
response = requests.get(url="https://www.affirmations.dev").json()
return response.get('affirmation')
except Exception:
# let's not try too hard
return "you can do it!"
def send_message(_):
affirmation = get_affirmation()
message = client.messages.create(
body=affirmation,
from_=from_number,
to=to_number
)
print(message.sid)
GPIO.add_event_detect(
pin_number,
GPIO.FALLING,
callback=send_message,
bouncetime=1000
)
# we need a loop here to keep the script running continuously
while True:
time.sleep(10)
I’m using an affirmations api here, but you can also write personalized affirmations for yourself. Put the affirmations in a list and use random.choice()
to select one each time the send_message function is called.
Try running the python script from the command line:
python3 sms_button.py
After pushing the button you should see some output that looks like this:
sending message
SMef651cc421a241e997c591401dbea41b
You should receive a text message affirmation on the cell number you provided. Hooray!
Note that sometimes the button takes a few seconds to initialize when the script first runs.
If you want to keep the script running continuously on the Pi, you’ll want to run it inside a screen session so the script can keep going after the ssh session terminates.
Take that, negative self-talk
At the end of the day, my impostor syndrome doesn’t define me. It’s just a thought I’m having.
Your impostor syndrome doesn’t define you either. You’re smart, you get things done, and I can’t wait to see what you create. If you build something with Twilio IoT, I’d love to hear about it! You can comment here or find me on Twitter.
Top comments (0)