So after coding for Arduino for a while I decided to make a robot for our garden to spray water on them whilst considering the amount they need as well.
Here is the pseudo code / program flow:
wait for a character ' ' // to be sent by the computer wirelessly
case A:
Run forward() until the collision sensor detects something and the robot will stop
then Arduino will send Serial.println('C') to my computer
//My PC will receive the 'C' sent by Arduino
//and send Another character to my arduino i.e. 'E'
Arduino will receive the 'E'
and will then operate the water pump in some number of seconds.
After the water pumping, the robot should run again forwards, detect with collision sensor and stop again for x number of times.(depending on the number of plants in the row)
The problem with this way is that after the collision sensor detects something and stop there, the next time it will run the forward-detect again it will detect the same pot again because it was not able to move forward a bit before it detects again. ![]()
here is what I have right now:
int serialData = 0;
int proxpin =6;
void setup()
{
Serial.begin(9600);
pinMode(2,OUTPUT); //for pump
pinMode(3,OUTPUT); //for pump
pinMode(4,OUTPUT); //for pump
pinMode(5,OUTPUT); //for pump
pinMode(8,OUTPUT); //Motor
pinMode(9,OUTPUT); //Motor
pinMode(10,OUTPUT); //Motor
pinMode(11,OUTPUT); //Motor
pinMode(proxpin,INPUT_PULLUP); //proximity collision sensor
}
void loop()
{
while (digitalRead(proxpin) == HIGH) {
if (Serial.available() > 0)
{
// Serial.println("listening");
serialData = Serial.read();
switch(serialData)
{
case 'A':
//Serial.println("move forward");
forward();
break;
case 'B':
//Serial.println("stop moving");
stopna();
break;
case 'E':
pump1sec();
pause(2);
forward();
break;
}
}
}
Serial.println("C");
stopna();
}
void forward()
{
// Serial.println("running forward");
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
}
void stopna()
{
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
void pump1()
{
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(1000);
}
My Code works up to the point where the robot stops when it detects something and Send 'C' to my Computer. And when My PC send 'E' to my computer the pumps would work and then stop there.