This simple sketch I tested successfully with L298 and 5V:
// Test mit 5V und Gleichstrommotor am 23.6.24
// Gleichstrommotor 1
int GSM1 = 10;
int in1 = 9;
int in2 = 8;
// Gleichstrommotor 2
/*int GSM2 = 5;
int in3 = 7;
int in4 = 6;*/
void setup()
{
pinMode(GSM1, OUTPUT);
// pinMode(GSM2, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
// pinMode(in3, OUTPUT);
// pinMode(in4, OUTPUT);
}
void loop()
{
digitalWrite(in1, HIGH); // Motor 1 beginnt zu rotieren
digitalWrite(in2, LOW);
analogWrite(GSM1, 150); // Motor 1 soll mit der Geschwindigkeit "200" (max. 255) rotieren bei 12V mit Testmotor 50
/*
digitalWrite(in3, HIGH); // Motor 2 beginnt zu rotieren
digitalWrite(in4, LOW);
analogWrite(GSM2, 200); // Motor 2 soll ebenfalls mit der Geschwindigkeit "200" (max. 255) rotieren
*/
delay(2000);
digitalWrite(in1, LOW); // Durch die Veränderung von HIGH auf LOW (bzw. LOW auf HIGH) wird die Richtung der Rotation verändert.
digitalWrite(in2, HIGH);
/*digitalWrite(in3, LOW);
digitalWrite(in4, HIGH); */
delay(2000);
digitalWrite(in1, LOW); // Anschließend sollen die Motoren 2 Sekunden ruhen.
digitalWrite(in2, LOW);
/*digitalWrite(in3, LOW);
digitalWrite(in4, LOW);*/
delay(2000);
}
As your peristaltic pump is working only in 1 direction, I too strongly recomend a mosfet driver, such as this:
They work very well and are cheap.
For distributing 5V a small switching power supply would have been easier to drive your pump and logic. Please be aware, that supplying 5V to arduino at the external power input is to small to reach 5V. You have to supply through USB input.
Best regards Andy