Yet another robot project

Hello!

In this thread I'm discussing and developing my robot project.

Project goal is to make a autonymous robot that skeets around house and does or does not do something useful or fun.

I will make tutorial videos during the process to help some people overcome the same obstacles that I meet!

-Tinkerers Tube

Version 0.005 code in the comments.

video of progress here: Arduino stepper motor driven two wheeled robot (28BYJ48 motors with ULN2003 drivers) - YouTube


#include <AccelStepper.h>
#include <SoftwareSerial.h>

// The pins we will use for the Serial
const int BTRX = 12;
const int BTTX = 13;

const int OctoTurn = 255;  // it is not but 1019 is a prime number..
const int QuartTurn = 510; // it is not but 1019 is a prime number..
const int HalfTurn = 1019;
const int TurnNinety = 3530;
const int FullTurn = 2038; // full turn of this motor is 2038 steps
const int Move = 5000;

int Goal1 = 0;
int Goal2 = 0;

//int StepperSpeed = 1000;
int StepperMaxSpeed = 555;
int StepperAccel = 1000.0;
int SpeedMultiplier = 1;

int target = 0;

int joke = 0;

int steps = 0; // keep track of the step count for motor

#define FULLSTEP 4
#define HALFSTEP 8

AccelStepper stepper1(HALFSTEP, 8, 10, 9, 11);  //choose half or full speed (recommended)
AccelStepper stepper2(HALFSTEP, 4, 6, 5, 7);    //choose half or full speed (recommended)

//AccelStepper stepper1(FULLSTEP, 8, 10, 9, 11);    //choose half or full speed
//AccelStepper stepper2(FULLSTEP, 4, 6, 5, 7);      //choose half or full speed

// The message we will send using BT
String strBtCommand;


SoftwareSerial SerialBT(BTRX, BTTX);

void dixie();

void setup() {

  stepper1.setMaxSpeed(StepperMaxSpeed);
  stepper1.setAcceleration(StepperAccel);
  stepper1.move(-1);  // I found this necessary

  stepper2.setMaxSpeed(StepperMaxSpeed);
  stepper2.setAcceleration(StepperAccel);
  stepper2.move(1);  // I found this necessary

  SerialBT.begin(9600); // 9600 is working
  SerialBT.println("Bluetooth connection successfully established.");
  SerialBT.println("Hello! My name is Kaika!");
  SerialBT.println("Use 'f','b','l','r' to move me.");
  SerialBT.println("Use 'spd' and to change my speed!");
  SerialBT.println(" ^__^ ");
  delay(1000);
}



void loop() {

  steps = stepper1.distanceToGo();

  stepper1.run();
  stepper2.run();


  if (SerialBT.available()) {
    strBtCommand = SerialBT.readString();
    SerialBT.print("OK, I'm ");

    if (steps != 0) {
      SerialBT.print("busy, wait! I still have to move ");
      SerialBT.print(steps);
      SerialBT.println(" Steps!");
    }

    else {



      if (strBtCommand.indexOf("f") >= 0) {
        stepper1.setCurrentPosition(0);
        stepper2.setCurrentPosition(0);
        target = Move;
        stepper1.moveTo(-target);
        stepper2.moveTo(target);
        SerialBT.println("marching on!");
      }

      else {

        if (strBtCommand.indexOf("b") >= 0) {
          stepper1.setCurrentPosition(0);
          stepper2.setCurrentPosition(0);
          target = Move;
          stepper1.moveTo(target);
          stepper2.moveTo(-target);
          SerialBT.println("going back!");
        }

        else {

          if (strBtCommand.indexOf("l") >= 0) {
            stepper1.setCurrentPosition(0);
            stepper2.setCurrentPosition(0);
            target = TurnNinety;
            stepper1.move(target);
            stepper2.move(target);
            SerialBT.println("turning left!");
          }

          else {

            if (strBtCommand.indexOf("r") >= 0) {
              stepper1.setCurrentPosition(0);
              stepper2.setCurrentPosition(0);
              target = TurnNinety;
              stepper1.move(-target);
              stepper2.move(-target);
              SerialBT.println("turning right!");
            }

            else {

              if (strBtCommand.indexOf("spd") >= 0) {
                SerialBT.print("My current speed is ");
                SerialBT.print(StepperMaxSpeed);
                SerialBT.println("rpm");
                SerialBT.println("Input speed 1 to 9 (input x 100 +100rpm)");
                while (SerialBT.available() == 0) {
                }
                int SpeedMultiplier = SerialBT.parseInt();
                if (SpeedMultiplier >= 9) {
                  SpeedMultiplier = 9;
                }
                if (SpeedMultiplier <= 1) {
                  SpeedMultiplier = 1;
                }


                StepperMaxSpeed = ((SpeedMultiplier * 100) + 100);
                stepper1.setMaxSpeed(StepperMaxSpeed);
                stepper2.setMaxSpeed(StepperMaxSpeed);
                SerialBT.print("My speed is set to ");
                SerialBT.print(StepperMaxSpeed);
                SerialBT.println("rpm");

                dixie();
              }

              else {

                if (strBtCommand.indexOf("joke") >= 0) {
                  SerialBT.println("telling you one right here!");
                  SerialBT.println("What’s the best thing about Switzerland?...");
                  SerialBT.println("...I don’t know, but the flag is a big plus! :D");
                }





                else {

                  SerialBT.print("Sorry, I've got no idea what you want!");
                  SerialBT.println(strBtCommand);
                }


              }
            }
          }
        }
      }
    }

  }
}

Needs more F().

Novel.

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