Cov txheej txheem:

Keypad Servo Xauv: 5 Kauj Ruam
Keypad Servo Xauv: 5 Kauj Ruam

Video: Keypad Servo Xauv: 5 Kauj Ruam

Video: Keypad Servo Xauv: 5 Kauj Ruam
Video: Sundays Are For Trucking #151 | Montana Info | American Truck Simulator | 1pm Central Time USA 2024, Hlis ntuj nqeg
Anonim
Keypad Servo Xauv
Keypad Servo Xauv
Keypad Servo Xauv
Keypad Servo Xauv
Keypad Servo Xauv
Keypad Servo Xauv

Nyob zoo txhua tus, vam tias koj muaj hnub zoo. Yog tias tsis cia siab koj tuaj yeem rov qab nrog qee qhov qhib siab rau qhov kev qhia no thiab qee cov suab paj nruag kho. Programming tuaj yeem ua teeb meem. Ua tsaug, qhov kev qhia no tsis yog qhov nyuaj, yog li koj tuaj yeem muaj peev xwm ua tiav qhov nrov npe hu ua (hauv lub suab muaj zog): LUB KAWG KAWG KEYPAD XAUS KAWG !!! Qhov ntawd tsuas yog kuv qhov kev qhia, vam tias koj nyiam nws. Xijpeem, cia peb ua kom peb cov ntiv tes sov rau kev ntaus ntawv. (Ib zaj nkauj txias: tuaj yeem-tuaj yeem hu nkauj (suab paj nruag qub)).

Khoom siv:

Koj cov ntiv tes

-Koj txhais tes ib yam nkaus, qhov tseem ceeb

-USB cable rau Arduino

Txhua hom arduino muaj (Kuv muaj Arduino Mega)

-Matrix Keypad (keyboard - ebay, keypad - amazon)

-Micro lossis Standard servo (Kuv siv micro servo)

-* Yeem tau* Breadboard - txhua yam

-* Yeem* Fais fab mov (5V)

Kauj ruam 1: Sijhawm Schematic

Schematic Lub Sijhawm!
Schematic Lub Sijhawm!
Schematic Lub Sijhawm!
Schematic Lub Sijhawm!

Yog li, ua ntej dab tsi? Txuas tus Arduino mus rau lub khoos phis tawj. Txuas tus keypad tom ntej. *Nco tseg - koj yuav tsum txuas tus pin los ntawm tus lej kawg ntawm tus keyboard yog thawj tus lej digital ntawm arduino. Thiab mus ntawm sab xis mus rau sab laug tom qab ntawd*. Keypad muaj tus pin 2-9 ntawm arduino. Lub servo muaj tus pin 10 ua cov cim digital. Tie thaj tsam ntawm arduino, keypad, thiab servo thiab 5V ib yam nkaus. * Tseem ceeb - qhov kev pabcuam zoo tshaj plaws nrog lub zog siv sab nraud lossis lub adapter nrog 5V (phab ntsa ntsaws -hauv), tab sis nws tseem xaiv tau.* Koj tsis tas yuav khi thaj chaw thiab 5V lub cev, kuv txhais li cas yog kom tsuas yog txuas cov xov hlau los ntawm Arduino mus rau servo. Cov txheej txheem no tsis pab pib, yog li cia kuv piav qhia luv luv. Yeej, tus pin kawg yog 2 thiab thawj tus yog 9, ob yog 8, peb yog 7, thiab ntxiv rau. Mus ntawm sab laug mus rau sab xis 22.

Kauj ruam 2: Coding Sijhawm

Sijhawm Coding!
Sijhawm Coding!
Sijhawm Coding!
Sijhawm Coding!

Yog li tam sim no peb tab tom mus rau ntu coding! Nov yog qhov uas khawv koob tiag tshwm sim! Yog li, muaj qhov kev tshuaj ntsuam xyuas thawj zaug los ntsuas cov keyboard thiab servo. Ntawm no:

//www.elegoo.com//2016.12.9

/* @file CustomKeypad.pde

|| @kev 1.0 1.0 @author Alexander Brevig || @contact [email protected] || || @kev piav qhia || | Ua piv txwv hloov pauv qhov loj me thiab cov txiaj ntsig tseem ceeb. || # */ # suav nrog

const byte ROWS = 4; // plaub kab

const byte COLS = 4; // plaub kab // piav qhia cymbols ntawm cov nyees khawm ntawm cov keypads char hexaKeys [ROWS] [COLS] = {{'1', '2', '3', 'A'}, {'4', '5 ',' 6 ',' B '}, {' 7 ',' 8 ',' 9 ',' C '}, {'*',' 0 ','#',' D '}}; byte rowPins [ROWS] = {9, 8, 7, 6}; // txuas rau kab pinouts ntawm cov keyboard byte colPins [COLS] = {5, 4, 3, 2}; // txuas mus rau kab ntawv pinouts ntawm cov keyboard

// pib qhov piv txwv ntawm chav kawm NewKeypad

Keypad customKeypad = Keypad (uaKeymap (hexaKeys), rowPins, colPins, ROWS, COLS);

void teeb tsa () {

Serial.begin (9600); } void loop () {char customKey = customKeypad.getKey (); yog (customKey) {Serial.println (customKey); }}

//www.elegoo.com//2016.12.08 #suav nrog

Servo tswj; // tsim cov khoom siv servo los tswj lub servo

// kaum ob yam khoom siv servo tuaj yeem tsim tau ntawm cov laug cam

int pos = 0; // sib txawv los khaws txoj haujlwm servo

