I have a problem for the fan speed control circuit I built with Arduino, no matter what I did, I could not run it as it should be. My circuit, which normally works by changing the on-off time according to the pot value, does not work in ESP32. Arduino is not enough to use the screen at the same time. so I can't use both screen and fan speed with a single arduino. When I use Ardiuno, I can't run the fan by delaying the on and off time when I put another query in between the screen. therefore I wanted to use ESP32.
I have made some modifications to the schematic I show below in order to use the higher energy capacity.
I used 1N5403 instead of 1N4007.
I used MOC3021 instead of MOC3020
I used BTA136 instead of BTA16.
I ran it with arduino until this part.
After switching to ESP32, I reduced the signals that may come 5v to 3V with 3.3K and 2.2K resistors so that the card would not be damaged. then everything is mechanically stable.
I moved the same system to ESP32 and provided the necessary conditions. the fan is always running. the output energy is always 220V. I even said 500ms stop 500ms run to try, it worked without stopping.
MOC3021 inputs and outputs are at the required value.
I can't see anything. Can anyone help me with my head comments.
Thanks in advance.
#include <Wire.h>
#include "SSD1306Wire.h"
#include <Adafruit_ADS1X15.h>
// OLED ekran nesnesi (I2C, 0x3C adresi, SDA=5, SCL=4)
SSD1306Wire display(0x3c, 5, 4);
// ADS1115 nesnesi
Adafruit_ADS1115 ads;
// Pin Tanımlamaları
#define ZCD_PIN 14 // Zero Crossing Detector (ZCD) pini
#define TRIAC_PIN 2 // TRIAC Gate kontrol pini
// Global Değişkenler
volatile bool zcdTriggered = false; // ZCD kesmesi tetiklendi mi?
float basincDegeri = 0.0; // Basınç değeri
int potDegeri = 0; // Potansiyometre değeri
void setup() {
Serial.begin(115200);
// OLED ekran başlatma
display.init();
display.setContrast(241);
// I2C başlatma
Wire.begin(5, 4); // SDA = GPIO 5, SCL = GPIO 4
// ADS1115 başlatma
if (!ads.begin()) {
Serial.println("ADS1115 başlatılamadı!");
while (1);
}
ads.setGain(GAIN_ONE); // ±4.096V giriş aralığı
// Pin modları
pinMode(ZCD_PIN, INPUT_PULLUP);
pinMode(TRIAC_PIN, OUTPUT);
// ZCD pinini kesme ile başlat
attachInterrupt(digitalPinToInterrupt(ZCD_PIN), onZCTrigger, FALLING); // Kesme başlat
// Çekirdek 0 için ekran ve ADS1115 görevini başlat
xTaskCreatePinnedToCore(
ekranVeOkumaTask, // Görev fonksiyonu
"Ekran ve Okuma", // Görev adı
10000, // Yığın boyutu
NULL, // Parametre
2, // Öncelik
NULL, // Görev tanıtıcı
0 // Çekirdek 0
);
// Çekirdek 1 için TRIAC kontrol görevini başlat
xTaskCreatePinnedToCore(
triacTask, // Görev fonksiyonu
"TRIAC Kontrol", // Görev adı
10000, // Yığın boyutu
NULL, // Parametre
1, // Öncelik
NULL, // Görev tanıtıcı
1 // Çekirdek 1
);
}
void loop() {
// loop() boş bırakıldı, görevler ile çalışıyoruz
}
// Çekirdek 0: Ekran ve ADS1115 okuma
void ekranVeOkumaTask(void* parameter) {
while (1) {
// ADS1115'ten basınç sensörünün değerini oku
int16_t adcBasinc = ads.readADC_SingleEnded(0); // Kanal 0'dan okuma
int16_t adcPot = ads.readADC_SingleEnded(1); // Kanal 1'den potansiyometre okuma
// Kalibrasyon değerlerini kontrol edin
float adc4mA = 3170; // 4 mA için ADS1115 değeri
float adc20mA = 6553.5; // 20 mA için ADS1115 değeri
// Basıncı hesapla (0-30 bar aralığında)
basincDegeri = ((adcBasinc - adc4mA) * (30.0 / (adc20mA - adc4mA)));
// Potansiyometre değerini 10-7200 aralığına eşle
potDegeri = map(adcPot, 0, 32767, 10, 7200); // ADS1115 16-bit çözünürlük
// OLED ekrana yazdır
display.clear();
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, "Basinc Degeri:");
display.drawString(80, 0, String(basincDegeri, 1) + " Bar");
display.drawString(0, 14, "Pot Degeri:");
display.drawString(80, 14, String(potDegeri));
display.drawString(0, 28, "adcPot :");
display.drawString(80, 28, String(adcPot));
display.drawString(0, 42, "zcdTriggered :");
display.drawString(80, 42, String(zcdTriggered));
display.display();
vTaskDelay(500 / portTICK_PERIOD_MS); // 500ms bekle
}
}
// Çekirdek 1: TRIAC kontrol
void triacTask(void* parameter) {
while(1) {
if (zcdTriggered) {
zcdTriggered = false; // Kesme bayrağını temizle
triac(); // TRIAC kontrol fonksiyonunu çağır
vTaskDelay(100 / portTICK_PERIOD_MS); // Task scheduler'ı rahatlat
}
}
}
void triac() {
// TRIAC tetikleme gecikmesi
delayMicroseconds(potDegeri); // Potansiyometreye göre gecikme
digitalWrite(TRIAC_PIN, HIGH); // TRIAC'ı tetikle
delayMicroseconds(50); // Tetikleme süresi
digitalWrite(TRIAC_PIN, LOW); // TRIAC'ı kapat
}
// ZCD Kesme Servis Rutini (ISR)
void onZCTrigger() {
zcdTriggered = true;
}
