Arduino LED Notification for Gmail on Linux
02 december 2011 | Classified in: Electronic, Linux | Tags: Arduino, RGB, LED, gmail
This is a small project to display new mail notification with a RGB LED connected to an Arduino.
Every few minutes, the computer will check a Gmail inbox for unread emails. If one or more unread emails are found, it will tell the Arduino to turn a light on.
This article is not complete yet. I'm going to had more details later...
Electrical Diagram:
Bash Script:
On the computer, a bash script is running to regularly check for unread emails on a Gmail account. Depending on the result, a number will be send to the Arduino in order to display a notification.
- 0: No new mail.
- 1: Red LED, error while fetching the number of unread mail.
- 2: Green Led, new emails.
- 3: Blue Led, new emails.
#!/bin/bash
#SCRIPT_NAME="Arduino Gmail Checker"
#SCRIPT_VERSION="0.1"
#figlet $SCRIPT_NAME $SCRIPT_VERSION
#########################################################################################
# Description: Check Gmail for unread email and switch RGB LED on Arduino in accordance #
# Dependencies: sed, curl, #
# Author: Virtualmix #
# http://blog.trollmaker.com/article10/arduino-led-notification-for-gmail-on-linux #
# License: CC BY #
#########################################################################################
# Enter Gmail username and password below (Warning: Unsafe storage):
USERID=yourUsernameHere
PASSWORD=yourPasswordHere
# Enter number of seconds between email verification:
WAIT=300
#########################################################################################
# Loop to check for new mail every X minutes:
while [ "1" -eq "1" ]; do
# Command line to fetch the number of unread emails:
MAILCOUNTER=`curl -u $USERID:$PASSWORD --silent "https://mail.google.com/mail/feed/atom" | sed -n 's|<fullcount>\(.*\)</fullcount>|\1|p'`
if [[ "$MAILCOUNTER" = "" ]]; then
echo "ERROR: The program coulndn't fetch the account for user \"$USERID\"."
echo "- Are you connected to the Internet?"
echo -e "- Is the userid and password correct for \"$USERID\"?\n"
echo 111 > /dev/ttyUSB0 # Turn Red Led on
elif [[ "$MAILCOUNTER" -eq "0" ]]; then
echo "* There is 0 new email for user $USERID."
echo 000 > /dev/ttyUSB0 # Turn all leds off
elif [[ "$MAILCOUNTER" -gt "0" ]]; then
echo "* There is $MAILCOUNTER new email for user $USERID."
echo 232 > /dev/ttyUSB0 # Turn blue and then green led on
fi
echo "* Waiting $WAIT seconds before checking for emails again."
echo "* (^C to quit the program)"
sleep 300
done
Arduino Code:
The program running on the Arduino is very simple. All it does is wait to receive a number sent via serial communication from the computer.
- 0: The LED will is turned off.
- 1: Red LED is switched on.
- 2: Green LED is switched on.
- 3: Blue LED is switched on.
/*****************
RGB LED connected to Arduino with 330 ohm resistor to GND
Read value from serial and set LED high or low depending on the number received
0: All off
1: Red LED on
2: Green LED on
3: Blue LED on
******************/
int redLed = 11;
int greenLed = 10;
int blueLed = 9;
void setup() {
Serial.begin(9600);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
}
void loop () {
int value = Serial.read();
if (value == '0') {
digitalWrite(redLed,LOW);
digitalWrite(greenLed,LOW);
digitalWrite(blueLed,LOW);
}
if (value == '1') {
digitalWrite(redLed,HIGH);
digitalWrite(greenLed,LOW);
digitalWrite(blueLed,LOW);
}
if (value == '2') {
digitalWrite(redLed,LOW);
digitalWrite(greenLed,HIGH);
digitalWrite(blueLed,LOW);
}
if (value == '3') {
digitalWrite(redLed,LOW);
digitalWrite(greenLed,LOW);
digitalWrite(blueLed,HIGH);
}
delay(1000);
}
Download:
Bash Script and Arduino Code:
Let me know if you ever make something cool with it!


8 comments