Arduino IO pin Mapping
Summary | http://arduino.cc/en/Main/ArduinoBoardUno | |
Microcontroller | ATmega328 | |
Operating Voltage | 5V | |
Input Voltage (recommended) | 7-12V | |
Input Voltage (limits) | 6-20V | |
Digital I/O Pins | 14 (of which 6 provide PWM output) | |
Analog Input Pins | 6 | |
DC Current per I/O Pin | 40 mA | |
DC Current for 3.3V Pin | 50 mA | |
Flash Memory | 32 KB (ATmega328) of which 0.5 KB used by bootloader | |
SRAM | 2 KB (ATmega328) | |
EEPROM | 1 KB (ATmega328) | |
Clock Speed | 16 MHz | |
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 a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms. 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: 2 and 3. These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details. | ||
PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function. | ||
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 connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off. | ||
TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the Wire library. | ||
ATmega328 Pin Mapping | I/O | |
Pin 1 | Reset | |
Pin 2 | PD0 (Rs232 - Rx) | 0 |
Pin 3 | PD1 (Rs232 - Tx) | 1 |
Pin 4 | PD2 (Int / Rs232 - Rx.1) | 2 |
Pin 5 | PD3 (Int / Rs232 - Tx.1 / PWM_3) | 3 |
Pin 6 | PD4 | 4 |
Pin 7 | VCC (5v) | |
Pin 8 | GND | |
Pin 9 | TOSC1 | |
Pin 10 | TOSC2 | |
Pin 11 | PD5 (PWM_5) | 5 |
Pin 12 | PD6 (PWM_6) | 6 |
Pin 13 | PD7 | 7 |
Pin 14 | PB0 | 8 |
Pin 15 | PB1 (PWM_9) | 9 |
Pin 16 | PB2 (PWM_10) | 10 |
Pin 17 | PB3 (PWM_11) | 11 |
Pin 18 | PB4 | 12 |
Pin 19 | PB5 (LED) | 13 |
Pin 20 | AVCC | |
Pin 21 | AREF | |
Pin 22 | GND | |
Pin 23 | PC0 (ADC0) | ADC0 |
Pin 24 | PC1 (ADC1) | ADC1 |
Pin 25 | PC2 (ADC2) | ADC2 |
Pin 26 | PC3 (ADC3) | ADC3 |
Pin 27 | PC4 (ADC4) | ADC4 |
Pin 28 | PC5 (ADC5) | ADC5 |
Arduino LCD KeyPad Shield
The LCD Keypad shield is developed for Arduino compatible boards, to provide a user-friendly interface that allows users to go through the menu, make selections etc. It consists of a 1602 white character blue backlight LCD. The keypad consists of 5 keys — select, up, right, down and left. To save the digital IO pins, the keypad interface uses only one ADC channel. The key value is read through a 5 stage voltage divider.
see also: Enhanced LiquidCrystal_I2C library
in | Function |
---|---|
Analog 0 | Button (select, up, right, down and left) |
Digital 4 | DB4 |
Digital 5 | DB5 |
Digital 6 | DB6 |
Digital 7 | DB7 |
Digital 8 | RS (Data or Signal Display Selection) |
Digital 9 | Enable |
Digital 10 | Backlit Control |
Sample Code
Example use of LiquidCrystal library
//Sample using LiquidCrystal library #include <LiquidCrystal.h> /******************************************************* This program will test the LCD panel and the buttons Mark Bramwell, July 2010 ********************************************************/ // select the pins used on the LCD panel LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // define some values used by the panel and buttons int lcd_key = 0; int adc_key_in = 0; #define btnRIGHT 0 #define btnUP 1 #define btnDOWN 2 #define btnLEFT 3 #define btnSELECT 4 #define btnNONE 5 // read the buttons int read_LCD_buttons() { adc_key_in = analogRead(0); // read the value from the sensor // my buttons when read are centered at these valies: 0, 144, 329, 504, 741 // we add approx 50 to those values and check to see if we are close if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result // For V1.1 us this threshold if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 250) return btnUP; if (adc_key_in < 450) return btnDOWN; if (adc_key_in < 650) return btnLEFT; if (adc_key_in < 850) return btnSELECT; // For V1.0 comment the other threshold and use the one below: /* if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 195) return btnUP; if (adc_key_in < 380) return btnDOWN; if (adc_key_in < 555) return btnLEFT; if (adc_key_in < 790) return btnSELECT; */ return btnNONE; // when all others fail, return this... } void setup() { lcd.begin(16, 2); // start the library lcd.setCursor(0,0); lcd.print("Push the buttons"); // print a simple message } void loop() { lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over lcd.print(millis()/1000); // display seconds elapsed since power-up lcd.setCursor(0,1); // move to the begining of the second line lcd_key = read_LCD_buttons(); // read the buttons switch (lcd_key) // depending on which button was pushed, we perform an action { case btnRIGHT: { lcd.print("RIGHT "); break; } case btnLEFT: { lcd.print("LEFT "); break; } case btnUP: { lcd.print("UP "); break; } case btnDOWN: { lcd.print("DOWN "); break; } case btnSELECT: { lcd.print("SELECT"); break; } case btnNONE: { lcd.print("NONE "); break; } } }
DHT22 digital Temperature Humidity
DHT22 Temperature and humidity module
Introduction
DHT22 capacitive humidity sensing digital temperature and humidity module is one that contains the compound has been calibrated digital signal output of the temperature and humidity sensors. Application of a dedicated digital modules collection technology and the temperature and humidity sensing technology, to ensure that the product has high reliability and excellent long-term stability.
The sensor includes a capacitive sensor wet components and a high-precision temperature measurement devices, and connected with a high-performance 8-bit microcontroller. The product has excellent quality, fast response, strong anti-jamming capability, and high cost.
Standard single-bus interface, system integration quick and easy. Small size, low power consumption, signal transmission distance up to 20 meters, making it the best choice of all kinds of applications and even the most demanding applications.
DHT22 has higher precision and can replace the expensive imported SHT10 temperature and humidity sensor.
It can measure the environment temperature and humidity to meet the high demand.The product has high reliability and good stability.If it's used and combined with special sensor Arduino expansion board,it will be easily implemented the interactive effect which related to the temperature and humidity perception.
Caution: DHT22 digital temperature and humidity sensor is designed for analog sensor interfaces.The analog port will be used as the digital which will not occupy the original digital port of the Arduino.The lines of the sensor which can transform the analog function to digital that can be use on digital port.
Note:The line of the DHT22 sensor module is analog--digital
Specifications
- Supply voltage: 5V
- Output voltage: 0-3.3V
- Temperature range:-40-80℃ resolution0.1℃ error <±0.5℃
- Humidity range:0-100%RH resolution0.1%RH error±2%RH
- size: 38 x 20mm
Tutorial
Connection
Sample code
Please download the Library of DHT22 at first.This program is used to test the temperature and humidity of the DHT22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
//DHT11 -- DIGITAL 7 #include <DHT22.h> // Only used for sprintf #include <stdio.h> // Data wire is plugged into port 7 on the Arduino #define DHT22_PIN 7 // Setup a DHT22 instance DHT22 myDHT22(DHT22_PIN); void setup( void ) { //start serial port Serial.begin(9600); Serial.println( "DHT22 Library Demo" ); } void loop( void ) { DHT22_ERROR_t errorCode; // The sensor can only be read from every 1-2s, and requires a minimum // 2s warm-up after power-on. delay(2000); Serial.print( "Requesting data..." ); errorCode = myDHT22.readData(); switch (errorCode) { case DHT_ERROR_NONE: Serial.print( "Got Data " ); Serial.print(myDHT22.getTemperatureC()); Serial.print( "C " ); Serial.print(myDHT22.getHumidity()); Serial.println( "%" ); /*Alternately, with integer formatting which is clumsier but more compact to store and*/ /*can be compared reliably for equality:*/ char buf[128]; sprintf (buf, "Integer-only reading: Temperature %hi.%01hi C, Humidity %i.%01i %% RH" , myDHT22.getTemperatureCInt()/10, abs (myDHT22.getTemperatureCInt()%10), myDHT22.getHumidityInt()/10, myDHT22.getHumidityInt()%10); Serial.println(buf); break ; case DHT_ERROR_CHECKSUM: Serial.print( "check sum error " ); Serial.print(myDHT22.getTemperatureC()); Serial.print( "C " ); Serial.print(myDHT22.getHumidity()); Serial.println( "%" ); break ; case DHT_BUS_HUNG: Serial.println( "BUS Hung " ); break ; case DHT_ERROR_NOT_PRESENT: Serial.println( "Not Present " ); break ; case DHT_ERROR_ACK_TOO_LONG: Serial.println( "ACK time out " ); break ; case DHT_ERROR_SYNC_TIMEOUT: Serial.println( "Sync Timeout " ); break ; case DHT_ERROR_DATA_TIMEOUT: Serial.println( "Data Timeout " ); break ; case DHT_ERROR_TOOQUICK: Serial.println( "Polled to quick " ); break ; } } |