Skip to main content
Arduino

Return to Question

Commonmark migration
Source Link

[![enter image description here][1]][1]enter image description here

Thanks in advance. [1]: https://i.sstatic.net/2ic8q.png

[![enter image description here][1]][1]

Thanks in advance. [1]: https://i.sstatic.net/2ic8q.png

enter image description here

Thanks in advance.

#include <SoftwareSerial.h>
#define DEBUG true
int relay = 8;
SoftwareSerial esp8266(2, 3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
// This means that you need to connect the TX line from the esp to the Arduino's pin 2
// and the RX line from the esp to the Arduino's pin 3
void setup()
{
 Serial.begin(9600);
 esp8266.begin(115200); // your esp's baud rate might be different
 pinMode(relay, OUTPUT);
 digitalWrite(relay, LOW);
 sendData("AT+RST\r\n", 2000, DEBUG); // reset module
 sendData("AT+CWMODE=3\r\n", 1000, DEBUG); // configure as access point
 sendData("AT+CWJAP=\"xxxx\",\"xxx\"\r\n", 5000, DEBUG); // configure as access point
 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
 sendData("AT+CIFSR\r\n", 5000, DEBUG); // get ip address
 sendData("AT+CIFSR\r\n", 5000, DEBUG); // get ip address
}
void loop()
{
 if (esp8266.available()) // check if the esp is sending a message
 {
 if (esp8266.find("+IPD,"))
 {
 delay(1000);
 int connectionId = esp8266.read() - 48; // subtract 48 because the read() function returns
 // the ASCII decimal value and 0 (the first decimal number) starts at 48
 if (esp8266.find("=="))
 {
 Serial.print("State : ");
 char c = esp8266.read();
 Serial.print(c);
 if (c == '1') {
 digitalWrite(relay, HIGH);
 }
 else {
 digitalWrite(relay, LOW);
 }
 }
 String webpage = "A";
 String cipSend = "AT+CIPSEND=";
 cipSend += connectionId;
 cipSend += ",";
 cipSend += webpage.length();
 cipSend += "\r\n";
 sendData(cipSend, 1000, DEBUG);
 sendData(webpage, 1000, DEBUG);
 String closeCommand = "AT+CIPCLOSE=";
 closeCommand += connectionId; // append connection id
 closeCommand += "\r\n";
 sendData(closeCommand, 3000, DEBUG);
 }
 }
}
String sendData(String command, const int timeout, boolean debug)
{
 String response = "";
 esp8266.print(command); // send the read character to the esp8266
 long int time = millis();
 while ( (time + timeout) > millis())
 {
 while (esp8266.available())
 {
 // The esp has data so display its output to the serial window
 char c = esp8266.read(); // read the next character.
 response += c;
 }
 }
 if (debug)
 {
 Serial.print(response);
 }
 return response;
}
#include <SoftwareSerial.h>
#define DEBUG true
int relay = 8;
SoftwareSerial esp8266(2, 3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
// This means that you need to connect the TX line from the esp to the Arduino's pin 2
// and the RX line from the esp to the Arduino's pin 3
void setup()
{
 Serial.begin(9600);
 esp8266.begin(115200); // your esp's baud rate might be different
 pinMode(relay, OUTPUT);
 digitalWrite(relay, LOW);
 sendData("AT+RST\r\n", 2000, DEBUG); // reset module
 sendData("AT+CWMODE=3\r\n", 1000, DEBUG); // configure as access point
 sendData("AT+CWJAP=\"xxxx\",\"xxx\"\r\n", 5000, DEBUG); // configure as access point
 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
 sendData("AT+CIFSR\r\n", 5000, DEBUG); // get ip address
 sendData("AT+CIFSR\r\n", 5000, DEBUG); // get ip address
}
void loop()
{
 if (esp8266.available()) // check if the esp is sending a message
 {
 if (esp8266.find("+IPD,"))
 {
 delay(1000);
 int connectionId = esp8266.read() - 48; // subtract 48 because the read() function returns
 // the ASCII decimal value and 0 (the first decimal number) starts at 48
 if (esp8266.find("=="))
 {
 Serial.print("State : ");
 char c = esp8266.read();
 Serial.print(c);
 if (c == '1') {
 digitalWrite(relay, HIGH);
 }
 else {
 digitalWrite(relay, LOW);
 }
 }
 String webpage = "A";
 String cipSend = "AT+CIPSEND=";
 cipSend += connectionId;
 cipSend += ",";
 cipSend += webpage.length();
 cipSend += "\r\n";
 sendData(cipSend, 1000, DEBUG);
 sendData(webpage, 1000, DEBUG);
 String closeCommand = "AT+CIPCLOSE=";
 closeCommand += connectionId; // append connection id
 closeCommand += "\r\n";
 sendData(closeCommand, 3000, DEBUG);
 }
 }
}
String sendData(String command, const int timeout, boolean debug)
{
 String response = "";
 esp8266.print(command); // send the read character to the esp8266
 long int time = millis();
 while ( (time + timeout) > millis())
 {
 while (esp8266.available())
 {
 // The esp has data so display its output to the serial window
 char c = esp8266.read(); // read the next character.
 response += c;
 }
 }
 if (debug)
 {
 Serial.print(response);
 }
 return response;
}
#include <SoftwareSerial.h>
#define DEBUG true
int relay = 8;
SoftwareSerial esp8266(2, 3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
// This means that you need to connect the TX line from the esp to the Arduino's pin 2
// and the RX line from the esp to the Arduino's pin 3
void setup()
{
 Serial.begin(9600);
 esp8266.begin(115200); // your esp's baud rate might be different
 pinMode(relay, OUTPUT);
 digitalWrite(relay, LOW);
 sendData("AT+RST\r\n", 2000, DEBUG); // reset module
 sendData("AT+CWMODE=3\r\n", 1000, DEBUG); // configure as access point
 sendData("AT+CWJAP=\"xxxx\",\"xxx\"\r\n", 5000, DEBUG); // configure as access point
 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
 sendData("AT+CIFSR\r\n", 5000, DEBUG); // get ip address
 sendData("AT+CIFSR\r\n", 5000, DEBUG); // get ip address
}
void loop()
{
 if (esp8266.available()) // check if the esp is sending a message
 {
 if (esp8266.find("+IPD,"))
 {
 delay(1000);
 int connectionId = esp8266.read() - 48; // subtract 48 because the read() function returns
 // the ASCII decimal value and 0 (the first decimal number) starts at 48
 if (esp8266.find("=="))
 {
 Serial.print("State : ");
 char c = esp8266.read();
 Serial.print(c);
 if (c == '1') {
 digitalWrite(relay, HIGH);
 }
 else {
 digitalWrite(relay, LOW);
 }
 }
 String webpage = "A";
 String cipSend = "AT+CIPSEND=";
 cipSend += connectionId;
 cipSend += ",";
 cipSend += webpage.length();
 cipSend += "\r\n";
 sendData(cipSend, 1000, DEBUG);
 sendData(webpage, 1000, DEBUG);
 String closeCommand = "AT+CIPCLOSE=";
 closeCommand += connectionId; // append connection id
 closeCommand += "\r\n";
 sendData(closeCommand, 3000, DEBUG);
 }
 }
}
String sendData(String command, const int timeout, boolean debug)
{
 String response = "";
 esp8266.print(command); // send the read character to the esp8266
 long int time = millis();
 while ( (time + timeout) > millis())
 {
 while (esp8266.available())
 {
 // The esp has data so display its output to the serial window
 char c = esp8266.read(); // read the next character.
 response += c;
 }
 }
 if (debug)
 {
 Serial.print(response);
 }
 return response;
}
#include <SoftwareSerial.h>
#define DEBUG true
int relay = 8;
SoftwareSerial esp8266(2, 3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
// This means that you need to connect the TX line from the esp to the Arduino's pin 2
// and the RX line from the esp to the Arduino's pin 3
void setup()
{
 Serial.begin(9600);
 esp8266.begin(115200); // your esp's baud rate might be different
 pinMode(relay, OUTPUT);
 digitalWrite(relay, LOW);
 sendData("AT+RST\r\n", 2000, DEBUG); // reset module
 sendData("AT+CWMODE=3\r\n", 1000, DEBUG); // configure as access point
 sendData("AT+CWJAP=\"xxxx\",\"xxx\"\r\n", 5000, DEBUG); // configure as access point
 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
 sendData("AT+CIFSR\r\n", 5000, DEBUG); // get ip address
 sendData("AT+CIFSR\r\n", 5000, DEBUG); // get ip address
}
void loop()
{
 if (esp8266.available()) // check if the esp is sending a message
 {
 if (esp8266.find("+IPD,"))
 {
 delay(1000);
 int connectionId = esp8266.read() - 48; // subtract 48 because the read() function returns
 // the ASCII decimal value and 0 (the first decimal number) starts at 48
 if (esp8266.find("=="))
 {
 Serial.print("State : ");
 char c = esp8266.read();
 Serial.print(c);
 if (c == '1') {
 digitalWrite(relay, HIGH);
 }
 else {
 digitalWrite(relay, LOW);
 }
 }
 String webpage = "A";
 String cipSend = "AT+CIPSEND=";
 cipSend += connectionId;
 cipSend += ",";
 cipSend += webpage.length();
 cipSend += "\r\n";
 sendData(cipSend, 1000, DEBUG);
 sendData(webpage, 1000, DEBUG);
 String closeCommand = "AT+CIPCLOSE=";
 closeCommand += connectionId; // append connection id
 closeCommand += "\r\n";
 sendData(closeCommand, 3000, DEBUG);
 }
 }
}
String sendData(String command, const int timeout, boolean debug)
{
 String response = "";
 esp8266.print(command); // send the read character to the esp8266
 long int time = millis();
 while ( (time + timeout) > millis())
 {
 while (esp8266.available())
 {
 // The esp has data so display its output to the serial window
 char c = esp8266.read(); // read the next character.
 response += c;
 }
 }
 if (debug)
 {
 Serial.print(response);
 }
 return response;
}
deleted 2 characters in body
Source Link

I'm completely new to Arduino and doesdo not have an electronics background. I'm really keen to do a POC on home automation. As a start, I decided to switch on a tube light using ESP8266, Arduino Uno R3 and isolated relay. I have read that this can be done without arduino also.

I'm completely new to Arduino and does not have an electronics background. I'm really keen to do a POC on home automation. As a start, I decided to switch on a tube light using ESP8266, Arduino Uno R3 and isolated relay. I have read that this can be done without arduino also.

I'm completely new to Arduino and do not have an electronics background. I'm really keen to do a POC on home automation. As a start, I decided to switch on a tube light using ESP8266, Arduino Uno R3 and isolated relay. I have read that this can be done without arduino also.

Source Link
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /