Iot physicall and cloud button

hi, a i have a project, i want to enable a relay with a phisical button and a cloud button (made with arduino iot cloud and a nano 33 iot).

basically, the relay need to change is state when the physicall button or the cloud button is pressed.

i try many thing whitout succes. i need your help, have you any idea ?

thanks and sorry for my english, its not my first languange :slight_smile:

Hi, welcome. The first thing we want to know is, what you have tried.

Sometimes, a failed attempt is only one wire, or one line of code, from working.

Hi, I want the same thing, i have read some documentation at IoT Cloud Variables
It says:

"Let's say we create an integer variable called "sensor_value". To use this in a sketch, we simply use:
sensor_value = analogRead(A0);
We do not need to define the variable anywhere, as it has already been configured in thingProperties.h "

With that it mind I just made a switch in my DASH BOARD and I connected a pull-up button to G16 pin of my ESP32 DEV MODULE.

Here is my code at .ino

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/82dcf978-4086-40b9-bca4-c383ef0b784d 

  Arduino IoT Cloud Variables description

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

  bool switch_1;

  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"

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(23,OUTPUT);
  pinMode(16, INPUT_PULLUP); //PIN G16 DECLARED AS INPUT FOR MY PHYSICAL BUTTON
  // 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 
  
  
}


/*
  Since Led is READ_WRITE variable, onLedChange() is
  executed every time a new value is received from IoT Cloud.
*/

void onSwitch1Change()  {
  if(switch_1== true|| button_1 == LOW)
  {
    digitalWrite (23,HIGH);
  }
  else 
  {
    digitalWrite (23,LOW);
  }
  // Add your code here to act upon Switch1 change
}

Here is thingProperties.h where I declared my variable



// Code generated by Arduino IoT Cloud, DO NOT EDIT.

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char DEVICE_LOGIN_NAME[]  = "************************";

const char SSID []************= SECRET_SSID;    // Network SSID (name)
const char PASS[]************= SECRET_OPTIONAL_PASS;    // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[]  = **********************;    // Secret device password

void onSwitch1Change();

bool switch_1;
int button_1 = digitalRead (16); //PHYSICAL BUTTON ADDED TO MY ESP32 DEV MODULE

void initProperties(){

  ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
  ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
  ArduinoCloud.addProperty(switch_1, READWRITE, ON_CHANGE, onSwitch1Change);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.