NANO A6 / A7

Hi

I am using Arduino Nano for a project. I am left with D2 and A6/A7.
I have two more inputs to go:

a) Simple push button
b) Input from IR Rx/Tx sensor circuit attached

The push button can be connected to D2. For the input from the sensor circuit, can it be somehow connected to A6 or A7?

This post should be read before Post#1 as I have mistakenly removed my post while attempting to modify it. I am extremely sorry for it. After the removal of my post, I have suddenly seen @Delta_G post which will appear as floating without my this post.

1. For NANO, the A6 and A7 pins are analog channels for the internal 10-bit ADC of the MCU. These pins can not be used as digital IO lines. You may connect the push button with A6-pin. After that the following codes could be executed to check the closed condition of the push button. Please, do not forget to connect an external 2.2k pull-up resistor with A6-pin.

void setup() 
{
  Serial.begin(9600);
  int x = analogRead(A6);
  if(x == 0)
  {
    Serial.println("Button is closed.");
  }
  
}

void loop() 
{

}

You have said to put some smaller value instead of 0. In fact, I did think about this value; but, I was refrained from doing that having had a look on this operation: if(digitalRead(DPin) == 0){}.

I agree with you that there should be given some value instead of 0 as A6-pin is an analog channel and the ADC has an error of about +/- 2.5 mV (1/2 of LSBit weight). Will it be alright to put 1 in place of 0? The revised codes are:

void setup() 
{
  Serial.begin(9600);
  int x = analogRead(A6);
  if(x <= 1)
  {
    Serial.println("Button is closed.");
  }
  
}

void loop() 
{

}

I checked with NANO and found the values as 1023 and 0 for the key's open and close conditions.

I wanted to put the comparison value as 1 having thought that the ADC could at best generate 5 mv (5000/1024) error which will put LH on the LSBit. Now, I see that your analysis is more cultivated based on VOL concept and accordingly the comparison value of 340 (4.88 mV * 340 ~= 1.6V) is rational.

Yes, I was also thinking of the same idea.

Thanks for your inputs, both of you.

By the way, will this idea work on A7 too?

Delta_G:
What? No, I'm simply being realistic about the values that might come back and leaving some room for error. As usual @Golam, you're WAY over-analyzing this.

You have been realistic based on sound reasoning and (hidden) calculation -- that's all I have wanted to mean. The values 340 and 1.5V should have some kind of connection, and I have established this connection for my own education. I am surprised to see your reaction in the mirror of What?!

Well, since this sensor has a push-pull output, it can be fed into an analog input without requiring a pull-up resistor. Perform an analog read and compare the value to 500.

If you connect the pushbutton to D2, you can use INPUT_PULLUP and probably will not require an extra pull-up.

A7 works exactly the same as A6.

Delta_G:
With digitalRead you get a LOW for anything below 1.5V. So you could really use a value as high as 340 there and still match what digitalRead does. I don't think you need to or want to insist that the value come all the way to 1 or 0.

Delta_G:
I am surprised that you needed to do any calculation to understand how that was going to work.

1. For a typical TTL gate, the VOL (maximun value that will be recognized as LOW) is 0.5V and VOH (minimum value that will be recognized as HIGH) is 2.7V. I can't find the source of 1.5V for VOL. Any value between 0.5 and 2.7 is the forbidden zone.

2. For ATmega328P VOL is 0.9V and VOH is 4.2V.

3. The 340 of your post cannot be a magic number; it must have some kind of theoretical support. Taking your value 1.5V as VOL, I have come very close to 340 ((1024/5000)*1.5 ~= 308?) under 10-bit accuracy of the ADC Module of ATmega328P MCU.

4. If any body wants to connect a push button with an analog channel of the ATmega328P MCU, he must use the following if(){} structure with comparison value of: (1024/5000)*0.9 ~= 184; there is no theoretical support for 340?). No doubt, the credit for the concept of this non-zero parameter goes to @Delta_G; the credit for the accurate value of this parameter goes to whom?).

if(ananlogRead(A6) <=184)
{
   Serial.print("Button is closed");
}

5. And still, there is something to say --
(1) The push button is simply an ON/OFF switch; it will be either at closed condition (with zero contact resistance) or at open condition (with infinite resistance). Any value in between for the contact resistance will qualify the button as a bad one, and it should be replaced.

(2) According to data sheet, the error of the ADC Module of the ATmega328P MCU is 2-bit. Therefore, it should be good enough to use the following if() structure with comparison value of 3 (11b) to decide the close condition of a push button:

if(ananlogRead(A6) <=3)
{
   Serial.print("Button is closed.");
}

(3) Is there really any need to use the comparison value of: 340 or 184 or 500 (Post#11)?

The output swing of an LM358 on a 5volt supply is not 0-5volt, but more like 0.1-3.7volt.

Theoretical switchpoints of an Atmega328 digital pin are 0.3VCC and 0.6VCC (see datasheet).

You could compare analogRead to those theoretical switch values (0.31024= <307 and 0.61024= >614).

But since the opamp outputs a digital signal, I don't see a problem why you can't compare it to a single theoretical switchpoint center value of 0.45*1024= ~460.
Leo..

GolamMostafa:
For a typical TTL gate, the VOL (maximun value that will be recognized as LOW) is 0.5V and VOH (minimum value that will be recognised as HIGH) is 2.7V. I can't find the source of 1.5V for VOL. Any value between 0.5 and 2.7 is the forbidden zone.

Why would we even be discussing a logic system - TTL - that has been completely obsolete for twenty years now?

This is totally irrelevant! :roll_eyes:

GolamMostafa:
3. The 340 of your post cannot be a magic number; it must have some kind of theoretical support. Taking your value 1.5V as VOL, I have come very close to 340 ((1024/5000)*1.5 ~= 308?) under 10-bit accuracy of the ADC Module of ATmega328P MCU.

@GolamMostafa

That is the whole point about magic numbers. You don't need to spell things out you use them and they work under all circumstances. Sure there is a theoretical background but spelling this out in agonising detail is doing a beginner no service at all.

This forum is about education and your posts are no good for education a beginner. I have seen this effect before in some so called educators. They are so busy trying to cover all bases and all eventualities that they fail in their aim of educating.

I am dyslexic, and when I was young I was taught spelling rules. BUT no sooner had a rule been explained, all the exceptions to the rule were also pointed out. That is very bad because the effect is to say, "there is no point in learning the rule, because it dosn't work".

So the best magic number to use here is 512, explanation:- it is half way between the maximum and minimum values you can get. Nothing else NEEDS to be explained. Any further explanation without being asked is just showing how poor you are at explaining things.

I tried both, the IR sensor output and simple push button input.
Unexpectedly, the IR sensor output was fairly easy to handle in contrast with the push button, which I could not get to work. The discussions above indicate it should work, I will check at some later time. Right now, I will use A6 for input from the IR sensor module.

Thanks everyone for his share of valued information.

in contrast with the push button, which I could not get to work.

How was this wired up. It should be connected between ground and the input and then enable the pull up resistor in software.