I have been trying to upload this code to the Arduino Uno R3 (with ESP8266 module):
/*
Integrated Sketch for Motor Control via Wi-Fi and Arduino IoT Cloud
Description:
- Combines motor control functionality (L298N driver) with Arduino IoT Cloud integration.
- Controls two motors (Motor A and Motor B) based on cloud variables `motor1ON` and `motor2ON`.
- Connects to Wi-Fi and Arduino IoT Cloud for remote control.
Cloud Variables:
- motor1ON: Controls Motor A (ON/OFF)
- motor2ON: Controls Motor B (ON/OFF)
Dependencies:
- ArduinoIoTCloud
- ESP8266WiFi
- WiFiClientSecure
*/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include "thingProperties.h"
// Motor A Pin Configuration
int motorAPin1 = 3; // IN1 on L298N
int motorAPin2 = 4; // IN2 on L298N
int motorAEnable = 9; // ENA on L298N (PWM control)
// Motor B Pin Configuration
int motorBPin1 = 5; // IN3 on L298N
int motorBPin2 = 6; // IN4 on L298N
int motorBEnable = 10; // ENB on L298N (PWM control)
// Initialize Wi-Fi connection
void setup() {
Serial.begin(115200);
delay(1500);
Serial.println("\nStarting up...");
// Initialize IoT Cloud properties
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(4);
ArduinoCloud.printDebugInfo();
// Wi-Fi connection
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(SECRET_SSID, SECRET_OPTIONAL_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWi-Fi connected!");
Serial.print("Device IP Address: ");
Serial.println(WiFi.localIP());
// Motor pin setup
pinMode(motorAPin1, OUTPUT);
pinMode(motorAPin2, OUTPUT);
pinMode(motorAEnable, OUTPUT);
pinMode(motorBPin1, OUTPUT);
pinMode(motorBPin2, OUTPUT);
pinMode(motorBEnable, OUTPUT);
// Initialize motors to OFF state
analogWrite(motorAEnable, 0);
analogWrite(motorBEnable, 0);
}
void loop() {
// Update IoT Cloud connection
ArduinoCloud.update();
}
/*
Motor Control Functions
These functions are triggered when cloud variables `motor1ON` and `motor2ON` change.
*/
void onMotor1ONChange() {
if (motor1ON) {
Serial.println("Motor A turned ON (Forward)");
analogWrite(motorAEnable, 255); // Full speed for Motor A
digitalWrite(motorAPin1, HIGH);
digitalWrite(motorAPin2, LOW);
} else {
Serial.println("Motor A turned OFF");
analogWrite(motorAEnable, 0); // Stop Motor A
digitalWrite(motorAPin1, LOW);
digitalWrite(motorAPin2, LOW);
}
}
void onMotor2ONChange() {
if (motor2ON) {
Serial.println("Motor B turned ON (Forward)");
analogWrite(motorBEnable, 255); // Full speed for Motor B
digitalWrite(motorBPin1, HIGH);
digitalWrite(motorBPin2, LOW);
} else {
Serial.println("Motor B turned OFF");
analogWrite(motorBEnable, 0); // Stop Motor B
digitalWrite(motorBPin1, LOW);
digitalWrite(motorBPin2, LOW);
}
}
When I upload this code to the ESP8266 module (using DIP 5, 6 & 7), I receive a message that the sketch was successfully uploaded. However, after switching back the DIP switches to 5 & 6 and opening the serial monitor at baud rate 115200, this retrieves the following error message:
ets Jan 8 2013,rst cause:4, boot mode:(3,7)
wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v951aeffa
~ld
When I look at the connected devices in the router, I do see that the ESP module is connected to WiFi. Nonetheless, the devices appears in the offline state in Arduino Cloud.
