sábado, 12 de noviembre de 2016

LABORATORIO #8

DESCRIPCIÓN

Mostrar En Una Interfaz de Procesamiento La Temperatura y Humedad ( DTH11 ), y El Nivel de Iluminación capturado con Una  fotoresistencia  (LDR, CdS): Medidas de las Naciones Unidas Través de la Unidad ONU Arduino.

MATERIALES DEL LABORATORIO 

-  Computador con placa el IDE de Arduino y el Controlador de Nuestra
- Arduino Uno
- Placa protoboard
- Fotoresistencia (LDR)
- Resistencia 10K Ω
- Cables Macho - Macho
- Sensor DHT11


DIAGRAMAS


FOTOS MATERIALES Y MONTAJE














CÓDIGO

ARDUINO
  1. /*
  2. ********** Arduino **********
  3. */
  4. #include <dht.h>
  5. #define dht_apin A0
  6. dht DHT;
  7. int pinLDR = A1;
  8. int valorLDR = 0;  
  9. void setup(){
  10.   Serial.begin(9600);
  11. }
  12. void loop(){
  13.   valorLDR= analogRead(A1);
  14.   DHT.read11(dht_apin);
  15.   Serial.print(DHT.temperature);
  16.   Serial.print(".");
  17.   Serial.print(DHT.humidity);
  18.   Serial.print(".");
  19.   Serial.println(valorLDR);
  20.   delay(1000);
  21. }


PROCESSING


  1. /*
  2. ********** Processing **********
  3.  * Laboratorio 08
  4.  * 
  5. */
  6. import processing.serial.*;
  7. Serial myPort;
  8. String sensorReading="0.0.0.0.0";
  9. PImage fondo;
  10. void setup() {
  11.   size(600, 600);
  12.   fondo = loadImage("fondo.jpg");
  13.   String portName = Serial.list()[0];
  14.   myPort = new Serial(this, portName, 9200);
  15.   myPort.bufferUntil('\n');
  16. }
  17. void draw() {
  18.   background(255);
  19.   image(fondo, 0, 0);
  20.   int sensors[] = int(split(sensorReading, '.'));
  21.   drawTemp(sensors[0]);
  22.   drawHumedad(sensors[2]);
  23.   drawIluminacion(sensors[4]);
  24.   fill(0);
  25.   textSize(14);
  26.   text("Sistema de medición", 10, 500);
  27.   println("Temperatura: "+sensors[0]+" - Humedad: "+sensors[2]+" - Iluminación: "+sensors[4]);
  28. }
  29. void drawTemp(int temp){
  30.   // la temperatura va de -40º a 50º centigrados
  31.   int altura = (int) map(temp, -40, 50, 0, -295);
  32.   stroke(255, 0, 0);
  33.   fill(255, 0, 0);
  34.   rect(83, 400, 8, altura);
  35. }
  36. void drawHumedad(int hum){
  37.   int cx = 323, cy = 146, radio = 100;
  38.   // la humedad va de 0% a 100%
  39.   float angulo = map(hum, 0, 100, -240, 60) * (PI/180);
  40.   stroke(250,48,48);
  41.   strokeWeight(4);
  42.   line(cx, cy, cx + cos(angulo) * radio, cy + sin(angulo) * radio);
  43. }
  44. void drawIluminacion(int ilum){
  45.   int cx = 323, cy = 475, radio = 130;
  46.   // la potencia de la luz va de 0 a 100 en una escala de 10x
  47.   float angulo = map(ilum/10, 0, 200, -140, 60) * (PI/180);
  48.   stroke(250,48,48);
  49.   strokeWeight(4);
  50.   line(cx, cy, cx + cos(angulo) * radio, cy + sin(angulo) * radio);
  51. }
  52. void serialEvent (Serial myPort){
  53.   sensorReading = myPort.readStringUntil('\n');
  54.   if(sensorReading != null){
  55.     sensorReading=trim(sensorReading);
  56.   }
  57. }

No hay comentarios.:

Publicar un comentario