//Transmitter
#include <DHT.h>
#include <Adafruit_BMP085.h>
#include <Wire.h>
#include <VirtualWire.h>
// Definimos el pin digital donde se conecta el sensor
#define DHTPIN 8
// Dependiendo del tipo de sensor
#define DHTTYPE DHT11
// Inicializamos el sensor DHT11
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085 bmp;
const int LDRPin = A0;
const int umbral = 100;
char msg0[3];
char msg1[3];
char msg2[3];
char msg3[3];
char msg4[3];
char msg5[3];
void setup() {
// Inicializamos comunicación serie
Serial.begin(9600);
pinMode(LDRPin, INPUT);
vw_set_tx_pin(12);
vw_setup(2000); // velocidad: Bits per segundo
// Comenzamos el sensor DHT
dht.begin();
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
}
void loop() {
// Esperamos 1 segundos entre medidas
delay(1000);
// Leemos la humedad relativa
float h = dht.readHumidity();
// Leemos la temperatura en grados centígrados (por defecto)
float t = dht.readTemperature();
// Leemos la temperatura en grados Fahreheit
float f = dht.readTemperature(true);
// Comprobamos si ha habido algún error en la lectura
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Error obteniendo los datos del sensor DHT11");
return;
}
// Calcular el índice de calor en Fahreheit
float hif = dht.computeHeatIndex(f, h);
// Calcular el índice de calor en grados centígrados
float hic = dht.computeHeatIndex(t, h, false);
// Leemos la cantidad de luz
int input = analogRead(LDRPin);
itoa(h, msg1, 10); // Converting humidity to an array of chars
itoa(t, msg0, 10); // Converting the temperature to an array of chars
itoa(f, msg2, 10);
itoa(hif, msg3, 10);
itoa(hic, msg4, 10);
itoa(input, msg5, 10);
strcat(msg0, msg1); // Adding/joining the two arrays
strcat(msg3, msg4);
strcat(msg2, msg5);
vw_send((uint8_t *)msg0, strlen(msg0)); // Sending the msg
vw_send((uint8_t *)msg3, strlen(msg3));
vw_send((uint8_t *)msg2, strlen(msg2));
vw_wait_tx(); // Wait for tx to finish
Serial.print("Humedad: ");
Serial.print(h);
Serial.print(" %\t");
Serial.println(" *F");
Serial.print("Temperatura: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.println(" *F");
Serial.print("Indice de calor: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
Serial.print("Presion = ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
// Calculate altitude assuming 'standard' barometric
// pressure of 1013.25 millibar = 101325 Pascal
Serial.print("Altura = ");
Serial.print(bmp.readAltitude());
Serial.println(" metros");
// you can get a more precise measurement of altitude
Serial.print("Altura Real = ");
Serial.print(bmp.readAltitude(101500));
Serial.println(" metros");
Serial.print("El valor de luz es: ");
Serial.print(input);
Serial.println();
delay(500);
}
//Receiver
#include <Wire.h>
#include <LiquidCrystal.h>
#include <VirtualWire.h>
int tem = 0;
int i;
const int rs=13, en=8, d4=5, d5=4, d6=3, d7=2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(9600);
Serial.println("Iniciando...");
lcd.begin(16,2);
lcd.clear();
// Se inicializa el RF
vw_set_rx_pin(11);
vw_setup(2000); // velocidad: Bits per segundo
vw_rx_start(); // Se inicia como receptor
}
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN]; // Variable to hold the received data
uint8_t buflen = VW_MAX_MESSAGE_LEN; // Variable to hold the length of the received data
delay(1000);
lcd.setCursor(0,0);
lcd.print("Temp: ");
if (vw_get_message(buf, &buflen)) // If data is received
{
for (i=0;i<2;i++) // Get the two first bytes
{
Serial.write(buf[i]); // Debugging purpose
lcd.write(buf[i]); // Write the first bytes on the LCD
}
Serial.println(); // Debugging purpose
lcd.write(1); // Write the degree symbol on the LCD
lcd.print(" C");
lcd.setCursor(0,1);
lcd.print("Hum: ");
for (i=2;i<4;i++) // Get the two last bytes
{
Serial.write(buf[i]); // Debugging
lcd.write(buf[i]); // Write the last bytes on the LCD
}
Serial.println();
lcd.print("% RH");
}
}
Solo me imprime el ultimo array, cualquier ayuda se les agradece!