greetings,
I try to power up 3 water pump by using l298p dual motor shield and 5v relay. can someone help me verify my source code.
im using
- ph sensor
- salinity sensor
- 3 mini water pump
- dual motor shield with external power supply. 12V,5A
what im planning to do is to control the ph and salinty of water in the tank.
please help me..
#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 9, 8, 3, 2);
int backLight = 11;
float pptValue = 0;
float phValue = 0;
const int maxppt = 44; //max salinity value
const int minppt = 5; //min salinity value
const int maxph = 12; //max pH value
const int minph = 5; //min pH value
//Arduino PWM Speed Control:
int E1 = 5;
int M1 = 4;
int E2 = 6;
int M2 = 7;
int h2opump = 10; //water pump pin out 10
void setup()
{
{
Serial.begin (9600);
Serial.println("pH and salinity control experiment");
Serial.println(" (Salinty) (pH) ");
}
{
lcd.begin(16, 2);
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(h2opump, OUTPUT);
}
}
void loop()
{
{
{
int salinitySensor = analogRead(A5); //read the salinity value
pptValue = salinitySensor * 0.0064;
if (pptValue > maxppt) // if the analog value > max salinity, turn on water pump:
{
digitalWrite(h2opump, HIGH);
}
else if // if the analog value < min salinity, turn on salinity pump:
(pptValue < minppt)
{
digitalWrite(M1, HIGH);
analogWrite(E1, 100);
}
else // else do nothing
{
analogWrite(E1, 0);
digitalWrite(h2opump, LOW);
}
}
{
int phSensor = analogRead(A4); //read ph value
phValue = 0.01709 * phSensor;
if (phValue > maxph) // if the analog value > max pH, turn on water pump:
{
digitalWrite(h2opump, HIGH);
}
else if // if the analog value < min pH, turn on pH pump:
(phValue < minph)
{
digitalWrite(M2, HIGH);
analogWrite(E2, 100);
}
else // else do nothing
{
analogWrite(E2, 0);
digitalWrite(h2opump, LOW);
}
}
}
{
Serial.print("\t");
Serial.print(pptValue);
Serial.print("\t");
Serial.print(" ");
Serial.print(phValue);
Serial.println("\t");
delay(1000);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ppt:");
lcd.setCursor(5, 0);
lcd.print(pptValue);
lcd.setCursor(0, 1);
lcd.print("pH:");
lcd.setCursor(4, 1);
lcd.print(phValue);
delay(1000);
}
#include<LiquidCrystal.h>
Spacesareuseful.
LiquidCrystal lcd(12, 11, 9, 8, 3, 2);
int backLight = 11;
You can't connect the backlight to a pin that the LCD is using.
void setup()
{
{
Serial.begin (9600);
Serial.println("pH and salinity control experiment");
Serial.println(" (Salinty) (pH) ");
}
{
lcd.begin(16, 2);
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(h2opump, OUTPUT);
}
}
{What are}
{all the}
{useless braces}
{for?}
void loop()
{
{
{
int salinitySensor = analogRead(A5); //read the salinity value
I gave up!
Hi PaulS,
Thx for your feedback. Im realy new to arduino and coding. I will post the diagram of the project.. Hopefully you can help and guide me through this..
Did you make the requested code changes? Did it work?