background image

SainSmart UNO R3 Starter Kit For Arduino

 

Chapter9 Potentiometer 

 
What’s Analog Pins? 
 
1.

 

A/D converter 

The Atmega168 contains an onboard 6 channel 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. 

2.

 

Pin mapping 

The Arduino pin numbers corresponding to the analog pins are 14 through 19. Note that these 
are Arduino pin numbers, and do not correspond to the physical pin numbers on the Atmega168 
chip. The analog pins can be used identically to the digital pins, so for example, to set analog pin 
0 to an output, and to set it HIGH, the code would look like this: 

pinMode(14, OUTPUT); 
digitalWrite(14, HIGH); 
3.

 

Pullup resistors 

The analog pins also have pullup resistors, which work identically to pullup resistors on the digital 
pins. They are enabled by issuing a command such as 

digitalWrite(14, HIGH);    // set pullup on analog pin 0   

while the pin is an input. 
Be aware however that turning on a pullup will affect the value reported by analogRead() when 
using some sensors if done inadvertently. Most users will want to use the pullup resistors only 
when using an analog pin in its digital mode. 

4.

 

Details and Caveats 

The analogRead command will not work correctly if a pin has been previously set to an output, 
so if this is the case, set it back to an input before using analogRead. Similarly if the pin has been 
set  to  HIGH  as  an  output,  the  pullup  resistor  will be  on, after  setting  it  back  to  an  INPUT  with 
pinMode. 
The Atmega168 datasheet also cautions against switching digital pins in close temporal proximity 
to  making  A/D  readings  (analogRead)  on other  analog pins.  This  can cause  electrical  noise  and 
introduce  jitter  in  the  analog  system.  It  may  be  desirable,  after  manipulating  analog  pins  (in 
digital mode), to add a short delay before using analogRead() to read other analog pins. 
 

analogRead() 

 

Description 

Reads  the  value  from  the  specified  analog  pin.  The  Arduino  board  contains  a  6  channel  (8 
channels on the Mini and Nano, 16 on the Mega), 10-bit analog to digital converter. This means 
that  it  will  map  input voltages between 0  and 5 volts  into  integer  values between  0  and  1023. 
This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. 
The input range and resolution can be changed using analogReference(). 

Содержание UNO R3

Страница 1: ...physical computing platform which is based on the Processing multimedia programming environment Feature Schematic design of the open source development interface free download and also according to t...

Страница 2: ...or battery to get started Performance Revision 3 is the last SainSmart UNO development board version Parameter 3 3V 5V Supply Voltage and IO Voltage can be switched at the same time More 3 3V modules...

Страница 3: ...grammar not only put some related parameters Settings are function change we have no need to understand his bottom let us to know AVR micro control unit MCU friend can also easy to fit in So here I ll...

Страница 4: ...use can combine experimental procedure Structure void setup The setup function is called when a sketch starts Use it to initialize variables pin modes start using libraries etc The setup function wil...

Страница 5: ...in miliseconds specified as parameter There are 1000 milliseconds in a second unit ms delayMicroseconds us Math min x y minimum value max x y maximum value abs x absolute value constrain x a b Constra...

Страница 6: ...intln Hello World void loop Explain Serial begin 9600 The comment says 9600 bps and just so you know bps stands for bits per second we will refer to this as the baud rate Communicate with computer you...

Страница 7: ...SainSmart UNO R3 Starter Kit For Arduino...

Страница 8: ...pment we need is the Arduino which each experiment must have and USB download cable Next we connect small lamp in accordance with the following experimental schematic physical map Accordance with the...

Страница 9: ...Kit For Arduino define interface is output light up led lamp delay 1s go out led lamp delay 1s After downloading the program you can see our 13 foot LED lights flashing so that our small lights flicke...

Страница 10: ...lectron and hole recombination can radiate visible light and thus can be used to prepare a light emitting diode in the circuit and the instrument as the indicator or the composition of the text or dig...

Страница 11: ...delay 1000 delay 1000ms 1000ms 1s setup The setup function is called when a sketch starts Use it to initialize variables pin modes start using libraries etc The setup function will only run once after...

