Multisetting Dc motor

still nothing. The program itself has a problem based on the application tinkercad. the circuit diagram also came from tinkercad

Hi,
Can you post some pictures of your project please?
So we can see your component layout.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Umm i dont have an actual diagram since we only use tinkercad but here are the components:
3 switches
1 arduino uno
1 motor driver
2 dc motors
1 9v batter
1 potentiometer

Hi,

Well now is the time to pull your project into the real world.
Relying on the response of a CAD program, will not solve or show all the possible bugs.

Tom.... :grinning: :+1: :coffee: :australia:

sir even if I were to create an actual diagram the arduino ide Application is not gonna allow me to upload my code into my arduino since there is something wrong with my program

So your code is not COMPILING ?

Tom.... :grinning: :+1: :coffee: :australia:

Yes

Hi,
Try this, I have got rid of your compile problems, but there are some major coding bugs.

const int lowSWPin = 6;
const int highSWPin = 11;
const int controlPin1 = 3;
const int controlPin2 = 2;
const int controlPin3 = 4;
const int controlPin4 = 5;
const int enablePin1 = 9;
const int enablePin2 = 10;
const int onOffSwitchStateSWPin = 8;
const int potPin = A0;

int lowSWState = 0;
int highSWState = 0;
int motorEnabled = 0;
int potentiometerVal = 0;
int speed = 0;
int motorValue = 0;
int onOffSWState = 0;
int previousOnOffSWState = 0;

void setup()
{
  pinMode(onOffSwitchStateSWPin, INPUT);
  pinMode(lowSWPin, INPUT);
  pinMode(highSWPin, INPUT);
  pinMode(controlPin1, OUTPUT);
  pinMode(controlPin2, OUTPUT);
  pinMode(controlPin3, OUTPUT);
  pinMode(controlPin4, OUTPUT);
  pinMode(enablePin1, OUTPUT);
  pinMode(enablePin2, OUTPUT);

  digitalWrite(enablePin1, HIGH);
  digitalWrite(enablePin2, HIGH);
}
void loop()
{
  potentiometerVal = analogRead(potPin) / 4;
  onOffSWState = digitalRead(onOffSwitchStateSWPin);
  delay(1);
  if (onOffSWState != previousOnOffSWState) {
    if (onOffSWState == HIGH) {
      motorEnabled = !motorEnabled;
    }
  }
  if (potentiometerVal >= 127) {
    digitalWrite(controlPin1, HIGH);
    digitalWrite(controlPin3, HIGH);
  }
  else {
    digitalWrite(controlPin1, LOW);
    digitalWrite(controlPin3, LOW);
  }
  if (potentiometerVal <= 127) {
    digitalWrite(controlPin2, HIGH);
    digitalWrite(controlPin4, HIGH);
  }
  else {
    digitalWrite(controlPin2, LOW);
    digitalWrite(controlPin4, LOW);
  }
  if (motorEnabled == 1) {
    analogWrite(enablePin1, motorEnabled);
    analogWrite(enablePin2, motorEnabled);
  }
  else {
    analogWrite(enablePin1, 0);
    analogWrite(enablePin2, 0);
  }
  previousOnOffSWState = onOffSWState;
}
//========================================
void setSpeedButton1()
{
  while (1) {
    lowSWState = digitalRead(lowSWPin);
    highSWState = digitalRead(highSWPin);
    if (lowSWState == HIGH) {
      speed = speed - motorValue;
      if (speed < 0) {
        speed = 0;
      }
    }
    if (highSWState == HIGH) {
      speed = speed + motorValue;
      if (speed > 255) {
        speed = 255;
      }
    }
    analogWrite(enablePin1, speed);
    analogWrite(enablePin2, speed);
  }
}

Tom.... :grinning: :+1: :coffee: :australia:

you mean by compile problems the one under the //==== ?
if so i cant do that cause thats part of my project as well i need the 2 buttons to chance speed
of rpm

Hi,
You shouldn't have compiling problems with the code I posted and UNO selected as controller.
Yes this bit of code compiles but has a serious bug.

void setSpeedButton1()
{
  while (1) {
    lowSWState = digitalRead(lowSWPin);
    highSWState = digitalRead(highSWPin);
    if (lowSWState == HIGH) {
      speed = speed - motorValue;
      if (speed < 0) {
        speed = 0;
      }
    }
    if (highSWState == HIGH) {
      speed = speed + motorValue;
      if (speed > 255) {
        speed = 255;
      }
    }
    analogWrite(enablePin1, speed);
    analogWrite(enablePin2, speed);
  }
}

while(1)
will cause that while to loop continuously, and you cannot leave it .
Please rethink how that bit is supposed to work.

Tom.... :grinning: :+1: :coffee: :australia:

Hello
Describe in simple words how the function should work and do it very simply.

Well there are 3 switches and a potentiometer the potentiometer moves the motors from left to right
1st switch - on and off
2nd switch - lowrpm
3rd switch - high rpm

I see ill try to find some ways for me to interconnect those void loop and the void setspeed

Hi,

So the pot controls the speed and direction, or does it just control direction?
If it just changes direction, why not use a switch?

Tom..... :grinning: :+1: :coffee: :australia:

I cant we are demanded to use it for direction and the switches are responsible for: 1st switch on and off,2nd switch low rpm,3rd switch highrpm

Hi,
So why not;
Button 1 selects STOP
Button 2 selects START/FWD
Button 3 selects START/REV

Potentiometer sets the speed.

If you have been supplied with these components, can you post an image/copy of the project task sheet you would have been given?

Tom... :grinning: :+1: :coffee: :australia:

We were instructed to do what she said that:
Potentiometer-direction
Switch 1- on/off
Switch 2- highrpm
Switch 3- lowrpm

Hi,
So what does your code do now, when you press buttons and turn the control?

Tom... :grinning: :+1: :coffee: :australia:

Well its still not working if i remove the void set speed it does the switch 1 and potentiometer to work but switch 2 and 3 still not gonna work

I am a trifle puzzled. Are you not supposed to discuss this project with your tutor? Is your tutor not paid to help you? :face_with_raised_eyebrow: