You got the ESP8266 wifi module but have absolutely no idea how to make it work or what to do with it. Don't worry, I was there and once again made it out with the forbidden tricks but chill out my bros, this one post is all you need to properly get started on IoT and be able to use your wifi module to connect to a wifi network.
(Check out this blog for more advance projects on ESP8266).
I'll get straight to the meat of it - If you ever wished to connect your project to your wifi or to the internet and control things - servos, leds, entire projects etc. That's where the ESP8266 brings the party.( drinking is not cool kids )
This Wifi module is very similar to your HC-05 bluetooth modules except somebody decided to make it very hard to use, at least to a beginner. It took me on - off a month to finally get the hang of it but chill out my bros you don't have to. You came to the one stop destination, where I give you nothing but only the necessary morsels of information to make the darn thing work as fast as possible.
Okay I assume you've just bought the ESP8266 ( just the module ), it's arrived but now what. Here's what, if you don't have these things buy them :
1. 1k ohm Resistors - 3
2. Breadboard Power Supply module - optional but makes life very easy
3. Install the ESP8266 serial library to your IDE.
Now, check if you have these things or get them too.
1. Arduino UNO2. Breadboard3. Male to Male Jumpers4. Female to Male jumpers5. Patience...
Out of the box, your wifi module needs to be configured to communicate with the Ardiuno.Use the Circuit Diagram given below to set up the system.
IMPORTANT - DON'T POWER THE ESP8266 USING THE ARDUINO'S 5V PIN. USE IT'S 3.3V PIN OR BETTER USE A BREADBOARD POWER SUPPLY. BE CAREFUL WITH THE CONNECTIONS.
*seems there's a confusion over the fritzing image
5V Power rail could go to Vin on the arduino.
Once it's all connected, switch on the power supply and upload the following code to your Arduino
...........................................................................................................................................
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX
void setup()
{
Serial.begin(115200); // communication with the host computer
//while (!Serial) { ; }
// Start the software serial for communication with the ESP8266
ESPserial.begin(115200);
Serial.println("");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("Ready");
Serial.println("");
}
void loop()
{
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }
// listen for user input and send it to the ESP8266
if ( Serial.available() ) { ESPserial.write( Serial.read() ); }
}
...........................................................................................................................................
After you've uploaded the code, open the Serial monitor and type in
ATand hit enter. See below
If you get an OK awesome, we're talking with the ESP8266.
Now we'll send a series of commands to change the wifi module's baud rate from 115200 ( too fast ) to 9600.
Send this command
AT+UART_DEF=9600, 8, 1, 0, 0If you get back an OK awesome again, we have changed the modules' baud rate to 9600. If you try giving it any commands it shouldn't work as intended.
Close the serial monitor and change this in the code
Change 115200 to 9600 in both the places.Upload the code.
We changed the baud rate and now we'll try connect to a network.Open the serial monitor and send the command
ATIf it looks like this after sending the command. cool
Now, send this command to set the module on mode 1 -
AT+CWMODE=1The result should look like this.
Get an OK cool!
Dessert Time - We'll search for nearby Wifi networks by sending this command -
AT+CWLAPThe monitor should show you the networks like this.
As an example, let's try connecting to Liberty MediaSend the command -
AT+CWJAP="Liberty Media", "nlj-hyiyk187"As understood just replace Liberty Media with your wifi's name and nlj..... with your password.:)
If you get WIFI CONNECTED and WIFI GOT IP. Damn kid you did it We connected !!To know the IP address send in this command -
AT+CIFSRAnd that's your IP address. Congratulations you've just opened up to an exciting field in robotics - IoT ( Internet of things)
Next post, we'll learn how to control a servo using an ESP8266 and an arduino through a webpage So stay connected ! Go to virginrobotics.blogspot.com for more of these projects.
Comments
Please log in or sign up to comment.