Botões, Arduino e Resistor Pull-up e Pull-Down - Tutorial

|


Ao fazer a leitura de um botão com uma das portas do Arduino é importante estabelecer como a porta deve ler o valor. Por exemplo:
1° Caso: Porta do Arduino inicialmente em nivel lógico baixo(0V) e ao pressionar um botão ter uma entrada em nivel lógico alto(5V).
2° Caso: Porta do Arduino inicialmente em nível logico alto(5V) e pressinoarmos um botão e ter uma entrada de nivel lógico baixo(0V).
Bem... O que fazer e em que condições isso acontece? Como programar para interpretar cada situção?
Vamos ao passo a passo:



Monte o circuito na sua matriz de contato:
 Clicar na imagem para ampliar




A1-Execute o programa abaixo:



/*

Botões, Arduino e Resistor Pull-up e Pull-Down - Tutorial
Programa by Gamesh_
10/01/2011
http://brasilrobotics.blogspot.com/
*/

int BotaoPino = 7; // pino a ser lido
int val= 0;
int i=0; //Variavel para incremento


void setup() {

pinMode(BotaoPino, INPUT);
Serial.begin(9600);
}


void loop()
{
val= digitalRead(BotaoPino);
delay(100);

  if(val!=0){
   Serial.print(i++);
   Serial.print("-Valor:");
   Serial.println(val);
   }
}



Agora clicar no icone: Serial Monitor:


Você verá essa tela:


Ao pressionar o botão acontecerá isso:



Comentário sobre o Programa e o Circuito:
O programa faz a leitura constantemente do botão e somente em nível lógico alto(5V) mostra na tela que detectou algo. 
Temos então um caso de Resistor em Pull-Down pois mantém em nível baixo a porta quando o botão não é pressionado.


-Vamos fazer algumas modificações?

Monte o circuito na sua matriz de contato:
-Atenção: Os fios amarelo e verde estão em posições contrárias ao circuito anterior.


 Clicar na imagem para ampliar




A2-Execute o programa abaixo:


/*

Botões, Arduino e Resistor Pull-up e Pull-Down - Tutorial
Programa by Gamesh_
10/01/2011
http://brasilrobotics.blogspot.com/
*/

int BotaoPino = 7; // pino a ser lido
int val= 0;
int i=0; //Variavel para incremento


void setup() {

pinMode(BotaoPino, INPUT);
Serial.begin(9600);
}


void loop()
{
val= digitalRead(BotaoPino);
delay(100);

if(val!=1){
Serial.print(i++);
Serial.print("-Valor:");
Serial.println(val);
}
}



Agora clicar no icone: Serial Monitor:


Você verá essa tela:



Ao pressionar o botão acontecerá isso:




Comentário sobre o Programa e o Circuito:
O programa faz a leitura constantemente do botão e somente em nível lógico baixo(0V) mostra na tela que detectou algo. 
Temos então um caso de Resistor em Pull-up pois mantém em nível alto a porta quando o botão não é pressionado.


Gostou do tutorial? Incentive mais tutoriais visitando:

8 comentários:

Anônimo disse...

Υοur ѕtylе is sο unіque cοmpared to other
peoplе І hаve read stuff from. Thаnk yοu for postіng when you've got the opportunity, Guess I will just book mark this blog.

Also visit my webpage ... resistance of a resistor

Anônimo disse...

Ι think that is among the so muсh ѕignifiсant info for me.
And і'm satisfied studying your article. But should statement on few normal things, The website style is ideal, the articles is actually nice : D. Good task, cheers

Review my weblog - resistor code

Anônimo disse...

I hаve been suгfing on-line greater thаn thгeе hourѕ
toԁay, but І nevег disсoνеred
any interеsting аrtiсlе like yours.
It is lovely prіce ѕufficіеnt foг me.
Personallу, if all webmastеrs аnd bloggers maԁe just right сontеnt material aѕ
you prοbably did, the web shall be much morе hеlpful than ever before.


Feel free tо viѕіt my webpаge :: www.orca.uhi.ac.uk

Anônimo disse...

Hi there everyone, it's my first go to see at this website, and post is truly fruitful designed for me, keep up posting these articles.

Look into my page; Resistor resistance

Anônimo disse...

I every time spent my hаlf an hоur to read this
wеb site's articles or reviews daily along with a cup of coffee.

Also visit my site :: Power rating

Anônimo disse...

Good day! This iѕ my first visіt to your blog!
We are a grοup of volunteeгs and
starting a new projеct in a community in the sаme niche.
Үour blog pгοvideԁ us useful informаtion
to work on. Υou have donе a wonderful јob!


Αlso vіsіt my site: Lineary potentiometer

Anônimo disse...

Haѵing reаd this I believed it waѕ very informative.

I appreciate yоu finding the time and effοrt to
put this contеnt together. I once again find myself pеrsonаlly spending a lot of
time both readіng and leaving comments.

But so ωhat, it ωaѕ still worthwhіle!



my web page; Www.Partiebas.Com

Anônimo disse...

Muito bons os seus tutoriais!
Parabéns!!!

 

©2010 Brasil Robotics | by Gamesh_