Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ledPin = 13;
- int TurnOffVolume = 600;
- //-------------------------- YF-S201 Sensor ------------------------------------------
- //---------------------------------------------./Global Variables-----------------------
- int sensorPin = 2;
- float k = 6.0337;
- volatile long NumPulses;
- float volume = 0;
- void CountPulses() {
- NumPulses++;
- }
- void Volume(int number_of_pulses) {
- volume = (number_of_pulses * 1.00) / (k * 60.00 / 1000.0); // Volume in milli-Liters
- }
- //--------------------------------------------------------------------------------------
- void setup() {
- Serial.begin(9600);
- pinMode(ledPin, OUTPUT);
- //-------------------------- YF-S201 Sensor ----------------------------------------
- //-----------------------------------------------./Setup------------------------------
- pinMode(sensorPin, INPUT);
- attachInterrupt(0, CountPulses, RISING);
- interrupts();
- //------------------------------------------------------------------------------------
- }
- void loop() {
- if (volume + 60 >= TurnOffVolume) {
- digitalWrite(ledPin, HIGH);
- }
- else {
- digitalWrite(ledPin, LOW);
- }
- //-------------------------- YF-S201 Sensor ----------------------------------------
- //-----------------------------------------------./Loop-------------------------------
- Volume(NumPulses);
- /*
- Serial.print("Number of Pulses: :");
- Serial.println(NumPulses);
- Serial.print("\n\nVolume of Liquid: :");
- Serial.print(volume / 1000.0);
- Serial.println(" Liter");
- Serial.print("Volume of Liquid: :");
- Serial.print(volume);
- Serial.println(" mL");
- Serial.println("--------------------------------");*/
- delay(100);
- //------------------------------------------------------------------------------------
- }
- #include <Keypad.h>
- long value = 0;
- const byte ROWS = 4; //four rows
- const byte COLS = 4; //four columns
- char keys[ROWS][COLS] = {
- {'1', '4', '7', '*'},
- {'2', '5', '8', '0'},
- {'3', '6', '9', '#'},
- {'A', 'B', 'C', 'D'}
- };
- byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {11, 10, 9, 8}; //connect to the column pinouts of the keypad
- Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- char key = keypad.getKey();
- if (key == 'A' || key == 'B' || key == 'C' || key == 'D') {
- Serial.print("");
- }
- else Serial.print(key);
- delay(1);
- if (key != NO_KEY)
- {
- if ( (key >= '0') && (key <= '9') )
- {
- value = value * 10;
- value = value + key - '0';
- }
- if ( key == 'A' )
- {
- Serial.println();
- Serial.println(value);
- // Remove this line and add it to the sensor value checker complete
- value = 0; //Now reset ready for next input
- }
- }
- if (key == 'B')
- {
- value = 0; //Now reset ready for next input
- Serial.println();
- Serial.println("Enter A New Number Please:");
- }
- if (key == 'C')
- {
- // Do whatever you like
- //digitalWrite(ValvePin, LOW); // if relay is Active LOW
- }
- if (key == 'D')
- {
- // Do whatever you like
- //digitalWrite(ValvePin, HIGH); // if relay is Active LOW
- }
- }//end of loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement