Built-in project · ESP32 DevKit V1 and Arduino Uno R3

An ESP32 and an Arduino Uno talking over serial: an ESP32 DevKit and an Arduino Uno

An ESP32 reads a knob and sends the number to an Arduino Uno over a serial wire; the Uno sets an LED’s brightness from it. The whole build, an ESP32 DevKit and an Arduino Uno and 3 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate Runs in your browser. Free, and no account needed.

An ESP32 and an Arduino Uno talking over serial · ESP32 DevKit V1live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · ESP32 DevKit V1
// ESP32: reads a potentiometer on GPIO 34 and sends the reading to an
// Arduino Uno as a line of text, four times a second.
//
//   ESP32 GPIO 4 (TX)  ->  Uno pin 2 (RX)
//   ESP32 GND          --  Uno GND
//
// One way only, on purpose. The ESP32 drives 3.3 V, which an Uno reads as
// HIGH. The Uno drives 5 V, which a real ESP32 pin is not rated for, so a
// link back would need a divider or a level shifter on that wire.

#include <SoftwareSerial.h>

SoftwareSerial link(-1, 4);  // no RX, TX on GPIO 4

void setup() {
  Serial.begin(115200);
  link.begin(9600);
  Serial.println("ESP32: sending the knob to the Uno");
}

void loop() {
  int knob = analogRead(34);  // 0 to 4095 on the ESP32's 12-bit ADC
  link.print("knob ");
  link.println(knob);
  Serial.print("sent knob ");
  Serial.println(knob);
  delay(250);
}
sketch.ino · Arduino Uno R3
// Arduino Uno: reads "knob N" lines from the ESP32 on pin 2 and turns the
// LED on pin 9 up and down to match, with PWM.

#include <SoftwareSerial.h>

SoftwareSerial link(2, 3);  // RX on pin 2 (pin 3 is not used)

char line[24];
byte len = 0;

void setup() {
  Serial.begin(9600);
  link.begin(9600);
  pinMode(9, OUTPUT);
  Serial.println("Uno: listening to the ESP32");
}

void loop() {
  while (link.available()) {
    char c = link.read();
    if (c == '\n') {
      line[len] = 0;
      len = 0;
      if (strncmp(line, "knob ", 5) != 0) continue;
      int knob = atoi(line + 5);
      // The ESP32 counts to 4095; analogWrite takes 0 to 255.
      analogWrite(9, map(knob, 0, 4095, 0, 255));
      Serial.print("Uno got knob ");
      Serial.println(knob);
    } else if (c != '\r' && len < sizeof(line) - 1) {
      line[len++] = c;
    }
  }
}

Parts list

5 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

7 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • ESP32 DevKit V1 pin D34; Potentiometer pin 2
  • Ground: ESP32 DevKit V1 pin GND; Potentiometer pin 3; Arduino Uno R3 pin GND
  • ESP32 DevKit V1 pin D4; Arduino Uno R3 pin 2
  • ESP32 DevKit V1 pin 3V3; Potentiometer pin 1
  • Arduino Uno R3 pin 9; Resistor, 220 Ω pin 1
  • Ground: Arduino Uno R3 pin GND; LED, green pin C
  • Resistor, 220 Ω pin 2; LED, green pin A

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.