Arduino

The pins on the Arduino can be configured as either inputs or outputs.

Arduino analog pins can be configured as digital pins.

Digital pins

Properties of Pins Configured as INPUT

  • by default pin is input (no need to declare pinMode() for making it input)

  • input pin is in a high-impedance state (like 100 MOhm is front)

    • small current switches state from 0 -> 1

    • U=Iāˆ—RU = I * R

  • => if pin is pinMode(pin, INPUT) but nothings is connected to it => random change of state on the pin because of noise signal

Pullup Resistors with pins configured as INPUT

Often it is useful to steer an input pin to a known state if no input is present. This can be done by adding a pullup resistor (to +5V), or a pulldown resistor (resistor to ground) on the input. A 10K resistor is a good value for a pullup or pulldown resistor.

Properties of Pins Configured as OUTPUT

  • Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state.

  • This means that they can provide a substantial amount of current to other circuits. Atmega pins can source (provide positive current) or sink (provide negative current) up to 40 mA (milliamps) of current to other devices/circuits. This is enough current to brightly light up an LED (don't forget the series resistor), or run many sensors, for example, but not enough current to run most relays, solenoids, or motors.

Analog pins

  • The ATmega controllers used for the Arduino contain an onboard 6 channel (8 channels on the Mini and Nano, 16 on the Mega) analog-to-digital (A/D) converter.

  • The converter has 10 bit resolution, returning integers from 0 to 1023.

  • While the main function of the analog pins for most Arduino users is to read analog sensors, the analog pins also have all the functionality of general purpose input/output (GPIO) pins (the same as digital pins 0 - 13).

Consequently, if a user needs more general purpose input output pins, and all the analog pins are not in use, the analog pins may be used for GPIO.

Pin mapping

pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);

The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH.

The analog pins also have pull-up resistors, which work identically to pull-up resistors on the digital pins.

digitalRead() // returns HIGH or LOW.
analogRead() // returns any number from 0-1023

Last updated