اكتشاف الظلام باستخدام مقاومة LDR الضوئية 🌞

هل تساءلت يومًا كيف يتم تشغيل ضوء الشارع تلقائيًا عندما يحل الظلام؟


ربما تعتقد أن شخصًا ما مسؤول عن تشغيله وإيقافه، أو أنه يعتمد في تشغيله على  مؤقت!


ولكن ماذا لو ظهرت بعض الغيوم فجأة وأصبح الطريق مظلما؟


استخدام الـ LDR هو الخيار الأفضل في هذه الحالة. ترمز LDR إلى المقاومات التي تعتمد على الضوء، أو المقاومات الضوئية. وهي مقاومة حساسة للضوء تختلف قيمتها باختلاف شدة الضوء.


مقدمة


تتناسب قيمة الــ LDR عكسًيا مع كمية الضوء. هذا يعني أن قيمة مقاومة LDR تزداد في الظلام، بينما تقل في وجود الضوء.


لهذا، يمكن أن نستخدمها للاستدلال على شدة الضوء أو وجوده أو غيابه.


في هذا الدرس، سوف نستخدم الاردوينو لقراءة قيمة مقاومة LDR واكتشاف الظلام. يمكنك تطوير هذا المشروع للتحكم في LED ليتم تشغيله عندما يذهب الضوء وينطفئ عندما يعود الضوء مرة اخري، تماماً مثل فكرة عمل الإنارة في الشارع!


الحصول علي القطع


ستحتاج إلى المكونات التالية لهذا المشروع، يمكنك شراؤها من متجر ڤولتات.

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat Photocell - LDR (4 pieces)
1 QAR
Sale Off
Voltaat Jumper Wires - Male to Male (40 Pack)
10 QAR
Sale Off
Voltaat 1/4 Watt Resistor (20 Pack)
2 QAR

التوصيل


توضح الصورة التالية كيفية توصيل الأسلاك بين LDR و الاردوينو. بمجرد توصيل LDR والاردوينو ببعضهما البعض، قم بتوصيل الاردوينو بجهاز الكمبيوتر الخاص بك باستخدام كابل USB.



التوصيلات من الاردوينو إلى لوح التجارب:

• Arduino pin GND ← Breadboard ground line

• Arduino pin 5V ← Breadboard 5V line

• Arduino pin A3 ← Common pin between LDR and the 10KΩ resistor


التوصيلات من LDR:

• First pin← Breadboard 5V line

• Second pin ← 10KΩ resistor left pin

• 10KΩ resistor right pin ← Breadboard ground line


برمجة الاردوينو


الغرض من نص البرمجة هذا هو قراءة قيم مقاومة LDR باستخدام الاردوينو. تتناسب قيمة مقاومة LDR تناسباً عكسياً مع شدة الضوء، مما يعني أنه يمكننا الاعتماد على  هذه القيم للتمييز بين وجود الضوء والظلام.


سنقوم أيضًا بعرض هذه القيم على جهاز الكمبيوتر الخاص بك.


نص البرمجة سهل. يمكنك استخدامه مباشرة أو تعديله ليناسب مشاريعك.



/*
Voltaat learn (http://learn.voltaat.com)

Link for full tutorial: https://bit.ly/3AntKyL
Tutorial: Use the LDR to know the state of the light
The function of this sketch is to read the values of the LDR resistance
- via the input pin of the Arduino.

Connections from the Arduino to the breadboard:
• Arduino pin GND → Breadboard ground line
• Arduino pin 5V → Breadboard 5V line
• Arduino pin A3 → Common pin between LDR and the 10KΩ resistor

Connections from the LDR:
• First pin→ Breadboard 5V line
• Second pin→ 10KΩ resistor left pin
• 10KΩ resistor right pin→ Breadboard ground line
*/


// Define the variable ldr to Analog Input A3.
constint ldr = A3;

// Define ldrStatus variable
int ldrStatus;

// Commands inside void setup run once.
void setup()
{

  // ldr is defined as an input
  pinMode(ldr, INPUT);

  // Start the serial monitor at 9600 baud rate (9600 bits per second)
  Serial.begin(9600);


}

// Commands inside void loop run forever
void loop()
{
  // Read the value of analog input from LDR and assign it in the variable ldrStatus
  ldrStatus = analogRead(ldr);

  // This value can change depending on the intensity of the surrounding light and the sensitivity of the LDR
  if(ldrStatus <= 450)
  {

    // print "It is dark here " to the serial monitor at the same line
    Serial.print("It is dark here ");

    // print The ldrStatus value to the serial monitor at a new line
    Serial.println(ldrStatus);


  }
  else
  {

    // print "The light has returned " to the serial monitor at the same line
    Serial.print("The light has returned ");

    // print The ldrStatus value to the serial monitor at a new line
    Serial.println(ldrStatus);

  }

}

قم باختباره




بعد تحميل نص البرمجة علي الاردوينو، يمكنك الآن الوصول إلى شاشة التواصل وعرض البيانات من Arduino IDE الخاص بك من خلال النقر على أيقونة العدسة المكبرة في الزاوية اليمنى العليا.


نافذة التواصل وعرض البيانات هي أداه رائعة في Arduino IDE تمكنك من إجراء اتصال بين جهاز الكمبيوتر الخاص بك والاردوينو. تسمح بإرسال أوامر واستقبال البينات المختلفة وتكون مفيدة في عرض البيانات مثل القراءات من الحساسات المختلفة.


الآن كما نرى في الصورة التالية، تعرض شاشة التواصل وعرض البيانات حالة وجود الضوء أو الظلام وكذلك قيمة قراءة المقاومة الضوئية.


يجب عليك أيضًا التأكد من اختيارك لمعدل baud الصحيح (9600) كما هو محدد في البرنامج.


المصادر


Arduino Code

Fritzing Wiring file

دروس أخري


In this tutorial, we will use the PIR sensor to send a message to your computer when someone enters your house.


A soil moisture sensor is a device that measures the amount of water in the soil. The sensor consists of two metal probes that can be inserted into the soil to measure the moisture levels.

Most of us are familiar with the switches used in household devices. A relay is a type of switch that can be connected to an Arduino or any other microcontroller.