You are on page 1of 4

// Automatic bottle filling machine code by

//Engr. Usman Ahmad


//Easy HomeMade Projects
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int stepPin = 3;
const int dirPin = 4;
int buttonPin;
int r;
int buzzer = 10;
int m = 8;

void setup()
{
buttonPin = 11;//whatever pin your button is plugged into
r = 12;
pinMode(buttonPin, INPUT_PULLUP);
pinMode(r, INPUT);

// initialize the LCD


lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.clear();
lcd.setCursor(2,0); // column, row
lcd.print("Press Start");

// Sets the two pins as Outputs


pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(m,OUTPUT);

while(digitalRead(r) == LOW)
{
digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 400; x++)
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);

if(digitalRead(r) == HIGH)
break;

}
}
void loop()
{

//check button pressed, if so enter program condition (inside if statement)


if(digitalRead(buttonPin) == HIGH) //functions based off of button pulling input
pin LOW
{
tone(buzzer, 800);
delay(1000);
noTone(buzzer);
lcd.clear();
lcd.setCursor(0,0); // column, row
lcd.print("Start Filling");

delay(500);
lcd.setCursor(2,1); // column, row
lcd.print("Bottle 1/6");
digitalWrite(m,HIGH);
delay(1850);
digitalWrite(m,LOW);
delay(1000); // One second delay
tone(buzzer, 1000);
delay(200);
noTone(buzzer);
}
{
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular
direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 100; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}
delay(500);
lcd.setCursor(2,1); // column, row
lcd.print("Bottle 2/6");
digitalWrite(m,HIGH);
delay(1850);
digitalWrite(m,LOW);
delay(1000); // One second delay
tone(buzzer, 1000);
delay(200);
noTone(buzzer);
}
{
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular
direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 100; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}
delay(500);
lcd.setCursor(2,1); // column, row
lcd.print("Bottle 3/6");
digitalWrite(m,HIGH);
delay(1850);
digitalWrite(m,LOW);
delay(1000); // One second delay
tone(buzzer, 1000);
delay(200);
noTone(buzzer);
}
{
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular
direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 100; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}
delay(500);
lcd.setCursor(2,1); // column, row
lcd.print("Bottle 4/6");
digitalWrite(m,HIGH);
delay(1850);
digitalWrite(m,LOW);
delay(1000); // One second delay
tone(buzzer, 1000);
delay(200);
noTone(buzzer);
}
{
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular
direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 100; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}
delay(500);
lcd.setCursor(2,1); // column, row
lcd.print("Bottle 5/6");
digitalWrite(m,HIGH);
delay(1850);
digitalWrite(m,LOW);
delay(1000); // One second delay
tone(buzzer, 1000);
delay(200);
noTone(buzzer);
}
{
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular
direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 100; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}
delay(500);
lcd.setCursor(2,1); // column, row
lcd.print("Bottle 6/6");
digitalWrite(m,HIGH);
delay(1850);
digitalWrite(m,LOW);
delay(1000); // One second delay
}

lcd.clear();
lcd.setCursor(0,0); // column, row
lcd.print("Job Done! Place");
lcd.setCursor(2,1); // column, row
lcd.print("New Bottles");
tone(buzzer, 1500);
delay(300);
noTone(buzzer);
delay(100);
tone(buzzer, 1500);
delay(300);
noTone(buzzer);
delay(100);
tone(buzzer, 1500);
delay(300);
noTone(buzzer);
delay(100);
tone(buzzer, 1500);
delay(300);
noTone(buzzer);
delay(100);
tone(buzzer, 1500);
delay(300);
noTone(buzzer);
delay(100);

}}

You might also like