Control L298N driver with Spectrum Shield (Dancing fountain)

Hello Guys! :slight_smile:
My project is a dancing fountain


-Arduino Mega 2560
-Spectrum shield
-4 X L298N drivers
-7 X water pumps motor (6V-12V max)

Git spectrum shield pwm demo

I’m trying to get SparkFun’s ‘spectrum shield’ working, with 7 water pumps as output thru L298N drivers.
With the PWM demo (i edited the code below), my pumps are working ,but the motor working voltage is 6V (anything less than 6V, the water will not came across the fountain water line).
I’ve been thinking to use Map function, but i couldn’t really understand how to do it correctly.

Any suggestions as to How can i “reset” the ratio of arduino PWM pins to start from 2.5V and to end in 5V (so the motor will go from 6V to 12V in the same ratio) ?

SparkFun Spectrum Shield PWM Demo
Toni Klopfenstein @ SparkFun Electronics
February 2015

This sketch shows the basic functionality of the Spectrum Shield, working with a basic RGB LED Matrix.

The Spectrum Shield code is based off of the original demo sketch by Ben Moyes @Bliptronics.  
This sketch is available in the Spectrum Shield repository. 

Development environment specifics:
Developed in Arduino 1.6.

This code is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round!
Distributed as-is; no warranty is given.

//Declare Spectrum Shield pin connections
#define STROBE 52
#define RESET 53
#define DC_One A0
#define DC_Two A1 

//Declare pumps driver ENA pin connections
int PUMP[] = {2, 3, 4, 5, 6, 7};

//Define spectrum variables
int freq_amp;
int Frequencies_One[7];
int Frequencies_Two[7]; 
int i;

/********************Setup Loop*************************/
void setup() {
  //Set LED pin configurations
  for(i=0; i<7; i++)
    pinMode(PUMP[i], OUTPUT);
    digitalWrite(PUMP[i], LOW);
  //Set Spectrum Shield pin configurations
  pinMode(STROBE, OUTPUT);
  pinMode(RESET, OUTPUT);
  pinMode(DC_One, INPUT);
  pinMode(DC_Two, INPUT);  
  digitalWrite(STROBE, HIGH);
  digitalWrite(RESET, HIGH);

//Set pumps driver In1 pins
  pinMode(22, OUTPUT);
  pinMode(24, OUTPUT);
  pinMode(26, OUTPUT);
  pinMode(28, OUTPUT);
  pinMode(30, OUTPUT);
  pinMode(32, OUTPUT);
  pinMode(34, OUTPUT);

  //Initialize Spectrum Analyzers
  digitalWrite(STROBE, LOW);
  digitalWrite(RESET, HIGH);
  digitalWrite(STROBE, HIGH);
  digitalWrite(STROBE, LOW);
  digitalWrite(RESET, LOW);

/**************************Main Function Loop*****************************/
void loop() {

/*******************Pull frequencies from Spectrum Shield********************/
void Read_Frequencies(){
  //Read frequencies for each band
  for (freq_amp = 0; freq_amp<7; freq_amp++)
    Frequencies_One[freq_amp] = analogRead(DC_One);
    Frequencies_Two[freq_amp] = analogRead(DC_Two); 
    digitalWrite(STROBE, HIGH);
    digitalWrite(STROBE, LOW);

/*******************Control pumps based on frequencies*****************************/
void Graph_Frequencies(){
   for( i= 0; i<7; i++)
     if(Frequencies_Two[i] > Frequencies_One[i]){
        analogWrite(PUMP[i], Frequencies_Two[i]/4);
          digitalWrite(22, HIGH);
          digitalWrite(24, HIGH);
          digitalWrite(26, HIGH);
          digitalWrite(28, HIGH);
          digitalWrite(30, HIGH);
          digitalWrite(32, HIGH);
          digitalWrite(34, HIGH);
        analogWrite(PUMP[i], Frequencies_One[i]/4);


The ancient, inefficient L298N can drop up to 4 V internally, so it is a very poor choice for your fountain.

Pololu has a good selection of modern, efficient motor drivers.

Note that many small water pumps now have brushless motors that cannot be used with PWM drivers.

Hello there!

I agree with jremington that the L298N is not the greatest (but not the worst either) way to control motors.

The motor shield that I swear by is the Pololu Dial MC33926 Arduino MotorShield that is designed to fit into an Arduino, but can also be controlled separately. It takes a PWM signal to control the motor speed, and a digital pin for motor direction. A total of 6 pins for each shield including ground a 5V. The shield also allows the battery to control the Arduino if you so desire.

Better yet, the ratio of PWM to supply (PWM to 5V) controls how much of the battery voltage(and current) is applied to each motor. So a "analogWrite(pin, 255)" command will provide the full battery voltage to the specific motor.

Why a motor driver (H-bridge) for a pump.
Do you want to pump the water in two directions? In and out.
Seems more logical to me to just use logic level mosfets.