Hello
Hardware :
ESP32
K-type
MAX6675
18VDC Lithium regulated to 12VDC
Tongling 12VDC relay
This project is to control a BBQ fire.
I am trying to trigger a relay to run a 12VDC fan, the fan is a four wire PWM but i have it wired up staright 12VDC as the PWM is out of my reach for now.
The relay is triggered by a k-type thermocouple wired up to a MAX7765 board.
The thermocouple also virtualwrites to my iphone blynk app (all good)
Everything is working as it should except the relay.
I can trigger the relay with a false signal to the ‘in’ wire, so the wiring and hardware should be correct.
I have measured the ESP32 ‘relay’ (4) pin with a multimeter and cannot detect anything.
Code:
[code]
#include <SPI.h>
#define BLYNK_PRINT Serial
#include "max6675.h"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "removed";
char ssid[] = "removed";
char pass[] = "removed";
BlynkTimer timer; // Create a Timer object called "timer"!
int thermoDO = 19;
int thermoCS = 23;
int thermoCLK = 5;
int relay = 4;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
void myFan()
{
float t = thermocouple.readCelsius();
if (t >= 40)
{
digitalWrite(relay, LOW); // too hot, turn fan on
}
if (t <= 30)
{
digitalWrite(relay, HIGH); // too cool, turn fan off
}
// otherwise leave fan doing whatever it was before
}
void myTimerEvent()
{
float t = thermocouple.readCelsius();
if (t >= 80)
Blynk.notify("BIG HEAT - Temperature over 125C!");
if (isnan (t))
Blynk.notify("Failed to read thermocouple!");
Blynk.virtualWrite(V4, thermocouple.readCelsius());
Serial.print("C = ");
Serial.println(thermocouple.readCelsius());
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, myTimerEvent);
timer.setInterval(1200L, myFan);
pinMode (relay, OUTPUT);
}
void loop() {
Blynk.run();
timer.run(); // BlynkTimer is working...
}
[/code]
A few notes :
- Where have i gone wrong
- Is it good practice to create a separate void like a have for “myFan”
- Do i need a ground between ESP32 and relay board or will GPIO 4 send a signal without a closed circuit?
- I haven’t wired it up as PWM as i am not hardware savvy, if i were to wire FG (frequency feedback) and PWM to the ESP32 wouldn’t the fan run fulltime without a PWM signal?
- Sorry for my poor coding technique, I have the ability to learn off youtube only
Thankyou in advance if you reply.