Top Banner
PRÁCTICAS DE PROGRAMACIÓN CON ARDUINO A4: Interruptor crepuscular DE LUZ José Pujol Pérez IES Vicente Aleixandre
20

P4: Kiwibot Basic Shield: Interruptor crepuscular

Jan 20, 2017

Download

Education

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: P4: Kiwibot Basic Shield: Interruptor crepuscular

PRÁCTICAS DE PROGRAMACIÓN CON ARDUINO

A4: Interruptor crepuscular DE LUZ

José  Pujol  Pérez  IES  Vicente  Aleixandre  

Page 2: P4: Kiwibot Basic Shield: Interruptor crepuscular

OBJETIVOS

•  Leer entradas analógicas

•  Imprimir por el puerto serie

•  Realizar un sistema automático  

Page 3: P4: Kiwibot Basic Shield: Interruptor crepuscular

Ideas Previas:

•  ¿Sabe alguien qué es un interruptor crepuscular?

•  ¿Cómo nos podemos comunicar con Arduino?

•  ¿Qué es un sensor de luz? ¿Cómo funciona? ¿Que

aparatos incluyen un sensor de luz?

•  ¿Que esquema de entradas y salidas necesitamos

para hacer un interruptor crepuscular?

 

INTRODUCCIÓN

Page 4: P4: Kiwibot Basic Shield: Interruptor crepuscular

Realizar un interruptor crepuscular que encienda la luz

de un LED (blanca) según la luz ambiental.

Para ello imprimir primero los valores de la LDR por el

puerto serie.

Opcional:

Con el LED RGB realizar un display tipo Vúmetro

 

HACER

Page 5: P4: Kiwibot Basic Shield: Interruptor crepuscular

•  ENTRADAS ANALÓGICAS

•  ESQUEMA LDR ARDUINO

•  COMUNICACIÓN SERIE

•  FUNCIÓN SERIAL

•  EJEMPLO COMUNICACIÓN SERIE

•  LECTURA DE SENSORES

•  OPERADORES BOOLEANOS

 

INFORMACIÓN

Page 6: P4: Kiwibot Basic Shield: Interruptor crepuscular

 

ENTRADAS Y SALIDAS

ENTRADAS

LDR (A)

SALIDAS

arduino LED RGB (D)

Page 7: P4: Kiwibot Basic Shield: Interruptor crepuscular

 

PSEUDOCÓDIGO

•  Inicio

•  Leer el sensor

•  Si el valor es menor que "valor límite" encender el LED –  Sino apagar el LED

 

Page 8: P4: Kiwibot Basic Shield: Interruptor crepuscular

 

DIAGRAMA DE FLUJO

Page 9: P4: Kiwibot Basic Shield: Interruptor crepuscular

 

LEER EL SENSOR

Page 10: P4: Kiwibot Basic Shield: Interruptor crepuscular

 

ENTRADAS ANALÓGICAS

Hay 6 pines para leer entradas analógicas A0-A5

analogRead(A0-A5);

Leen valores entre 0-5v en una escala de 210 =1024

Para guardar su valor los almacenamos en una variable

sensorValue=analogRead(sensorPin);

Page 11: P4: Kiwibot Basic Shield: Interruptor crepuscular

ESQUEMA LDR ARDUINO

Page 12: P4: Kiwibot Basic Shield: Interruptor crepuscular

COMUNICACIÓN SERIE

•  Utiliza los pines Rx (D0) y Tx (D1) para comunicarse

•  Permite enviar datos de Arduino al PC (y del PC a

Arduino)

•  Nos permite monitorizar sensores

Page 13: P4: Kiwibot Basic Shield: Interruptor crepuscular

 

EJEMPLO COMUNICACIÓN SERIE

Page 14: P4: Kiwibot Basic Shield: Interruptor crepuscular

FUNCIÓN SERIAL

- Serial.begin (velocidad);Abre el puerto serie y establece la velocidad de

comunicación en baudios, se declara en el set up Serial.begin (9600);

- Serial.print ();Imprime los datos por el puerto serie Serial.print ("Texto");Serial.print (variable);

- Serial.println ();Añade retorno de carro

Page 15: P4: Kiwibot Basic Shield: Interruptor crepuscular

LECTURA DE SENSORES

Page 16: P4: Kiwibot Basic Shield: Interruptor crepuscular

 

ESTRUCTURA DE CONTROL IF ELSE

Page 17: P4: Kiwibot Basic Shield: Interruptor crepuscular

 

LED RGB

digitalWrite(pin,ESTADO);

Page 18: P4: Kiwibot Basic Shield: Interruptor crepuscular

OPERADORES BOOLEANOS

Page 19: P4: Kiwibot Basic Shield: Interruptor crepuscular

•  ¿Qué hemos conseguido hacer?

 

reflexionamos

Page 20: P4: Kiwibot Basic Shield: Interruptor crepuscular

     Este  guía  se  distribuye  bajo  licencia  Reconocimiento-­‐  ComparBrIgual  CreaBve  commons  4.0    

   

(cc)  2014  José  Pujol  Pérez  Some  rights  reserved.  This  work  licensed  under  CreaBve  Commons  AOribuBon-­‐ShareAlike  License.  To  view  a  copy  of  full  license,  see                  

hOp://creaBvecommons.org/licenses/by-­‐sa/3.0/  or  write  to  CreaBve  Commons,  559  Nathan  AbboO  Way,  Stanford,  California  94305,  USA.    

Some  of  the  figures  have  been  taken  from  the  Internet  Source,  and  author  and  licence  if  known,  is  specified.    

For  those  images,  fair  use  applies.    

 

licencia