praktek penggunaan arduino dan sensor LDR | P5 rekayasa dan teknologi

3 min read 4 hours ago
Published on Sep 25, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, we will learn how to use an Arduino Uno to control an LED based on readings from a Light Dependent Resistor (LDR). This project demonstrates the practical application of sensors and microcontrollers in electronics, making it ideal for beginners in engineering and technology.

Step 1: Gather Your Materials

Before starting, ensure you have the following materials ready:

  • 1 Arduino Uno
  • 1 smartphone with the Arduino Droid app installed
  • 1 LED
  • 2 resistors (220 ohm, 1/4 watt)
  • 5 jumper wires
  • 1 USB cable (to connect Arduino and smartphone)
  • 1 OTG cable (if necessary)
  • 1 breadboard (project board)

Step 2: Set Up the Circuit

Follow these steps to connect the components correctly:

  1. Connect the LED:

    • Insert the LED into the breadboard.
    • Connect the longer leg (anode) of the LED to a digital pin on the Arduino (e.g., pin 8).
    • Connect the shorter leg (cathode) to one end of a 220-ohm resistor.
    • Connect the other end of the resistor to the ground (GND) on the Arduino.
  2. Connect the LDR:

    • Place the LDR on the breadboard.
    • Connect one terminal of the LDR to the 5V pin on the Arduino.
    • Connect the other terminal of the LDR to an analog input pin on the Arduino (e.g., A0).
    • Connect a second 220-ohm resistor from the same terminal (connected to A0) to the ground (GND).
  3. Verify Connections:

    • Double-check all connections to ensure they match the circuit diagram. A wrong connection can lead to incorrect readings or damage the components.

Step 3: Program the Arduino

Now we need to upload the code to the Arduino:

  1. Download the Code:

    • Access the provided code using this link.
  2. Upload the Code:

    • Open the Arduino IDE on your computer.
    • Copy and paste the downloaded code into the IDE.
    • Select the appropriate board type (Arduino Uno) and port.
    • Click on the upload button to transfer the code to your Arduino.
  3. Review the Code:

    • Ensure that the code reads the LDR value and controls the LED based on the light intensity. The basic structure should include:
    int ledPin = 8;
    int ldrPin = A0;
    void setup() {
        pinMode(ledPin, OUTPUT);
    }
    void loop() {
        int ldrValue = analogRead(ldrPin);
        if (ldrValue < threshold) {
            digitalWrite(ledPin, HIGH);
        } else {
            digitalWrite(ledPin, LOW);
        }
        delay(100);
    }
    

Step 4: Test the Setup

  1. Connect the Arduino to Your Smartphone:

    • Use the USB cable to connect your Arduino to your smartphone.
    • If using an OTG cable, connect the OTG to your smartphone, then plug in the Arduino.
  2. Run the Application:

    • Open the Arduino Droid app on your smartphone.
    • Ensure it detects the Arduino connection.
  3. Observe the LED Behavior:

    • Test the setup by covering and uncovering the LDR. The LED should turn on in low light and turn off in bright light.

Conclusion

You've successfully built a simple light-activated LED circuit using an Arduino Uno and an LDR. This project serves as a foundation for more complex Arduino applications involving sensors. For future projects, consider experimenting with different sensors or integrating more LEDs. Happy coding and experimenting!