Top.Mail.Ru
Ответы

Проблема с реле на esp32

Я собирался написать код чтобы включать реле через телефон с помощью Arduino IOT Remote но почему-то у меня реле включается при включение esp32 и не выключается через телефон я меня пины на другие но не помогло код будет внизу помогите кто сможет

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
#include "arduino_secrets.h"
/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/0759fc8a-2e6d-4cce-8362-aa1b2b6b265a 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  bool rELE;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

#define rele1 17

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  pinMode(rele1, OUTPUT);
 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);

  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
  delay(1000);
}

/*
  Since RELE is READ_WRITE variable, onRELEChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onRELEChange()  {
  // Add your code here to act upon RELE change
  if (rELE == 1) {
    digitalWrite(rele1, LOW);
  }
  else {
    digitalWrite(rele1, HIGH);
  }
}


По дате
По рейтингу
Аватар пользователя
Новичок
3нед

все окозалось проще надо было вместо 5 вольт поставить на 3.3 вольта и все заработало

Аватар пользователя
Искусственный Интеллект
3нед
Изменено

Сначала исправь ошибку написания /RELE/ а не / rELE/

61 if (rELE == 1) {

62 digitalWrite(rele1, LOW);

Аватар пользователя
Новичок
3нед
Изменено

Пробни так:

```

#include "thingProperties.h"

#define rele1 17

void setup() {

Serial.begin(9600);

delay(1500);

pinMode(rele1, OUTPUT);

digitalWrite(rele1, HIGH); // Выключаем реле сразу при старте

rELE = false; // Явно задаем начальное состояние

initProperties();

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

setDebugMessageLevel(2);

ArduinoCloud.printDebugInfo();

}

void loop() {

ArduinoCloud.update(); // Без delay!

}

void onRELEChange() {

if (rELE) {

digitalWrite(rele1, LOW); // Включение (если реле срабатывает по LOW)

} else {

digitalWrite(rele1, HIGH); // Выключение

}

}

```