Hello, I'm trying to turn ON/OFF a DC motor from Arduino Iot Cloud. I have to turn it ON/OFF physically and through the cloud, physically it works well but from the cloud it does nothing. I'm using an Arduino MKR WiFi 1010, a L298N Dual full bridge,9V DC motor and a push buttom.
I tried with a LED and it wprked very well, but with the motor doesn't. My code is
#include "thingProperties.h"
#include <FTDebouncer.h>
#define MOTOR_PIN 2
#define BUTTON_PIN 5
FTDebouncer buttons;
void setup() {
pinMode(MOTOR_PIN, OUTPUT);
buttons.addPin(BUTTON_PIN, LOW);
buttons.init();
setDebugMessageLevel(2);
Serial.begin(9600);
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
}
void loop() {
buttons.update();
ArduinoCloud.update();
onMotorChange();
}
void onPinActivated(int pinNr) {
// do something according to the _pinNR that is triggered. For instance:
Serial.println(pinNr);
toggle = !toggle;
}
void onPinDeactivated(int pinNr) {
// do something according to the _pinNR that is triggered. For instance:
Serial.println(pinNr);
}
void onMotorChange() {
digitalWrite(MOTOR_PIN, toggle || motor);
Serial.print("The motor is ");
if (toggle) {
Serial.println("ON");
}
}
Thanks for help