security system (not responding after combining ultrasonic sensor code and esp8266 code )

The base of this project is https://www.instructables.com/id/SIMPLE-ARDUINO-ULTRASONIC-SENSOR-DOOR-ALARM-/
&http://randomnerdtutorials.com/door-status-monitor-using-the-esp8266/


I changed according to my uses from above links

I tryed by dividing into two parts one for ultrasonic sensor and other for esp8266 they worked fine while separating

ultrasonic and buzzer are working in (Tools <board<Arduino/Generic uno)
and wifi module is working in onlt(Tools <board<(any esp8266 in down column)
when i mix ultrasonic and buzzer nothing happening)
any idea


here is the code


#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial


#define trigPin 9
#define echoPin 10
#define piezoPin 8
ESP8266WiFiMulti WiFiMulti;
int normalDistance;
boolean triggered = false;

long duration, distance;

void setup() {
  USE_SERIAL.begin(115200);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(piezoPin, OUTPUT);

  long duration, distance;

while (millis() < 5000) {
  digitalWrite(piezoPin, HIGH);
      digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance= duration*0.034/2;
        normalDistance = distance;
     
USE_SERIAL.print("Distance: ");
USE_SERIAL.println(distance);
    
   digitalWrite(piezoPin, LOW);
   for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
}
WiFiMulti.addAP("username", "pass");
}
}
void loop() {

digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance= duration*0.034/2;

USE_SERIAL.print("Distance: ");
USE_SERIAL.println(distance);
if (distance < normalDistance-5) {
      triggered = true;
    }
    else {
        triggered = false;
    }
    if (triggered) {
    tone(piezoPin, 635);
    delay(500);
    tone(piezoPin, 912);
    delay(250);
    if((WiFiMulti.run() == WL_CONNECTED)) {
        HTTPClient http;

        USE_SERIAL.print("[HTTP] begin...\n");
       
        http.begin("iftt link.........................."); //HTTP

        USE_SERIAL.print("[HTTP] GET...\n");
        // start connection and send HTTP header
        int httpCode = http.GET();

        // httpCode will be negative on error
        if(httpCode > 0) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == HTTP_CODE_OK) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }

        http.end();
    }
    }
}

any idea about whats going on

Thanks

Hemanth

sort by: active | newest | oldest
1-10 of 18Next »
msuzuki7778 months ago

Which version of ESP8266 are you using? I don't believe any of them support 9, 10 and 8 as digital pins. I think they're usually connected to flash memory in the ESP8266 board.

https://github.com/esp8266/Arduino/blob/master/doc...

LOG

hemanth kumar reddy (author)  msuzuki7778 months ago
Can we use ultrasonic header files so that i can use directly
http://www.ardublog.com/library-for-arduino-ultrasonic-ranging-hc-sr04/
Like in that link

I could access the link but if you are using a UNO, it should work okay.

LOG

hemanth kumar reddy (author)  msuzuki7778 months ago

OK IF U FIND HOW TO ACCESS HTTP KINK WITH AT COMMANDS PLZ

LET ME KNOW I WILL TRY ANOTHER METHOD IN CODING BY HEADER FILES

THANKS

hemanth kumar reddy (author)  msuzuki7778 months ago

esp8266 (01)

ya esp is not connect to digital pin

my connection are

GND----GND

GPI0----GND

VCC------3.3V

RX-----RX

TX------TX

CH_PD------3.3V

When you are using these:

#include <ESP8266WiFi.h>

#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

then the Arduino environment will look for an ESP8266 as the only microcontroller. The ESP8266 does have digital pins called GPIO pins. So when your code includes these lines:

#define trigPin 9

#define echoPin 10

#define piezoPin 8

it is talking about digital pins on the ESP8266. I think the only permitted digital pins are 0,2,12,13,14,15,18.

I think what you are trying to do is connect a regular Arduino with an ESP8266. This code will not do that. Look at the following for a way to do that:

https://www.instructables.com/id/Wireless-Temperat...

The other alternative would be to connect the ultrasonic sensor directly to the ESP8266 and not use a regular Arduino. If you have an ESP-01, this would be hard to do.

Hope this helps.

LOG

hemanth kumar reddy (author)  msuzuki7778 months ago

I AM USING URDINO UNO

what can i do now is there no way to make it work with this setup

With an Arduino UNO you can hook up the ultrasonic and buzzer as in the Instructable you found. The you would have to hook up the ESP8266 serially like that example:

https://www.instructables.com/id/Wireless-Temperat...

then you would have to write code for the UNO to send 'AT' commands to the ESP8266 to do the WiFi stuff. I don't know how to do that. You would have to figure that out for yourself or see if you can find some examples on the Internet.

LOG

hemanth kumar reddy (author)  msuzuki7778 months ago

Thanks for your help and i will try your idea if find anything feel free to let me know

Thanks

hemanth kumar reddy (author)  msuzuki7778 months ago

)The other alternative would be to connect the ultrasonic sensor directly to the ESP8266 and not use a regular Arduino. If you have an ESP-01, this would be hard to do.)

whats that means

Thanks for ur help

1-10 of 18Next »