Skip to main content

Arduino กับการใช้งานสวิทซ์

Arduino กับการใช้งาน ปุ่มกด


สวิตซ์แบบต่างๆ

ในบทความนี้จะเป็นตัวอย่างการใช้งานบอร์ด Arduino กับสวิตซ์ โดยให้บอร์ด Arduino อ่านค่าสถานะทางดิจิทัลของสวิตซ์เพื่อเป็นอินพุตไปสั่งงานฟังก์ชันต่างๆ ตามที่ผู้ใช้ต้องการ

สำหรับวงจรในการต่อสวิตซ์นั้นจะมีอยู่ 2 แบบคือ 
  1. แบบ pull-up (โดยปกติสถานะจะมีค่าเป็น '1' แต่ถ้ากดปุ่ม สถานะจะมีค่าเป็น '0')
  2. แบบ pull-down (โดยปกติสถานะจะมีค่าเป็น '0' แต่ถ้ากดปุ่ม สถานะจะมีค่าเป็น '1')

วงจรสวิตซ์แบบ pull-up, pull-down

สำหรับในบทความนี้จะต่อวงจรแบบ pull-up (โดยปกติมีค่าเป็น '1' แต่ถ้ากดปุ่มจะมีค่าเป็น '0') โดยตัวอย่างการต่อมีดังนี้

ต่อสวิตซ์แบบ pull-up
ตัวอย่างโปรแกรมที่ใช้
แต่ภายในบอร์ด Arduino มีฟังก์ชันพิเศษสำหรับใช้งานวงจร pull-up ภายใน ดังนั้นจึงสามารถ ต่อเพียงเเค่สวิตซ์ได้ (แต่ต้องมีการประกาศเป็น INPUT_PULLUP)
ต่อสวิตซ์โดยใช้วงจร pull-up ภายใน
ตัวอย่างโปรแกรมที่ใช้
หลังจากอัพโหลดโปรเเกรมลงบนบอร์ด Arduino ดูผลลัพธ์การรันโปรแกรมได้จาก Serial Monitor หรือ Serial Plottor
Serial Monitor
Serial Plottor

Comments

Popular posts from this blog

Arduino กับการใช้งาน Serial Monitor

Arduino กับการใช้งาน Serial Monitor Serial Monitor คือ ส่วนหนึ่งของโปรแกรม Arduino IDE สามารถใช้งานได้ 2 อย่าง คือ - แสดงผลลัพธ์จากบอร์ด Arduino - ใช้รับข้อมูลจากผู้ใช้ แล้วส่งข้อมูลไปยังบอร์ด Arduino รูปแบบการใช้งาน Serial Monitor เริ่มต้นใช้งาน void setup() {    Serial.begin(9600); } แสดงผลออกทาง Serial Monitor Serial.print("Hello World");       /* แสดงคำว่า Hello World */ Serial.println("Hello World");     /* แสดงคำว่า Hello World และขึ้นบรรทัดใหม่ */   อ่านค่าจาก Serial Monitor Serial.read(); วิธีเปิด Serial Monitor 1. กด Ctrl + Shift + M 2. กด Icon ตัวอย่างการแสดงผลลัพธ์จากบอร์ด Arduino แสดงผลลัพธ์จากบอร์ด Arduino ตัวอย่างการรับค่าจาก Serial Monitor - ส่ง 1 เพื่อ On LED -  ส่ง 0 เพื่อ Off LED แสดงผลลัพธ์การรับค่าจาก Serial Monitor * ถ้าไม่สำเร็จ ตรวจสอบว่าเลือก No line ending และบอดเรทเป็น 9600 เเล้วหรือยัง

How to Use Arduino IDE without install in windows?

How to Use Arduino IDE without install in windows? Arduino IDE For this article is a short article. How to use Arduino IDE without install on the computer. Users can download files from Arduino.cc website and extract files to use immediately. Installing Arduino IDE Open your Internet Browser and go to https://www.arduino.cc/en/Main/Software Select your operating system. Select JUST DOWNLOAD After downloading the program, extract the file arduino-1.8.5.zip Open the program and test the compile. Notice Windows Only