ESP 8266 Issues

Hi
I am a newbie to Arduino. I am working on a simple project using ESP8266 ESP01 to connect WIFI and send commands from phone to Arduino Board. I am able to get the AT commands working from the Serial Monitor but when I try to Send the AT commands from Code using SoftwareSerial, its not working. I am using SoftwareSerial wifi(2,3) and my ESP Tx is connected to 0 (Rx) of Arudino and ESP Rx is connected to Pin 1(Tx) on Arduino . When I send the command from inside the Setup() or Loop() I am not getting any response.

My Second question is whenever I reboot Arduino Board or Try to upload a new sketch my Home router automatically reboot and all other devices connected to the router get disconnected.

Can you please help me in figuring out the issue.

I am using Arduino UNO with ESP 8266 ESP 01 and AMS 1117 Voltage Regulator to convert the Arduino 5v to 3.3 V.

VCC, RST and CH_PD connected to 3.3 V
GPIO0 and GPIO2 - Open
GND to GND of AMS1117 which is connected to Ground of Arduino
RXD to Tx of Arduino
TXD to Rx of Arduino.

Thank You

I am using SoftwareSerial wifi(2,3) and my ESP Tx is connected to 0 (Rx) of Arudino and ESP Rx is connected to Pin 1(Tx) on Arduino .

You are using SoftwareSerial on pins 2 and 3 to talk to the ESP that is connected to pins 0 and 1? How's that working for you?

Never mind, I read further... 8)

Thank you for the response. I tried setting both 0,1 and 2,3 but it is not working on either.
Its works fine from Serial Monitor or Putty but not from the code.
I am using 115200 as baudrate.

Please suggest me what I am doing wrong.

thanks

I tried setting both 0,1 and 2,3 but it is not working on either.

I don't understand this. Did you try connecting the RX pin from the ESP to pin 2, with the TX pin connected to pin 3?

If you tried changing the SoftwareSerial instance to use pins 0 and 1, I can see why that didn't work.

Yes I tried changing the Software Serial to 0,1 but no luck.

I read somewhere that Software Serial Library consider 2,3 as Tx and Rx of Arduino that's why I was trying like that but that was also not working.

I also tried connecting the ESP Tx and Rx to Pin 2 and 3 of my UNO Board but that did not work either.

Tx of arduino is 5v, rx of esp is 3.3v.
Post the code, if you send the commands via serial message, you have to write '/r' for return carriage.

I also tried a voltage divider circuit (using 3 x 10k Resistors in series) but that did not work either.
Here is my code.

#include <SoftwareSerial.h>

#define DEBUG true

SoftwareSerial esp8266(2,3); 

void setup()
{
 Serial.begin(115200);
 esp8266.begin(115200);
 
 sendData("AT+RST\r\n",2000,DEBUG); // reset module
 sendData("AT+CWMODE=2\r\n",1000,DEBUG); // configure as access point
 sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
 sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
 sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
}

void loop()
{
 if(esp8266.available())  
 {

  while(esp8266.available())
     {
       char c = esp8266.read(); 
       response+=c;
     }  

    Serial.print(response);

 }
}


String sendData(String command, const int timeout, boolean debug)
{
   String response = "";
   
   esp8266.print(command); 
   
   long int time = millis();
   
     if(esp8266.available())  
     {
        while(esp8266.available())
       {
         char c = esp8266.read(); 
         response+=c;
       }  
     Serial.print(response);
     }
   
   return response;
}

Right, first things first.

Go and read the instructions, then go back and modify your post (use the "More --> Modify" option to the bottom right of the post) to mark up the code as such so we can examine it conveniently and accurately.

Albeit it is not too complex at present, but it may well get more so.

Note: Also mark up any data in the same way. This includes error output that you get from the IDE.

Try without the new line '/n' syntax.

Yes I tried changing the Software Serial to 0,1 but no luck.

Is there some part of "You can't do SoftwareSerial on the hardware serial pins while doing hardware serial on the hardware serial pins" that you think doesn't apply to you?

I'm curious as to what point you tried using the voltage divider for level conversion? If you did it after the 5 volt TTL didn't work, likely it didn't work after because you damaged the ESP8266.

Or - you may have a bad ESP8266? Have you tried using a 3.3 volt FTDI to USB adaptor, and getting the ESP8266 working standalone with your PC? In other words - take the Arduino out of the equation...

Lastly - when you use a voltage divider as a level converter, you will be limited in your baud rate, so don't try to go much beyond 9600 baud.

Note also that the ESP8266 - depending on the firmware installed - may have any number of different values for it's default baud rate. So, you need to find this out, and if needed, reset the baud rate to 9600 baud. Then use your voltage divider and such, and set the baud on the Arduino at 9600 too. You will also likely need to use the hardware serial port on the Arduino with the ESP8266; I have read that it doesn't work well with the standard Software Serial library because of the lack of buffering (though I wonder if maybe there is another library that can help - or perhaps if you lowered the baud rate to something stupid slow, it might work OK).

Thank you everyone.
I was able to fix the issue by lowering the baudrate to 9600.

Can you please tell me whats the reason for my other issue: Whenever I reset the arduino board my home router also restarts and disconnect all other devices.

thanks