Unit 1 - Training�Lab 1C : Introduction to Arduino code and Evaluating Speed of Sound
UCLA Physics Department
University of California, Los Angeles
Department of Physics and Astronomy
Physics 4AL
Outline of Lab 1C
UCLA Physics Department
Introduction to Arduino code
UCLA Physics Department
Arduino Input/Output
Input/output pins
PWM Pins(~): 3, 5, 6, 9, 10, 11
Digital Pins: 2, 4, 7, 8, 12, 13
USB input/output/power
Battery power
Output power + ground
Analog Input
Connecting an Arduino
UCLA Physics Department
5
Downloads and references
UCLA Physics Department
Arduino 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
Example code - Comments
UCLA Physics Department
Example code - Upload
UCLA Physics Department
LED operation
Using the Arduino to Create a Blinking LED
UCLA Physics Department
Commands: timing
18
External LED Blink
19
TA Checkpoint 1 - External LED Blink
20
Code basics : Analog Input/Output
UCLA Physics Department
LED Brightness Changing
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
Connecting the Ultrasonic Sensor
UCLA Physics Department
24
HC-SR04 Ultrasonic Sensor
25
Working Principle
26
Arduino extension board
Attach Arduino extension board to the Arduino ensuring that corresponding pins match.
27
Arduino extension board
28
Mini breadboard
Pull off the yellow adhesive cover to attach the mini breadboard on the Arduino extension board permanently. However, the circuit on the breadboard can be modified and the extension board can be detached whenever required.
29
Arduino with attached mini breadboard
30
Arduino with attached mini breadboard
The pins on the Arduino extension board correspond to the pins on the Arduino. This setup also has more ground pins and 5V pins.
31
Arduino with attached mini breadboard
Each row with 5 pins are electrically connected. However, the mini breadboard does not have the red and blue rails that were connected to 5V and ground. Instead there are more 5V and ground pins on the extension board.
32
Attach ultrasonic sensor
33
Wiring Diagram
34
Connect ultrasound module
35
Connect Ultrasonic Sensor
36
Using the Ultrasonic Sensor
UCLA Physics Department
37
Serial Class
38
Code - Part 1
39
Code - Part 2
40
Code - Part 3
41
Serial Monitor
Serial Monitor readings.
42
You can download this code here
Reset button
Click reset button on the extension board to collect new data.
43
Ultrasonic Sensor Function
44
The Speed of Sound
UCLA Physics Department
45
TA Checkpoint 3 - Plotting with Error Bars
46
TA Checkpoint 4 - The Speed of Sound
47
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
Make a copy of this document to submit the post-lab for Week 2.