int receive_pin = 2;

#define MAX 120
int value[MAX];
unsigned long time[MAX];
int changes;
int printed;

void setup() {                
    pinMode(receive_pin, INPUT);

    changes = 0;
    printed = 0;
    attachInterrupt(2, change_handler, CHANGE);
    Serial.println("Receiver 433MHz setup");

void change_handler()
    if (changes >= MAX) return;
    value[changes] = digitalRead(receive_pin);
    time[changes] = micros();

void loop() {
  if (printed + 1 < changes) {
      Serial.println(time[printed+1] - time[printed]);

Hi all

when i run this sketch after the result its stop and i close the serial monitor to run it again

my question how to make it run with out restart it

  • 1
    test the code with a button on pin 2 – Juraj Mar 19 '18 at 10:24
  • Without knowing what your goals are and what you expect this sketch to do, it is really hard to figure out how to help you. Please add more details, so what should this sketch do and what you want it to do. I think that Juraj's comment is right, but since the whole target of this setch seems to be to count the pulses, well, it seems strange that you don't know that you have to make a pulse on pin 2 to detect it... – frarugi87 Mar 20 '18 at 10:24
  • atleast declare int changes to be volatile. – Maximilian Gerhardt Mar 20 '18 at 22:30
  • @frarugi87, based on the "Receiver 433MHz setup", I suspect that the source of the pulses is some other device – Juraj Mar 21 '18 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.