Page cover image

LAB: Basic Digital Input/Output

การวัดค่าแรงดันของวงจรและเขียนโปรแกรมสำหรับรับและส่งข้อมูลดิจิตอลผ่านขา I/O ของ Embedded board

จุดประสงค์

  1. สามารถอ่านจาก Datasheet ของ LED และคำนวณหาค่าความต้านทาน(Resistor)ที่เหมาะสมกับวงจรได้

  2. สามารถวัดและอ่านค่าแรงดันของขาอุปกรณ์ด้วย Digital Multimeter ได้

  3. สามารถเขียนโปรแกรมลง Embedded board เพื่อควบคุมอุปกรณ์ผ่านขา I/O ด้วยสัญญาณดิจิตอลได้

Lab 1: การวัดค่าแรงดันขา Output ที่ส่งสัญญาณ แบบ Digital

ทดลองเขียนโปรแกรมส่งสัญญาณแบบดิจิตอลผ่านขา Output ของ Arduino board และใช้ MyDAQ การวัดค่าแรงดันที่ค่า output ของบอร์ด

อุปกรณ์ทดลอง

Component Quantity

Arduino mega2560

1

myDAQ

1

โปรแกรม

  1. Arduino IDE

  2. โปรแกรม NI ELVISSmx

Code

// lab1: basic digital output 
  const int Output_digital = 7; //set pin 7 to active

void setup() {
  // put your setup code here, to run once:
  pinMode (Output_digital,OUTPUT); // assingn Output_digital to work as Output 
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(Output_digital,HIGH); // Make this pin to be High
}

บันทึกผลการทดลอง

  1. ทำการวัดและอ่านค่าแรงดันที่แสดงผลบน Digital multimeter Application

  2. บันทึกผลการทดลอง template ที่ได้รับมอบหมาย

Lab 2: การเลือกค่าความต้านทาน(Resistor)ที่เหมาะสมกับวงจร LED

  • อ่าน Datasheet ของ LED ที่ให้มาแล้วคำนวณหาค่า ความต้านทาน ที่รองรับแรงดัน 5V เพื่อไม่ให้แรงดันที่ตกคร่อม LED เกินกว่าค่าที่ระบุไว้ใน Datasheet

  • ทำการต่อวงจรและวัดค่าแรงดันที่ตกคร่อม LED พร้อมทั้งจดบันทึกผล

อุปกรณ์ทดลอง

Component Quantity

Arduino mega2560

1

myDAQ

1

Red LED

1

Resistor

1

โปรแกรม

  1. Arduino IDE

  2. โปรแกรม NI ELVISSmx

Schematic

Circuit Diagram

บันทึกผลการทดลอง

  1. ทำการวัดแรงดันและอ่านค่าแรงดันตกคร่อม led และ ตัวต้านทาน จาก Digital multimeter Application

  2. บันทึกผลการทดลอง template ที่ได้รับมอบหมาย

Lab3: Basic Digital Input/Output

ทดลองเขียนโปรแกรมรับข้อมูลแบบดิจิตอลจาก button ผ่านขา Input และส่งข้อมูลแบบดิจิตอลเพื่อควบคุม LED ผ่านขา Output ของ Aduino Uno R3

อุปกรณ์ทดลอง

Component Quantity

Arduino Uno R3

1

Pushbutton

1

Resistor

1

Red LED

1

โปรแกรม

  1. Arduino IDE

  2. โปรแกรม NI ELVISSmx

Schematic

Circuit Diagram

Code

// Lab3: Basic Digital Input/Output
const int Output_digital = 7; //set pin 7 to active
const int Input_digital = 8;  //set pin 8 to active

void setup() {
  // put your setup code here, to run once:
  pinMode (Output_digital,OUTPUT); //set pin 7 as output
  pinMode (Input_digital,INPUT_PULLUP);   //set pin 8 as input
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  int Input = 0;
  Input = digitalRead(Input_digital);
  if (Input == 1)
    digitalWrite(Output_digital,HIGH); //when output is High LED is lit
  else
    digitalWrite(Output_digital,LOW);  //when output is Low LED is off

}

บันทึกผลการทดลอง

  1. บันทึกผลการทดลอง template ที่ได้รับมอบหมาย

Last updated

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University