Blog > News > UNO board IO pin introduction
UNO board IO pin introduction

admin

2017-02-01 15:47:33

News

287 Views

3 Comments


UNO board IO pin introduction

UNO Technical spacs

Microcontroller
ATmega328P
Operating Voltage
5V
Input Voltage(recommended)
7-12V
Input Voltage(limit)
6-20V
Digital I/O Pins
14(of which 6 provide PWM output)
PWM Digital I/O Pins
6
Analog Input Pins
6
DC Current per I/O Pin
20mA
DC Current for 3.3V Pin
50mA
Flash Memory
32KB(ATmega328P) of which 0.5 KB used by bootloader
SRAM
2KB(ATmega328P)
EEPROM
1KB(ATmega328P)
Clock Speed
16 MHz
LED_BUILTIN
13
Lenght
68.6mm
Width
53.4mm
Weight
25g


Input and Output

Each of the 14 digital pins on the Uno can be used as an input or output, using pinMode(), digitalWrite and digitalRead() functions. They operate at 5 volts. Each pin can provide or receive 20 mA as recommended operating condition and has an internal pull-up resistor (disconnected by default) of 20-50k ohm. A maximum of 40mA is the value that must not be exceeded on any I/O pin to avoid permanent damage to the microcontroller.

In addition, some pins have specialized functions:

Serial: 0 (RX and 1 (TX). Used to receive (RX and transmit (TX) TTL serial data. These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL Serial chip.

External Interrupts:

PWM:

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication using the SPI library.

LED: 13. There is a built-in LED driven by digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.

TWI: A or SDA pin and A or SCL pin. Support TWI communication using the Wire library.

The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and the analogReference() function.

There are a couple of other pins on the board:

AREF. Reference voltage for the analog inputs. Used with analogReference().

Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields which block the one on the board.

Functions

Digital I/O

pinMode()

Description:

Configures the specified pin to behave either as an input or an output. See the description of digital pins for details on the functionality of the pins.

As of Arduino 1.0.1, it is possible to enable the internal pullup resistors with the mode INPUT_PULLUP. Additionally, the INPUT mode explicitly disables the internal pullups.

Syntax

pinMode(pin, mode)

Parameters

pin: the number of the pin whose mode you wish to set

mode: INPUT, OUTPUT,.

Returns

None

digitalWrite()

Description

Write a HIGHLOW value to a digital pin.

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V for HIGH, 0V (ground) for LOW.

If the pin is configured as an INPUT, digitalWrite() will enable (HIGHLOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor.

NOTE: If you do not set the pinMode() to OUTPUTdigitalWrite(pin,HIGH), the LED may appear dim. Without explicitly setting pinMode(), digitalWrite() will have enabled the internal pull-up resistor, which acts like a large current-limiting resistor.

Syntax

digitalWrite(pin, value)

Parameters

pin: the pin number

value: HIGH LOW

Returns

None

digitalRead()

Description

Reads the value from a specified digital pin, either HIGHLOW.

Syntax

digitalRead(pin)

Parameters

pin: the number of the digital pin you want to read (int)

Returns

HIGHLOW

Example

Sets pin 13 to the same value as pin 7, declared as an input.


int ledPin = 13; // LED connected to digital pin 13
int inPin = 7;   // pushbutton connected to digital pin 7
int val = 0;     // variable to store the read value
 
void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
  pinMode(inPin, INPUT);      // sets the digital pin 7 as input
}
 
void loop()
{
  val = digitalRead(inPin);   // read the input pin
  digitalWrite(ledPin, val);    // sets the LED to the button's value
}


Analog I/O

analogRead()

Description

Reads the value from the specified analog pin. The Arduino board contains a 6 channel, 10-bit analog to digital converter. This means that it will map input voltages between and 5 volts into integer values between and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.

It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

Syntax

analogRead(pin)

Parameters

pin: the number of the analog input pin to read from 0 to 5

Returns

int (0 to 1023)

Example


int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3
                   // outside leads to ground and +5V
int val = 0;          // variable to store the value read
 
void setup()
{
  Serial.begin(9600);          //  setup serial
}
 
void loop()
{
  val = analogRead(analogPin);    // read the input pin
  Serial.println(val);             // debug value
}



analogWrite()-PWM

Description

Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite()digitalRead()digitalWrite() on the same pin). this function works on pins and 11.

You do not need to call pinMode() to set the pin as an output before calling analogWrite().

The analogWrite function has nothing to do with the analog pins or the analogRead function.

Syntax

analogWrite(pin, value)

Parameters

pin: the pin to write to.

value: the duty cycle: between 0 (always off and 255 (always on).

Returns

nothing

Example

Sets the output to the LED proportional to the value read from the potentiometer.


int ledPin = 9;      // LED connected to digital pin 9
int analogPin = 3;   // potentiometer connected to analog pin 3
int val = 0;         // variable to store the read value
void setup(){
  pinMode(ledPin, OUTPUT);   // sets the pin as output
}
void loop(){
  val = analogRead(analogPin);   // read the input pin
  analogWrite(ledPin, val / 4);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}




Save

Last article : How to install and use Geany IDE in the Raspberry Pi or Ubuntu?
Next article : Control a Relay by Matrix Keyboard

COMMENTS

Identifying:

Luck

helpful

Reply 2017-03-13 18:24:16

Luck

Test!

Reply 2017-03-13 18:25:01

Luck

Thanks!

Reply 2017-03-13 18:24:40

  Related Products
  Related Blogs
  • CONNECT WITH US 
Copyright © 2016 Adeept.com All Rights Reserved.