Body 101 · บทที่ 17 AI กับหุ่นยนต์ ทีมเดียวกัน · ระดับ 9

ชุดโครงงาน AI ขับรถ

ชุดนี้ต่อ AI ที่หนูสอนเองใน Teachable Machine เข้ากับรถจากบทที่ 16 กล้องของคอมพิวเตอร์ดูการ์ดลูกศรหรือท่ามือ AI ในเบราว์เซอร์เลือกตัวอักษร F L R หรือ S แล้วส่งลงสาย USB ไปให้ Arduino หมุนล้อ AI เป็นสมอง รถเป็นร่างกาย สายเป็นเส้นประสาท และหนูเป็นคนดูผลแล้วเปลี่ยนท่ามือ

English version below · อ่านวิธีทำเต็มๆ ในบทเรียน ระดับ 9

บอกกันตรงๆ หน้าเว็บทดสอบแล้วกับรถจำลองและกล้องจำลอง ยังไม่ได้ทดสอบกับรถจริงและกล้องจริง โค้ด Arduino ทดสอบตรรกะบนคอมพิวเตอร์แล้ว แต่ยังไม่เคยคอมไพล์ลงบอร์ด ต้องกด Verify ในโปรแกรม Arduino ก่อนใช้

ไฟล์ในชุด

อินเทอร์เน็ตและความเป็นส่วนตัว อ่านกับผู้ใหญ่ก่อนเปิด
  • หน้า AI Driver โหลดไลบรารี AI สองตัวจาก cdn.jsdelivr.net คือ TensorFlow.js รุ่น 4.22.0 และ @teachablemachine/image รุ่น 0.8.5 และโหลดโมเดลของหนูจากเซิร์ฟเวอร์ของ Google
  • ภาพจากกล้องถูกประมวลผลในเบราว์เซอร์ หน้า AI Driver ไม่ได้อัปโหลดภาพออกไป
  • ลิงก์โมเดลที่ได้จาก Upload my model เป็นลิงก์สาธารณะ ใครมีลิงก์ก็ใช้โมเดลได้ จึงสอน AI ด้วยการ์ดลูกศรหรือท่ามือเท่านั้น ห้ามถ่ายหน้าคน
  • ระหว่างฝึก Google บอกว่าภาพตัวอย่างอยู่ในคอมพิวเตอร์ของเรา เว้นแต่เลือกบันทึกโปรเจกต์ลง Google Drive
  • หน้านี้ที่หนูกำลังอ่านอยู่ไม่มีสคริปต์และไม่ได้ส่งข้อมูลอะไรออกไป

หาซื้ออุปกรณ์ใน Lazada

ปุ่มจะพาไปหน้าค้นหาของ Lazada ในแท็บใหม่ ไม่ได้ผูกกับร้านใดร้านหนึ่ง ให้ผู้ใหญ่เป็นคนเลือกร้านและกดสั่งซื้อ

ง่ายที่สุด ซื้อเป็นชุดรวม ชุดรถเดินตามเส้นราว 550 ถึง 750 บาท อ่านรายการของในกล่องก่อนซื้อ ชุดส่วนใหญ่ไม่มีเซ็นเซอร์ HC-SR04 และสาย USB ยาว และรางถ่านอาจไม่มีสวิตช์ ต้องซื้อเพิ่มจากตารางข้างล่าง

ค้นหาชุดรถใน Lazada

หรือซื้อแยกทีละชิ้น รวมราว 400 ถึง 700 บาท ไม่รวมถ่าน

ชิ้นส่วนราคาโดยประมาณดูให้ดีก่อนซื้อค้นหา
บอร์ด Arduino Uno R3 พร้อมสาย USB140 ถึง 220 บาทบางร้านขายแต่บอร์ด ไม่รวมสาย ดูให้ดีว่ามีสาย USB มาด้วยLazada
บอร์ดขับมอเตอร์ L298N40 ถึง 75 บาทแผงสีแดง มีครีบระบายความร้อนสีดำLazada
โครงรถ 2 ล้อพร้อมมอเตอร์90 ถึง 150 บาทต้องมีมอเตอร์เกียร์สีเหลือง 2 ตัว ล้อ 2 ล้อ และล้อหมุนอิสระ ไม่ใช่แผ่นอะคริลิกเปล่าLazada
โมดูลเซ็นเซอร์ TCRT5000 จำนวน 2 ชิ้น20 ถึง 35 บาทต่อชิ้นเลือกแบบโมดูลที่มีแผงวงจรเล็กและขา 3 ขา ไม่ใช่ตัวเซ็นเซอร์เปล่าราคาไม่กี่บาท และไม่ใช่แบบ 5 ช่องLazada
รางถ่าน AA 4 ก้อน แบบมีสวิตช์20 ถึง 45 บาทต้องมีสวิตช์เปิดปิด เพื่อตัดไฟได้ทันทีLazada
สายจัมเปอร์15 ถึง 30 บาทซื้อทั้งแบบผู้กับเมีย และแบบผู้กับผู้Lazada
เซ็นเซอร์อัลตราโซนิก HC-SR04 สำหรับโครงงาน 3 บทที่ 1630 ถึง 60 บาทถ้าไม่ทำโครงงานหลบสิ่งกีดขวาง ไม่ต้องซื้อLazada
สาย USB ยาว 3 เมตร สำหรับโครงงาน AI ขับรถ บทที่ 1720 ถึง 45 บาทดูหัวต่อบนบอร์ดก่อน บอร์ดส่วนใหญ่ใช้หัว Type B แต่บางรุ่นใช้ Type-CLazada

ราคาโดยประมาณจากหน้าค้นหาของ Lazada เมื่อเดือนกันยายน 2569 ร้านและราคาเปลี่ยนได้ตลอด ควรเลือกร้านที่มีรีวิวดีและส่งจากในไทย เว็บไซต์นี้ไม่ได้รับค่าตอบแทนจากร้านค้าหรือ Lazada

วิธีเปิดหน้า AI Driver

เบราว์เซอร์ยอมให้ใช้พอร์ตและกล้องเฉพาะหน้าที่ปลอดภัย คือหน้าที่เปิดจาก https หรือจาก localhost

ทางที่ง่ายที่สุด เปิดจากหน้านี้เลย

หน้านี้อยู่บนเว็บที่ขึ้นต้นด้วย https กดปุ่ม เปิดหน้า AI Driver ข้างบนใน Chrome หรือ Edge ได้เลย ไม่ต้องใช้ python และไม่ต้องพิมพ์คำสั่งอะไร

อีกทาง เปิดจากไฟล์ในเครื่อง ผ่าน localhost (ผู้ใหญ่ทำ)

  1. ดาวน์โหลดไฟล์ zip แล้วแตกไฟล์ไว้ในโฟลเดอร์หนึ่ง
  2. เปิด Terminal (Mac หรือ Linux) หรือ Command Prompt (Windows) ในโฟลเดอร์ที่มีไฟล์ ai-driver.html
  3. พิมพ์คำสั่งนี้ (บน Windows ถ้าหาคำสั่ง python3 ไม่เจอ ลอง py -m http.server)
    python3 -m http.server
  4. เปิด Chrome หรือ Edge ไปที่ http://localhost:8000/ai-driver.html
  5. เล่นเสร็จแล้ว กลับไปที่ Terminal แล้วกด Ctrl + C

ดับเบิลคลิกไฟล์ตรงๆ อาจใช้ได้ใน Chrome แต่ยังไม่ยืนยัน

ใช้ Chrome หรือ Microsoft Edge บนคอมพิวเตอร์ Windows Mac Linux หรือ ChromeOS ใช้ Safari ไอโฟน และไอแพดไม่ได้ Firefox รุ่นใหม่และ Chrome บน Android รุ่นใหม่รองรับแล้ว แต่ยังไม่ได้ทดสอบกับโครงงานนี้ จึงแนะนำให้ใช้คอมพิวเตอร์

⚠ ปลอดภัยไว้ก่อน
  • ทำกับผู้ใหญ่ทุกครั้ง
  • เล่นบนพื้นเท่านั้น ห้ามบนโต๊ะ
  • ใช้ความเร็วต่ำตามโค้ด
  • ผู้ใหญ่อยู่ใกล้สวิตช์ถ่านตลอดเวลา
  • ทดสอบล้อลอยก่อน
  • นิ้วห่างล้อ
  • ปิดถ่านก่อนถอดสาย
  • ไม่ทิ้งให้รถวิ่งโดยไม่มีคนดู
  • เรื่องถ่าน ห้ามใช้ถ่านเก่าปนใหม่ ห้ามลัดวงจร ถอดถ่านเมื่อเล่นเสร็จ
  • ใช้ท่ามือหรือการ์ด ไม่ใช้หน้าคน
  • ไม่ต่อแบบไร้สายในโครงงานแรก

