ATMegaZero ESP32-S2 sends Serial Data to Arduino Nano

Description: An ATMegaZero ESP32-S2 connected to an Arduino Nano sends ON and OFF data via Serial(TX, RX). When an SPDT switch is flicked ON the green LED light turns ON and when flicked OFF turns the green LED light OFF.

ATMegaZero ESP32-S2 sends Serial Data to Arduino Nano

Supplies:

1 – Breadboard 400 Points
1 – ATMega Zero ESP32-S2   >> Link <<
1 – Arduino Nano
1 – Two Position Toggle Switch   >> Link <<
1 – LED

Arduino Code:

// Transmitter Code for ATMegaZero ESP32-S2

#include <HardwareSerial.h>
HardwareSerial MySerial(1);

#define switch 13

#define RXD2 44
#define TXD2 43

void setup() {

   MySerial.begin(115200, SERIAL_8N1, RXD2, TXD2);
   delay(1000);

  pinMode(switch, INPUT_PULLUP);

}

void loop() {

  while(digitalRead(switch) == HIGH); {
  MySerial.print("off");
  delay(100);
  }
  
  MySerial.println("");

  while(digitalRead(switch) == LOW); {
  MySerial.print("on");
  delay(100);
  }

  MySerial.println("");
}
// Receiver Code for Arduino Nano

String Message;

void setup() {
  
  Serial.begin(115200);
  Serial.setTimeout(50); // default is 1 second
  delay(100);
  pinMode(9, OUTPUT);
  
}
void loop() {
  
  if (Serial.available()) {
  Message = Serial.readString();
  
}

delay(4);

  if (Message == "on") {
  digitalWrite(9, HIGH);
  
}
  if (Message == "off") {
  digitalWrite(9, LOW);
  
}
}

Leave a Comment

61 − = 52