ESP8266 sends data via Serial TX/RX to an Arduino Nano to control an LED

Description: A Wemos Lolin D1 Mini Pro V2 transmits data via Serial Communication to an Arduino Nano which acts as the receiver, reads the data, and then executes the transmitted code which blinks an LED connected to the Arduino Nano.

ESP8266 serial communication with Arduino Nano

Notes: Disconnect the TX/RX wires from the microcontollers when uploading code with the Arduino IDE, since the code will not upload properly when the TX or RX pins are connected to any wires during upload.

Supplies:

1 – Breadboard 400 Points
1 – Wemos Lolin D1 Mini Pro V2
1 – Arduino Nano
1 – LED
1 – 220 Ohm Resistor

Arduino Code:

// Transmitter Code

void setup() {

  Serial.begin(9600);
  delay(100);

}

void loop() {

  Serial.print("on");
  delay(1000);
  Serial.print("off");
  delay(1000);

}

— — — — — — — — — — — — — — — — — —

// Receiver Code

String Message;

void setup() {

  Serial.begin(9600);
  Serial.setTimeout(50); // default is 1 second
  delay(100);
  pinMode(3, OUTPUT);

}

void loop() {

  if (Serial.available()) {

  Message = Serial.readString();

}

delay(4);

  if (Message == "on") {

  digitalWrite(3, HIGH);

}

  if (Message == "off") {

  digitalWrite(3, LOW);

}

}

Leave a Comment

+ 44 = 45