Applied HIGH to Arduino pin. Removed HIGH signal. Arduino read HIGH for 3s extra - Page 1
Forum section: electronics / beginners

author: renzoms
author_rank: Regular Contributor
timestamp: December 17, 2021, 06:09:28 pm
content: Used a NANO as an AND gate.Two pins for inputs (A = D11, B = D12)Lit up an LED as you can expect.I printed out feedback text.When I plugged 5V into A, the text reflected that.When I unplugged A and left it floating, the text printed "A = HIGH" for about 3 more seconds before falling to "A = 0".Any ideas? I expected instant response. Thanks!picIt is better that I find a quick answer to this type of question than google, read a data sheet, poke around with the oscilloscope, and jot down ideas.

author: DrG
author_rank: Super Contributor
timestamp: December 17, 2021, 06:27:34 pm
content: Quote from: renzoms on December 17, 2021, 06:09:28 pmHow about if you post your code.

author: renzoms
author_rank: Regular Contributor
timestamp: December 17, 2021, 06:37:38 pm
content: Code://define boolean ANDboolean AND;//define i/o pinsint inputA = 11;int inputB = 12;int LEDAND = 2;//define variables for A and Bboolean A;boolean B;void setup(){Serial.println("Starting program");//9600 bps for the serial monitor outputSerial.begin(9600);//Set pin 2 to type: outputpinMode(LEDAND, OUTPUT);}void loop(){//read D11-D12 pinsA = digitalRead(inputA);Serial.print("A = ");Serial.println(A);B = digitalRead(inputB);Serial.print("B = ");Serial.println(B);//logical operators.AND = A & B;Serial.print("A & B = ");Serial.println(AND);if (AND == 1){digitalWrite(LEDAND, HIGH);}else{digitalWrite(LEDAND, LOW);}delay(2000);}

author: DrG
author_rank: Super Contributor
timestamp: December 17, 2021, 06:40:14 pm
content: Quote from: renzoms on December 17, 2021, 06:37:38 pmdelay(2000); <---

author: DrG
author_rank: Super Contributor
timestamp: December 17, 2021, 07:10:09 pm
content: fromhttps://www.maximintegrated.com/en/glossary/definitions.mvp/term/NAND%20Gate/gpk/1203Code:int Apin=11;int Bpin=12;int Aval=0;int Bval=0;void setup() {pinMode(Apin, INPUT);pinMode(Bpin, INPUT);Serial.begin(9600);}void loop() {Aval=digitalRead(Apin);Bval=digitalRead(Bpin);Serial.print(Aval);Serial.print(" ");Serial.print(Bval);Serial.print(" ");if ((Aval==1)&(Bval==1)){Serial.println("0");}else{Serial.println("1");}}Try this and see if it is more "responsive".

author: renzoms
author_rank: Regular Contributor
timestamp: December 17, 2021, 07:16:01 pm
content: I added that after witnessing the output stated.I added that to reduce the nonstop text output to a more readable output every few seconds.

author: DrG
author_rank: Super Contributor
timestamp: December 17, 2021, 07:22:20 pm
content: Quote from: renzoms on December 17, 2021, 07:16:01 pmRun the code I just posted and you will see the changes in A B and X on the screen. Are you saying that you want the LED to be more responsive or the text or both? In any event, when you sit in the delay loop, the program can't be reading (from the input ports) or writing (to the output port). The 'dead' loop caused by Delay() is known as 'blocking' because it sits there and does nothing. You may want to search on 'non-blocking' delays for some ideas on how to do that on the Nano.

author: renzoms
author_rank: Regular Contributor
timestamp: December 17, 2021, 07:29:38 pm
content: Interesting nonblock/blocking.So I can’t remember if the LED was responsive (quickly/instantaneously), but the text was not instantaneously responsive.I did not have a delay.I was constantly printing A = x, B = x.The text wasn’t responsive. It took about 3 seconds for the text to respond. I can’t remember the LED, but it’s the first thing I’ll be doing when I get back to my house

author: ledtester
author_rank: Super Contributor
timestamp: December 17, 2021, 07:36:16 pm
content: Quote from: renzoms on December 17, 2021, 06:09:28 pmA floating gate can make a MOSFET stay on for a long time.In this video notice how the LED stays on even though the gate is not connected to anything:How to make simple touch switch with IRF44ZN MOSFET -- Electrologyhttps://youtu.be/THA_9TkeIxc?t=1m15s

author: DrG
author_rank: Super Contributor
timestamp: December 17, 2021, 07:58:21 pm
content: Quote from: ledtester on December 17, 2021, 07:36:16 pmI think that by floating, he means pulling the lead off of gnd or +5 and, I suppose, that is a legitimate use of the term. On my Nano, where I was testing this out, the pins held their last value when read. As to why, there are too many possibilities for me to bother with. Then I thought about introducing INPUT_PULLUP in the code and/or installing pull down resistors.I decided that addressing delay() was more relevant at this point. Not saying it is the best way to answer, but that is the way I answered.