មេរៀនទី ៦: Sensor Input (PIR, Light, Temperature)

Fire LED Lesson (2D)

មេរៀនទី ៦: Sensor Input (PIR, Light, Temperature)

**********************************************************************************************************************



មេរៀននេះអ្នកនឹងរៀនពីការប្រើ Sensor ៣ ប្រភេទជាមួយ Arduino៖ PIR Sensor, Light Sensor (LDR) និង Temperature Sensor (LM35)

1️⃣ PIR Sensor (Motion Detection)

🔌 ការភ្ជាប់ PIR Sensor
  • VCC → 5V Arduino
  • GND → GND Arduino
  • OUT → Pin 2

// PIR Sensor Code
int pirPin = 2;
int ledPin = 13;

void setup() {
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int motion = digitalRead(pirPin);
  if (motion == HIGH) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}

2️⃣ Light Sensor (LDR)

🔌 ការភ្ជាប់ LDR
  • LDR + Resistor → A0
  • 5V → LDR
  • GND → Resistor

// LDR Light Sensor
int ldrPin = A0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int lightValue = analogRead(ldrPin);
  Serial.println(lightValue);
  delay(500);
}

3️⃣ Temperature Sensor (LM35)

🔌 ការភ្ជាប់ LM35
  • VCC → 5V Arduino
  • OUT → A1
  • GND → GND Arduino

// LM35 Temperature Sensor
int tempPin = A1;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int value = analogRead(tempPin);
  float voltage = value * (5.0 / 1023.0);
  float tempC = voltage * 100;
  Serial.println(tempC);
  delay(1000);
}
======================================================================================================================

Post a Comment

0 Comments