# LAB: Basic Digital Input/Output

## **จุดประสงค์**&#x20;

1. &#x20;สามารถอ่านจาก Datasheet ของ LED และคำนวณหาค่าความต้านทาน(Resistor)ที่เหมาะสมกับวงจรได้
2. สามารถวัดและอ่านค่าแรงดันของขาอุปกรณ์ด้วย Digital Multimeter ได้&#x20;
3. สามารถเขียนโปรแกรมลง Embedded board เพื่อควบคุมอุปกรณ์ผ่านขา I/O ด้วยสัญญาณดิจิตอลได้&#x20;

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

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

### **อุปกรณ์ทดลอง**&#x20;

<table><thead><tr><th width="397">Component </th><th>Quantity</th></tr></thead><tbody><tr><td>Arduino mega2560</td><td>1</td></tr><tr><td>myDAQ</td><td>1</td></tr></tbody></table>

![](/files/eMVHQLfMlqbZNMPNEzO9)

### โปรแกรม

1. Arduino IDE
2. โปรแกรม NI ELVISSmx

### **Code**

```arduino
// 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
}

```

### **บันทึกผลการทดลอง**&#x20;

1. ทำการวัดและอ่านค่าแรงดันที่แสดงผลบน Digital multimeter Application&#x20;
2. บันทึกผลการทดลอง template ที่ได้รับมอบหมาย&#x20;

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

* อ่าน [Datasheet](https://components101.com/sites/default/files/component_datasheet/5mm-LED-Datasheet.pdf) ของ LED ที่ให้มาแล้วคำนวณหาค่า ความต้านทาน ที่รองรับแรงดัน 5V เพื่อไม่ให้แรงดันที่ตกคร่อม LED เกินกว่าค่าที่ระบุไว้ใน [Datasheet](https://components101.com/sites/default/files/component_datasheet/5mm-LED-Datasheet.pdf)&#x20;
* ทำการต่อวงจรและวัดค่าแรงดันที่ตกคร่อม LED พร้อมทั้งจดบันทึกผล

### **อุปกรณ์ทดลอง**&#x20;

| Component        | Quantity |
| ---------------- | -------- |
| Arduino mega2560 | 1        |
| myDAQ            | 1        |
| Red LED          | 1        |
| Resistor         | 1        |

![](/files/A0lKtSUIPQTeU2sCLBGW)

### โปรแกรม

1. Arduino IDE
2. โปรแกรม NI ELVISSmx

### **Schematic**&#x20;

![](/files/SIWD3KElmx7LsbuzMuVk)

### **Circuit Diagram**

![](/files/C2psTvXajI6JuPcE0TDj)

### **บันทึกผลการทดลอง**&#x20;

1. ทำการวัดแรงดันและอ่านค่าแรงดันตกคร่อม led และ ตัวต้านทาน จาก Digital multimeter Application&#x20;
2. บันทึกผลการทดลอง template ที่ได้รับมอบหมาย&#x20;

## **Lab3:** **Basic Digital Input/Output**

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

### **อุปกรณ์ทดลอง**&#x20;

| Component      | Quantity |
| -------------- | -------- |
| Arduino Uno R3 | 1        |
| Pushbutton     | 1        |
| Resistor       | 1        |
| Red LED        | 1        |

![](/files/qCo0bjvc0WBI21WhHJw9)

### โปรแกรม

1. Arduino IDE
2. โปรแกรม NI ELVISSmx

### **Schematic**&#x20;

![](/files/hwDIFJBDxLiHqspvfwtV)

### **Circuit Diagram**

![](/files/liiHRJmDkPTRU428qbDY)

### **Code**

```arduino
// 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

}
```

### **บันทึกผลการทดลอง**&#x20;

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/embedded-systems/resources/basic-hardware-and-firmware/lab1-oscilloscope/basic-digital-and-analog-i-o/lab-basic-digital-input-output.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
