Getting Started With ESP32 & Arduino IDE: Simple I/O

Required Hardware

  • ESP32
  • Breadboard
  • 5 mm LED
  • 330 Ω resistor
  • Pushbutton
  • 10k Ω resistor
  • Jumper wires
  • Laptop
  • Micro USB cable

Required Software

  • Arduino IDE
  • USB to UART port driver

Project 1

Part 1: Assemble circuit

project 1 circuit

Part 2: Code

// set pin numbers
const int buttonPin = 4; // the number of the pushbutton pin
const int ledPin = 23; // the number of the LED pin

// variable for storing the pushbutton status
int buttonState = 0;

void setup() {
Serial.begin(115200);
// initialize the pushbutton pin as an input
pinMode(buttonPin, INPUT);
// initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
}

void loop() {
// read the state of the pushbutton value
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH
if (buttonState == HIGH) {
// turn LED on
digitalWrite(ledPin, HIGH);
} else {
// turn LED off
digitalWrite(ledPin, LOW);
}
}

Part 3: Verify & Upload

Project 2

Part 1: Assemble circuit

project 2 circuit

Part 2: Code

// set pin numbers
const int buttonPin = 4; // the number of the pushbutton pin
const int ledPin1 = 23; // the number of the first LED pin
const int ledPin2 = 21; // the number of the second LED pin
// variable for storing the pushbutton status
int buttonState = 0;
void setup() {
Serial.begin(115200);
// initialize the pushbutton pin as an input
pinMode(buttonPin, INPUT);
// initialize both LED pin as an output
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop() {
// read the state of the pushbutton value
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH
if (buttonState == HIGH) {
// turn LED on
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
} else {
// turn LED off
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin1, LOW);
}
}

Part 3: Verify & Upload

--

--

--

Can I please get a crumb of 𝒱𝒶𝓁𝒾𝒹𝒶𝓉𝒾𝑜𝓃

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Best of Programming on Medium (August 2021)

Process Mining in Application Maintenance and Support — Part 3

Install Flask in virtual environment in windows 10

Home Pro

header

Real Time Edge Detection in Browser

The edges detected around my cat

Unity x Ardity

Difference between Argument and Parameters

The Cooking Challenge: for once not stirring data!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tubagus Baraka Kautsar Sofiuddin

Tubagus Baraka Kautsar Sofiuddin

Can I please get a crumb of 𝒱𝒶𝓁𝒾𝒹𝒶𝓉𝒾𝑜𝓃

More from Medium

Create and Broadcast Custom JSON on the Hive Blockchain with Python

hive-dev.jpg

Project 1: Getting Started with the ESP32

How to Display Images from Cloneable Fields — P2 — with Oxygen

How to Display Images from Cloneable Fields — P2 — with Oxygen