anti-theft system

hello, I’m trying to create an anti-theft system, I use a Pir sensor for motion detection and a esp8266 to send a variable (1 or 0) to a local server with tcp protocol and at command . when I turn on the arduino it sends a 0 (no movement) but after it sends only 1 (there is a movement),
she doesn’t return to the initial state.
I tested the sensor alone, it works very well .
Any help please ?

#include<SoftwareSerial.h>
SoftwareSerial Serial1(1,0); //RX, TX
#define DEBUG true
void setup() {
    Serial1.begin(115200);
      

      
    
    pinMode(2, INPUT);
    pinMode(8, OUTPUT);
 
  
  
  }

  void loop(void) {

    if(digitalRead(2) == HIGH)
        {
              tone(8, 50);
                 
                Serial.println("hight");
           send(1); 
       
        }
    else
      {        
        noTone(8);
                      Serial.println("low"); 
                send(0);
               
      }
 
}

void send(int val)
{
  
  String rest1 = "AT+CIPMUX=1";
  rest1 += "\r\n";
  sendData(rest1, 2000, 0);

  
  char inv = '"';
  String add = "AT+CIPSTART";
  add += "=1,";
  add += inv;
  add += "TCP";
  add += inv;
  add += ",";
  add += inv;
  add += "192.168.46.102";  // Host_server_name
  add += inv;
  add += ",";
  add += "80";
  add += "\r\n";
  sendData(add, 3000, 0);  // Establishing a TCP Connection. ( AT+CIPSTART = "TCP","Host_server_name",80 )

  String rest = "AT+CIPSEND=1,87";
  rest += "\r\n";
  sendData(rest, 2000, 0); //Number of characters to send. ( "AT+CIPSEND=90" )


  String hostt = "GET /sp_notification/upload.php?value=";
  hostt += val;
  hostt +=" HTTP/1.1";
  hostt += "\r\n";
  hostt += "HOST:192.168.46.102";
  hostt += "\r\n\r\n\r\n\r\n\r\n";
  String views = sendData(hostt, 2000, 0);  // GET request ( GET /apps/thinghttp/send_request?api_key=XXXXXXXXXXXXXXXX 
                                            //               Host: Host_server_name ) 
}

String sendData(String command, const int Goldout, boolean debug)
{
  String response = "";

  Serial1.print(command); // send the read character to the Serial1

  long int Gold = millis();

  while ( (Gold + Goldout) > millis())
  {
    while (Serial1.available())
    {

      // The esp has data so display its output to the serial window
      char c = Serial1.read(); // read the next character.
      response += c;
    }
  }

  if (debug)
  {
    Serial.print(response);
  }

  return response;
}

sketch_aug09a.ino (2.1 KB)

Please post your code.

already posted

Read the forum guidelines !!!!! , you need to post your code correctly as people don’t want to download and have to open it in the IDE with all that involves . Those on mobile phones are unable to see it , hence the guidelines, which you should read before using any forum !

Clue “ code tags”

ok bro

noTone(8); <<< There is your issue by not using code tags.

You are indicating that once this condition is met if(digitalRead(2) == HIGH), that pin 2 does not go low again? If that's the case then the PIR could be at fault for not detecting a no thing.

You seem to be using SoftwareSerial on what would normally be the hardware Serial pins (0,1). And in your code you use both Serial and Serial1 but I can't see any begin() for one of them.

Steve

The pir automatically changes state
why am I going to use begin() ?

IZMA_22:
why am I going to use begin() ?

The usual reason - to initialise the serial port.

IZMA_22:
The pir automatically changes state

How have you proven that the PIR is not holding pin 2 high?

Also what voltage is the PIR sending to the 8266? You do know that the ESP8266 is NOT 5V tolerant? If you have put more than 3.3V on pin2, it's fried and could have damaged the I/O pin matrix.

Also pin 2 and GPIO2 on the ESP's are not the same pins.

pin 2, 8266, is the LNA signal, antenna. Pin 14 is GPIO2.

i already did ,check the code Serial1.begin(115200);
1- the buzzer didn"t run so that s how i proved that the pin 2 is not high
2- i used 5v for the PIR
3 - Also pin 2 and GPIO2 on the ESP's are not the same pins.

pin 2 is the LNA signal, antenna. Pin 14 is GPIO2.
i didn"t understand what do u mean by that. (i just start using arduino ^^')

You called begin on the Serial1 object, but not the Serial object - check the code.

what will be changed if i do that serial.begin(115200) ?

Your Serial.prints will work, hopefully.

IZMA_22:
1- the buzzer didn"t run so that s how i proved that the pin 2 is not high
2- i used 5v for the PIR
3 - Also pin 2 and GPIO2 on the ESP’s are not the same pins.

pin 2 is the LNA signal, antenna. Pin 14 is GPIO2.
i didn"t understand what do u mean by that. (i just start using arduino ^^’)

So the PIR sent / put 5V to the non-5V tolerant GPIO pin on the 8266; that’s a problem.

Look at the schematic for a ESP8266.

should i make serial.begin(115200) or serial.begin(9600) ??
because when i have maked serial.begin(115200) he didn"t send anything he just say high

First, I'd work on making sure the 8266 is not getting 5V from the PIR sensor.

How i can make sure that esp8266 is not getting 5v from the PIR

IZMA_22:
How i can make sure that esp8266 is not getting 5v from the PIR

A level shifter. If you can solder and will only need our or two you can make them, otherwise use a discrete component. Do internet search on 'level shifter'.

If your 8266 has received 5V onto a 3.3V pin, consider the 8266 defective.