Skip to main content
3 of 4
replaced http://electronics.stackexchange.com/ with https://electronics.stackexchange.com/

https://electronics.stackexchange.com/search?q=url%3Ahttp%3A%2F%2Farduino.stackexchange.comYou can always use the analog pins for digital writing.

  • digitalRead() works on all pins. It will just round the analog value received and present it to you. If analogRead(A0) is greater than or equal to 512, digitalRead(A0) will be 1, else 0.
  • digitalWrite() works on all pins, with allowed parameter 0 or 1. digitalWrite(A0,0) is the same as analogWrite(A0,0), and digitalWrite(A0,1) is the same as analogWrite(A0,255)
  • analogRead() works only on analog pins. It can take any value between 0 and 1023.
  • analogWrite() works on all analog pins and all digital PWM pins. You can supply it any value between 0 and 255.

The analog pins let you read/write analog values - basically, instead of giving out a voltage of 0 or 5 (as with digital), they can give a range of voltages between 0 and 5 (both as input and output). Note that the voltage during analog output is only the observed voltage with a multimeter. In reality, the analog pins send pulses of 0V and 5V signals to get an output that "looks" analog (this is PWM).

Regarding the number of pins: keep in mind that the PWM pins can be used for analog output. If you run out of pins, you can use multiplexing to make more. It is not necessary to get another Arduino.

Manishearth
  • 3k
  • 2
  • 23
  • 33