Hello.
(Totally new in the Arduino world and forum so if there is something wrong with the post, I will try to correct it ASAP).
I am making a laboratory equipment where user can set the speeds of peristaltic pumps using L298N Dual Bridge H-motor controller (idea is set up the transfer pumps with user controlled speeds).
When trying to give the PWM speed by the user for the test sketch when controlling only one pump:
#include <Wire.h>
// Dosing pump pins
int dir1PinA = 7;
int dir2PinA = 8;
// Transfer pump 1 pins
int dir3PinA = 3;
int dir4PinA = 4;
int speedPinA = 9; // Needs to be a PWM pin to be able to control motor speed
// Transfer pump 2 pins
int dir5PinA = 5;
int dir6PinA = 6;
int speedPinB = 10; // Needs to be a PWM pin to be able to control motor speed
//select one by uncommenting
byte ValueS1;
//int ValueS1;
//byte ByteS2;
//int ValueS2;
void setup() {
Serial.begin(9600);
// Motor output
pinMode(dir1PinA, OUTPUT);
pinMode(dir2PinA, OUTPUT);
pinMode(dir3PinA, OUTPUT);
pinMode(dir4PinA, OUTPUT);
pinMode(dir5PinA, OUTPUT);
pinMode(dir6PinA, OUTPUT);
pinMode(speedPinA, OUTPUT);
pinMode(speedPinB, OUTPUT);
Serial.begin(9600); //initialize serial communication
Serial.println ("Give speed to transfer pump 1");
while (Serial.available() <= 0) //if <= 0, there is no input
{
// read the value sent from keyboard, wait until there is incoming serial data
}
ValueS1 = Serial.read();
}
void loop() {
// put your main code here, to run repeatedly:
// ValueS1 = map(ValueS1, 0, 1023, 0, 255);
analogWrite(speedPinA, ValueS1);//Sets speed variable via PWM
digitalWrite(dir3PinA, HIGH);
digitalWrite(dir4PinA, LOW);
Serial.println("Transfer pump on, speed"); // Text to screen
Serial.println(byte(ValueS1));
Serial.println(ValueS1);
Serial.println(int(ValueS1));
Serial.println(" "); // Empty line
}
by inputting value 255 from the serial monitor, the response is:
"Transfer pump on, speed
50
50
50"
and for the input value 100 the PWM is 49, input value 0 the PWM is 48, etc. and motor is not getting the correct PWM value (motor is turning slowly but not pumping)
So far I have tried:
- When changing
analogWrite(speedPinA, ValueS1);//Sets speed variable via PWM
ValueS1 to 255 the pump works fine at full speed, but even still PWM input 1 gives the output of 49.
- Tested between int and byte for the ValueS1, no change in function
- Tested if the problem was with analog read/write (1023 to 255 value), no change
- Tested with input methods, no change. Checked that serial input 255 is read as 255.
- Checked the connections (ruled out when replacing user defined value with 255 pump works, not the output)
Thanks, any help is appreciated!
