Что такое findslide.org?

FindSlide.org - это сайт презентаций, докладов, шаблонов в формате PowerPoint.


Для правообладателей

Обратная связь

Email: Нажмите что бы посмотреть 

Яндекс.Метрика

Презентация на тему Simple Digital and Analog Inputs

Содержание

Simple Digital and Analog InputsThe Arduino’s ability to sense digital and analog inputs allows it to respond to you and to the world around youDigital input pins sense the presence and absence of voltage on a
IMPLEMENTING IOEAssist. Prof. Rassim Suliyev - SDU 2017Week 4 Simple Digital and Analog InputsThe Arduino’s ability to sense digital and analog Simple Digital and Analog InputsdigitalRead(pin) - tells your sketch if a voltage Simple Digital and Analog InputsStill need more?Analog pins 0 through 15 are Sensors & InputsMany sensors are variations on switchesSwitches make or break a Many Kinds of SwitchesTilt sensor has a little ball insideMagnetic switches are Digital InputSwitches make or break a connectionBut Arduino wants to see a From Switch to HIGH / LOWWith no connection, digital inputs “float” between Pull-up and Pull-downpull-up resistors – pull the voltage up to the 5V Control the BlinkingConnect a button to pin 2 with a pull-down resistorTurn Control the Blinking// Pushbutton sketch a switch connected to pin 2 lights Let’s Wire It UpGoing from schematic to physical circuit. Solderless Breadboards Useful Tools Making Jumper Wires Using Solderless BreadboardsUsing needle nose pliers can help push wires & components into holes All Wired Up Using Switches to Make DecisionsOften you’ll want to choose between actions, based Control the Blinking (pull-up) Switch Without External ResistorsArduino has internal pull-up resistors that can be enabled Reliably Detecting the Switch Statecontact bounce produces spurious signals at the moment Analog InputTo computers, analog is chunky Analog InputMany states, not just two (HIGH/LOW)Number of states (or values, or Analog InputArduino (ATmega168) has six ADC inputs(ADC = Analog to Digital Converter)Reads Analog InputSure sure, but how to make a varying voltage?With a potentiometer. (pot) PotentiometersMoving the knob is like moving where the arrow taps the voltage What good are pots at?Anytime you need a ranged inputMeasure rotational positionsteering Arduino Analog InputPlug pot directly into breadboardTwo “legs” plug into +5V & Pot & LED Circuit Pot Blink Rate/* Pot sketch blink an LED at a rate set
Слайды презентации

Слайд 2 Simple Digital and Analog Inputs
The Arduino’s ability to

Simple Digital and Analog InputsThe Arduino’s ability to sense digital and

sense digital and analog inputs allows it to respond

to you and to the world around you

Digital input pins sense the presence and absence of voltage on a pin
Analog input pins measure a range of voltages on a pin


Слайд 3 Simple Digital and Analog Inputs
digitalRead(pin) - tells your

Simple Digital and Analog InputsdigitalRead(pin) - tells your sketch if a

sketch if a voltage on a pin is HIGH

(5 volts) or LOW (0 volts)
pinMode(pin, INPUT) – configure pin as an INPUT
14 digital pins (numbered 0 to 13)
Pins 0 and 1 (marked RX and TX) are used for the USB serial connection
Need more?
Analog pins 0 through 5 can be used as digital pins 14 through 19

Слайд 4 Simple Digital and Analog Inputs
Still need more?
Analog pins

Simple Digital and Analog InputsStill need more?Analog pins 0 through 15

0 through 15 are digital pin numbers 54 through

69

Слайд 5 Sensors & Inputs
Many sensors are variations on switches
Switches

Sensors & InputsMany sensors are variations on switchesSwitches make or break

make or break a connection
Single pole = only one

circuit is being controlled
Double pole = two circuits are being controlled at once
Single throw = only one path for circuit
Double throw = two potential paths for circuit

Слайд 6 Many Kinds of Switches
Tilt sensor has a little

Many Kinds of SwitchesTilt sensor has a little ball insideMagnetic switches

ball inside
Magnetic switches are delicate
The hex switch is actually

many switches in one, and outputs 4 signals

Слайд 7 Digital Input
Switches make or break a connection
But Arduino

Digital InputSwitches make or break a connectionBut Arduino wants to see

wants to see a voltage
Specifically, a “HIGH” (5 volts)

or a “LOW” (0 volts)
How do you go from make/break to HIGH/LOW?

Слайд 8 From Switch to HIGH / LOW
With no connection,

From Switch to HIGH / LOWWith no connection, digital inputs “float”

digital inputs “float” between 0 & 5 volts (LOW

& HIGH)
Resistor “pulls” input to ground (0 volts)
Pressing switch “pushes” input to 5 volts
Press is HIGH
Not pressed is LOW

Pull-down resistor

Слайд 9 Pull-up and Pull-down
pull-up resistors – pull the voltage

Pull-up and Pull-downpull-up resistors – pull the voltage up to the

up to the 5V line that the resistor is

connected to
pull-down resistors – pull the voltage down to 0 volts
Although 10K ohms is a commonly used value, anything between 4.7K and 20K or more will work

