You’re closer than you think to a career in tech. Our grads have launched rewarding new careers — you can too.View Our Jobs Report
What the What with the Gmail
After my first experiment with Ruby and Arduino, I wanted to try writing a sketch that would build off of the code I had written from the blinking LED test. Using the blinking LED as an indicator, I thought it would be interesting to see if I could get my Ardunio talking with Gmail to alert me if I had any unread inbox messages. After doing some research, I found a Ruby gem called Gmail that allows me to do just that.
Requiring the Right Gems
Here we’re going to set up the sketch with the gems we’ll be running.
Board in the USA
Dino requires us to define our board, tell it that we’ll be inputing and outputing data, and tell it that we’re using a serial connection (since my Ardunio is hooked up via USB). Next, we’ll be defining our LED variable, which should be easy since it was in the previous sketch. Note: Dino also offers a good directory full of example code for setting up any given component.
Setting up dino
You’ve Got Mail
In the next few lines of code we: call on Gmail to let us access our inbox, check if our inbox is empty, set the led variable to a resting state, and define a variable equal to the number of unread emails. Note: In the code listed below, you’d actually pass in your real email address and password.
Now that we have access to our inbox, we can finish up this sketch by writing an if statement to blink our led when our inbox is not at zero.
I’m hoping to take this further by:
Writting in a delay and loop so that the sketch runs every 5-10 min
Adding an rgbLED so that I can light up a red LED when the inbox is full and a green LED when the inbox is empty.
Blog Post Author
Since we opened our doors in 2012, thousands of students have joined Flatiron School to launch new careers in tech.
Find the perfect course for you across our in-person and online programs designed to power your career change.
Connect with students and staff at meetups, lectures, and demos – on campus and online.
Have a question about our programs? Our admissions team is here to help.