user88284: #define monitor_pin 14

void setup()
{
  pinMode(monitor_pin , INPUT);
}

void loop()
{
    unsigned long d1 = pulseIn(14, HIGH);
    if (d1>0){//trigger function}
}


I know there is a function pulseIn(), but it doesnt really solve my problem. I just want to trigger a function when voltage change from LOW to HIGH/HIGH to LOW. pulseIn() need to wait for the voltage to back to original level which in my case will exceed 3 minutes and cause timeout.
How can  I detect a voltage change other than pulseIn()?

user42015: You can save the previous state of the pin and then trigger the function when the current state is different from the previous state:
#define monitor_pin 14
int previous_state;

void setup()
{
  pinMode(monitor_pin , INPUT);
  previous_state = digitalRead(monitor_pin); // Initialize previous state with initial reading of the pin
}

void loop()
{
  int current_state = digitalRead(monitor_pin);
  if(current_state != previous_state){
    // Execute your code here
    previous_state = current_state; // update previous state
  }
}


88284: <pre><code>#define monitor_pin 14

void setup()
{
  pinMode(monitor_pin , INPUT);
}

void loop()
{
    unsigned long d1 = pulseIn(14, HIGH);
    if (d1&gt;0){//trigger function}
}

</code></pre>
<p>I know there is a function pulseIn(), but it doesnt really solve my problem. I just want to trigger a function when voltage change from LOW to HIGH/HIGH to LOW. pulseIn() need to wait for the voltage to back to original level which in my case will exceed 3 minutes and cause timeout.</p>
<p>How can  I detect a voltage change other than pulseIn()?</p>
 42015: <p>You can save the previous state of the pin and then trigger the function when the current state is different from the previous state:</p>
<pre><code>#define monitor_pin 14
int previous_state;

void setup()
{
  pinMode(monitor_pin , INPUT);
  previous_state = digitalRead(monitor_pin); // Initialize previous state with initial reading of the pin
}

void loop()
{
  int current_state = digitalRead(monitor_pin);
  if(current_state != previous_state){
    // Execute your code here
    previous_state = current_state; // update previous state
  }
}
</code></pre>