12 ขั้นแบบย่อ

  1. ตรวจร่างกายก่อน อัปโหลดโค้ดทดสอบของบทที่ 16 วางรถบนกล่องให้ล้อลอย ดูว่าล้อหมุนเดินหน้าทั้งสองข้าง
  2. ทำการ์ด 4 ใบ ลูกศรขึ้น ซ้าย ขวา และรูปฝ่ามือ
  3. สอนตาใน Teachable Machine กลุ่ม Forward Left Right Stop และ Nothing กลุ่มละอย่างน้อย 50 ภาพ ถ่ายแค่การ์ดหรือมือ
  4. ฝึกแล้วทดสอบในหน้าตัวอย่าง ทุกท่าควรขึ้นถึง 80% อย่างสม่ำเสมอ
  5. Export แล้ว Upload my model แล้วคัดลอกลิงก์
  6. ปิดสวิตช์ถ่าน กด Verify แล้ว Upload ai_driver_car.ino แล้วปิด Serial Monitor
  7. เปิดหน้า AI Driver ใน Chrome หรือ Edge จาก https หรือ localhost
  8. ล้อลอยอยู่ เปิดสวิตช์ถ่าน กด 1. Connect robot เลือกพอร์ต วางลิงก์ กด 2. Start camera
  9. ทดสอบความปลอดภัย 8 ข้อตอนล้อลอย ต้องผ่านครบ รวมถึง กด STOP กด Esc และสลับแท็บ ล้อต้องหยุด
  10. ขับบนพื้นเท่านั้น เคลียร์ที่รอบรถ ไม่มีสัตว์เลี้ยงหรือน้องเล็ก ผู้ใหญ่ถือสายให้หย่อนและอยู่ใกล้สวิตช์ถ่าน ใช้ความเร็วตามโค้ด กด STOP หรือ Esc ได้ทุกเมื่อ
  11. ทดลองต่อ เช่น เปลี่ยน THRESHOLD เป็น 0.6 หรือ 0.95 การแก้โค้ดต้องใช้ไฟล์ในเครื่อง ดาวน์โหลดชุดไฟล์ zip แก้ ai-driver.html ด้วยโปรแกรมแก้ข้อความ แล้วเปิดผ่าน localhost ตามอีกทางข้างบน หน้าบนเว็บแก้ไม่ได้
  12. เก็บของ กด STOP แล้วปิดสวิตช์ถ่าน แล้วถอดสาย USB

รายละเอียด เหตุผลของแต่ละขั้น เกมเรียงขั้น และรายการตรวจที่พิมพ์ได้ อยู่ในบทเรียน ระดับ 9


Body 101 · Lesson 17 AI + Robots, One Team · Level 9

AI Driver kit

This kit connects an image model that you train yourself in Teachable Machine to the robot car from lesson 16. The computer's webcam looks at an arrow card or a hand sign, the AI in the browser picks one letter (F, L, R or S) and sends it down the USB cable, and the Arduino turns the wheels. The AI is the brain, the car is the body, the cable is the nerve, and you watch the result and change your hand sign.

Full step-by-step guide in the lesson (level 9)

Honest note The web page was tested with a pretend robot and a pretend camera. It has not been tested with a real robot and a real camera. The Arduino code was logic-tested on a computer but has never been compiled for a board. Press Verify in the Arduino IDE before you use it.

Files

Network and privacy (read with an adult first)
  • The AI Driver page loads two libraries from cdn.jsdelivr.net, TensorFlow.js 4.22.0 and @teachablemachine/image 0.8.5 (pinned versions), and loads your model from Google's servers.
  • Camera frames are processed in the browser. The AI Driver page does not upload them.
  • The link you get from "Upload my model" is public: anyone who has it can use the model. Train on arrow cards or hand signs only, never on faces.
  • Google says the example photos stay on your computer while you train, unless you choose to save the project to Google Drive.
  • This page you are reading has no scripts and sends nothing anywhere.

Buying the parts on Lazada

Each button opens a Lazada search in a new tab and is not tied to any one shop. An adult should choose the shop and place the order.

Easiest: buy a complete kit. A line-follower car kit costs about 550 to 750 baht. Read the list of what is in the box before buying. Most kits have no HC-SR04 sensor and no long USB cable, and the battery holder may have no switch, so add those from the table below.

