Hello Guys!
My project is a dancing fountain
Using:
-Arduino Mega 2560
-Spectrum shield
-4 X L298N drivers
-7 X water pumps motor (6V-12V max)
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
https://github.com/sparkfun/Spectrum_Shield
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);
delay(1);
digitalWrite(RESET, HIGH);
delay(1);
digitalWrite(STROBE, HIGH);
delay(1);
digitalWrite(STROBE, LOW);
delay(1);
digitalWrite(RESET, LOW);
}
/**************************Main Function Loop*****************************/
void loop() {
Read_Frequencies();
Graph_Frequencies();
delay(50);
}
/*******************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);
delay(1);
digitalWrite(24, HIGH);
delay(1);
digitalWrite(26, HIGH);
delay(1);
digitalWrite(28, HIGH);
delay(1);
digitalWrite(30, HIGH);
delay(1);
digitalWrite(32, HIGH);
delay(1);
digitalWrite(34, HIGH);
delay(1);
}
else{
analogWrite(PUMP[i], Frequencies_One[i]/4);
}
}
}
Thanks!