Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIR Sensor A6
#1
Hello, everyone!
I'm relatively new to using the models here, so I have a few questions:
I’m trying to connect some sensors for testing. The only one I’ve successfully used is the DHT22, and now I’m attempting to get the PIR Sensor (the cheap ones) to work, but I haven’t been able to do so. Do you know if there’s anything specific regarding the setup, or is it just how the sensor operates?
Regarding the setup, I powered the PIR using both the 12V input of the A6 (the sensor operates from 5V to 20V) and an external power supply. I can see a reading of P0 indicating it’s connected to P0 or P1, P2... Pn. However, when I try to display the data obtained from the sensor, it doesn’t print in the Arduino IDE Serial monitor.
Do you know if these sensors work with the A6? I’m looking to use basic components for future automation projects.
Thank you all!


Here is my code:

#include <Wire.h>
#include "PCF8574.h"

#define SDA 4
#define SCL 15
#define PIR_SENSOR_PIN P0  // P0 pin on PCF8574 for the PIR sensor

PCF8574 pcf8574(0x22, SDA, SCL);  // I2C address 0x22, SDA GPIO4, SCL GPIO15

unsigned long timeElapsed;  // Variable to measure time
int warm_up = 1;  // Variable to control PIR warm-up

void setup() {
  Serial.begin(115200);  // Initialize serial communication
  Serial.println(__FILE__);
  delay(2000);

  Serial.println("System ready!");
  delay(2000);

  pcf8574.pinMode(PIR_SENSOR_PIN, INPUT);  // Set P0 pin as input for the PIR
  Serial.println("Init pcf8574...");
  if (pcf8574.begin()){
      Serial.println("OK");
  } else {
      Serial.println("KO");
  }
}

void loop() {
  // Read the value of the PIR connected to P0 of the PCF8574
  uint8_t sensor_output = pcf8574.digitalRead(PIR_SENSOR_PIN);

  // Check if the PIR detected motion
  if (sensor_output == LOW) {
    Serial.println("PIR ACTIVATED (Nothing detected)");
  } else {
    Serial.println("PIR DETECTED (Motion)");
  }

  delay(200);  // Delay to avoid excessive readings
}
Reply
#2
PIR is binary sensor, so you can connect with digital input port of KC868-A6.
here is a demo code for monitor digital input ports: https://www.kincony.com/forum/showthread.php?tid=1865
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)