วชิ า ง20216 ระบบอตั โนมัติฯ ชน้ั มัธยมศึกษาปีท่ี 2 ผู้สอน นายกฤษฎา ทองกาเหนดิ การใชก้ ลอ่ งสมองกลฝังตัว IoT ชุด Arduino Uno R3 กิจกรรม การควบคมุ ตาแหนง่ Servo Motor โดยใช้ Potentiometer Servo คอื Motor ทเ่ี ราสามารถส่งั งานหรอื ตั้งค่า แล้วตวั Motor จะหมุนไปยงั ตาแหนง่ องศาทเี่ ราสัง่ ได้เองอยา่ งถกู ต้อง Potentiometer (โพเทนชโิ อมิเตอร์). คือตัวตา้ นทานปรบั ค่าได้ เป็นตัวตา้ นทานทีค่ า่ ความตา้ นทาน สามารถปรับเปลีย่ นได้ อาจมีปุ่มสาหรบั หมุน หรอื เลอ่ื น เพื่อปรับค่าความต้านทาน การเช่อื มต่อวงจร เช่อื มตอ่ Arduino UNO R3 กับ Servo Motor และ Potentiometer ดงั น้ี Arduino Servo Potentiometer 5v Red Right GND Brown Left D9 Orange - A0 - Middle การโปรแกรม #include <Servo.h> Servo myservo; // create servo object to control a servo int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin void setup(){ myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop(){ // reads the value of the potentiometer (value // between 0 and 1023) val = analogRead(potpin); // scale it to use it with the servo (value // between 0 and 180) val = map(val, 0, 1023, 0, 179); myservo.write(val); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there }
ใบงาน กิจกรรม การควบคมุ ตาแหน่ง Servo Motor โดยใช้ Potentiometer จงอธบิ ายการทางานของคาสง่ั แตล่ ะบรรทดั #include <Servo.h> ………………………………………………………… myservo.attach(9); ………………………………………………………… val = analogRead(potpin); ………………………………………………………… val = map(val, 0, 1023, 0, 179); ………………………………………………………… myservo.write(val); ………………………………………………………… ผลลพั ธ์ของโปรแกรมน้ี คือ ………………………………………………………………………………………………….............................................................. ………………………………………………………………………………………………….............................................................. ………………………………………………………………………………………………….............................................................. ………………………………………………………………………………………………….............................................................. ความรู้ทไ่ี ด้รับจากกิจกรรมน้ี ………………………………………………………………………………………………….............................................................. ………………………………………………………………………………………………….............................................................. ………………………………………………………………………………………………….............................................................. …………………………………………………………………………………………………..............................................................
Search
Read the Text Version
- 1 - 2
Pages: