Arduino Speed/Direction control with 4 DC Motors and 2 Pots, need help

" Arduino Speed/Direction control with 4 DC Motors and 2 Pots, need help "

Hi everyone,
I need some knowledge of yours. I am newbie and I have encountered with some problems. I hope that some of you might answer my questions below, thanks.

I am using this Arduino sketch as a backbone while using diot, transistor,pot,and resistor for dc speed control.

And this is the code that I am using to control the speed of dc motor :

int analogInPin = A0;
int sensorValue1 = 0;
int outputValue = 0;
int transistorPin1 = 3;

void setup() {
  Serial.begin(9600); 
  
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(transistorPin1, OUTPUT);
}

void loop() {
  sensorValue1 = analogRead(analogInPin)/4;            
  outputValue = map(sensorValue1, 0, 1023, 0, 255);  

  analogWrite(transistorPin1, sensorValue1);
  
  if (sensorValue >= 160) { //example
    digitalWrite(8, HIGH);
    digitalWrite(9, LOW);
  } else {
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
  }
    
  delay(10);                     
}

This sketch and controlling speed of 1 dc motor works fine. However, it doesn't work with multiple dc motors. I tried some addings to see if I can do the way I want ;but as always failed :(.

I added these to see what will happen ( if it works or not; and it doesn't work ) :

int sensorValue2 = 0;
int transistorPin2 = 17;
analogWrite(transistorPin1 , sensorValue1);
  analogWrite(transistorPin2 , sensorValue1);

I want to learn that is there something like while writing in analogWrite, digitalRead at etc. commands ?

analogWrite(transistorPin1 && transistorPin2, sensorValue1);

How can I control speed of 4 dc motors with potentiometer while using diot and transistor ;and how might be the new sketch ( I need to make another diot and transistor connections to my breadboard for 2nd-3rd-4th dc motors ) ? I don't have any problem at 1 dc motor speed control with 1 potetiometer coding or sketch; but I cannot move 4 dc motors with above coding ,even I tried to add/do something myself but failed.

For dc motor's direction controls ( forward/backward,brake,reverse ) I need to have a motor shield or we can do it without motor shields too ? if it is possible without motor shield would you give me a guidance website link please ;or if we need a motor shield which shield is easy to use ( which ons has more tutorial with some sample,basic examples : Arduino motor shield or Adafruit motor shield or dfrobot motor shield or any brand motor shields ) ?

In your circuit that diode is in the wrong place it needs to be across the motor.

int transistorPin2 = 17;

You sure that is analog pin 3, it will work though did you set the pin mode to output before you tried it?

analogWrite(transistorPin1 && transistorPin2, sensorValue1);

No you can't do that the && is a logic AND not an "as well sort of and" the C language does not work like that.
You need one analogWrite function call for each pin.

With 4 motors you might need an external power supply and capacitors across the supply to reduce the interference given by the motors.

That code doesn't compile (you do not declare the variable sensorValue).

I suggest you post the code representing your best attempt to support multiple motors, and the circuit you are using to drive the motors, and tell us what you intend it to do and what it actually does.

how can I make a circuit that will handle 4 dc motors ( how and where can I connect the extra diots/transistor/capacitor etc. components for handling the 4 dc motors ) ?

My 1 dc motor wants 9-12V ;so for 4 dc motors ,minimum, how much voltage and amper I need for good results for my robot tank project which is 6kg weightness?

This is my test area :

This sketch and above code works fine with 1 dc motor control speed with potention meter. I want to control 4 dc motors ;so what should I add, put ;and how to build the circuit I desire on my breadboard ?

This is a short video demonstration :

I hope that you understood my intend my clear now^^.

What I want is I want to control 4 dc motors' speed with a potentiometer and I want to control the direction of the motor ( forward/backward/brake/reverse ).

For example, for determining the direction of the motors I need a motor shield or I can code it without a motor shield ?

how can I make a circuit that will handle 4 dc motors

I think we are going round in circles, you have already been told this. Take what you have already ( once you put the diode in the correct place ) and repeat it four times. Connect it to four different outputs.
If you want bidirectional control then use a H-bridge circuit. It does not have to be on a motor shield you can just wire up H-bridge circuits on a board. Do not use solderless bread board it is very unreliable, solder things up on strip board.

how much voltage and amper I need for good results for my robot tank

Only you can decide what is good or bad performance. If you do not get good results then you need a motor that takes more current at what ever voltage you are going to give it.

What I want is I want to control 4 dc motors' speed with a potentiometer

OK something new here, you simply make one of the sides of the H-bridge into a PWM signal to control the speed.

There are four pages her on motors of various types:-
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

At my university, there is American system. At the first everyone sees the same lessons, at second year we start to choose the lessons which branch we want to be, at 3rd year we start to learn only the our branch lessons. Me, I am a 3rd class mechatronic engineering student new ( at this semester ). At university we learned the theorical parts ( always theroical calculations; nothing more ). I want to improve myself. I saw that the real time applications are totally different that theorical ones really. I do research on the internet but at some parts I don't know how to apply.

Thus, Grumpy_Mike or anyone, would you draw a simple diagrom for me a " H-Bridge " how to control 4 dc motors at bidirectional control ( for 4 dc motor speed and direction control with a potentiometer )that will show how to connects multiple diots, capacitors or if it is needed add capacitor for decoupling ? thanks.

Without H-Bridge I cannot control 4 dc motors' speed with a potentiometer ? if there is a way without using H-Bridge to control 4 dc motors' speed and direction with a potentiometer Would you give me a diagram how we connect the components ;and how many/what components I need ? thanks.

I hope that someone might help me about this issue soon, I will wait your replies, friend, thank you again.

This is a circuit for controlling four motors using two SN754410 chips and one 74LS04 chip.

Connect the enable pins to a PWM pin and feeding that pin with a value read from the analog port will allow you to control the speed of each of the motors.
The direction can be any output pins.

The motor supply can be between 5V and 12V but use separate power supply as the USB can not power this many motors.

You might have to add decoupling if the motors cause interference, which they well might.
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Motor control.pdf (31.1 KB)

http://www.ecs.umass.edu/ece/m5/tutorials/H-Bridge_tutorial.html

For higher currents, there is the L298D chip that can/should be bolted to a heat sink.