Go Down

Topic: anti-theft system (Read 434 times) previous topic - next topic

IZMA_22

Aug 27, 2019, 01:00 pm Last Edit: Aug 27, 2019, 04:12 pm by IZMA_22
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 ?
Code: [Select]

#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;
}

   
 

TheMemberFormerlyKnownAsAWOL

Please post your code.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

IZMA_22


hammy

#3
Aug 27, 2019, 03:11 pm Last Edit: Aug 27, 2019, 03:13 pm by hammy
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"

IZMA_22


Idahowalker

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

Idahowalker

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.

slipstick

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

IZMA_22

#8
Aug 27, 2019, 05:14 pm Last Edit: Aug 27, 2019, 05:20 pm by IZMA_22
The pir automatically changes state
why am I going to use begin() ?

TheMemberFormerlyKnownAsAWOL

why am I going to use begin() ?
The usual reason - to initialise the serial port.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

Idahowalker

#10
Aug 27, 2019, 05:28 pm Last Edit: Aug 27, 2019, 05:34 pm by Idahowalker
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.

IZMA_22

#11
Aug 27, 2019, 05:33 pm Last Edit: Aug 27, 2019, 05:38 pm by IZMA_22
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 ^^')

TheMemberFormerlyKnownAsAWOL

You called begin on the Serial1 object, but not the Serial object - check the code.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

IZMA_22

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

TheMemberFormerlyKnownAsAWOL

Your Serial.prints will work, hopefully.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

Go Up