Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Motion sensor with esp01

MuhammadAnas25

Newbie level 5
Joined
Jun 21, 2023
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
51
Hello Helpers,

I need some help I have an Rcwl-0516 microwave sensor and an esp01 project basically I made a code but it's not working properly I wanted to make any logic like that if the person enters the room the device detects the person and turns on the Air conditioner using IR command and when a person leaves the room then it ac should be turn off but from my code it on the ac and turn off the ac but when the person in the room it automatically turn off the ac can you check my code or give any recommendation?
 
ok I share my code
Code:
//Libraries
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiManager.h>
WiFiManager wm;
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define WEBSERVER_H
 #include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>

AsyncWebServer server(80);
HTTPClient http;
//Variables
char msg[50];

WiFiClient wifiClient;
const uint16_t kIrLed = 4;
const int motionSensorPin = 5;
bool motionDetected = false;
// Timer configuration
const unsigned long lightTimeout = 300000;  // Time in milliseconds to turn off lights after inactivity
unsigned long lastMotionTime = 0;
String IP;

#define DHT_PIN 0
IRsend irsend(kIrLed);
const unsigned long eventInterval1 = 10000;
unsigned long previousTime1 = 0;
// const unsigned long eventInterval = 60000;
// unsigned long previousTime = 0;

uint16_t rawDataon[229] = {3050,3000,3050,4350,550,1650,550,500,600,1600,600,500,550,550,550,1600,600,1600,600,500,550,550,550,500,600,500,550,550,550,500,600,1600,600,1600,550,550,550,550,550,500,550,550,550,550,550,500,600,500,550,1650,550,550,550,500,550,550,550,550,550,550,550,500,550,550,550,550,550,500,600,500,550,1650,550,550,550,1600,600,500,550,550,550,550,550,500,550,550,550,550,550,1650,550,500,550,550,550,550,550,550,550,500,550,550,550,550,550,500,600,1600,550,1650,550,1650,550,1650,550,500,550,550,550,550,550,1650,550,500,550,550,550,550,550,500,600,500,550,550,550,550,550,500,550,1650,550,1650,550,1650,550,1650,550,500,550,550,550,550,550,500,600,500,550,550,550,550,550,500,550,550,550,550,550,550,550,500,550,550,550,550,550,500,600,500,550,550,550,550,550,500,550,550,550,550,550,550,550,550,500,550,550,550,550,500,600,500,550,550,550,550,550,500,550,550,550,550,550,1650,550,500,550,1650,550,1650,550,1650,550,1650,550,500,550,1650,550,1650,550};
uint16_t rawDataoff[229] = {3100,2950,3100,4350,550,1650,550,500,600,1600,600,500,550,550,550,1600,600,1600,600,500,550,550,550,1650,550,500,600,1600,550,550,550,550,550,1600,600,500,550,550,550,550,550,500,600,1600,600,500,550,1650,550,1650,550,1650,550,500,550,550,550,550,550,550,550,500,550,550,550,550,550,550,550,500,550,550,550,550,550,1650,550,500,550,550,550,550,550,1650,550,500,600,500,550,1650,550,550,550,500,600,500,550,550,550,550,550,500,600,500,550,550,550,1650,550,1650,550,1600,600,1600,550,550,550,550,550,550,550,1600,600,500,550,550,550,550,550,500,550,550,550,550,550,550,550,500,550,1650,550,1650,550,1650,550,1650,550,500,600,500,550,550,550,550,550,500,600,500,550,550,550,550,550,500,600,500,550,550,550,550,550,500,550,550,550,550,550,550,550,500,550,550,550,550,550,550,550,500,550,550,550,550,550,550,550,500,550,550,550,550,550,550,550,500,550,550,550,1650,550,550,550,1650,550,1600,550,550,550,1650,550,550,550,500,600,500,550,550,550,1650,550};
#define DHTTYPE DHT22
DHT dht(DHT_PIN, DHTTYPE);
float targetTemperature = 25.0;

//Start setup
void setup() {
  //  delay(60000);
  irsend.begin();
  Serial.println("All Systems initialize");
#if ESP8266
  Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
#else  // ESP8266
  Serial.begin(115200, SERIAL_8N1);
#endif  // ESP8266
  //  Serial.begin(115200);
    pinMode(motionSensorPin, INPUT);
  bool res;

    res = wm.autoConnect("Motion device 3"); // password protected ap
     if(!res) {
        Serial.println("Failed to connect");
     }
    else {
        //if you get here you have connected to the WiFi   
        Serial.println("connected");
    }
   dht.begin();
    AsyncElegantOTA.begin(&server);    // Start AsyncElegantOTA
  server.begin();
  Serial.println("HTTP server started");
 
}

void loop() {
 
   int motionStatus = digitalRead(motionSensorPin);
    IP=WiFi.localIP().toString();
   float currentTemperature = dht.readTemperature();
   dtostrf(currentTemperature,2,2,msg);
 
   motiondetect(motionSensorPin);
 


}
void motiondetect(int motionPin)
{
  if (digitalRead(motionPin) == HIGH) {
     if (!motionDetected) {
    // Motion detected
    // delay(1000);
    // digitalWrite(lightPin, HIGH);  // Turn on the lights
    lastMotionTime = millis();
     motionDetected = true;
     irsend.sendRaw(rawDataon, 229, 38);
  
    Serial.println("Motion detection");    // Update the last motion detection time
    delay(1000);                   // Delay to avoid multiple rapid triggers
  }
  } if (digitalRead(motionPin) == LOW){
    if(motionDetected){
 
    // No motion detected
    Serial.println("Motion detection time: "+String(lastMotionTime));
    if (millis() - lastMotionTime >= lightTimeout) {
      //  delay(300000);
       irsend.sendRaw(rawDataoff, 229, 38);
 
      motionDetected = false;
      // digitalWrite(lightPin, LOW);  // Turn off the lights after timeout
      Serial.println("nO MOTION");
    }
    }
  }
  }

I just want that when a person enters in the room it triggered the ac on and when he left the room it turn off but in my case, it gets turned off after a specific time I want turn off when the person is not in the room


[ code tags added by moderator ]
 
Last edited by a moderator:
Does your code distinguish approaching versus receding to make the decision ?

Discussion here : https://github.com/jdesbonnet/RCWL-0516

You may ervern want to look into Neural net implementation to create a learning system
to make decision across so many variables and states possible in this application. Videos
on youtube for introduction.


Regards, Dana.
 
Last edited:
Hi,
The Rcwl-0516 microwave sensor, is a motion sensor, not a 'human' presence sensor.
So if the human in the room does not move, the motion sensor output will be inactive.

G
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top