Can I use this pins like this ?.

Hello All,

I am doing home automation project. So I planned IO.

Here I am using the pins for my application.

2,3 wifi rx ansd tx software serial.

A4,A5,A6,A7 analog input (pot input for vary the fan speed).

9,10,11,12,13 nRF24L01.

0,1 tx rx bluetooth hardware serial.

6 Pwm output triac BTA12.

A0,A1,A2,A3 digital output for trigger the relay(Just on/off).

4,5,7,8 digital input (button input).

Why I am asking this. I faced a problem while I am using A0,A1,A2,A3,A4,A5 as digital input.
I just make pin A0 as button input and 8 pin as led output. on that time I just press A1,A2,A3,A4,A5 buttons that time also the 8 pin glowing. but in program said when A0 pressed that time only the 8 pin on.

I just pullup A0 pin only. A1,A2,A3,A4,A5 left floating.

I just used "button" Arduino builtin example for this testing purpose.

Please help me.

Which Arduino is this? Please post your code.

Also Can I use these pin configuration at same time ?.

A0,A1,A2,A3 as digital output.
A4,A5,A6,A7 as analog input.
2,3 software serial.
9,10,11,12,13 as nRF24L01(SPI).
0,1 tx rx bluetooth (HW serial).
6 Pwm output (for Triac Dimmable loads).
4,5,7,8 digital input (Button inputs).

Can I use this pin configuration ?.

My question is any modes affect another modes ? for example A0 to A3 as digital output. at the same time can I use A4 to A7 as analog input ?.

same 4,5,6,7 as I config as digital input. at this time can I use 6 pin as pwm output ?.

This is my question.

What board are you talking about?

Normally analog pins can be used as digital. On the MCU, anolog functionality is usually just alternate function of digital port.

You should post the circuit diagram and the sketch.

const int buttonPin = A0;     // 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);
  }
}

I just used built in "button" example.

In this time just I give the input for A1,A2,.. upto A7. the led is glowing

How is the input wired ?
Do you have a pulldown resistor in place to keep the input LOW except when the button is pressed ?

Also Can I use these pin configuration at same time ?.

A0,A1,A2,A3 as digital output.
A4,A5,A6,A7 as analog input....

Yes, you can (but it could depend on the board type). Which board?
Arduino Mega 2560 (e.g.) has A0-A7 completely independent. Each one can be set different.

same 4,5,6,7 as I config as digital input. at this time can I use 6 pin as pwm output ?.

Once you use port 6 as input you cannot use it as PWM output at the same time.

The sketch is quite simple also example circuit but you are writing about A1-A7. How about their connection.
Show the circuit.

Here is the circuit I made.

for your verification try this. just upload the Built in example “Button” with changed sketch A3 as button input. 8 pin as output. just upload this code. then make sure the program is working. mine working well. then you just change(hardware side only) the wire from A3 to A4 then you press the button then you got the LED is 8 pin is glowing.

Which means the program only define A3 as input. But in the hardware side is A4 button accept the input without configuring.

Note:

I did not config A4 as input. But the pin get input

Please find the circuit. I have attached.

I did not config A4 as input. But the pin get input

Pins default to being inputs.

Ok. Then how to solve this ?.

SureshKumar2610:
Ok. Then how to solve this ?.

Solve what ? I do not understand your problem. If you don't want to know whether A4 is HIGH or LOW then don't read from it. If you want it to stay in a known state then add an external pulldown or pullup resistor or neater, use pinMode(A4, INPUT_PULLUP); to turn on the built in pullup resistor and wire the switch to take the pin LOW when pressed.

SureshKumar2610:
A4,A5,A6,A7 analog input (pot input for vary the fan speed).

Not in the circuit you posted they aren't.

I am doing home automation project. So I planned IO.

Before making the PCB I need to verify the pin functions and configurations. As I posted in previous #1 message
Before proceeding I verify the pins which is good for input and output

In this conversation I again check and verify the problem(While I am posting this I just make sure the same. Because I don't want waste your's time).

I Just try this in hardware.

Promini 5v 16mhz.
CP2102 for Programming.

1.Edit A1 as input and upload built in "button" example.
2.On bread board I made the connection A1 pin grounded through a 10K resistor. also this pin connected with VCC through button. I checked this example is work are not. Its is working good.
3.Then I just remove the wire and connect with A2 pin in my promini(This time the A1 pin left float). Then I press the button the LED was glowing.(I did not config and changing the code and I did not upload the code also. I just making this changes only in hardware side. not programming side.)
What is the error ?.

My opinion
That time(disconnect the button wire from A1 and connect with A2 pin) the A1 pin was left float. this making problem ?.
In this time the some voltage variation maybe affect the A1 pin(Because the A1 pin was left floating. when I press button the nearest pin A2 consume some little amount current and making voltage variation(noise). So this is the reason for malfunction. I am correct ?.
So I am using another 10k resistor for making this A1 pull down.
I am checking..........

Surprise.
Yes. Now the LED not glowing. Which means some little bit noise affect the nearest pin(left float pin). that is why when I press the (even not config A2) A2 pin the LED was glowing.

Conclusion and learning.
Once a pin config as input that pin must be strongly pull up or pull down. If making the input as left float. the electrical noise or some nearest pin may also chance for affect the pin. means the nearest pin consume and making voltage drop that time the input pin affect.

Theory:
Don't leave the INPUT configured pin as left float. Making pull up or pull down.
If not the nearest pin or nearest electrical noise may affect processor. so the total system malfunction.
Oh god thank you very much for all.

Once a pin config as input that pin must be strongly pull up or pull down.

Weakly would be better. For example 10k or 20k.