The idea struck me when my wife always complained about the house stinking when she got off of work. Well, my geek side kicked in and I can freshen the house from any computer connected to the internet via IRC (internet chat relay).
NOTE: I know the circuitry is bad; and the op amp isn’t needed. I wanted to use what I had lying around. The only thing I’m concerned with is that it works.
The complete build took me about 5 hours, and the code took 20min.
I went to the local Walmart and bought a $7 Glade Sense and Spray. (Figure 1-1)
The next step was to rip it apart and find the pins for the push button that triggered it to spray. The pin needed is labeled R18 or R29 something like that. (Figure 1-2)
Next build a circuit to read an arduino pin and trigger it to spray. I used a relay to “close” the circuit/ act as the push button for the Glade’s circuit board. The relay is powered with a NPN transistor that was suposed to read the HIGH value from the arduino, but the value wasn’t a high enough voltage to trigger the NPN; I used an Op Amp to increase the voltage from the arduino to trigger the NPN to power the relay to turn the Glade…Spray on. Wow, that was a mouth full… It is a simple circuit.
EDIT::: The op amp isn’t needed. I found out I had the transistor and relay set up wrong thanks to BenF from the arduino forum:::(Figure 1-3)
Now for the code. First the Arduino Sketch. I’m using an ArduinoBT board.
int buffByte = 0; int cntrlPin = 13; void setup() { Serial.begin(115200); //BT requires baud 115200 pinMode(cntrlPin, OUTPUT); digitalWrite(cntrlPin, LOW); } void loop() { if (Serial.available() > 0) { buffByte = Serial.read(); //ASCII 65 is equal to "A" if (buffByte == 65) { digitalWrite(cntrlPin, HIGH); delay(100); digitalWrite(cntrlPin, LOW); } } }
Now for the IRC bot. Written in Python 2.6 I’m not going to explain what goes on here, its pretty self explainotory
import serial, socket, time, string, os os.system("color 0a") #My bluetooth COM port for the Arduino is COM9 #found in device manager s = serial.Serial('COM9', baudrate=115200) chan = 'BotTestz' ircsite = 'irc.freenode.net' port = 6667 irc = socket.socket() irc.connect((ircsite, port)) print irc.recv(1024) n = 'NetBotV1' irc.send('NICK %s\r\n' % n) irc.send("USER Ohlook itsnotmy blahh :Realname\r\n") time.sleep(4) irc.send("JOIN #%s\r\n" % chan) readbuffer = '' while True: readbuffer = irc.recv(1024) temp = string.split(readbuffer, "\n") Check = readbuffer.split(":") print readbuffer #if pinged, respond with PONG if "PING" in readbuffer: irc.send("PONG :%s" % Check[1]) #Write ASCII char 65 to the COM port #if smellGood command was sent if "^smellGood" in readbuffer: s.write("A")