Unit 1 - Training�Lab 1C : Introduction to ESP32 code and Evaluating Speed of Sound
UCLA Physics Department
University of California, Los Angeles
Department of Physics and Astronomy
Physics 4AL
JupyterLab Repository Updated
Log in link:
https://physhub.oarc.ucla.edu/hub/login?next=%2Fhub%2F
Physics 4AL:
Please note that material pulled from this link will be periodically updated as the course is changing throughout the quarter.
UCLA Physics Department
Outline of Lab 1C
UCLA Physics Department
Introduction to ESP32 code
UCLA Physics Department
ESP32 Input/Output
5
Component List
Component List
6
Component List
Component List
7
Downloads and references
For Mac users, Please download Xcode to compile the ESP code
UCLA Physics Department
Library Install
ESP32 Connection
UCLA Physics Department
Code basics
UCLA Physics Department
Code basics - void setup()
UCLA Physics Department
UCLA Physics Department
void setup() {
Commands here
}
Code basics - void loop()
UCLA Physics Department
void loop() {
Commands here
}
Code Basics - Variables
UCLA Physics Department
Code Basics - Variable types
UCLA Physics Department
Code Basics - Digital Input/Output
UCLA Physics Department
Using the ESP32 to Create a Blinking LED
UCLA Physics Department
Example code - Comments
UCLA Physics Department
Example code - Upload
UCLA Physics Department
LED operation
Upload Process
Commands: timing
22
External LED Blink
23
TA Checkpoint 1 - External LED Blink
24
Code basics : Analog Input/Output
UCLA Physics Department
LED Brightness Changing
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
Note: The LED pin is changed to pin number 9. Only the ponds with the squiggly line (~) in front of them are capable of analog control.
You do not have to type in the code, you can download it here
TA Checkpoint 2 - LED Brightness Changing
if (brightness <= 0 || brightness >= 255)
Connecting the Ultrasonic Sensor
UCLA Physics Department
28
HC-SR04 Ultrasonic Sensor
29
Working Principle
30
Using the Ultrasonic Sensor
UCLA Physics Department
31
Wiring Diagram
32
Trig 2
Echo 4
Accessing Serial Monitor
3 ways to access, keyboard shortcut (Ctrl+Shift+M), clicking it on the tools menu, clicking the magnifying glass
Code Overview
Please refer to 1A slides for the IDE setup.
34
ESP32 Connection (Windows)
35
Check if the computer can find the device. It should download CH340 automatically once connected. If not, follow further instructions.
You can also go to the start menu and type “Device Manager”
IDE Environment Configuration
36
If everything’s right !
Make sure to select this board for the rest of the section
Serial Class
37
Ultrasonic Sensor Function
38
The Speed of Sound
UCLA Physics Department
39
TA Checkpoint 3 - Plotting with Error Bars
40
TA Checkpoint 4 - The Speed of Sound
41
TA Checkpoint 4 - The Speed of Sound
42
Troubleshooting for Problems with Arduino
This slide will be useful throughout the quarter.
UCLA Physics Department
Post-Lab Requirements for lab 1C
UCLA Physics Department