MicroControllerArduinoArduino StartingArduino SetupArduino BlinkArduino Digital PinArduino Digital I/O |
Arduino Digital PinsThere are 20 I/O pins on the Arduino Duemilanove. 14 pins are named digital pins and 6 pins are named analog pins. If necessary these analog pins can also be configured as I/O pins. The corresponding Arduino pin numbers to Atmega168 chip are as following.
Pin ModePins can be configured as either input or output by command pinMode(). The syntax is pinMode(pin,mode), where pin is the pin number and mode is either "INPUT" or "OUTPUT". e.g. pinMode(10,INPUT); //Digital pin 10 is used as input pinMode(11,OUTPUT); //Digital pin 11 is used as output; Pin StateThere are two states for a digital pin, for examples HIGH or LOW. However the meaning of state is depending on the pin mode. For input mode, a HIGH state means a 3V or higher voltage signal is present at the pin, while a LOW state means a 2v or lower voltage signal is present at the pin. For output mode, a HIGH state means a 5V signal is set at the pin, while a LOW state means a 0v signal is set at the pin. Pin Digital InputThe state of input pin can be read by command digitalRead() The syntax is digitalRead(pin), where pin is the pin number. The return value is "HIGH" or "LOW". e.g. pinMode(10,INPUT); //digital pin 10 is used as input int val=0; //variable val to store the read value. val=digitalRead(10); //read Digital pin 10 to val Pin Digital OutputThe state of output pin can be set by command digitalWrite() The syntax is digitalWrite(pin,value), where pin is the pin number and value is "HIGH" or "LOW". e.g. pinMode(11,OUTPUT); //digital pin 11 is used as output; digitalWrite(11,HIGH); //sets digital pin 11 to HIGH state Pull-up ResistorTo prevent the floating of input pin state when the pin is not connected to anything, a pull-up or pull-down resistor can be added to keep an input to a known state. For the Atmega168, there are internal pull-up resistances and they can be selected for each pin. These built-in pull-up resistors can be activated as following: pinMode(10,INPUT); //use digital pin 10 as input digitalWrite(10, HIGH);//activate internal pull-up resistance. Pin 13Arduino Duemilanove has a build-in resistor and LED circuit soldered to Pin 13. When pin 13 is used as a digital input with a pull-up resistor, the LED will be lighted up and the pin voltage will hang at around 1.8V instead of 5V. Therefore, an external pull-down resistor should be used when using the pin 13 as a digital input. Last Modified on 7/2/2010 |
Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 29 August 2019