Hi guys, I wanted your help on my project with Liquid pumps. I was trying to follow this project "https://arduinogetstarted.com/tutorials/arduino-controls-pump" while I added SerialEvents to be able to control the pump through the Serial Monitor. Unfortunately I kept on encountering a problem where the Serial would either completely freeze and be unresponsive or it would reset itself and go back to void setup. Please note that I am using the Raspberry Pi3 to run the Arduino IDE which is then connected to the Arduino Uno through a USB cable.
const int RELAY_PIN1 = 7;
//int inputValue = 0; for Communicating with the RPI
int pumpcount = 0;
String inputString = "";
boolean stringComplete = false;
void setup()
{
pinMode(RELAY_PIN1, OUTPUT);
digitalWrite(RELAY_PIN1, LOW);
Serial.begin (9600);
/*
while (Serial.available()<=0)
{
Serial.println("Waiting For Command:");
delay(500);
}
*/
}
void loop()
{
if (stringComplete)
{
if(inputString.startsWith("pump"))
{
pumpOn(2000);
}
else
{
Serial.println("Invalid Command");
}
//Reset String
stringComplete = false;
inputString = "";
}
delay(10);
}
void serialEvent()
{
while (Serial.available())
{
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n')
{
stringComplete = true;
}
}
}
void pumpOn(int secs)
{
Serial.println(pumpcount);
pumpcount +=1;
digitalWrite(RELAY_PIN1, HIGH);
Serial.print(" :Pump is ON");
delay(secs);
digitalWrite(RELAY_PIN1, LOW);
Serial.println("Pump is OFF");
delay(secs);
}
-----Sample Serial Monitor Output------
0
:Pump is ONPump is OFF
1
:Pump is ONPump is OFF
2
:Pump is ONPump is OFF
3
:Pump is ONPump is OFF
4
:¨0
:Pump is ONPump0
:Pump is ONPump is OFF
1
:Pump is ONPump is OFF
2
:Pump is ¯ú0
:Pump is ONPumÿ0
:Pump is ONPump is OFF
1
:Pump is ONPump is OFF
2
:Pump is O
-----Sample Serial Monitor Output------
Was hoping you guys could help me figure out the problem.
