Site icon Renzo Mischianti

If high temperature then send email using Arduino Uno and Ethernet Shield W5100

Hello, Im having the Task to code an Arduino to read the Temperature and show it in an LCD Screen and have some Rules so if its over 30 it should send an email to me but the problem is im trying since a week to do it but i cant i have already tried lots of examples but its nothing. I already configured an IP on my Arduino and now i would need help and a guide on how to do it so that it sends an email to me. This is what i have coded until now and it works.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Initialize the LCD
LiquidCrystal_I2C lcd(0x27, 16, 2); //The LCD address and size. You can change according to your setup

#define ONE_WIRE_BUS 2 //pin for sensor

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/*
   The setup function. We only start the sensors here
*/
void setup(void)
{
  // Start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
  
  // Initialize LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("PEGASUS");
  lcd.setCursor(0, 1);
  lcd.print("Measure it");
  delay(2000);
  lcd.clear();
}
/*
   Main function, get and show the temperature
*/
void loop(void)
{
  delay(3000);
  // Request temperature readings
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  
  // Read temperature from the sensor
  float tempC = sensors.getTempCByIndex(0);
  delay(1000);
  
  // Check if reading was successful
  if (tempC != DEVICE_DISCONNECTED_C)
  {
    Serial.print("Temperature for the device 1 (index 0) is: ");
    Serial.println(tempC);
    
    // Display temperature on LCD
    lcd.setCursor(0, 0);
    lcd.print("Temperature:");
    lcd.setCursor(0, 1);
    lcd.print(tempC);
    lcd.print((char)223);
    lcd.print("C");
    lcd.print(" | ");
    lcd.print(DallasTemperature::toFahrenheit(tempC));
    lcd.print(" F");

    // Check if temperature exceeds 29°C
    if (tempC >= 29.00) {
      delay(3000);
      lcd.clear();
      lcd.print("Oida 's is warm");
      delay(3000);
    } 
    // Check if temperature falls below 15°C
    else if (tempC <= 15.00) {
      delay(3000);
      lcd.clear();
      lcd.print("Oida is des koid ");
      delay(3000);
    } 
    else {
      lcd.setCursor(0, 2);
      lcd.print("             "); // Clear the line
    }
    delay(3000);
  }
  else
  {
    Serial.println("Error: Could not read temperature data");
  }
}
Exit mobile version