Okay, so my project is supposed to email someone after a certain temperature is reached or a button is pressed, it all works out great except the LCD that displays the current temperature screws up after the arduino runs the "sendMail" function i set up... After it's run the LCD goes blank and then displays "N" and stays like that even after the sendMail function is finished. Could someone help me out?
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,101,165 };
byte gateway[] = {192,168,101,1};
byte subnet[] ={255,255,255,0};
// Enter the IP address of the server you're connecting to:
byte server[] = { 192,168,101,9 };
Client client(server, 25);
const int buttonPin = 2;
int buttonState = 0;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int tmp102Address = 0x48;
byte res;
int val;
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
Wire.begin();
}
//main loop
void loop()
{
buttonState = digitalRead(buttonPin);
// as long as there are bytes in the serial queue,
// read them and send them out the socket if it's open:
while (Serial.available() > 0) {
char inChar = Serial.read();
if (client.connected()) {
client.print(inChar);
}
}
Wire.requestFrom(tmp102Address,2);
byte MSB = Wire.receive();
byte LSB = Wire.receive();
int TemperatureSum = ((MSB << 8) | LSB) >> 4; //it's a 12bit int, using two's compliment for negative
float celsius = TemperatureSum*0.0625;
float fahrenheit = (TemperatureSum*0.1125) + 32;
if (buttonState == HIGH||fahrenheit > 77) {
sendMail();
}
lcd.print("F:");
lcd.setCursor(2,0);
lcd.print(fahrenheit);
lcd.setCursor(0,1);
lcd.print("C:");
lcd.setCursor(2,1);
lcd.print(celsius);
delay(500);
lcd.clear();
}
//SEND MAIL FUNCTION
void sendMail()
{
// start the Ethernet connection:
Ethernet.begin(mac, ip,gateway,subnet);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect()) {
Serial.println("connected");
client.println("ehlo person"); /* terminate connection */
delay(1000);
client.println("auth login"); /* terminate connection */
delay(1000);
client.println("YXJkaQ=="); /* terminate connection */
delay(1000);
client.println("YXJkaTEx"); /* terminate connection */
delay(1000);
client.println("YXJkaTEx"); /* terminate connection */
delay(1000);
client.println("MAIL FROM:Ardi@lgit.org"); /* terminate connection */
delay(1000);
client.println("RCPT TO:Mbecker@lgit.org"); /* terminate connection */
delay(1000);
client.println("RCPT TO:Legnox@gmail.com"); /* terminate connection */
delay(1000);
client.println("DATA"); /* terminate connection */
delay(1000);
client.println("SUBJECT:Test message from Ardi!"); /* terminate connection */
delay(1000);
client.println("The temperature of the room is"); /* terminate connection */
delay(1000);
client.println("."); /* terminate connection */
delay(1000);
client.println("QUIT"); /* terminate connection */
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
Serial.println();
Serial.println("disconnecting.");
client.stop();
}