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 816 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