Hello there, i need an urgent help
I'm trying to pass dht11 readings through IR transmitter KY-005 and IR receiver KY-022
The problem is that i can't realize to a solution for that
I want only to send a 2 digit number through IR, although the connection works properly but the results are completely not as the reading on the first arduino (real value reading) is completely different from the result printed after the transmission ( only random numbers)
Any help please?
Are you sure they are random numbers? Could you at least share a wiring diagram and transmit and receive programs as well as what Arduino you are using would help us try to help you.
Continuing the discussion from Sending dht11 through IR:
Yes well im using Arduino uno for receiving and teensy 3.2 microcontroller and whatever the protocol im using i can't figure out a way to recalibrate or decode the original signal im sending and those sequences of numbers that i get they are not fixed, i mean they are variable sequences of numbers
the part of the code responsible of sending data is the following
void sendTemperatureIR(int temperature) {
irsend.sendRC5(temperature, 12);
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
the code of receiving
IRrecv irrecv(irReceiverPin);
int receivedTemperature = 0;
irrecv.enableIRIn(); //in void setup
if (IrReceiver.decode(&results)) {
receivedTemperature = results.value & 0xFFF;
Serial.print("Received Temperature: ");
Serial.println(receivedTemperature);
irrecv.resume();
So that we can better understand your project and its difficulties, post the complete codes for both the transmitter and receiver
Remembering that this KY-022 sensor only identifies transmissions with 38 KHz modulation.
transmission code
#include "DHT.h"
#include <Wire.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <CRC32.h>
#define DHT11_PIN A1 // pin connected to the DHT11 sensor
#define DHTTYPE DHT11 // DHT11 sensor type
#define irLedPin 13 // pin connected to IR LED
#define slave_address 9 // I2C slave address
CRC32 crc;
DHT dht(DHT11_PIN, DHTTYPE);
IRsend irsend;
int counter = 0;
void setup() {
dht.begin();
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(6, INPUT); // Setup for leads off detection LO +
pinMode(2, INPUT); // Setup for leads off detection LO -
pinMode(irLedPin, OUTPUT);
Wire.begin(); // Initialize I2C communication
}
void loop() {
int sensorValue = analogRead(A0); // Read the sensor value
delay(1);
counter++;
if (counter == 5000) {
int temperature = dht.readTemperature();
if (!isnan(temperature)) {
sendTemperatureIR(temperature);
Serial.print("Temperatura: ");
Serial.println(temperature);
}
float humidity = dht.readHumidity();
if (!isnan(humidity)) {
senddataI2C(humidity,temperature);
}
counter = 0;
}
}
void sendTemperatureIR(int temperature) {
// Convert temperature to a 16-bit value (0x0000 to 0xFFFF)
unsigned int tempValue = map(temperature, 0, 100, 0, 0xFFFF);
// Calculate CRC32 checksum for temperature value
crc.reset();
crc.update((uint8_t *)&tempValue, sizeof(tempValue));
uint32_t checksum = crc.finalize();
// Send temperature data along with CRC32 checksum using Sony IR protocol
irsend.sendSony(tempValue, 16);
delay(50); // Add a small delay between transmission of temperature and checksum
irsend.sendSony(checksum, 32);
// Blink LED to indicate transmission
digitalWrite(LED_BUILTIN, HIGH);
delay(100); // Blink duration
digitalWrite(LED_BUILTIN, LOW);
}
void senddataI2C(float humidity,int temp) {
int humidityInt = static_cast<int>(humidity);
Wire.beginTransmission(slave_address);
Wire.write("Umidita=");
Wire.write(String(humidityInt).c_str());//per convertire il valore in una stringa
Wire.write("\n");
Wire.write("Temperatura=");
Wire.write(String(temp).c_str());
Wire.endTransmission();
}
receiving code
#include <Wire.h>
#include <IRremote.h>
#define irReceiverPin 13 // Pin connected to IR receiver
IRrecv irrecv(irReceiverPin);
decode_results results;
int slave_address=9;
int receivedTemperature = 0;
int receivedTemperature1 = 0;
void servizio(int a){
String dataReceived = "";
while(Wire.available()){
char c = Wire.read();
dataReceived += c;
}
Serial.println(dataReceived);
receivedTemperature = dataReceived.toInt();
}
void receiveIR() {
if (irrecv.decode(&results)) {
receivedTemperature1 = results.value;
Serial.print("Received Temperature (Hex): 0x");
Serial.println(receivedTemperature1, HEX); // Print received value in hexadecimal format
irrecv.resume(); // Receive the next value
}
void setup() {
Wire.begin(slave_address); // Join I2C bus with address 9
Serial.begin(9600);
irrecv.enableIRIn();
Wire.onReceive(servizio);
}
void loop() {
receiveIR();
delay(1000);
}
Have a close look at the parameters of the send function and you will see your error!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.