void teeb tsa () {

myservo.attach (9); // txuas cov servo ntawm tus pin 9 rau cov khoom siv servo}

void voj () {

rau (pos = 0; pos = 0; pos -= 1) {// mus los ntawm 180 degrees mus rau 0 degrees myservo.write (pos); // qhia servo mus rau txoj haujlwm hauv qhov sib txawv 'pos' ncua (15); // tos 15ms rau servo kom mus txog txoj haujlwm}}

Nov yog qhov phiaj xwm phiaj xwm (Kuv yuav ua ncaj ncees rau koj, Kuv tsis tau ua ntau yam, Kuv tsuas yog ntxiv qhov kev pabcuam, hais ua tsaug rau cov neeg uas ua txhua txoj cai!):

#suav nrog Password.h

#suav nrog Keypad

/*

|| Kev nkag tus lej nkag yooj yim Siv Matrix Keypad || 4/5/2012 Hloov Kho tshiab Nathan Sobieck: [email protected] || *

/* yog txhawm rau txheeb xyuas tus password

//# yog rov pib dua tus password

/////////////////////////////////////////////////////////////////

#suav nrog

//https://www.arduino.cc/playground/uploads/Code/Password.zip #include //https://www.arduino.cc/playground/uploads/Code/Keypad.zip

Lo lus zais = Lo lus zais ("1234");

Servo tswj; // tsim cov khoom siv servo los tswj lub servo

#define servoPin 10

const byte ROWS = 4; // Plaub kab

const byte COLS = 4; // kab ntawv // Txhais cov Keymap char [ROWS] [COLS] = {{'1', '2', '3', 'A'}, {'4', '5', '6', ' B '}, {' 7 ',' 8 ',' 9 ',' C '}, {'*',' 0 ','#',' D '}};

byte rowPins [ROWS] = {9, 8, 7, 6}; // Txuas cov keyboard ROW0, ROW1, ROW2 thiab ROW3 rau cov pin Arduino.

byte colPins [COLS] = {5, 4, 3, 2,}; // Txuas cov keyboard COL0, COL1 thiab COL2 rau cov Pin Arduino.

// Tsim cov Keypad

Keypad keypad = Keypad (uaKeymap (tuav), rowPins, colPins, ROWS, COLS);

void teeb tsa () {

myservo.attach (servoPin); // txuas cov servo ntawm tus pin 9 rau cov khoom siv servo

Serial.begin (9600);

keypad.addEventListener (keypadEvent); // ntxiv tus neeg mloog qhov xwm txheej rau cov keyboard no

myservo.write (0);

}

void voj () {

keypad.getKey ();

}

// saib xyuas qee qhov xwm txheej tshwj xeeb

void keypadEvent (KeypadEvent eKey) {hloov (keypad.getState ()) {case PRESSED: hloov (eKey) {case '*': checkPassword (); tawg; default: password.append (eKey); }}}

void checkPassword () {

yog (password.evaluate () == tseeb) {Serial.println ("Ua tiav"); // Ntxiv cov cai los ua haujlwm yog tias nws ua haujlwm

myservo.write (180);

ncua (3000);

myservo.write (0);

password.reset ();

} lwm tus yog (password.evaluate () == tsis tseeb) {

Serial.println ("Tsis yog");

myservo.write (0);

// ntxiv cov cai los khiav yog tias nws tsis ua haujlwm

}

}

Kauj Ruam 3: Txhua Qhov No Puas Yog?

Txhua Qhov No Puas Yog?
Txhua Qhov No Puas Yog?

Cov cai saum toj no (thawj tus) yuav muab lub teeb liab rau Servo kom "cheb" lossis tsuas yog mus ntawm 0 txog 180 degrees. Lossis tsuas yog ua kom tiav ib nrab ntawm lub voj voog ntawm kev sab laug mus rau sab xis lossis sab xis mus rau sab laug. Yog tias koj xav paub ntau ntxiv ntawm tus lej kuv tuaj yeem qhia koj. Tsuas yog thov nug. Tsis muaj kev phom sij ua tiav, tsuas yog lo lus nug me me yooj yim. Los, koj ua tau! Xijpeem, txoj cai nyob hauv nruab nrab ntsuas txhua lub pob ntawm cov keyboard. Thiab qhov kawg ntawm txoj cai tsuas yog "xauv" nrog lub servo thaum koj ntaus tus lej "1234" rau hauv, koj kwv yees nws, cov keyboard.

Kauj ruam 4: Troubleshooting

Teeb meem
Teeb meem

Q: Kuv lub keyboard tsis ua haujlwm.

A: Nco ntsoov thawj tus pin yog 9 yog li nqis los ntawm qhov ntawd. Tsis tas li nco ntsoov txuas lub arduino mus rau USB chaw nres nkoj ntawm lub computer thiab program Arduino.

Q: Servo tsis ua haujlwm.

A: Nco ntsoov tias tus pin servo yog tus pin 10 thiab koj xav tau ib qho hauv av, yog tias koj txuas ncaj qha los ntawm Arduino, nco ntsoov tias tus txiv kab ntxwv tus pin (ntawm micro servo) yog tus pin 10, tus pin liab yog 5V, thiab tus pin xim av yog GND tus pin.

Q: Arduino tsis ua haujlwm:

A: Koj puas tau txuas nws? Qhov ntawd zoo li yog teeb meem ntawm tus kheej

Kauj Ruam 5: Yog tias Koj Muaj Lus Nug, Ua Ntej Xav Nug Hauv Kab Lus Tawm thiab Nco ntsoov Sau Npe

Bye, ua tsaug rau kev saib kuv cov lus qhia. Nws tau lom zem.

Pom zoo: