So Im new on the arduino world, and I think I have a ambitious project, I want to make a machine that its going to fill up a bucket with some quantity of food for horses, Each horse will have a code and each code will open a servo certain amount of time so the food quantity its the exact amount needed for each horse.
I have many problems the first its that I haven't been able to put different codes for the horses, I already made the code for one horse and its works pretty nice, but haven figure out how to increase the quantity of If and else statements for different times of servo opening.
I think that its easier if you guys take a look to the code and let me know.
But before this I would also like to input the code through a Number KEYPAD, I already have it working but only for printing on the serial screen not as the code input, but that would be for the future, firs I want to make the code working for several horses.
PLEASE PLEASE HELP ME.
#include <Servo.h> // Servo Library
Servo myservo; // defines myservo as Servo
int inicialpostion = 0; // Defines inicial postion of Servo
int fillingpos = 90; // Defines postion where food will be served
int horsecode; // Defines horsecode
int timetrueno = 4000; // Defines the time the servo would be open for Trueno Horse
int timeluna = 3500; // Defines the time the servo would be open for Luna Horse
int horseconfirmation; // Defines the horse name confirmation
int bucketconfirm; // Defines the int that would confirm if the bucket its in place
void setup() {
Serial.begin(9600); // Serial on
myservo.attach(12); // Defines servo in pin 12
myservo.write(inicialpostion); // Puts servo in postion 0
}
void loop() {
Serial.println("Codigo del Caballo"); // We ask the horse code
while (Serial.available()==0){} // Wait for answer
horsecode = Serial.parseInt (); // Read the horse code
if(horsecode == 001){ // confirm that its correct
Serial.println("Caballo Trueno ? 1 = Si 2 = No"); // Check horse name
while (Serial.available()==0){}
horseconfirmation = Serial.parseInt();} // Read confirmation
else { // If the code its wrong prints error and goes back to the start of the loop.
Serial.println("Error!!!");
Serial.println("Intente Nuevamente");
delay(1500);
return;
}
if(horseconfirmation == 1){ // If the horse its correct, prints confirmed.
Serial.println ("Confirmado");
delay(1500);}
else {
return;
}
Serial.println("Recipiente en su Lugar ? 1 = Si 2 = No"); // We ask to check if the bucket its in place
while (Serial.available()==0){}
bucketconfirm = Serial.parseInt();
if (bucketconfirm == 1){ // If the answer its yes, then the bucket its filled up.
Serial.println ("Confirmado");
delay(1500);
myservo.write(fillingpos);
delay(timetrueno);
myservo.write(inicialpostion);
delay(2000);
}
else{ // Goes back to start of the Loop.
return;
}
return; // end of the code, goes back to the Start of the loop and waits for next horse.
}