1

I have a project where I want to control a pump, I use an Arduino, connected to a driver L298N and I will connect the pin 5, 6, 7 of the arduino to the pin IN2, IN1, ENA of the driver respectively and the motor will be connected to the output

My materiel :

  • Arduino Uno R3
  • Multimeter
  • Arduino IDE 2.1.1

The issue : When I use the function analogWrite the voltage vary only between two value (0v or 5.5v). The pin used was the Digital pin n°7, noted in the code 7.

The code :

#define PUMP_DIR_1 5
#define PUMP_DIR_2 6
#define PUMP_PWM 7
#define INVERTED 0
void setup() {
 Serial.begin(9600);
 pinMode(PUMP_PWM, OUTPUT);
}
void set_pump_speed(int speed){
 Serial.print("Set speed ");
 Serial.print(speed);
 Serial.print("\r\n");
 analogWrite(PUMP_PWM, speed);
}
void loop() {
 set_pump_speed(255);
 delay(3000);
 set_pump_speed(0);
 delay(3000);
 set_pump_speed(125);
 delay(3000);
}

As output I obtained :

00:32:17.184 -> Set speed 0
00:32:20.175 -> Set speed 125
00:32:23.178 -> Set speed 255
00:32:26.182 -> Set speed 0
00:32:29.197 -> Set speed 125
00:32:32.201 -> Set speed 255

From the mutlimeter I obtained :

0v when speed = 0
0v when speed = 125
5.5v when speed = 255

The arduino is not wired to anything

Rohit Gupta
6122 gold badges5 silver badges18 bronze badges
asked Aug 2, 2023 at 22:38

1 Answer 1

1

Pin 7 isn't a PWM pin. Use, say, pin 6 and you will get correct results. The PWM pins are marked with a "~" on the board.

answered Aug 3, 2023 at 0:10
2
  • Thank your for your answer, I feel stupid, because it is not the first time I use PWM on Arduino and I never took this in consideration. Commented Aug 3, 2023 at 9:49
  • @Nept0 Don't worry! It must have worked last time by chance, now you know why. :) Commented Aug 3, 2023 at 9:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.