Created
November 2, 2023 13:05
-
-
Save penpencool/46ad79e7ace2705da1376f8244703009 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int sensorPin = 2; // ต่อเข้ากับขาของ Infrared Barrier Tracking Module | |
| int sensorStatus = 0; // ตัวแปรเก็บสถานะของเซนเซอร์ | |
| void setup() { | |
| pinMode(sensorPin, INPUT); // กำหนดขา sensorPin เป็น INPUT | |
| Serial.begin(9600); // เริ่มการสื่อสารผ่าน Serial ที่ความเร็ว 9600 bps | |
| } | |
| void loop() { | |
| sensorStatus = digitalRead(sensorPin); // อ่านค่าจากเซนเซอร์ | |
| if (sensorStatus == LOW) { // บางครั้งเซนเซอร์จะให้ค่าเป็น LOW เมื่อตรวจจับวัตถุ | |
| Serial.println("Object Detected!"); // แสดงข้อความเมื่อตรวจจับวัตถุ | |
| } else { | |
| Serial.println("No Object Detected."); | |
| } | |
| delay(500); // หน่วงเวลา 0.5 วินาที | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment