Hi there.
As per the title I have 2 potentiometers controlling 2 motors via PWM but 1 of the motors receives no PWM no matter how I twist the potentiometer.
I am no coding expert so I combined code from the website (https://tronixlabs.com.au/news/tutorial-l298n-dual-motor-controller-module-2a-and-arduino/) and from the arduino example called AnalogInput. I then made it so that the potentiometer values are output to the sensor so that I could tune the pots to output 0-255. Potentiometer values tested to range from 0-1023 and the motor PWMs are set to range from 0-255 so I figured that dividing by 4 in the code like this "analogWrite(enA, sensor1Value/4);" for both motors would work, but for some reason multiplying by a bit over 16 makes the motor output 255! Therefore, I have the code as "analogWrite(enA, sensor1Value*16);" and the same for motor B of course. The thing is that motor B only receives a sensor value of zero at all times. The two pots and motors are wired in exactly the same way. Motor A uses pin A0 on the Arduino and motor B uses pin A1. Both negatives on the potentiometer go to GND and both positives go to 5V. Any ideas as to how to get the 2nd pot to give a reading to motor B rather than nothing nada zilch? The code is below. Also, photo attached. Thanks.
int sensor1Pin = A0; // select the input pin for the potentiometer
int sensor1Value = 0; // variable to store the value coming from the sensor
int sensor2Pin = A1; // select the input pin for the potentiometer
int sensor2Value = 0; // variable to store the value coming from the sensor
// connect motor controller pins to Arduino digital pins
// motor one
int enA = 10;
int in1 = 9;
int in2 = 8;
// motor two
int enB = 5;
int in3 = 7;
int in4 = 6;
void setup()
{
// set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
Serial.begin(9600);
}
void loop()
{
{
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, sensor1Value16);
delay(100);
Serial.print(" Sensor 1 = ");Serial.print(sensor1Value16);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(enB, sensor2Value16);
delay(100);
Serial.print(" Sensor 2 = ");Serial.print(sensor2Value16);
}
// read the value from the sensor:
sensor1Value = analogRead(sensor1Pin);
sensor2Value = analogRead(sensor2Pin);
}