LAB: Pulse Width Modulation (PWM)
จุดประสงค์
เข้าใจหลักการทำงานของ PWM
สามารถสร้างกราฟสัญญาณ PWM โดยใช้ Arduino board ได้
LAB: การสร้างสัญญาณ PWM
การทดลองปรับค่า potentiometer จนได้ duty cycle 50% บันทึกผลกราฟ และอ่านค่าความถี่(Hz), แรงดัน(V) จากกราฟที่ได้
อุปกรณ์ทดลอง
Component
Quantity
Arduino mega2560
1
myDAQ
1
Potentiometer
1

โปรแกรม
Arduino IDE
โปรแกรม NI ELVISSmx
Schematic

Circuit Diagram

Code
//Arduino Mage 2560 read potentiometer and write LED
int sensorPin = A8; // connect this pin to potentiometer
int ledPin = 2; // connect this pin to external LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT); // set this pin to output
Serial.begin(9600); // start serial monitor
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
sensorValue = map(sensorValue, 0,1023,0,255);
// turn the ledPin on
analogWrite(ledPin, sensorValue);
Serial.println(sensorValue); // bright LED with read value
}
บันทึกผลการทดลอง
บันทึกภาพวงจร ผลกราฟ, serial monitor และอธิบายการทดลองลง template ที่ได้รับมอบหมาย
Last updated
Was this helpful?