Страница 12: ...is a steady voltage between 0 and 5v controlling the brightness of the LED In the graphic below the green lines represent a regular time period This duration or period is the inverse of the PWM freque...

Страница 13: ...3 5 6 9 10 and 11 On the Arduino Mega it works on pins 2 through 13 Older Arduino boards with an ATmega8 only support analogWrite on pins 9 10 and 11 The Arduino Due supports analogWrite on pins 2 th...

Страница 14: ...t the value is the amount of brightness variations change void setup pinMode 9 OUTPUT set pin9 is output void loop analogWrite 9 brightness write the value of brightness in pin9 brightness brightness...

Страница 15: ...SainSmart UNO R3 Starter Kit For Arduino Chapter5 Advertising LED Experiment component LED lamp 6 220 resistors 6 Breadboard Jumper wires Connect your circuit as the below diagram...

Страница 16: ...ned char j for j 1 j 6 j every 200ms light up one of led lamps with 1 6 pin in turn digitalWrite j HIGH light up the led lamps with j pin delay 200 delay 200ms for j 6 j 1 j every 200ms got out one of...

Страница 17: ...ub 2 led lamp run the example 3 program void style_3 void unsigned char j k led lamp run the example 3 program k 5 set k is 5 for j 1 j 3 j digitalWrite j HIGH light up digitalWrite j k HIGH light up...

Страница 18: ...enclosed in curly braces An increment counter is usually used to increment and terminate the loop The for statement is useful for any repetitive operation and is often used in combination with arrays...

Страница 19: ...Double click the icon to open it Then you will see that it is the arduino programming software window with the experimental program code int ledred 10 define digital pin10 red int ledyellow 7 define d...

Страница 20: ...it For Arduino digitalWrite ledyellow HIGH light up yellow lamp delay 200 delay 200 ms digitalWrite ledyellow LOW go out digitalWrite ledgreen HIGH light up green lamp delay 1000 delay 1000 ms digital...

Страница 21: ...their drive different way teach you to distinguish between active buzzer and passive buzzer A small buzzer for sale on the market now because of its small size diameter is only 11mm light weight low p...

Страница 22: ...sue and the resistance is more than hundreds of Europe that is active buzzer Active buzzer directly connected to the rated power indicate on the new buzzer s label can be continuous sound rather passi...

Страница 23: ...dboard Jumper wires Connect your circuit as the below diagram Example code int buzzer 7 set buzzer s digital pin IO in control void setup pinMode buzzer OUTPUT set digital pin IO OUTPUT void loop unsi...

Страница 24: ...loops Description while loops will loop continuously and infinitely until the expression inside the parenthesis becomes false Something must change the tested variable or the while loop will never ex...

Страница 25: ...ferent physical mechanism This type of sensor is the environmental friendly version of a mercury switch It contains a metallic ball inside that will commute the two pins of the device from on to off a...

Страница 26: ...SainSmart UNO R3 Starter Kit For Arduino Example code void setup pinMode 8 OUTPUT set pin8 output void loop int i define i while 1...

Страница 27: ...SainSmart UNO R3 Starter Kit For Arduino i analogRead 5 read voltage values of pin5 if i 200 if more than 512 2 5V digitalWrite 8 HIGH light up led lamp else digitalWrite 8 LOW go out led lamp...

Страница 28: ...log pin 0 while the pin is an input Be aware however that turning on a pullup will affect the value reported by analogRead when using some sensors if done inadvertently Most users will want to use the...

Страница 29: ...ound from one of the outer pins of the potentiometer The second goes from 5 volts to the other outer pin of the potentiometer The third goes from analog input 2 to the middle pin of the potentiometer...

Страница 30: ...0 void setup pinMode ledpin OUTPUT set analog pin13 output Serial begin 9600 set baud rate 9600 void loop digitalWrite ledpin HIGH light up led in pin13 delay 50 delay 0 05s digitalWrite ledpin LOW go...

Страница 31: ...terial these production materials having characteristics in light of a specific wavelength its resistance decreases rapidly This is due to the light generated carriers are involved in the electrical c...

Страница 32: ...age int ledPin 12 define ledPin12 is the output port of led s level int val 0 define original of val void setup pinMode ledPin OUTPUT set ledPin output void loop val analogRead photocellPin get the va...

Страница 33: ...SainSmart UNO R3 Starter Kit For Arduino digitalWrite ledPin HIGH when the value of val is less than 512 2 5V light up led lamp else digitalWrite ledPin LOW...

Страница 34: ...s a core part of the temperature measuring instruments and a wide variety In accordance with the measurement method is divided into contact and non contact two major categories In accordance with the...

Страница 35: ...e few Connection First ready experimental board Follow the LM35 temperature sensor connection connected to VOUT is connected to an analog 0 Such temperature alarm experimental circuit connected Experi...

Страница 36: ...perature Serial print dat print the value of dat Serial println C print C means degree delay 500 delay 0 5s Program function Download the program to the experimental board open the monitor you can see...

Страница 37: ...SainSmart UNO R3 Starter Kit For Arduino Chapter12 Nixie tube Experiment component digital tube x1 220 resistance x4 Breadboard jumper wire Connect your circuit as the below diagram...

Страница 38: ...11 j go out else digitalWrite j HIGH digitalWrite dp HIGH go out decimal point dp display number2 void digital_2 void unsigned char j digitalWrite b LOW digitalWrite a LOW for j 9 j 11 j digitalWrite...

Страница 39: ...id digital_5 void unsigned char j for j 7 j 9 j digitalWrite j LOW digitalWrite c LOW digitalWrite d LOW digitalWrite dp HIGH digitalWrite b HIGH digitalWrite e HIGH display number6 void digital_6 voi...

Страница 40: ...rite j LOW digitalWrite dp HIGH void setup int i define i for i 4 i 11 i pinMode i OUTPUT set pin4 pin11 output void loop while 1 digital_1 number 1 delay 2000 delay 2s digital_2 delay 2000 digital_3...

Страница 41: ...t digital tube Digital tube has be divided into 1 2 4 and so on digital tube depend on how many 8 it can show Digital tube is divided into common anode digital tube and common cathode digital tube by...

Страница 42: ...ponding fields are alight when a field emitting cathode of the diode is low which are not bright when a field of the cathode is high Connection One end of the current limiting resistor plugged into th...

Страница 43: ...miting resistor connection The first one is connected with D1 d4 anode totally connect four This connection method s benefit is needs of relatively less resistance but generates different the digital...

Страница 44: ...SainSmart UNO R3 Starter Kit For Arduino Refer to figure below wiring for the 5643S...

Страница 45: ...ne the parameters set anode interface int a 1 int b 2 int c 3 int d 4 int e 5 int f 6 int g 7 int p 8 set cathode interface int d4 9 int d3 10 int d2 11 int d1 12 Set variables long n 0 int x 100 int...

Страница 46: ...earLEDs pickDigit 1 pickNumber n x 1000 10 delayMicroseconds del clearLEDs pickDigit 2 pickNumber n x 100 10 delayMicroseconds del clearLEDs pickDigit 3 dispDec 3 pickNumber n x 10 10 delayMicrosecond...

Страница 47: ...igitalWrite d1 LOW break case 2 digitalWrite d2 LOW break case 3 digitalWrite d3 LOW break default digitalWrite d4 LOW break void pickNumber int x define pickNumber x Its role is to show digital x swi...

Страница 48: ...d clearLEDs clear the screen digitalWrite a LOW digitalWrite b LOW digitalWrite c LOW digitalWrite d LOW digitalWrite e LOW digitalWrite f LOW digitalWrite g LOW digitalWrite p LOW void zero Define th...

Страница 49: ...ite b HIGH digitalWrite c LOW digitalWrite d HIGH digitalWrite e HIGH digitalWrite f LOW digitalWrite g HIGH void three digitalWrite a HIGH digitalWrite b HIGH digitalWrite c HIGH digitalWrite d HIGH...

