Ungasilawula njani isantya seMoto yeDC kunye neArduino

NguJohn Nussey

Ngaba ufuna ulawulo ngakumbi lwenjini yakho yeDC? Ungasebenzisa umzobo weMotorControl kwiArduino ukubeka igalelo kwimoto yeDC ukukunika ulawulo olupheleleyo lwemoto kubhabho.



Umzobo weMotorControl

Ukufumana isantya seemoto zakho nanini na xa uyidinga, kuya kufuneka wongeze potentiometer kwisekethe yakho.

Udinga:

Fumana indawo kwibhodi yesonka ukubeka i-potentiometer yakho. Iphini esembindini ye-potentiometer iqhagamshelwe ngasemva kwipini ye-9 isebenzisa ucingo oluxhuma, kwaye izikhonkwane ezimbini eziseleyo zixhunywe kwi-5V kwelinye icala kunye ne-GND kwelinye.

umfanekiso0.jpg

I-5V kunye ne-GND zinokubakho macala omabini, kodwa ukuzitshintsha kuya kuguqula ixabiso elithunyelwa yi-potentiometer kwi-Arduino. Nangona i-potentiometer isebenzisa amandla afanayo kunye nomhlaba njengemoto, qaphela ukuba ziisekethe ezahlukileyo ezinxibelelana ngeArduino.

umfanekiso1.jpg

Emva kokuba uyenzile isekethe, vula umzobo omtsha weArduino kwaye uwugcine ngelinye igama elingalibalekiyo, njengeMyMotorControl. Emva koko chwetheza le khowudi ilandelayo.

  int  potPin = A0;  int  motorPin = 9;  int  potValue = 0;  int  motorValue = 0; void setup() { Serial.begin(9600); } void loop() { potValue =  analogRead  (potPin); motorValue =  map  (potValue, 0, 1023, 0, 255);  analogWrite  (motorPin, motorValue); Serial.print('potentiometer = ' );  Serial.print  (potValue); Serial.print('t motor = ');  Serial.println  (motorValue);  delay  (2); }

Emva kokuba uchwethezile umzobo, ugcine kwaye ucofe iqhosha lokuHlanganisa ukuqaqambisa naziphi na iimpazamo zes syntax. .

Ukuba umzobo uqokelelwa ngokuchanekileyo, cofa u-Layisha ukuze ulayishe umzobo kwibhodi yakho. Xa ugqibile ukulayisha, kuya kufuneka ukwazi ukulawula imoto yakho usebenzisa i-potentiometer. Ukuguqula i-potentiometer kwicala elinye kubangela ukuba imoto ikhawuleze; Ukuyijika ngenye indlela kubangela ukuba icothe.

Ukwahlulwa kweSketch kweMotorControl

Lo mzobo yiyantlukwano kumzobo we-AnalogInOutSerial kwaye usebenza ngokuchanekileyo ngendlela efanayo notshintsho lwamagama ambalwa ukubonisa ngcono into olawulayo kunye nokubeka iliso kwisekethe.

m a10 ipilisi eblue

Njengamaxesha onke, ubhengeza izinto ezahlukeneyo ezisetyenzisiweyo kumzobo. Usebenzisa i-potPin ukunika i-potentiometer pin kunye ne-motorPin ukuthumela umqondiso kwimoto. Umahluko kwi-potValue usetyenziselwa ukugcina ixabiso eliluhlaza le-potentiometer kunye ne-motorValue eguquguqukayo egcina ixabiso eliguquliweyo ofuna ukulikhuphela kwi-transistor ukutshintsha imoto.

  int  potPin = A0;  int  motorPin = 9;  int  potValue = 0;  int  motorValue = 0;

Uyenza njani i-sketch yeMotorControl

Ungafumanisa ukuba kukho isantya esincinci emva koko iimoto ziya kungxola. Yenza njalo kuba ayinamandla ngokwaneleyo okujikeleza. Ngokubeka esweni amaxabiso athunyelwe kwimoto usebenzisa iMotControl sketch, ungafumana elona xabiso lisezantsi lemoto ukujika nokwandisaImotoValueukuguqula imoto kuluhlu lwayo lokwenyani.

Ukufumana uluhlu lweImotoValue, landela la manyathelo:

  1. Ngomzobo weMotorControl olayishiwe, cofa iqhosha lokubeka esweni ngasekunene kwewindow yakho yeArduino.

    Iwindows yokujonga esweni iya kukubonisa ixabiso le-potentiometer elilandelwa lixabiso lemveliso elithunyelwa kwimoto, ngale ndlela:

    potentiometer = 1023 iimoto = 255

    Ezi xabiso ziboniswa kuluhlu olude kunye nohlaziyo njengoko uguqula i-potentiometer. Ukuba awuboni uluhlu oluskrolela ezantsi, qiniseka ukuba ukhetho lwe-Autoscroll lukhethiwe.

  2. Ukuqala nge-potentiometer yakho yokufunda ixabiso elingu-0, jika i-potentiometer yakho kancinci kancinci kude kuyeke ukungxola kwaye imoto iqala ukujikeleza.

    suprep mathumbu exabiso lekhithi
  3. Yenza inqaku lexabiso eliboniswe kweli nqanaba.

  4. Sebenzisa iukubaIsiteyitimenti sokuxelela isithuthi ukuba sitshintshe isantya kuphela ukuba ixabiso likhulu kunesantya esincinci esifunekayo ukujikeleza imoto, ngolu hlobo lulandelayo:

    (ukuya). Fumana indawo yekhowudi yakho ebhala ifayile ye-ImotoValuekwimoto:

      analogWrite  (motorPin, motorValue);

    (b). Faka endaweni yale khowudi ilandelayo:

      if  (motorValue > yourValue) {      analogWrite  (motorPin, motorValue); }  else  {      digitalWrite  (motorPin, LOW); }
  5. Ngoku buyiselayakhoValuengenani olibhalileyo.

    Ukuba ixabisoImotoValueinkulu kunaleyo, iimoto ziyakhawuleza. Ukuba iphantsi kunoko, ipini ibhaliweNGAPHANTSIukuze icinywe ngokupheleleyo. UnokuchwethezaI-analogWrite (imotoPin, 0)ukufezekisa into efanayo. Ukulungiswa okuncinci oku kunokukunceda ukuba iprojekthi yakho isebenze kakuhle, kungekho ntshukumo ichithayo okanye amaxabiso.