Hello all.
I have a 433 MHz ASK-based receiver that uses the RadioHead library that receives telemetry from a DHT-11 sensor and I'm trying to get an LED to turn/off at at a given arbitrary value. (When it gets cold outside)
I'm a noob but I'm using friggin' code tags.
/*
433 MHz RF Module Receiver Demonstration 2
RF-Rcv-Demo-2.ino
Demonstrates 433 MHz RF Receiver Module with DHT-22 Sensor
Use with Transmitter Demonstration 2
DroneBot Workshop 2018
https://dronebotworkshop.com
*/
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define LED_PERFECT 2 // LED output Pin 2
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define output strings
String str_humid;
String str_temp;
String str_out;
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
Serial.begin(9600);
// initialize the LCD
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
// use Arduino pins
pinMode(2, OUTPUT);// set pin 2 as output
}
void loop()
{
delay(100); // needed?
// Set buffer to size of expected message
uint8_t buf[11];
uint8_t buflen = sizeof(buf);
// Check if received packet is correct size
if (rf_driver.recv(buf, &buflen))
{
// Message received with valid checksum
// Get values from string
// Convert received data into string
str_out = String((char*)buf);
// Split string into two values
for (int i = 0; i < str_out.length(); i++) {
if (str_out.substring(i, i+1) == ",") {
str_humid = str_out.substring(0, i);
str_temp = str_out.substring(i+1);
break;
}
}
// Print values to Serial Monitor
Serial.print("Humidity: ");
Serial.print(str_humid);
Serial.print(" - Temperature: ");
Serial.println(str_temp);
// Print values to LCD
lcd.setCursor(3,0);
lcd.print("Humidity: ");
lcd.print(str_humid);
lcd.setCursor(1,1);
lcd.print("Temperature: ");
lcd.print(str_temp);
// if temperature goes below 80, turn the LED OFF
if(str_temp.read)() < 80.0 ){
digitalWrite(2, LOW);// set pin 10 LOW
}else{
digitalWrite(2, HIGH);// set pin 10 HIGH
}
}
delay(1000);
}
Feel free to tell me what I'm doing wrong.
I'm a noob, that's why I'm here.