Cov txheej txheem:

Tsis tshua muaj neeg yooj yim, tsis suav nrog Servo Compass: 7 Kauj Ruam
Tsis tshua muaj neeg yooj yim, tsis suav nrog Servo Compass: 7 Kauj Ruam

Video: Tsis tshua muaj neeg yooj yim, tsis suav nrog Servo Compass: 7 Kauj Ruam

Video: Tsis tshua muaj neeg yooj yim, tsis suav nrog Servo Compass: 7 Kauj Ruam
Video: New song 2018 Nkauj Mog Mim Hlub Yim Leej : By Nplooj Siab Vaj. The original. 2024, Kaum ib hlis
Anonim
Tsis tshua muaj neeg yooj yim, tsis suav nrog Servo Compass
Tsis tshua muaj neeg yooj yim, tsis suav nrog Servo Compass

Nov tsuas yog cov lus qhia yooj yim rau txoj haujlwm uas kuv tab tom ua haujlwm. Qhov no yog qhov tsis muaj nuj nqis thiab yog qhov pib yooj yim ua rau chav kawm. Hauv cov lus qhia tom qab, Kuv yuav qhia yuav ua li cas ntsuas nws.

Kuv yuav tsis cia siab ntau qhov zoo los ntawm qhov no yog tias kuv yog koj, nws tau sau ntau ntxiv txog cov txheej txheem.

Khoom siv

  • Micro servo (Kuv siv HXT900 Micro Servo los ntawm Hobby King)
  • Arduino (Kuv siv Uno)
  • LSM303DLHC yog lub sensor
  • Cables, solder, thiab lwm yam
  • Cov qhob cij

Kauj Ruam 1: Sib Sau Txhua Yam

Sib Sau Txhua Yam
Sib Sau Txhua Yam
Sib Sau Txhua Yam
Sib Sau Txhua Yam

Xyuas kom tseeb tias koj lub taub hau tau muab tso rau ntawm koj lub ntsuas kom raug thiab koj muaj koj cov xov hlau thiab daim txiag ntoo.

Kauj ruam 2: Code Libraries

Cov Tsev Qiv Ntawv
Cov Tsev Qiv Ntawv
Cov Tsev Qiv Ntawv
Cov Tsev Qiv Ntawv

Koj yuav xav kom ntseeg tau tias koj tau rub tawm cov ntawv no.

Lwm lub tsev qiv ntawv koj yuav siv, wire.h thiab servo.h, yuav tsum tau teeb tsa los ntawm lub neej ntawd.

Kauj ruam 3: Code

Qhib lub tsev qiv ntawv kos duab 'Compass' los ntawm qhov koj nyuam qhuav rub tawm. Txhawm rau siv servo, koj xav muab tus lej servo rau hauv tus lej no. Kuv ua ke nws nrog Hanie Kiana tus lej los ntawm no. Thawj yog los ntawm Hanie Kiani, tsis yog kuv. Nws yuav tsum zoo li no.

#suav nrog

#include #include #include #include Adafruit_LSM303DLH_Mag_Unified mag = Adafruit_LSM303DLH_Mag_Unified (12345); int servoPin = 3; Servo Tsav 1; teeb tsa tsis muaj dab tsi (tsis muaj dab tsi) {Serial.begin (9600); Hlau.begin (); Servo1.attach (servoPin); Serial.println ("Kev Xeem Magnetometer"); Serial.println (""); yog (! mag.begin ()) {Serial.println ("Ooops, tsis muaj LSM303 kuaj pom … Txheeb xyuas koj cov thaiv!"); thaum (1); }} void loop (tsis muaj dab tsi) { / * Tau txais qhov xwm txheej sensor tshiab * / sensors_event_t kev tshwm sim; mag.getEvent (& kev tshwm sim); ntab Pi = 3.14159; // Xam lub kaum sab xis ntawm vector y, x ntab nqe lus = (atan2 (event.magnetic.y, event.magnetic.x) * 180) / Pi; // Ua rau 0-360 yog tias (nqe lus <0) {nqe lus = 360 + nqe lus; } Serial.print ("Compass Heading:"); Serial.println (nqe lus); Servo1.write (180-nqe lus); ncua (10); }

Kauj Ruam 4: Txuas Nws Ua Ke

Hlau Nws Ua Ke
Hlau Nws Ua Ke

Koj xav tau tus pin sab laug- SCL- txuas nrog A5 cov ntaub ntawv nkag mus

Qhov ib sab nws- SDA- txuas nrog A4 chaw nres nkoj.

Ground mus rau Ground.

VIN mus rau 5v chaw nres nkoj.

Kauj Ruam 5: Ntxiv Servo rau Xov Tooj

Ntxiv Servo rau Txuas
Ntxiv Servo rau Txuas

Hauv av thiab qhov hluav taws xob hais lus rau lawv tus kheej, tab sis koj xav kom cov ntaub ntawv tus pin yog ~ 3.

Kauj Ruam 6: Xeem Txoj Cai

Xeem Txoj Cai
Xeem Txoj Cai

Yog tias koj txav lub tshuab ntsuas hluav taws xob maj mam, tus servo yuav tsum txav nrog nws. Nws yuav tsis txawv qhov tseeb, tab sis nws tsawg kawg ua haujlwm nrog cov cai, yog li ib feem ua tiav. Nws tseem tsis tau ntsuas, tab sis nws ua haujlwm.

Pom zoo: