Programmed Pump
We programmed a pump to drop few drops every 30 seconds.
Supplies
Pump. Wires. Soldering supplies. Arduino board. Arduino top. Button. Tube.
Solder the wires together. Connect to power supply to make sure the pump works.
Program the Arduino. Connect to button and to the pump.
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Adafruit Motorshield v2 - DC Motor test!");
if (!AFMS.begin()) { // create with the default frequency 1.6KHz
// if (!AFMS.begin(1000)) { // OR with a different frequency, say 1KHz
Serial.println("Could not find Motor Shield. Check wiring.");
while (1);
}
Serial.println("Motor Shield found.");
// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor->setSpeed(50);
myMotor->run(FORWARD);
// turn on motor
myMotor->run(RELEASE);
pinMode(2, INPUT);
}
void loop() {
int buttonState = digitalRead(2);
Serial.println(buttonState);
delay(1);
if (buttonState == 1) {
myMotor->run(FORWARD);
myMotor->setSpeed(50);
delay(4000);
}
else {
myMotor->run(RELEASE);
delay(200);
}
}