The code below is the sample provided by Handson Tech for the Xy160D motor driver. I added the built in LED flash code to make sure it was looping. It runs perfectly on an Elegoo Mega2560 R3 and two different Nanos (Arduino and clone), but will not run on my Arduino NANO 33 IoT devices (I've tried two). On the IoT 33s, the LED blinks so I know the code is running, but the motor (in this case on a linear actuator) does not. I've triple checked the wiring. I've tried powering the devices using both USB and a benchtop power supply set to 5V.
When I connect the driver board's power, plus the PWM plus the INA line, the actuator powers up and runs continuously. If I disconnect the INA and connect INB, the actuator runs continuously in the opposite direction. With the PWN, INA, and INB all connected to the IoT 33, the actuator does nothing.
I've tried using different pins on the IoT 33 with the same result. Any ideas?
Note: the code is provided for both sides of the driver board (what the author notes as Motor1 and Motor2), but I am only using Motor1 on Arduino pins 5, 4, and 6.
/*==========================================================================
// Author : Handson Technology
// Project : Arduino Uno with H-Bride 7A Motor Driver
// Description : XY160D 7A high Power H-Bridge motor Driver Module
// Source-Code : H-Bride-7A-Motor-CTR.ino
// Program: Control 2 DC motors using L298N H Bridge Driver
//==========================================================================
*/
const int IN1=5;
const int IN2=4;
const int ENA=6;
const int IN3=8;
const int IN4=7;
const int ENB=9;
bool ledState;
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(13,OUTPUT);
}
void loop() {
ledState = !ledState;
if (ledState) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
Motor1_Brake();
Motor2_Brake();
delay(100);
Motor1_Forward(200);
Motor2_Forward(200);
delay(1000);
Motor1_Brake();
Motor2_Brake();
delay(100);
Motor1_Backward(200);
Motor2_Backward(200);
delay(1000);
}
void Motor1_Forward(int Speed)
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
analogWrite(ENA,Speed);
}
void Motor1_Backward(int Speed)
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
analogWrite(ENA,Speed);
}
void Motor1_Brake()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
}
void Motor2_Forward(int Speed)
{
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
analogWrite(ENB,Speed);
}
void Motor2_Backward(int Speed)
{
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
analogWrite(ENB,Speed);
}
void Motor2_Brake()
{
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}