Страница 50: ...ite b LOW digitalWrite c HIGH digitalWrite d HIGH digitalWrite e HIGH digitalWrite f HIGH digitalWrite g HIGH void seven digitalWrite a HIGH digitalWrite b HIGH digitalWrite c HIGH digitalWrite d LOW...

Страница 51: ...lWrite c HIGH digitalWrite d HIGH digitalWrite e LOW digitalWrite f HIGH digitalWrite g HIGH In front of setup defined range of digital display routines the definition of these subroutines can be easy...

Страница 52: ...lights just with Arduino how many its I O will be occupied The answer is eight However one arduino uno only have 20 I O port 8 small lights have take up too many resources The purpose we use 74HC595...

Страница 53: ...SainSmart UNO R3 Starter Kit For Arduino This schematic seems are complex after analysis and combined with reference we will find it very simple...

Страница 54: ...ND int ledState 0 void setup pinMode latchPin OUTPUT pinMode clockPin OUTPUT pinMode dataPin OUTPUT void loop int delayTime 100 for int i 0 i 256 i updateLEDs i delay delayTime void updateLEDs int val...

Страница 55: ...ay pin position What s more the IN4001 diodes are divided into positive and negative Do not look at the relay circuit is slightly complex but the kiev program is very simple The relay is digital signa...

Страница 56: ...O R3 Starter Kit For Arduino Result We will see small red lights and green lights flashing take turns This is the end of this chapter s experiment we hope that you could enjoy it and create more inter...

Страница 57: ...SainSmart UNO R3 Starter Kit For Arduino Chapter15 8x8 matrix LEDs The following figure is a matrix LED internal schematic Wiring diagram One LED of LED 8X8 matrix is lit as follows...

Страница 58: ...the row pin 2 const int row8 14 the number of the row pin 5 the pin to control COl const int col1 6 the number of the col pin 13 const int col2 7 the number of the col pin 3 const int col3 8 the numbe...

Страница 59: ...w3 LOW digitalWrite row4 LOW digitalWrite row5 LOW digitalWrite row6 LOW digitalWrite row7 LOW digitalWrite row8 LOW digitalWrite col1 LOW digitalWrite col2 HIGH digitalWrite col3 HIGH digitalWrite co...

Страница 60: ...SainSmart UNO R3 Starter Kit For Arduino The code in the folder 8x8 the matrix LEDs experimental can be used as a reference made more exciting experiments...

Страница 61: ...he specific frequency of the signal and restoring it into a binary pulse code That is demodulated How it work Built in receiver tube infrared emission tube emitted light signal is converted to a weak...

Страница 62: ...out NEC protocol NEC protocol introduction Feature 1 8 bit address spaces 8 bit command spaces 2 address bits and command bits are transmitted twice for reliability 3 Pulse position modulation 4 Carri...

Страница 63: ...ll divided receiving end s wave form into four parts Primer searching code 9ms And 4 5ms pulse the address code 16 including an 8 bit address and 8 bit address is negated the command code 16 package I...

Страница 64: ...ion TCCR1A 0X00 TCCR1B 0X05 set timer clock source TCCR1C 0X00 TCNT1 0X00 TIMSK1 0X00 Ban timer interrupt overflow void remote_deal void Implement the decoding function data presentation Serial printl...

Страница 65: ...ar Analysis of the remote control code user code value for i 0 i 16 i if logic_value 1 if 1 ir_code 1 i Save key value Analytical remote control code commands in the code for i 0 i 8 i if logic_value...

Страница 66: ...h TCNT1 TCNT1 0 if Pulse_Width 140 Pulse_Width 141 9ms while digitalRead IR_IN if high wait Pulse_Width TCNT1 TCNT1 0 if Pulse_Width 68 Pulse_Width 72 4 5ms pulse_deal return else if Pulse_Width 34 Pu...

Страница 67: ...SainSmart UNO R3 Starter Kit For Arduino while 1 remote_decode decode remote_deal Executive decoding results...

Отзывы: