Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Inconsistent Sensor Readings with PIC16F877A and DHT22 (Read 2299 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Inconsistent Sensor Readings with PIC16F877A and DHT22

I'm working on a project with a PIC16F877A microcontroller and a DHT22 sensor, but I'm getting inconsistent readings. Here are the details:

Setup:
Microcontroller: PIC16F877A
Sensor: DHT22
Connections:
VCC to 5V
GND to Ground
Data to RA0 (10k pull-up resistor)
Code:
c

#include <xc.h>
#define _XTAL_FREQ 20000000

// Configurations
#pragma config FOSC = HS, WDTE = OFF, PWRTE = ON, BOREN = ON, LVP = OFF, CPD = OFF, WRT = OFF, CP = OFF

void init() {
    TRISA = 0x01;
    ADCON1 = 0x07;
}

void read_sensor() {
    // Reading logic
}

void main() {
    init();
    while(1) {
        read_sensor();
        __delay_ms(2000);
    }
}
Issue:
Readings fluctuate significantly.
No correlation with actual conditions.
Stable power supply and secure connections.
Help Needed:
Has anyone experienced this? Any advice on resolving these fluctuations?



Moderation: link removed

Re: Inconsistent Sensor Readings with PIC16F877A and DHT22

Reply #1
I just had this problem too. Did you solve it?

 

Re: Inconsistent Sensor Readings with PIC16F877A and DHT22

Reply #2
My (completely uninformed) guess is that the serial read protocol is incorrect so that the output data isn't properly synchronised and gets misinterpreted.  A quick skim of the datasheet leaves many questions unanswered.  This will be hard to solve unless you have an oscilloscope or serial analyser to view the signals and see what's happening (although suitable kit is very cheap these days).  An alternative is to ask the supplier of your DHT22 for support.

This forum does not seem to be the right place for this question, even in "off topic"!  Surely there are maker forums more suitable.
It's your privilege to disagree, but that doesn't make you right and me wrong.