From the course: Learning Arduino: Interfacing with Analog Devices
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Coding to read the LDR circuit - Arduino Tutorial
From the course: Learning Arduino: Interfacing with Analog Devices
Coding to read the LDR circuit
- [Narrator] Okay, I'm going to go ahead and start programming for the LDR. I'm going to write a simple to kind of mimic a light meter, whenever it's dark it shows on the serial monitor that it's dark. Whenever it's bright it shows that it's bright. So the very first point we are going to do is we are going to initialize and lock input, and name it to sensorPin. So I will go ahead, so it's an integer, sensorPin, and that was connected to a zero. The second thing I'm going to do is I'm going to initialize the variable, where we are going to store the values from the LDR. So, it's an integer, and then I'll name it as sensorValue. And then I'll initialize it to zero to start with. Okay, so in the void setup we need to initialize the serial again. Alright, in the void loop here, the very first thing is that we're going to read from the LDR, since we're doing an analog, so we are going to use analog, read, command, and then the value that we are going to read is from the sensorPin. Here…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
What are analog devices?2m 3s
-
Understanding analog-to-digital converters1m 50s
-
(Locked)
Exploring our temperature sensor (TMP37)2m 29s
-
(Locked)
Understanding how to interpret the sensor values2m 55s
-
(Locked)
Interpreting the sensor values1m 16s
-
(Locked)
Wiring up the temperature sensor57s
-
(Locked)
Coding to read the temperature sensor4m 56s
-
(Locked)
LDR (light-dependent resistor) sensor1m 36s
-
(Locked)
Using a voltage divider with our LDR3m 43s
-
Wiring up our LDR circuit1m 26s
-
(Locked)
Coding to read the LDR circuit3m 56s
-
(Locked)
Joystick module2m 9s
-
(Locked)
Wiring up our joystick1m 9s
-
(Locked)
Coding the joystick circuit4m 47s
-
-
-
-
-