Problem with a H-bridge?

I am bulding an arduino based robot. The robot is supposed to drive away from the light. I'm using:

  1. dc motors:
  • Motor supply voltage: max. 6 V
  • Torque: 0.8 kg*cm (0.78 Nm)
  • Engine speed without load: 90 +/- 10 rpm
  • Motor current consumption without load: 190 mA (max. 250 mA)
  • Motor current consumption when the shaft is stopped: 1 A
  1. h-bridge - L293D
    These are two-channel ICs, designed for use with voltages up to 36 V and current not exceeding 0.6 A per channel (temporary current can reach a maximum of 1.2 A per channel).
    Connected like this:
    image
  2. 2 Photoresistors 5-10kΩ GL5616
  3. 2 10k resistors (to photoresistors)
  4. 6V battery connected to h-bridge
  5. Arduino is powered by laptop but it will be powered by 9V battery in the final project
    My code looks like this:
// Definicje pinów czujników światła
const int leftSensorPin = A0;  // Pin dla lewego czujnika światła
const int rightSensorPin = A1; // Pin dla prawego czujnika światła

// Definicje pinów sterujących silnikami
const int leftMotorPin1 = 4;   // Pin 1 dla lewego silnika
const int leftMotorPin2 = 5;   // Pin 2 dla lewego silnika
const int leftMotorPinSteering = 6;
const int rightMotorPin1 = 8;  // Pin 1 dla prawego silnika
const int rightMotorPin2 = 7;  // Pin 2 dla prawego silnika
const int rightMotorPinSteering = 9;

// Stałe prędkości silników
const int baseSpeed = 100;     // Bazowa prędkość silników

void setup() {
  // Inicjalizacja pinów jako wyjścia
  pinMode(leftSensorPin, INPUT);
  pinMode(rightSensorPin, INPUT);
  pinMode(leftMotorPin1, OUTPUT);
  pinMode(leftMotorPin2, OUTPUT);
  pinMode(rightMotorPin1, OUTPUT);
  pinMode(rightMotorPin2, OUTPUT);
  pinMode(leftMotorPinSteering, OUTPUT);
  pinMode(rightMotorPinSteering, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  // Odczyt wartości z czujników światła
  int leftLight = analogRead(leftSensorPin);
  int rightLight = analogRead(rightSensorPin);

  // Obliczenie różnicy między wartościami czujników
  int lightDifference = leftLight - rightLight;

  // Obliczenie prędkości silników w zależności od różnicy wartości odczytów
  int leftSpeed = baseSpeed + lightDifference;
  int rightSpeed = baseSpeed - lightDifference;

  // Ograniczenie prędkości do zakresu 0-255
  leftSpeed = constrain(leftSpeed, 0, 200);
  rightSpeed = constrain(rightSpeed, 0, 200);

  Serial.print("Left Light: ");
  Serial.print(leftLight);
  Serial.print("  |  Right Light: ");
  Serial.println(rightLight);
  Serial.print("Left speed: ");
  Serial.print(leftSpeed);
  Serial.print("  |  RrightSpeed: ");
  Serial.println(rightSpeed);

  delay(10000);

  // Ustawienie kierunku obrotów silników
 
  digitalWrite(leftMotorPin1, HIGH);
  digitalWrite(leftMotorPin2, LOW);
  digitalWrite(rightMotorPin1, HIGH);
  digitalWrite(rightMotorPin2, LOW);
  analogWrite(leftMotorPinSteering, leftSpeed);
  analogWrite(rightMotorPinSteering, rightSpeed); 
}

There is no problem with photoresistors or code connected to calculating motorspeed, it is printed on serial monitor correctly, but the wheels won't spin, the motors make the noise typical for PWM. Is there something wrong with the voltage or something? Should I use different batteries? Maybe use resistors with h-bridge? I tried powering the whole project with just 9V battery connected to arduino connected to breadboard with h-bridge, it didn't work too. Any ideas what I am doing wrong?

Verify you have continuity between Arduino GND and the negative side of the 6V battery.

That dinosaur drops up to 4V from the battery voltage. Get a modern MOSFET motor driver board.

That means the motor voltage may drop down to 2V.

Or feed it with 10V...

First, what's your motor current - you ran it with 6V, can you measure the current?

9V from what type of battery?

So if I connect 14V to it it will be fine? Can I power both arduino and motors with it?

That may destroy your motors... they are built for 6V...

9V didn't work as well, 10V will?

How is your maths?

Bateria 9V 4022 6LR61 alkaliczna Varta Industrial Sklep Botland

9-4=5 and it doesn't work

That won't work for a different reason. Completely unsuitable type of battery for running motors.

I was hoping you would say 6x AA cells.

What I was pointing out is: 14-4=10V which could damage motor with max 6V

So what type of batteries should I use? I have 4 AA 1.5V batteries but it doesn't work too

See post #15

I cannot, don't have the device, I am fairly new to the topic as you can probably see

What device?

ammeter

Ah. You should get one. It doesn't have to be expensive. Even a £20 multimeter is good enough for almost all arduino projects. You are blind without one.