Analog Pins as Digital Output in Atmega328

Hi there

I want to use 16 pins of ATMega328 (without Arduino board) as Ouptut. I can use 13 digital but how to use Analog Pins as Digital Output?

I have supplied 5V to AVcc and ARef pins and coded as:

AnalogWrite (4, 255); // A4 as digital Out
AnalogWrite(5, 255); // A5 as digital Out

I burned the Arduino Nano Bootloader in the Atmega328 but the above code isnt making A4 and A5 high ... digital meter shows less than 1V on these pins ...

These pins need to drive a Relay via transistor ...

digitalWrite(14,HIGH); // 14 for A0, 15 for A1 etc. Set the pin as out in setup()

Analog inputs are alternate functions of digital port C pins.
Analog output is a pwm and hence can be used only on timer legs (OCx). Unless software simulated.

Did you remember to set the pinMode as "OUTPUT" in "setup()"?
i.e

pinMode (A4, OUTPUT);
pinMode (A5, OUTPUT);

You can "analogWrite" to any digital pin, whether or not it is PWM-capable, but if the pin is not PWM-capable it will only set the pin HIGH if the PWM value written is >= 128, LOW otherwise.

docosama:
I want to use 16 pins of ATMega328 (without Arduino board) as Ouptut. I can use 13 digital but how to use Analog Pins as Digital Output?

Not a problem. Those pins are labelled as "analog" on the Arduino but they're really digital pins with secondary "analog" function.

docosama:
AnalogWrite (4, 255); // A4 as digital Out
AnalogWrite(5, 255); // A5 as digital Out

Try this:

pinMode(A4,OUTPUT):
digitalWrite(A4,HIGH):