From the course: Learning Arduino: Interfacing with Analog Devices

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Coding to read the LDR circuit

Coding to read the LDR circuit - Arduino Tutorial

From the course: Learning Arduino: Interfacing with Analog Devices

Start my 1-month free trial

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…

Contents