Слайд 10 Control the Blinking
Connect a button to pin 2

Control the BlinkingConnect a button to pin 2 with a pull-down

with a pull-down resistor
Turn on LED if button pressed

and OFF if released

Слайд 11 Control the Blinking
// Pushbutton sketch a switch connected

Control the Blinking// Pushbutton sketch a switch connected to pin 2

to pin 2 lights the LED on pin 13

const

int ledPin = 13; // choose the pin for the LED
const int inputPin = 2; // choose the input pin (for a pushbutton)
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
}
void loop(){
int val = digitalRead(inputPin); // read input value
If (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED on if switch is pressed
} else {
digitalWrite(ledPin, LOW); // turn LED off
}
}

Слайд 12 Let’s Wire It Up
Going from schematic to physical

Let’s Wire It UpGoing from schematic to physical circuit.

circuit.


Слайд 13 Solderless Breadboards

Solderless Breadboards

Слайд 14 Useful Tools

Useful Tools

Слайд 15 Making Jumper Wires

Making Jumper Wires

Слайд 16 Using Solderless Breadboards
Using needle nose pliers can help

Using Solderless BreadboardsUsing needle nose pliers can help push wires & components into holes

push wires & components into holes


Слайд 17 All Wired Up

All Wired Up

Слайд 18 Using Switches to Make Decisions
Often you’ll want to

Using Switches to Make DecisionsOften you’ll want to choose between actions,

choose between actions, based on a data obtained from

switch-like sensor
E.g. “If motion is detected, turn on the lights”
E.g. “If flower pot soil is dry, turn on sprinklers”
Define actions, choose them from sensor inputs
Let’s try that with the actions we currently know
E.g.: If button is pressed send “Hello!” to serial port, and if released send “Goodbye!”

Слайд 19 Control the Blinking (pull-up)

Control the Blinking (pull-up)

Слайд 20 Switch Without External Resistors
Arduino has internal pull-up resistors

Switch Without External ResistorsArduino has internal pull-up resistors that can be

that can be enabled by writing a HIGH value

to a pin that is in INPUT mode

const int ledPin = 13;
const int inputPin = 2;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
digitalWrite(inputPin,HIGH);
// turn on internal pull-up
}
void loop(){
int val = digitalRead(inputPin);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}


Слайд 21 Reliably Detecting the Switch State
contact bounce produces spurious

Reliably Detecting the Switch Statecontact bounce produces spurious signals at the

signals at the moment the switch contacts close or

open
avoid false readings due to contact bounce - debouncing

boolean debounce(int pin) {
boolean state;
boolean previousState;
previousState = digitalRead(pin); // store switch state
for(int cnt=0; cnt < debounceDelay; cnt++) {
delay(1); // wait for 1 millisecond
state = digitalRead(pin); // read the pin
if( state != previousState) {
cnt = 0; // reset the counter if the state changes
previousState = state; // and save the current state
}
}
return state;
}


Слайд 22 Analog Input
To computers, analog is chunky

Analog InputTo computers, analog is chunky

Слайд 23 Analog Input
Many states, not just two (HIGH/LOW)
Number of

Analog InputMany states, not just two (HIGH/LOW)Number of states (or values,

states (or values, or “bins”) is resolution
Common computer resolutions:
8-bit

= 256 values
16-bit = 65,536 values
32-bit = 4,294,967,296 values

Слайд 24 Analog Input
Arduino (ATmega168) has six ADC inputs
(ADC =

Analog InputArduino (ATmega168) has six ADC inputs(ADC = Analog to Digital

Analog to Digital Converter)
Reads voltage between 0 to 5

volts
Resolution is 10-bit (1024 values)
In other words, 5/1024 = 4.8 mV smallest voltage change you can measure

Слайд 25 Analog Input
Sure sure, but how to make a

Analog InputSure sure, but how to make a varying voltage?With a potentiometer. (pot)

varying voltage?
With a potentiometer. (pot)


Слайд 26 Potentiometers
Moving the knob is like moving where the

PotentiometersMoving the knob is like moving where the arrow taps the

arrow taps the voltage on the resistor
When a resistor

goes across a voltage difference, like +5V to Gnd, the voltage measured at any point along a resistor’s length is proportional to the distance from one side.

Слайд 27 What good are pots at?
Anytime you need a

What good are pots at?Anytime you need a ranged inputMeasure rotational

ranged input
Measure rotational position
steering wheel, robotic joint, etc.
But more

importantly for us, potentiometers are a good example of a resistive sensor

Слайд 28 Arduino Analog Input
Plug pot directly into breadboard
Two “legs”

Arduino Analog InputPlug pot directly into breadboardTwo “legs” plug into +5V

plug into +5V & Gnd (red + & blue

-) buses
Middle “post” plugs into a row (row 7 here)
Run a wire from that row to Analog In 2

Слайд 29 Pot & LED Circuit

Pot & LED Circuit

  • Имя файла: simple-digital-and-analog-inputs.pptx
  • Количество просмотров: 132
  • Количество скачиваний: 0