Hi,
I’m working on a robot project. I want to control 2 DC Motors with joystick and 2 Stepper motors with individual buttons. I want to connect with USB for now. I searched a lot and tried to build a code. My motors worked but they are not controllable. It just executes the loop. I’m an architect who is new to arduino so I couldn’t find a solution by myself yet.
Here is the reference project that I used:
Boards, Shields and Motors which I used:
Arduino Uno
2 Adafruit Motor Shields v2
2 DC Motors (3V 13800rpm)
2 Stepper Motors (12VDC 32-Step 1/16 Gearing)
Code:
'#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"'
Adafruit_MotorShield ShieldTop(0x61);
Adafruit_MotorShield ShieldBot(0x60);
Adafruit_StepperMotor *stepper1 = ShieldBot.getStepper(513, 1);
Adafruit_StepperMotor *stepper2 = ShieldBot.getStepper(513, 2);
Adafruit_DCMotor *DC1 = ShieldTop.getMotor(3);
Adafruit_DCMotor *DC2 = ShieldTop.getMotor(4);
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3); // RX, TX
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>
char auth[] = "AuthtokenHere";
void setup() {
Serial.begin(9600);
Blynk.begin(auth);
}
void loop() {
Blynk.run();
if(analogRead(V0)==1024) {
DC1->setSpeed(150);
DC1->run(FORWARD);
}
if(analogRead(V0)==0) {
DC1->setSpeed(150);
DC1->run(BACKWARD);
}
if(analogRead(V1)==1024) {
DC2->setSpeed(150);
DC2->run(FORWARD);
}
if(analogRead(V1)==0) {
DC2->setSpeed(150);
DC2->run(BACKWARD);
}
if(analogRead(V2)==HIGH) {
stepper1->setSpeed(15);
stepper1->step(171, FORWARD, DOUBLE);
}
if(analogRead(V3)==HIGH) {
stepper2->setSpeed(15);
stepper2->step(171, FORWARD, DOUBLE);
}
}