Using a 240vac trigger to record last time a pump was run.

Hello,

I’m currently working on a project where I want to display the last time a pump was run on a 1602 lcd screen.

I am currently testing the code using a push button connected to pin d2 to simulate the pump running. Everything seems to be work as planned but now I’m not sure what would be the best way to use the 240vac power that runs the pump to trigger the arduino.

Please see my code below.

#include <RTClib.h>

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <DS1307RTC.h>



// digital pin 3 has a pushbutton attached to it. Give it a name:
int pushButton = 3;



LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

void setup()  
{

  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);
  
  lcd.begin(16,2); 
 
}



void loop() 
{

  // read the input pin:
  int buttonState = digitalRead(pushButton);

//tm = rtc.now();
tmElements_t tm;
//DateTime now = RTC.now();
RTC.read(tm);


  if (buttonState == 1) {             // if button is pressed
    //Serial.println(buttonState);
    lcd.clear();                      //clear lcd screen
    lcd.setCursor(0,0);               //set start point to 0,0
    lcd.print("Pump Activated");      //Text at 0,0
    printTime(0,1,tm);                //run printTime object
    printDate(10,1,tm);               //run printDate object
    
    delay(1000);                      //delay 1000ms
    }
  else{
    
    // print out the state of the button:
    //Serial.println(buttonState);
    //delay(100);        // delay b/n readings
    
    
     tmElements_t tm;                   //define element
  
    if (RTC.read(tm)) {                 //test if RTC is providing time
      printPump(0,0);
      //printInstTime(0,1,tm);
      //printDate(10,1,tm);  
     
    } 
    
    else 
    {                            //test if RTC is working
      if (RTC.chipPresent()) 
      {
        //The DS1307 is stopped. Please run the SetTime
      } else 
      {
        //DS1307 read error! Please check the circuitry
      }
      delay(2500);        //delay to check on RTC
    }
    delay(1000);      //delay between time reads (1sec)
    }
}
  
  void printTime(int character,int line, tmElements_t tm)
  {
    String seconds,minutes;
    lcd.setCursor(character,line);
    lcd.print(tm.Hour);
    lcd.print(":");
    if(tm.Minute<10)
    {
      minutes = "0"+String(tm.Minute);
      lcd.print(minutes);
    }else
    {
      lcd.print(tm.Minute);
    }
    lcd.print(":");
    if(tm.Second<10)
    {
      seconds = "0"+String(tm.Second);
      lcd.print(seconds);
    }else
    {
      lcd.print(tm.Second);
    }
  }

  void printInstTime(int character,int line, tmElements_t tm)
  {
    String seconds,minutes;
    lcd.setCursor(character,line);
    lcd.print(tm.Hour);
    lcd.print(":");
    lcd.print(tm.Minute);
    lcd.print(":");
    lcd.print(tm.Second);
  }
  
  void printDate(int character,int line, tmElements_t tm)
  {
    lcd.setCursor(character,line);
    lcd.print(tm.Day);
    lcd.print("/");
    lcd.print(tm.Month);
    //lcd.print("/");
    //lcd.print(tmYearToCalendar(tm.Year));
  }


  void printPump(int character,int line)
  {
    lcd.setCursor(character,line);
    lcd.print("Pump Last Run:");
  }

Put a relay on the pump power line. The relay switches when the pump turns on and the contacts are your switch. An AC optoisolator is another choice. And there are current sensors.

The other way is to look at what turns the pump on and whether you can get a signal from that

What access (if any) do you have to the pump or its controls?

Some kind of clamp-on current sensor may work, as long as you have a single wire somewhere you can clamp it on to.