Search Lazada for kits

Or buy the parts one by one. About 400 to 700 baht in total, not counting batteries.

PartApproximate priceCheck before you buySearch
Arduino Uno R3 board with USB cable140 to 220 bahtSome shops sell the board without the cable, so check that a USB cable is includedLazada
L298N motor driver board40 to 75 bahtA red board with a black heatsinkLazada
Two-wheel car chassis with motors90 to 150 bahtIt must come with 2 yellow gear motors, 2 wheels and a free-spinning caster, not just a bare acrylic plateLazada
2 TCRT5000 sensor modules20 to 35 baht eachChoose the module with a small circuit board and 3 pins, not the bare sensor that costs a few baht, and not the 5-channel versionLazada
4 x AA battery holder with a switch20 to 45 bahtIt must have an on/off switch so you can cut the power at onceLazada
Jumper wires15 to 30 bahtGet both male-to-female and male-to-maleLazada
HC-SR04 ultrasonic sensor, for project 3 in Lesson 1630 to 60 bahtYou only need it for the obstacle-avoider projectLazada
3-metre USB cable, for the AI Driver project in Lesson 1720 to 45 bahtCheck the socket on your board first: most use Type B, but some use Type-CLazada

Approximate prices from Lazada search pages in September 2026. Shops and prices change all the time. Choose shops with good reviews that ship from within Thailand. This website receives no payment from any shop or from Lazada.

How to open AI Driver

Browsers only allow serial ports and the camera on secure pages: pages opened from https or from localhost.

Easiest: open it from this page

This page is served over https, so just press Open AI Driver above in Chrome or Edge. No Python and no commands needed.

Alternative: run it from your own computer via localhost (adult step)

  1. Download the zip and unzip it into a folder.
  2. Open Terminal (Mac or Linux) or Command Prompt (Windows) in the folder that contains ai-driver.html.
  3. Type this command (on Windows, if python3 is not found, try py -m http.server):
    python3 -m http.server
  4. Open http://localhost:8000/ai-driver.html in Chrome or Edge.
  5. When you are done, go back to the terminal and press Ctrl + C.

Double-clicking the file may work in Chrome, but this is not confirmed.

Use Chrome or Microsoft Edge on a Windows, Mac, Linux or ChromeOS computer. Safari, iPhone and iPad do not work. Newer Firefox and newer Chrome on Android support Web Serial, but they have not been tested with this project, so please use a computer.

⚠ Safety first
  • Always build and drive with an adult.
  • Drive on the floor only, never on a table.
  • Keep the low speeds in the code.
  • An adult stays next to the battery switch the whole time.
  • Test with the wheels lifted first.
  • Keep fingers away from the wheels.
  • Switch the battery pack off before unplugging the USB cable.
  • Never leave the car running with nobody watching.
  • Batteries: never mix old and new, never short-circuit them, and take them out when you finish.
  • Use hand signs or cards, never faces.
  • No wireless connection in your first build.

The 12 steps in short

  1. Check the body first: upload the lesson 16 test code, put the car on a box with the wheels lifted, and check that both wheels turn forward.
  2. Make 4 cards: up arrow, left arrow, right arrow and an open palm.
  3. Teach the eyes in Teachable Machine: classes Forward, Left, Right, Stop and Nothing, at least 50 pictures each, cards or hands only.
  4. Train, then test in the preview: every sign should reach 80% reliably.
  5. Export, press Upload my model, and copy the link.
  6. Battery switch off: Verify, then Upload ai_driver_car.ino, then close the Serial Monitor.
  7. Open AI Driver in Chrome or Edge from https or localhost.
  8. Wheels still lifted: switch the battery on, press 1. Connect robot, pick the port, paste the link, press 2. Start camera.
  9. Run the 8 wheels-lifted safety tests. All must pass, including STOP, Esc and switching tabs (the wheels must stop).
  10. Drive on the floor only. Clear the area first, with no pets or small children nearby. An adult holds the cable loosely and stays next to the battery switch. Keep the speeds in the code, and press STOP or Esc at any time.
  11. Experiment, for example change THRESHOLD to 0.6 or 0.95. Editing the code needs your own copy: download the zip, edit ai-driver.html in a text editor, then open it through localhost (the alternative above). The page on this website cannot be edited.
  12. Pack up: press STOP, switch the battery off, then unplug the USB cable.