Advertisement
safwan092

Keypad + WaterFlow Sensor

May 12th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.21 KB | None | 0 0
  1. int ledPin = 13;
  2. int TurnOffVolume = 600;
  3.  
  4. //--------------------------  YF-S201 Sensor  ------------------------------------------
  5. //---------------------------------------------./Global Variables-----------------------
  6. int sensorPin = 2;
  7. float k = 6.0337;
  8. volatile long NumPulses;
  9. float volume = 0;
  10.  
  11. void CountPulses() {
  12.   NumPulses++;
  13. }
  14.  
  15. void Volume(int number_of_pulses) {
  16.   volume = (number_of_pulses * 1.00) / (k * 60.00 / 1000.0); // Volume in milli-Liters
  17. }
  18. //--------------------------------------------------------------------------------------
  19.  
  20.  
  21. void setup() {
  22.  
  23.   Serial.begin(9600);
  24.   pinMode(ledPin, OUTPUT);
  25.   //--------------------------  YF-S201 Sensor  ----------------------------------------
  26.   //-----------------------------------------------./Setup------------------------------
  27.   pinMode(sensorPin, INPUT);
  28.   attachInterrupt(0, CountPulses, RISING);
  29.   interrupts();
  30.   //------------------------------------------------------------------------------------
  31. }
  32.  
  33. void loop() {
  34.  
  35.   if (volume + 60 >= TurnOffVolume) {
  36.     digitalWrite(ledPin, HIGH);
  37.   }
  38.   else {
  39.     digitalWrite(ledPin, LOW);
  40.   }
  41.   //--------------------------  YF-S201 Sensor  ----------------------------------------
  42.   //-----------------------------------------------./Loop-------------------------------
  43.   Volume(NumPulses);
  44.   /*
  45.     Serial.print("Number of Pulses: :");
  46.     Serial.println(NumPulses);
  47.     Serial.print("\n\nVolume of Liquid: :");
  48.     Serial.print(volume / 1000.0);
  49.     Serial.println(" Liter");
  50.     Serial.print("Volume of Liquid: :");
  51.     Serial.print(volume);
  52.     Serial.println(" mL");
  53.     Serial.println("--------------------------------");*/
  54.   delay(100);
  55.   //------------------------------------------------------------------------------------
  56. }
  57.  
  58.  
  59.  
  60. #include <Keypad.h>
  61. long value = 0;
  62. const byte ROWS = 4; //four rows
  63. const byte COLS = 4; //four columns
  64. char keys[ROWS][COLS] = {
  65.   {'1', '4', '7', '*'},
  66.   {'2', '5', '8', '0'},
  67.   {'3', '6', '9', '#'},
  68.   {'A', 'B', 'C', 'D'}
  69. };
  70. byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
  71. byte colPins[COLS] = {11, 10, 9, 8}; //connect to the column pinouts of the keypad
  72. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  73. void setup() {
  74.   Serial.begin(9600);
  75. }
  76. void loop() {
  77.  
  78.   char key = keypad.getKey();
  79.   if (key == 'A' || key == 'B' || key == 'C' || key == 'D') {
  80.     Serial.print("");
  81.   }
  82.   else Serial.print(key);
  83.   delay(1);
  84.   if (key != NO_KEY)
  85.   {
  86.     if ( (key >= '0') && (key <= '9') )
  87.     {
  88.       value = value * 10;
  89.       value = value + key - '0';
  90.     }
  91.     if ( key == 'A' )
  92.     {
  93.       Serial.println();
  94.       Serial.println(value);
  95.       // Remove this line and add it to the sensor value checker complete
  96.       value = 0; //Now reset ready for next input
  97.     }
  98.   }
  99.   if (key == 'B')
  100.   {
  101.     value = 0; //Now reset ready for next input
  102.     Serial.println();
  103.     Serial.println("Enter A New Number Please:");
  104.   }
  105.   if (key == 'C')
  106.   {
  107.     // Do whatever you like
  108.     //digitalWrite(ValvePin, LOW); // if relay is Active LOW
  109.   }
  110.   if (key == 'D')
  111.   {
  112.     // Do whatever you like
  113.     //digitalWrite(ValvePin, HIGH); // if relay is Active LOW
  114.   }
  115.  
  116. }//end of loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement