Mega 2560: delay on detect Input13 transition ON->OFF

a simple sketch:

#include <Arduino.h>
void setup()
{
pinMode(13, INPUT);
pinMode(14,OUTPUT);
}

void loop()
{
digitalWrite(14, 13); // Actvate digital Out 14 when In13=true
}

The problem is:
transition IN13 0->1 = immediately
transition IN13 1->0 = it needs 1 or 2 seconds to detect the input is off (out still active)…!!

I verified this also using the MOdbus TCP library to directly read Input status…

How is it possible? Some idea?

Describe the hardware. Or, even better, post a schematic.

http://arduino.cc/en/Reference/DigitalWrite

Hello,
Welcome to the community.
Cant understand the question properly but I think you are trying to lit the PIN14 led when pin13 is high.
Here is a probable solution
Goto your arduino IDE > File > Example > 02. Digital > Button
Here is the code

/*  Button Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2.

 The circuit:
 * LED attached from pin 13 to ground
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground

 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 created 2005
 by DojoDave <http://www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe

 This example code is in the public domain.
 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Button is connected to pin2. Only when you press the button the pin13 LED will glow.
Cheers.

This...

  digitalWrite(14, 13);    // Actvate digital Out 14 when In13=true

...writes the constant value 13 to a digital pin. Which is theoretically invalid. HIGH and LOW are the only documented values for digitalWrite. However, digitalWrite treats zero / false values as LOW and everything else as HIGH. Which means that line of code is essentially this...

  digitalWrite(14, HIGH);    // Actvate digital Out 14 when In13=true

The problem is: transition IN13 0->1 = immediately transition IN13 1->0 = it needs 1 or 2 seconds to detect the input is off (out still active)...!!

That makes no sense. Pin 13 is the INPUT. Shouldn't you be looking for transitions on pin 14?

   digitalWrite(14, 13);    // Actvate digital Out 14 when In13=true

Do you mean:

   digitalWrite(14, digitalRead (13));    // Actvate digital Out 14 when In13=true

http://www.gammon.com.au/forum/?id=12153#trap2

[quote author=Nick Gammon link=topic=202941.msg1495995#msg1495995 date=1386275856]http://www.gammon.com.au/forum/?id=12153#trap2[/quote]

There it is! I could not find that page.

Generic URL: http://www.gammon.com.au/tips

However it looks like I can't add anchors to it, so the individual points have to use the "real" URL.

Doing like this nothig change… still delay on Out still active after releasing activation iput for some seconds… maybe hw problem?

this the code I used:

int In22 = 22; // Define “In22” init value 22
int Out24 = 24;
int buttonState=0;

void setup()
{
pinMode(In22, INPUT); // Set pin22 as input
pinMode(Out24,OUTPUT);
}
void loop()
{
buttonState=digitalRead(In22);
if (buttonState==HIGH){
digitalWrite(Out24, HIGH);
}
else{
digitalWrite(Out24,LOW);
}
}

nightcrawler218:
Hello,
Welcome to the community.
Cant understand the question properly but I think you are trying to lit the PIN14 led when pin13 is high.
Here is a probable solution
Goto your arduino IDE > File > Example > 02. Digital > Button
Here is the code

/*  Button Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2.

The circuit:

  • LED attached from pin 13 to ground

  • pushbutton attached to pin 2 from +5V

  • 10K resistor attached to pin 2 from ground

  • Note: on most Arduinos there is already an LED on the board
    attached to pin 13.
    created 2005
    by DojoDave http://www.0j0.org
    modified 30 Aug 2011
    by Tom Igoe

This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
*/

// constants won’t change. They’re used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}




Button is connected to pin2. Only when you press the button the pin13 LED will glow.
Cheers.

hki75:
Doing like this nothig change… still delay on Out still active after releasing activation iput for some seconds… maybe hw problem?

See reply #1. Also:

Please use code tags.

Read this before posting a programming question

[quote author=Nick Gammon link=topic=202941.msg1495995#msg1495995 date=1386275856] http://www.gammon.com.au/forum/?id=12153#trap2 [/quote]hi,

i have read that link. Pretty interesting & useful. Cant figure out how the RAM usage of 4Kb is calculated in Trap#5. will you please illustrate in brief.

Thanking you in anticipation.

ok, I've tried...but nothign change..that's strange..

if (digitalRead(In22)==HIGH){ digitalWrite(Out24, HIGH); } else{ digitalWrite(Out24,LOW); }

I think I have hw problem..

I think you are missing a PULL-DOWN resistor in the IN22 pin. Here is your solution.

Let us know what happened after you test it.

In your case pin2 will be IN22 pin

nightcrawler218: [quote author=Nick Gammon link=topic=202941.msg1495995#msg1495995 date=1386275856] http://www.gammon.com.au/forum/?id=12153#trap2

hi,

i have read that link. Pretty interesting & useful. Cant figure out how the RAM usage of 4Kb is calculated in Trap#5. will you please illustrate in brief. [/quote]

int myReadings [2000];

An int is two bytes. 2000 x 2 is 4000.

Thanks for the clarification... :)

got it.. I missed the pull-down resistor.. :astonished: I'm very new to arduino..habit for plc only... thanks All!! I'm going on to play with arduino!!!