Coffee addict enabler (FSR coaster + email)

Posted by sgeiger

sgeiger's picture

Description:

FSR attached to a coaster (wrapped around a sock to get the FSR to detect weight, was really my last resort).  Arduino reports back over serial empty and full statuses of a coffee mug on the coaster, manually calibrated -- which was terribly inaccurate due to a very finicky apparatus.  Python-based daemon sits and waits for empty status for 5 continuous seconds (needed because the sensor is finicky) and sends an e-mail to my imaginary assistant to get me some more coffee.  Resets when coffee is refilled (again for 5 seconds), and sends another e-mail when coffee is empty again.

 

E-mail daemon (in Python):

import os
import serial
import smtplib
from email.mime.text import MIMEText


ser = serial.Serial('/dev/ttyACM0',9600)
value = 0;
oldvalue = 0;

#Basic structure of the e-mail
msg = MIMEText('MOAR COFFEE NOW!')
msg['Subject'] = 'MOAR COFFEE!'
msg['From'] = 'sgeiger@gmail.com'
msg['To'] = 'sgeiger@gmail.com'
reset = 1

# Read from the serial, act if there is an empty or full response
while 1:
	value = ser.read()
	if value == 'R' and oldvalue != 'R':

		# Make sure it is set for five seconds, not just an FSR fluke
		for i in range(1,11):
			x = ser.read()
			print x,
			if x != 'R':
				break
			if i == 10:
				print 'OH BOY, A FRESH CUP OF JOE!!!!'

				# Reset the program, start detecting a new cup
				reset = 1

	if value == 'C' and reset == 1:

		# Make sure it is set for five seconds, not just an FSR fluke
		for i in range(1,11):
			x = ser.read()
			print x,
			if x != 'C':
				break
			if i == 10:
				print 'OFFEE, STAT!!!!'

				# Send that e-mail
				s = smtplib.SMTP('mail.stuartgeiger.com',587)
				s.login('coffee@stuartgeiger.com','youtriedtolookatmypassword')
				s.sendmail('coffee@stuartgeiger.com', 'sgeiger@gmail.com', msg.as_string())
				s.quit()
				reset = 0
	oldvalue=value

Arduino code:
 
int val1 = 0;
int val2 = 0;
int val3 = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  val1 = analogRead(A0);    // read the value from the sensor, between 0 - 1024
  val2 = analogRead(A1);    // read the value from the sensor, between 0 - 1024
  val3 = analogRead(A2);    // read the value from the sensor, between 0 - 1024  
  val3=map(val3, 0, 1023, 0, 255);  

  if (val3 > 5 && val3 < 25) {
   Serial.print('C');
  }
  if (val3 > 90) {
    Serial.print('R');
  }
  delay(500);
}

 

Video:

http://www.youtube.com/watch?v=Q2K29NKgnzU

Photos:

Hosted on imgur, because I apparently have no quota left here....

 

And yes, as the pictures clearly show, I spilled some water while testing near live circuits. Bad practice, I know!


 

0
Your rating: None