In this application, we
will make an LDR application with the Mblock program. LDR; It is a
photoresistor that changes value according to the incident light. You can turn
the lamp on and off according to the values in the LDR. In this application,
we will first learn to read the values in the LDR, then we will flash the
led.
Let's come to the
circuit elements.
1-Arduino Uno (1 pc)
2-BreadBoard
3-220Ω Resistor(1pcs)
5-LDR(1pcs)
6-Jump Cables
We need supplies.
Our circuit diagram is
as follows.
We connect a 220 ohm
resistor to one leg of our LDR. We connect a cable to one leg of the resistor
we connected and connect this cable to the 5 volt pin (blue cable) and we
connect it to the other free leg of the LDR with a GND (- terminal) cable.
Thus, we have prepared our circuit. It's time to write our code.
In the Mblock program,
we add the Arduino program starter code from the Robots menu. After adding the
repeat code from the control menu, we add our code to write to the serial port
inside. In this code, we add the code to read the pin to whichever analog pin
we connected our LDR to. We add the code to read the analogue pin from the
Robots menu. We write A0 because I connect it to the danalog pin A0. Thus, our
LDR will print the light value in the environment to the screen. This event is
constantly In order for us to run these codes, after connecting our arduino
board and circuit to the computer with a usb cable,
we first select the Serial port from the
Connect menu, let's choose the port to which our arduino board is connected
from there. Select the letter case in both send encode mode and recv encode
mode. After that, by pressing the Upload to Arduino button, we send the codes
we wrote to our Arduino board and upload them. Thus, our program becomes ready
to run.
Comments
Post a Comment