|
| 1 | +#include <SoftwareSerial.h> |
| 2 | + |
| 3 | +SoftwareSerial mySerial(10, 11); //RX,TX |
| 4 | + |
| 5 | +// Arduino pin 10 (RX) to ESP8266 TX |
| 6 | +// Arduino pin 11 to voltage divider then to ESP8266 RX |
| 7 | +// Connect GND from the Arduiono to GND on the ESP8266 |
| 8 | +// Pull ESP8266 CH_PD/EN HIGH |
| 9 | +// |
| 10 | +// When a command is entered in to the serial monitor on the computer |
| 11 | +// the Arduino will relay it to the ESP8266 |
| 12 | +/* |
| 13 | +“AT” This will check if the module is connected properly and its functioning, the module will reply with an acknowledgment. |
| 14 | +“AT+RST” This will reset the wifi module. Its good practice to reset it before or after it has been programmed. |
| 15 | +“AT+GMR” This will mention the firmware version installed on the ESP8266. (Optional) |
| 16 | +“AT+CWLAP” This will detect the Access points and their signal strengths available in the area. |
| 17 | +AT+CWJAP=”SSID”,”PASSWORD” This connects the ESP8266 to the specified SSID in the AT command mentioned in the previous code. |
| 18 | +“AT+CIFSR” This will display the ESP8266’s obtained IP address. If the user wants to disconnect from any access point then use the following AT command AT+CWJAP=””,”” |
| 19 | +“AT+CWMODE=1” This sets the Wifi mode. It should be always set to Mode 1 if the module is going to be used as a node (Like our mobile’s connection to the access points) |
| 20 | +After this step is done, repeat step 2 to reset the Wifi Module. “AT+RST” |
| 21 | +Now you can connect your ESP8266 to the internet and get started with IoT. |
| 22 | +
|
| 23 | + */ |
| 24 | +int LEDPIN = 13; |
| 25 | + |
| 26 | +void setup() |
| 27 | +{ |
| 28 | + pinMode(LEDPIN, OUTPUT); |
| 29 | + |
| 30 | + Serial.begin(9600); // communication with the host computer |
| 31 | + //while (!Serial) { ; } |
| 32 | + |
| 33 | + // Start the software serial for communication with the ESP8266 |
| 34 | + mySerial.begin(115200); |
| 35 | + |
| 36 | + Serial.println(""); |
| 37 | + Serial.println("Remember to to set Both NL & CR in the serial monitor."); |
| 38 | + Serial.println("Ready"); |
| 39 | + Serial.println(""); |
| 40 | +} |
| 41 | + |
| 42 | +void loop() |
| 43 | +{ |
| 44 | + // listen for communication from the ESP8266 and then write it to the serial monitor |
| 45 | + if ( mySerial.available() ) { Serial.write( mySerial.read() ); } |
| 46 | + |
| 47 | + // listen for user input and send it to the ESP8266 |
| 48 | + if ( Serial.available() ) { mySerial.write( Serial.read() ); } |
| 49 | +} |
0 commit comments