กลับไปหน้ารวมไฟล์
automated-rail-crossing-system-sheekar-banerjee-886da1.md

Diorama Realism: Automated Rail Crossing

ระบบทางรถไฟอัตโนมัติ (ที่นักสร้างอย่าง Sheekar Banerjee เคยทำไว้) จะเปลี่ยนโมเดลรถไฟที่อยู่นิ่งๆ ให้กลายเป็นโลกจำลองที่ตอบสนองได้สมจริงสุดๆ มันผสานการควบคุมเซอร์โวเข้ากับตรรกะการกะพริบไฟ LED แบบไม่บล็อกการทำงาน เพื่อเลียนแบบสัญญาณเตือนตามสถานีจริงได้อย่างเนี๊ยบ!

วงจรเบื้องต้น:

Arduino ต่อกับเซ็นเซอร์อัลตราโซนิก (HC-SR04) Arduino -----> HC-SR04 Vin -----> Vcc GND -----> GND ขา 2 -----> trigPin ขา 3 -----> echoPin

Arduino ต่อกับ Servo Motor Arduino -----> Servo Motor Vin -----> สายแดง (+) GND -----> สายดำหรือน้ำตาล (-) ขา Digital pin 9 -----> สายเหลือง/ส้ม (data)

ลงลึกเรื่องเทคนิค

การกะพริบไฟแบบ Non-Blocking (ไม่บล็อก)

ส่วนที่ยากที่สุดของโปรเจคนี้คือ ไฟสัญญาณเตือน นี่แหละ

  • ทางรถไฟจริงจะมีไฟสีแดงสองดวงที่กะพริบสลับกัน: ซ้าย, ขวา, ซ้าย, ขวา
  • ถ้าน้องเขียนโค้ดด้วย delay(500); ตัว Arduino จะหยุดทำงานทั้งหมด มันจะฟังค่าจากเซ็นเซอร์ไม่ได้ว่ารถไฟผ่านไปหรือยัง!
  • น้องต้องใช้โครงสร้างตรรกะของ millis() เทคนิค "Blink Without Delay" นั่นแหละ
  • if (currentMillis - previousMillis >= 500) { toggleLights(); }
  • วิธีนี้ทำให้ Arduino กะพริบไฟ LED สัญญาณอันใหญ่โตได้เนียนๆ พร้อมกับคำนวณความเร็วรถไฟที่กำลังเข้ามาได้อีกด้วย

การควบคุมบาร์เกต (Boom Gates)

  1. ตอนรถไฟมา: เราเอาเซ็นเซอร์ TCRT5000 IR Sensor ฝังไว้ใต้รางรถไฟ ห่างจากทางข้ามประมาณ 3 ฟุต
  2. Arduino ตรวจจับรถไฟได้ มันจะเริ่มลำดับการกะพริบไฟ LED แบบไม่บล็อกทันที
  3. มันจะสั่งให้ SG90 Micro Servos (ซ่อนไว้ใต้ถนน) 2 ตัว ค่อยๆ หมุน 90 องศา เพื่อปล่อยบาร์เกตลงมา
  4. ตอนรถไฟออก: เราเอาเซ็นเซอร์ตัวที่สองฝังไว้ห่างจากทางข้าม 3 ฟุต ด้านหลัง พอรถไฟส่วนท้ายผ่านเซ็นเซอร์ตัวที่สอง Arduino จะยกบาร์เกตขึ้นและปิดไฟสัญญาณเตือน!

รายการอุปกรณ์สำหรับจัดฉาก

  • Arduino Uno/Nano: ศูนย์บัญชาการใหญ่
  • IR Obstacle Sensors (x2) หรือ Light Dependent Resistors.
  • Micro Servos (SG90 x2).
  • LED สีแดงและตัวต้านทาน 220 โอห์ม (x4) สำหรับติดตั้งในเสาไฟสัญญาณที่ปริ้นจาก 3D
  • MP3 Sound Module (ตัวเลือกเสริม: เอาไว้เปิดเสียงกระดิ่ง "ติ๊ง ติ๊ง ติ๊ง" ดังๆ จาก micro-SD card!)

โค้ด:

//the code is entirely created by: SHEEKAR BANERJEE (at December 2017)
//Dept. of CSE, IUBAT
//AI-ML-IOT Solution Engineer and Researcher
#include<Servo.h>  //This calls the Header of the repository containing the library files of Servo Motor Driver Modules
#define trigPin 2  //This initializes the Trig pin of HC-05 Ultrasonic Sensor to the pin no. 2 of Arduino Microcontroller
#define echoPin 3 //This initializes the Echo pin of HC-05 Ultrasonic Sensor to the pin no. 3 of Arduino Microcontroller
Servo sm;     //Servo is a Class which is providing an independent data type // sm is a variable which is representing the servo motor
int sound=250;
void setup() {
 Serial.begin(9600); //Streaming 9600 bits of sensor data per second
 pinMode(trigPin,OUTPUT); //Here, Trig pin triggers the electrical impulses into the sensor as an output
 pinMode(echoPin,INPUT);  //Here, Echo pin inputs the reflective signals into the sensor
 sm.attach(9);   //Servo motor data pin is attached to Arduino Digital Pin 3
}
void loop() {
 long duration, distance;
 digitalWrite(trigPin, LOW);
 delayMicroseconds(2);
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin, LOW);
 duration=pulseIn(echoPin, HIGH);
 distance=(duration/2)/29.1;       //Calculation of distance
 if(distance<10)
 {
   sm.write(80);
 }
 else {
   sm.write(0);
}
}

ผลลัพธ์:

ระบบทางรถไฟอัตโนมัติ | Sheekar Banerjee

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x Arduino IDE"
author: "sheekar"
category: ""
components:
  - "1x SG90 Micro-servo motor"
  - "1x Arduino UNO"
  - "1x Ultrasonic Sensor - HC-SR04 (Generic)"
description: "โปรเจคเทพๆ สุดจัดไปนี้ พี่เค้าสร้างกันในเดือนธันวาคม 2017 โดยทีมวิจัยหน้าใหม่สายฮาร์ดแวร์อย่าง SENSO CODER ที่พี่ Sheekar Banerjee เป็นคนตั้งตระกูลเลยวัยรุ่น!"
difficulty: "Intermediate"
documentationLinks: []
downloadableFiles: []
encryptedPayload: "U2FsdGVkX187K3R1bzCCqaEiugm8mlWK6JmptNsNVnAfRwCd7I3UspmsmQO5/2oI03JXjWc0zMNxYcAKIo2EivKln7oHa9TscKQPctId34A="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/automated-rail-crossing-system-sheekar-banerjee-886da1_cover.jpg"
lang: "en"
likes: 0
passwordHash: "2f2c9b00f91e3ff462c81d5abee4f588b1e4e0348aacd8c1dff38ae2601d7b38"
price: 1120
seoDescription: "Automated Rail Crossing System project developed by Sheekar Banerjee and the SENSO CODER research team in December 2017."
tags:
  - "embedded"
  - "smart appliances"
  - "human welfare"
  - "passenger vehicles"
  - "internet of things"
  - "monitoring"
title: "ระบบทางรถไฟอัตโนมัติตึงๆ | งานง่ายแต่หล่อ by Sheekar Banerjee"
tools: []
videoLinks:
  - "https://www.youtube.com/embed/6h3EgZV3Rgc"
views: 1335