Digital Input -Output Functions

The digital inputs and outputs (digital I/O) on the Arduino are what allow you to connect the Arduino sensors, actuators, and other ICs. Learning how to use them will allow you to use the Arduino to do some really useful things, such as reading switch inputs, lighting indicators, and controlling relay outputs. etc

Digital Signal

Digital signals may not take any values within range. Digital signals have two distinct values HIGH or 1 and LOW or 0. You use digital signals in situations where the input or output will have one of those two values.

Function

The Arduino functions associated with digital signals that we will be using in this tutorial are

  1. pinMode (pin_number, mode)
  2. digitalWrite(pin_number,value)
  3. digitalRead(pin_number)

pinMode (pin_number, mode)

Because the Arduino digital I/O pins can be used for either input or output, you should first configure the pins you intend to use for digital I/O with this function. pin is the number of the pin you wish to configure. mode must be one of three values: INPUT, OUTPUT, our INPUT_PULLUP. When mode is set to INPUT_PULLUP, a 20 kohm pullup resistor is internally connected to the pin to force the input HIGH if there is nothing connected to the pin.

pinMode(pin,OUTPUT);  // set pin as  OUTPUT
pinMode(pin,INPUT);  // set pin as  INPUT

Note: INPUT/OUTPUT Constants used with pinMode() function to define the model of a digital pin as INPUT or OUTPUT.

digitalWrite(pin_number,value)

This function writes a digital value to a pin. pin specifies which Arduino pin the digital value will be written to, and value is the digital value to which the pin is set. Value must be either HIGH or LOW.

digitalWrite(pin,HIGH);   //set pin as HIGH

digitalRead(pin_number)

int reads = digitalRead(pin);	//read the digital value on pin

This function reads a digital value from a pin. pin is the number of the digital I/O pin you want to read. This function returns one of two values: HIGH or LOW.

Note: HIGH/LOW These constants define pin level as HIGH or LOW and used when reading or writing to digital pins.HIGH is defined as logic level 1, ON or 5 volts while LOW is logic level 0,OFF or 0 volts

Next : Analog Input-Output Functions