Thanks Paul. I didn't know the L298N was a chip. I thought it was the whole module. It does look like the module I have has an in-built voltage regulator. I've tried several times with the seller and I can't the get confirmation, but the Arduino is working well with that L298N chip-based module as an input (5V I assume, need to get a tester).
The below code is where I'm at with a Wemos D1 WiFi Arduino UNO Development Board (don't konw how to interact with a Wemos stand alone, I'm just too basic on this stuff).
It sends the email well (tested that already), but the Max6675 is giving me troubles. It shows the below code on the serial print. I've tested the Max6675 on the Arduino Mega and it works well, so I know the unit works and also my ArduinoIDE. I've tried different pins configuration, a bit lost. Fixing this one and I have the whole project going. I have ordered a DS18B20 as recommended, so will see in 3 weeks time if that solves it (if I can't get to a solution in the interim with your help).
ets Jan 8 2013,rst cause:4, boot mode:(3,0)
wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
My code below....
#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <ESP_Mail_Client.h>
#define WIFI_SSID "xxxxxxxxxxxxxx"
#define WIFI_PASSWORD "xxxxxxxxxxxxxxx"
#define SMTP_HOST "smtp.gmail.com"
#define SMTP_PORT 465
/* The sign in credentials */
#define AUTHOR_EMAIL "xxxxxxxxxxxxxxxxxx"
#define AUTHOR_PASSWORD "xxxxxxxxxxxxxxxxxxxxx"
/* Recipient's email*/
#define RECIPIENT_EMAIL "xxxxxxxxxxxxxxxxxxxxx"
/* The SMTP Session object used for Email sending */
SMTPSession smtp;
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status);
#include "max6675.h" //for MAX6675 thermocouple chip
//Constants
#define actuator 4
//Variables
float temp; //Stores temperature value
float maxTemp = 28; // define maximum temperature on which actuator starts
float minTemp = 20; // define minimmum temperature on which actuator retracts
float extremeTemp = 35; // define minimmum temperature on which actuator retracts
const int IN1_PIN = 14; // the Arduino pin connected to the IN1 pin L298N
const int IN2_PIN = 15; // the Arduino pin connected to the IN2 pin L298N
//initialising the thermocouple K / MAX6675
int thermoDO = 7;
int thermoCS = 6;
int thermoCLK = 5;
// initialise MAX6675
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
void setup(){
Serial.begin(115200);
// initialize digital pins as outputs.
pinMode(IN1_PIN, OUTPUT);
pinMode(IN2_PIN, OUTPUT);
}
void loop(){
//2000mS delay between reads
delay(10000);
//Read data and store it to variable temp
temp= thermocouple.readCelsius();
Serial.print("C = ");
Serial.println(temp);
if((temp>=extremeTemp) && (temp<100))
sendEmail(String(temp));
else if ((extremeTemp>temp) && (temp > maxTemp))
openHatch();
else if (temp <minTemp)
closeHatch();
}
void closeHatch(){
// retracts the actuator
digitalWrite(IN1_PIN, LOW);
digitalWrite(IN2_PIN, HIGH);
//only open for 5 seconds and leave hatch opened half way (when in doing so, temperature is mantained within min/max limits)
delay (2000);
digitalWrite(IN1_PIN, LOW);
digitalWrite(IN2_PIN, LOW);
}
void openHatch(){
// extend the actuator
digitalWrite(IN1_PIN, HIGH);
digitalWrite(IN2_PIN, LOW);
//only open for 5 seconds and leave hatch opened half way (when in doing so, temperature is mantained within min/max limits)
delay (2000);
digitalWrite(IN1_PIN, LOW);
digitalWrite(IN2_PIN, LOW);
}
void sendEmail(String temperature){
Serial.println();
Serial.print("Connecting to AP");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(200);
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
/** Enable the debug via Serial port
* none debug or 0
* basic debug or 1*/
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
/* Declare the session config data */
ESP_Mail_Session session;
/* Set the session config */
session.server.host_name = SMTP_HOST;
session.server.port = SMTP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.login.user_domain = "";
/* Declare the message class */
SMTP_Message message;
/* Set the message headers */
message.sender.name = "GreenHouse";
message.sender.email = AUTHOR_EMAIL;
String Str1 = "Greenhouse temperature alert: "+temperature+" degrees";
const char* string1 = Str1.c_str();
message.subject = string1;
message.addRecipient("Sara", RECIPIENT_EMAIL);
/*Send HTML message*/
String htmlMsg = "<div style=\"color:#2f4468;\"><h1>Please open hatch. Temperature has reached "+temperature+" degrees</h1></div>" +temperature;
message.html.content = htmlMsg.c_str();
message.html.content = htmlMsg.c_str();
message.text.charSet = "us-ascii";
message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
/* Connect to server with the session config */
if (!smtp.connect(&session))
return;
/* Start sending Email and close the session */
if (!MailClient.sendMail(&smtp, &message))
Serial.println("Error sending Email, " + smtp.errorReason());
}
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status){
/* Print the current status */
Serial.println(status.info());
/* Print the sending result */
if (status.success()){
Serial.println("----------------");
ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount());
ESP_MAIL_PRINTF("Message sent failled: %d\n", status.failedCount());
Serial.println("----------------\n");
struct tm dt;
for (size_t i = 0; i < smtp.sendingResult.size(); i++){
/* Get the result item */
SMTP_Result result = smtp.sendingResult.getItem(i);
time_t ts = (time_t)result.timestamp;
localtime_r(&ts, &dt);
ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
ESP_MAIL_PRINTF("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients);
ESP_MAIL_PRINTF("Subject: %s\n", result.subject);
}
Serial.println("----------------\n");
}
}