Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*==========================================================================
- Author : Fahmi Ghani
- Project : Test Peristaltic pump
- Date : 20 Sept 2014
- Video :https://www.youtube.com/watch?v=GdTUIwj5ros
- Hardware : Arduino Uno, LCD keypad shield. ULN2003(for switching motor)
- ==========================================================================*/
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(8,9,4,5,6,7);
- int keypad_pin = A0;
- int Keypad_value = 0;
- int Keypad_value_old = 0;
- char Btn_push;
- int Pump1 = 2;
- int volume = 10;
- int volumeOld = 10;
- int Pump1State =0;
- int MenuPage =1;
- int MenuPageOld =1;
- long previousMillis = 0;
- unsigned long currentMillis ;
- long interval = 1000;
- unsigned long multiplier = 1000; //value to change based on calibration
- //multiplier = milliseconds needed to fill 1ml liquid
- void setup()
- {
- lcd.begin(16,2); //Initialize a 2x16 type LCD
- pinMode(Pump1, OUTPUT);
- pinMode(10, OUTPUT);
- lcd.setCursor(0,0);
- lcd.print("Peristaltic Pump");
- lcd.setCursor(0,1);
- lcd.print("Test");
- lcd.clear();
- delay(1000);
- MenuDisplay(MenuPage);
- analogWrite(10,50);
- delay(1000);
- }
- void loop()
- {
- Btn_push = ReadKeypad();
- //Change menu
- if(Btn_push == 'L') MenuPage =1;
- if(Btn_push == 'R') MenuPage =2;
- if(MenuPage != MenuPageOld)
- {
- MenuDisplay(MenuPage);
- MenuPageOld = MenuPage;
- }
- if(MenuPage ==1)
- {
- if(Btn_push == 'U' && volume <100)
- volume+=1;
- if(Btn_push == 'D'&& volume>0)
- volume-=1;
- if(volumeOld != volume)//update lcd when got new volume
- {
- lcd.setCursor(8,0);
- lcd.print(volume);
- lcd.print("ml ");
- volumeOld = volume;
- }
- if(Btn_push == 'S' )
- {
- RunPump(volume);
- MenuDisplay(MenuPage);
- }
- }
- if(MenuPage ==2)
- {
- if(Btn_push == 'S')
- {
- if(!Pump1State )
- {
- digitalWrite(Pump1,1);
- lcd.setCursor(0,1);
- lcd.print("Pump Run ");
- Pump1State =1;
- }
- else
- {
- digitalWrite(Pump1,0);
- lcd.setCursor(0,1);
- lcd.print("Pump Stop ");
- Pump1State =0;
- }
- delay(100);
- }
- }
- delay(200);
- }//--------------- End of loop() loop ---------------------
- void MenuDisplay(int page)
- {
- switch (page)
- {
- case 1:
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Volume: ");
- lcd.setCursor(8,0);
- lcd.print(volume);
- lcd.print("ml ");
- break;
- case 2:
- lcd.clear();
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Flush Water");
- break;
- }
- }
- void RunPump(unsigned long ml)
- {
- previousMillis = millis();
- currentMillis = previousMillis;
- interval = ml *multiplier;
- digitalWrite(Pump1,1);
- lcd.setCursor(4,1);
- lcd.print("ml ");
- while(currentMillis - previousMillis < interval)
- {
- currentMillis = millis();
- lcd.setCursor(0, 1);
- lcd.print((currentMillis - previousMillis)/1000);
- }
- lcd.setCursor(0, 1);
- lcd.print((currentMillis - previousMillis)/1000);
- digitalWrite(Pump1,0);
- delay(1000);
- }
- char ReadKeypad()
- {
- /* Keypad button analog Value
- no button pressed 1023
- select 741
- left 503
- down 326
- up 142
- right 0
- */
- Keypad_value = analogRead(keypad_pin);
- if(Keypad_value < 100)
- return 'R';
- else if(Keypad_value < 200)
- return 'U';
- else if(Keypad_value < 400)
- return 'D';
- else if(Keypad_value < 600)
- return 'L';
- else if(Keypad_value < 800)
- return 'S';
- else
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment