반응형
다음은 HMC5883L을 Arduino 보드에 연결하는 단계입니다.
HMC5883L의 VCC 핀을 Arduino 보드의 3.3V 핀에 연결합니다.
HMC5883L의 GND 핀을 Arduino 보드의 GND 핀에 연결합니다.
HMC5883L의 SDA 핀을 Arduino 보드의 A4(SDA) 핀에 연결합니다.
HMC5883L의 SCL 핀을 Arduino 보드의 A5(SCL) 핀에 연결합니다.
HMC5883L이 Arduino 보드에 제대로 연결되어 있고 올바른 라이브러리가 Arduino IDE에 설치되어 있는지 확인하십시오. HMC5883L을 연결한 후 이전 답변에서 제공된 예제 코드를 사용하여 센서에서 자기장 값을 검색할 수 있습니다.
#include <Wire.h>
#include <HMC5883L.h>
HMC5883L compass;
void setup() {
Serial.begin(9600); // Initialize serial communication with a baud rate of 9600
Wire.begin(); // Start the I2C communication
compass.init(); // Initialize the magnetometer
compass.calibrate(); // Calibrate the magnetometer
}
void loop() {
Vector norm = compass.readNormalize(); // Read the magnetic field values
// Convert the magnetic field values to angles
float heading = atan2(norm.YAxis, norm.XAxis);
// Print the heading to the serial monitor
Serial.print("Heading: ");
Serial.println(heading * 180/M_PI);
delay(500); // Wait for 500 milliseconds
}
이 코드는 HMC5883L 라이브러리를 사용하여 자력계 센서와 통신하고 자기장 값을 검색합니다. 그런 다음 값이 각도로 변환되어 직렬 모니터에 인쇄됩니다.
반응형
'TECH' 카테고리의 다른 글
[Arduino] 아두이노로 LCD Display 사용하기 (0) | 2023.02.13 |
---|---|
Offboard vs Onboard Control (0) | 2023.02.13 |
[Arduino] 아두이노로 MPU-6050 가속도센서 사용하기 (0) | 2023.02.02 |
[Arduino] Xbee 통신 예제 코드 (0) | 2023.01.30 |
[Arduino] 7 Segments로 Serial Input 받은 숫자 표시하기 (0) | 2023.01.29 |
댓글