# I cannot run the Arduino circuit with ESP32 help please

**URL:** <https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613>\
**Category:** General Guidance\
**Created:** [December 28, 2024, 3:38pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613 "2024-12-28T15:38:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![umutsarac](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/umutsarac/32/1020566_2.png) [@umutsarac](https://forum.arduino.cc/u/umutsarac)\
**Post date:** [December 28, 2024, 3:38pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/1 "2024-12-28T15:38:36Z")

</div>

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.

```arduino
#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;
}

```

 ![Arduino-AC-Dimmer-Circuit](https://europe1.discourse-cdn.com/arduino/original/4X/5/3/f/53f3f37401ec39f01a71fb77d9c3c2d864fd7c29.jpeg)

---

<div class="post-metadata">

**Author:** ![Deva\_Rishi](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/deva_rishi/32/227254_2.png) [@Deva\_Rishi](https://forum.arduino.cc/u/Deva_Rishi)\
**Post date:** [December 28, 2024, 3:58pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/2 "2024-12-28T15:58:55Z")

</div>

In regards to your zero-cross circuit i would like to know, what is the power rating of resistor R1 & R2 ? because when i did the math i came to just over 0.5 Watt.

I use 2 x 33K created from 3x 100K in parallel and that leaves me with just under 1/4 Watt per resistor

> [@umutsarac](#):
>
> I even said 500ms stop 500ms run to try, it worked without stopping.

Well then that part of the circuit is obviously not at fault.

---

<div class="post-metadata">

**Author:** ![umutsarac](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/umutsarac/32/1020566_2.png) [@umutsarac](https://forum.arduino.cc/u/umutsarac)\
**Post date:** [December 28, 2024, 4:09pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/3 "2024-12-28T16:09:36Z")

</div>

R1 output is 110vAC 0.3A. R2 output 110VAC 0.3A  
yes it works but I cannot get energy drop at the output, it always works as 220VAC at the same speed. it does not cut.

---

<div class="post-metadata">

**Author:** ![anon85221860](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon85221860](https://forum.arduino.cc/u/anon85221860)\
**Post date:** [December 28, 2024, 4:17pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/4 "2024-12-28T16:17:02Z")

</div>

Could this be related to the form/choice of _pin numbering_ used ("Arduino" vs. "GPIO") ?

---

<div class="post-metadata">

**Author:** ![umutsarac](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/umutsarac/32/1020566_2.png) [@umutsarac](https://forum.arduino.cc/u/umutsarac)\
**Post date:** [December 28, 2024, 4:20pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/5 "2024-12-28T16:20:51Z")

</div>

Actually, this situation came to my mind, but I eliminated that situation because it works much faster than the arduino and gives the necessary energy when it opens and closes.

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [December 28, 2024, 4:21pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/6 "2024-12-28T16:21:40Z")

</div>

> [@umutsarac](#):
>
> I used MOC3021 instead of MOC3020

It’s working as expected. If you check the Schematic (changed mistype from datasheet) , you’ll find that **one component is zero-crossing, while the other is not**. This difference is crucial.

When you use a non-zero-crossing component in your circuit, it won’t wait for the AC signal to cross zero before switching. This behavior can result in the outcomes you’re observing, such as more noticeable noise or sudden current spikes. In contrast, a zero-crossing component ensures smoother operation by switching only when the AC signal passes through zero voltage, reducing transients and noise.

Make sure to confirm the type of component you're using U1 and match it to your circuit's requirements to achieve the desired behavior.

---

<div class="post-metadata">

**Author:** ![anon85221860](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon85221860](https://forum.arduino.cc/u/anon85221860)\
**Post date:** [December 28, 2024, 4:23pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/7 "2024-12-28T16:23:26Z")

</div>

> [@umutsarac](#):
>
> because it works much faster than the arduino

What are we talking about here ?

---

<div class="post-metadata">

**Author:** ![MaximoEsfuerzo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/maximoesfuerzo/32/923798_2.png) [@MaximoEsfuerzo](https://forum.arduino.cc/u/MaximoEsfuerzo)\
**Post date:** [December 28, 2024, 4:30pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/8 "2024-12-28T16:30:23Z")

</div>

> [@gilshultz](#):
>
> It’s working as expected. If you check the datasheet, you’ll find that one component is zero-crossing, while the other is not. This difference is crucial.

MOC3020, 21, 22 & 23 are all _non zero crossing triacs_

---

<div class="post-metadata">

**Author:** ![umutsarac](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/umutsarac/32/1020566_2.png) [@umutsarac](https://forum.arduino.cc/u/umutsarac)\
**Post date:** [December 28, 2024, 4:30pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/9 "2024-12-28T16:30:42Z")

</div>

I am writing using a translation application. sorry if I spoke a wrong word. let me explain. the pins give the energy they need to give at the speed and power they need to give. and while doing this, if desired, it has a faster response time than the arduino.

---

<div class="post-metadata">

**Author:** ![umutsarac](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/umutsarac/32/1020566_2.png) [@umutsarac](https://forum.arduino.cc/u/umutsarac)\
**Post date:** [December 28, 2024, 4:32pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/10 "2024-12-28T16:32:19Z")

</div>

@MaximoEsfuerzo and @gilshultz  
Obviously, I have run this circuit before. You may be right, then I ask you to suggest me a model and I will be happy to try it.

---

<div class="post-metadata">

**Author:** ![MaximoEsfuerzo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/maximoesfuerzo/32/923798_2.png) [@MaximoEsfuerzo](https://forum.arduino.cc/u/MaximoEsfuerzo)\
**Post date:** [December 28, 2024, 4:35pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/11 "2024-12-28T16:35:47Z")

</div>

> [@umutsarac](#):
>
> in order to use the higher energy capacity.  
> I used 1N5403 instead of 1N4007.

It is an unnecessary change, they only serve to turn on the LED of the optocoupler.

---

<div class="post-metadata">

**Author:** ![MaximoEsfuerzo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/maximoesfuerzo/32/923798_2.png) [@MaximoEsfuerzo](https://forum.arduino.cc/u/MaximoEsfuerzo)\
**Post date:** [December 28, 2024, 4:36pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/12 "2024-12-28T16:36:28Z")

</div>

I use MOC3021

---

<div class="post-metadata">

**Author:** ![umutsarac](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/umutsarac/32/1020566_2.png) [@umutsarac](https://forum.arduino.cc/u/umutsarac)\
**Post date:** [December 28, 2024, 4:39pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/13 "2024-12-28T16:39:28Z")

</div>

Dude, I laughed out loud. You're like deadpool. 😃 I use him too 😃 so where's the problem ☹

---

<div class="post-metadata">

**Author:** ![MaximoEsfuerzo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/maximoesfuerzo/32/923798_2.png) [@MaximoEsfuerzo](https://forum.arduino.cc/u/MaximoEsfuerzo)\
**Post date:** [December 28, 2024, 4:59pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/14 "2024-12-28T16:59:01Z")

</div>

I only objected to the change of diodes, you asked which opto-triac to use. 😉

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [December 28, 2024, 4:59pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/15 "2024-12-28T16:59:12Z")

</div>

> [@umutsarac](#):
>
> 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.

That could the problem. I don't see them on the schematic.  
Also:  
R3 is too small should be at least 4.7K  
R1 is too small, should be no smaller than 330

---

<div class="post-metadata">

**Author:** ![Deva\_Rishi](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/deva_rishi/32/227254_2.png) [@Deva\_Rishi](https://forum.arduino.cc/u/Deva_Rishi)\
**Post date:** [December 28, 2024, 5:55pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/16 "2024-12-28T17:55:05Z")

</div>

> [@umutsarac](#):
>
> R1 output is 110vAC 0.3A. R2 output 110VAC 0.3A

I start at 220V (AC) (i disregard the voltage drop of the 1N4007, but to be fair 220V AC is rare most places have upped it to 230V)  
V = I \* R, so I = 220 / (47.000 \* 2) = 0.00234 (for calculating the current it's either 220/ 94 or 110 / 47K  
P = V \* I, so P = 0.00234 \* 110 = 0.257 Watt. Are you using 1/4 Watt resistors ?

> [@jim-p](#):
>
> Also:  
> R3 is too small should be at least 4.7K  
> R1 is too small, should be no smaller than 330

R1 ?

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [December 28, 2024, 6:01pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/17 "2024-12-28T18:01:58Z")

</div>

> [@Deva\_Rishi](#):
>
> R1 ?

Need new glasses. R6

---

<div class="post-metadata">

**Author:** ![umutsarac](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/umutsarac/32/1020566_2.png) [@umutsarac](https://forum.arduino.cc/u/umutsarac)\
**Post date:** [December 28, 2024, 6:34pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/18 "2024-12-28T18:34:16Z")

</div>

yes. ı used 1/4. but what we ignore is that this structure works in arduino as it is. In fact, the fan is running constant and does not cut. I think there is a software error somewhere. I had no doubt in my circuit. I had a video, if I can upload it, I will upload it soon.

---

<div class="post-metadata">

**Author:** ![Deva\_Rishi](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/deva_rishi/32/227254_2.png) [@Deva\_Rishi](https://forum.arduino.cc/u/Deva_Rishi)\
**Post date:** [December 28, 2024, 6:34pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/19 "2024-12-28T18:34:20Z")

</div>

> [@jim-p](#):
>
> Need new glasses. R6

Yes that makes sense, i actually have 470R in my circuit.

In general either the MOC3021 is burned because of it, or the Triac is broken.  
I mean there could be other causes but it has to be excluded. Use 3.3v to switch the MOC3021 and see if the triac is actually switching.

If that test is successful we can see if the MCU can switch it.

---

<div class="post-metadata">

**Author:** ![Deva\_Rishi](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/deva_rishi/32/227254_2.png) [@Deva\_Rishi](https://forum.arduino.cc/u/Deva_Rishi)\
**Post date:** [December 28, 2024, 6:37pm UTC](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613/20 "2024-12-28T18:37:34Z")

</div>

> [@umutsarac](#):
>
> I think there is a software error somewhere.

Well i wasn't really going to look at that will the use of the 2nd core for it. Can you just confirm that the the output switching is working even with just a simple blink.

> [@umutsarac](#):
>
> this structure works in arduino as it is

You said that was with different components and therefore different soldering.

[Next page](https://forum.arduino.cc/t/i-cannot-run-the-arduino-circuit-with-esp32-help-please/1336613.md?page=2)
