maximkulkin / esp-homekit

Apple HomeKit accessory server library for ESP-OPEN-RTOS
MIT License
1.1k stars 168 forks source link

Read HC-SR501- infrared detector module #196

Open mateusmsantin opened 2 years ago

mateusmsantin commented 2 years ago

I used ‘Exemple04_MultipleAccessories’ multiple_accessories.ino example and change to read sensor pin HC-SR501.

// bool m = random_value(0, 10) < 5; 
  bool m = digitalRead(PIN_SENSOR);      
  if(m == HIGH){
       Serial.println( m ? "HIGH" : "LOW");       
   }else {
       Serial.println( m ? "HIGH" : "LOW");
    }
  LOG_D("SENSOR VALUE %u \n", m); //Here I can’t view at serial monitor. I believe it should show similar to the 'simple' example below.

But it is unstable, that is, when the sensor is active it does not show the door reading. When I use the same circuit simply, just to check the reading it works.

simple.ino (just to test)

//faz a leitura do sensor de presença (retorna HIGH ou LOW)
  bool sinal = digitalRead(PIN_SENSOR); 

//HIGH : motion detected
if(sinal == HIGH){      
      Serial.println(sinal ? "HIGH" : "LOW");
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  } else {
    digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
    Serial.println(sinal ? "HIGH" : "LOW");

 }

Thanks in Advanced.

maccoylton commented 2 years ago

Using an interrupt callback works fine for me, example and motion sensor firmware can be found here:- https://github.com/maccoylton/esp-homekit-motion-sensor/tree/master/src

mateusmsantin commented 2 years ago

Hi @maccoylton, thanks for replying. I try to compile the code on the Arduino platform, but I get the error:

ensor_HS501: 16: 10: fatal error: espressif / esp_wifi.h: This file or directory does not exist
     16 | #include <espressif / esp_wifi.h>
        | ^ ~~~~~~~~~~~~~~~~~~~~~~~~
compilation finished.
exit status 1
espressif / esp_wifi.h: This file or directory does not exist

What do you use to compile, please.

maccoylton commented 2 years ago

This is not for use with Arduino, it's normally built from the command line. You need to follow the instructions on esp-homekit to set up your development environment.

mateusmsantin commented 2 years ago

Ok, I will make a configuration environment to compile and test. Is it possible to compile the example with a generic ESP8266, or just with ESP32?

maccoylton commented 2 years ago

This should work with either, although I use ESP8266.

mateusmsantin commented 2 years ago

I’d like to use at Arduino interface, but I stay to try configuring and install environment to compile the example (https://github.com/maccoylton/esp-homekit-motion-sensor/tree/master/src). But I’m don’t have success to do. Can somebody suggest a manual to compile it at Mac Os please ? I saw a lot of examples, but many errors. I believe that I don’t have many concepts.