I have a RF remote control i want to trigger via an output on an arduino UNO!!

Hey, I have a question? I have a RF remote control i want to trigger via an output on an arduino UNO
The thing is that i only want a 1 second puls when i trigger the input button,
even if i hold the button for a long time (several seconds) on my arduino!
Each button press on the arduino unit should create a 1 second long pulse on the output.
Can someone help me? the code below almost works, but I have to reset my arduino device to trigger
the output again.

int led_pin = 11; // INDICATOR LED
int tx_pin = 10; // TX REMOTE
int button_pin = 2;
int alreadyBlinked = 0;
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(tx_pin, OUTPUT);
pinMode(button_pin, INPUT);
}
void loop() {
int button_state = digitalRead(button_pin);
if(alreadyBlinked == 0)
if (button_state == HIGH) {
digitalWrite(led_pin, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(tx_pin, HIGH); // turn the TX on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led_pin, LOW); // turn the LED off by making the voltage LOW
digitalWrite(tx_pin, LOW); // turn the TX off by making the voltage LOW
alreadyBlinked = 1;

} else {

}
}

I see where you set alreadyBlinked = 1. When is it ever set back to 0?

Also you're going to need to work on the button BECOMING pressed not just it being in the pressed state. Have a look at the StateChangeDetection example in the IDE.

Steve

This is happening now, the LED turns on for one second and the LED goes out.
To trigger the LED agan i have to reset arduino to make it possible to press the button again to create a new pulse?!

A short or long button press on the arduino, would only send ONE one-second puls to the LED / TX module.

This works :slight_smile:
Thanks holdingpattern!!!!

holdingpattern:
Sketch below inhibits the button during the pulse. And it's all delay()-less so the code's not blocked from doing any other stuff you may want to do.

// https://forum.arduino.cc/index.php?topic=670044

// 11 mar 2020

// 1s pulse regardless of how long button is pressed

/*
  BASED ON State change detection (edge detection) changed for INPUT PULLUP
              (button wired from pin to ground)
  https://www.arduino.cc/en/Tutorial/StateChangeDetection
*/

// this constant won't change:
const byte  button = 2;
const byte led_pin = 11;

// Variables will change:
bool buttonState;        // current state of the button
bool lastButtonState;    // previous state of the button
bool alreadyBlinked = false;
unsigned long blinkStartedAt;

void setup()
{
  // initialize serial communication:
  Serial.begin(9600);
  Serial.println("template");
  pinMode(button, INPUT_PULLUP);

//initialize button states
  buttonState = digitalRead(button);
  lastButtonState = buttonState;

pinMode(led_pin, OUTPUT);

Serial.println(" ");
  Serial.println("setup() done... press the button");
  Serial.println(" ");
}

void loop()
{
  // read the button:
  buttonState = digitalRead(button);

// compare the buttonState to its previous state
  if (!alreadyBlinked && buttonState == LOW && lastButtonState == HIGH)
  {
    Serial.print("New press");
    alreadyBlinked = true;
    blinkStartedAt = millis();
    digitalWrite(led_pin, HIGH);
  }// change to low

// Delay a little bit to avoid bouncing
  delay(50);

// save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;

if (alreadyBlinked && millis() - blinkStartedAt >= 1000)
  {
    digitalWrite(led_pin, LOW);
    alreadyBlinked = false;
  }

} //loop