QuestionsCategory: General QuestionESP8266 01 does not start when connected to ultrasonic
Hammas Majeed asked 1 month ago

https://drive.google.com/drive/folders/1rpjpHniTR330F0D3m1lxA5SzcaypDreM?usp=sharing I have this schematic and the code. When I connect the male to male usb cable to both ends then power the system up. The blue LED turn on and ESP8266-01 does not appear on the browser by 192.168.8.160/distance. When I disconnect the cable from any side then power the system up, ESP8266-01 turns on normally, appears in the browser with IP, then I connect the cable to ultrasonic, everything is fine, I can see the readings on browser.The problem is I must connect both ends of cable on start, ESP8266-01 does not response, Kindly help me. I don’t understand.. what is wrong.  ?

#include
// trig = 0 //
// echo = 2 //

int waterLevel = 0;
int duration = 0;
int distance_cm = 0;

IPAddress IP(192, 168, 8, 160);
IPAddress Gateway(192, 168, 8, 1);
IPAddress Subnet(255, 255, 255, 0);
char ssid[] = "mySSID";
char pass[] = "myPassword";
ESP8266WebServer server(80);

void setup() {
pinMode(0, OUTPUT);
pinMode(2, INPUT);
Serial.begin(9600);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
Serial.println(".");
delay(500);
}
Serial.println(WiFi.localIP());
WiFi.config(IP, Gateway, Subnet);
Serial.println(WiFi.localIP());
server.on("/distance", []() {
server.send(200, "text/html", String(waterLevel));
});
server.begin();
}
void loop () {
waterLevelCal();
server.handleClient();
}
void waterLevelCal() {
digitalWrite(0, LOW);
delayMicroseconds(2);
digitalWrite(0, HIGH);
delayMicroseconds(10);
digitalWrite(0, LOW);
duration = pulseIn(2, HIGH);
distance_cm = duration * 0.034 / 2;
waterLevel = distance_cm;
delay(2000);
}

Captcha loading...

Your Answer

10 + 7 =