สอนใช้งาน Arduino ระบุตำแหน่งพิกัด GPS บนพื้นโลกด้วย GPS Module GY-NEO6MV2 Ublox
โมดูล GPS มีหลายรุ่น ซึ่งมีมาตรฐานการสื่อสารและรูปแบบการจัดส่งข้อมูลคล้าย ๆ กัน
ในบทความนี้จะสอนใช้งาน Arduino อ่านค่า GPS Module เพื่อหาตำแหน่งพิกัดต่างๆบนพื้นโลก โดยใช้โมดูล NEO6MV2 ซึ่งสามารถใช้กับโมดูล GPS รุ่นอื่น ๆ ได้เช่นกันอุปกรณ์ที่ต้องใช้ใน บทความ สอนใช้งาน Arduino ระบุตำแหน่งพิกัด GPS บนพื้นโลกด้วย GPS Module GY-NEO6MV2 Ublox
วิธีการต่ออุปกรณ์ สอนใช้งาน Arduino ระบุตำแหน่งพิกัด GPS บนพื้นโลกด้วย GPS Module GY-NEO6MV2 Ublox
Arduino uno r3 -> GPS Module GY-NEO6MV2 Ublox
- 5V -> VCC
- GND -> GND
- ขา 4 -> Tx
- ขา 3 -> Rx
โหลด Library GPS Module GY-NEO6MV2 Ublox
วิธีลง Library ให้ดูตัวอย่างในบทความนี้
อัพโหลดโคดตัวอย่างลงบอร์ด Arduino uno r3 แล้วดูผลลัพธ์
---
เปิด Serial Monitor ขึ้นมา
จะเห็นค่าที่ Arduino อ่านได้จาก GPS Module GY-NEO6MV2 Ublox เป็นค่าตำแหน่งพิกัด ละติจูด ลองจิจูด วัน เดือน ปี ความเร็ว ความสูงจากน้ำทะเล
ถ้าเราเอาค่า ละติจูด ลองจิจูด นี้ ไปค้นหาใน Google map จะได้ตำแหน่งพิกัดของ GPS Module GY-NEO6MV2 Ublox ที่ติดตั้งอยู่บนพื้นโลก
GPS จำเป็นต้องมองเห็นท้องฟ้า เพื่อรับสัญญาณจากดาวเทียม ดังนั้นหลาย ๆ คนที่ทดลองในห้องแล้วพบว่าจับสัญญาณไม่ได้ วิธีแก้ง่าย ๆ คือออกไปทดลองในที่โล่ง
ตัวอย่างการใช้งาน NEO-6M Ublox/u-blox GPS Module
ดาวน์โหลดและติดตั้งไลบารี่ที่นี่
https://www.arduinoall.net/arduino-tutor/code/TinyGPSPlus-master.zip
โคดไลบารีแสดงพิกัด lat , lon ดาวน์โหลดได้ที่นี่
https://github.com/LessonStudio/Arduino_GPS
#include "TinyGPS++.h" #include "SoftwareSerial.h" SoftwareSerial serial_connection(10, 11); //RX=pin 10, TX=pin 11 TinyGPSPlus gps;//This is the GPS object that will pretty much do all the grunt work with the NMEA data void setup() { Serial.begin(9600);//This opens up communications to the Serial monitor in the Arduino IDE serial_connection.begin(9600);//This opens up communications to the GPS Serial.println("GPS Start");//Just show to the monitor that the sketch has started } void loop() { while(serial_connection.available())//While there are characters to come from the GPS { gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time } if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in { //Get the latest info from the gps object which it derived from the data sent by the GPS unit Serial.println("Satellite Count:"); Serial.println(gps.satellites.value()); Serial.println("Latitude:"); Serial.println(gps.location.lat(), 6); Serial.println("Longitude:"); Serial.println(gps.location.lng(), 6); Serial.println("Speed MPH:"); Serial.println(gps.speed.mph()); Serial.println("Altitude Feet:"); Serial.println(gps.altitude.feet()); Serial.println(""); } }ทดสอบโมดูล GPS แบบ Indoor
1.ดาวน์โหลดโปรแกรมทดสอบที่นี่2.ต่อโมดูลกับ USB TTL หรือบอร์ด Arduino Uno ที่ถอดชิฟ Atmega328P ออกแล้ว ดังนี้
- TX - TX
- RX - RX
- VCC - 5V
- GND - GND

3. เปิดโปรแกรมแล้วดูผลลัพธ์ จะเห็นว่ามีสัญญาณดาวเทียมขึ้น
กดปุ่ม Connect กับ Comport ให้ถูกต้อง

คลิกที่เมนู จะเห็นว่ามีการรับสัญญาณดาวเทียมได้แล้ว แต่ยังจับไม่ได้เพราะอยู่ในร่ม ถ้าออกไปใช้ในที่โลงก็จะจับได้ปกติ
ดูสอนวิธีใช้งาน Arduino บทต่อไป
#36 Arduino สอนใช้งาน Arduino วัดความเข้มแสงด้วยเซ็นเซอร์ GY-302 BH1750FVI
#38 Arduino สอนใช้งาน Arduino Rfid อ่านบัตรคีย์การ์ด ควบคุมเปิดปิดไฟ LED
หน้าหลักบทความสอน Arduino แบบย่อทั้งหมด