Cov txheej txheem:

Servo Positoning Nrog Keypad: 3 Kauj Ruam
Servo Positoning Nrog Keypad: 3 Kauj Ruam

Video: Servo Positoning Nrog Keypad: 3 Kauj Ruam

Video: Servo Positoning Nrog Keypad: 3 Kauj Ruam
Video: Arduino - Keypad Lock with LCD (Servo / Relay ) 2024, Hlis ntuj nqeg
Anonim
Servo Positoning Nrog Keypad
Servo Positoning Nrog Keypad

Hauv cov lus qhia no peb yuav tsim ib qhov haujlwm uas yuav tswj hwm Micro-Servo nrog cov keyboard ua haujlwm nrog Arduino Uno.

Cov Khoom Siv:

Arduino Ib

Cov qhob cij

4 x 4 Keypad

Micro-Servo Cov

Kauj ruam 1: Hlau Keypad

Hlau Keypad
Hlau Keypad
Hlau Keypad
Hlau Keypad

Thawj qhov xav tias koj yuav tsum tau ua yog xaim lub tsheb nqaj hlau fais fab thiab tsheb nqaj hlau hauv av ntawm koj lub khob cij los ntawm koj li Arduino

  1. Txuas tus pin 5V rau lub tsheb ciav hlau (liab)
  2. Txuas tus pin hauv av (GND) rau txoj kev tsheb ciav hlau (xiav)

Tam sim no tias daim ntawv qhia zaub mov muaj lub zog thiab yog hauv av, peb tuaj yeem pib txuas mus rau peb cov khoom siv.

Kev xaim lub Keypad yog ib qho yooj yim tab sis koj yuav tsum tau sau tseg ntawm tus pin ntawm cov keyboard thiab arduino. Nws yuav yooj yim dua thaum peb tig los mloog peb cov cai.

Nco ntsoov pib ntawm sab laug thaum siv koj cov xov hlau!

  • Thawj tus pin mus rau 13
  • Tus pin thib ob mus rau 12
  • Tus pin thib peb mus rau 11
  • Plaub tus pin mus rau 10
  • Thib tsib tus pin rau 9
  • Sixth Pin rau 8
  • Xya tus Pin rau 7
  • Yim Pin rau 6

Thaum xaim lub keypad, nco ntsoov khaws lub pwm pwm tus lej qhib. Peb yuav xav tau nws rau micro-servo

Ua ntej peb mus rau txoj cai, nco ntsoov tias koj tau teeb tsa Lub Tsev Qiv Ntawv Keypad. Nws tuaj yeem pom hauv koj daim duab, tom qab kos duab tab, suav nrog tsev qiv ntawv. Koj yuav tsis muaj peev xwm siv lub keypad yam tsis muaj nws.

Tam sim no cia tig mus rau txoj cai thiab xyuas kom cov keypad ua haujlwm thiab muab cov txiaj ntsig koom nrog

Cov Lus Cim Ceev: Nco ntsoov tias koj muaj daim ntawv yog los tshuaj xyuas lub keyboard, txwv tsis pub nws yuav tsis ua haujlwm. Kuj yuav tsum ceev faj ntawm kev ncua, lawv yuav cuam tshuam nrog cov nyees khawm tau sau npe los ntawm cov keyboard

#suav nrog

const byte kab = 4; // plaub kab txij li cov keypad puv lawm

const byte txhua = 4; // plaub kab, tib yam li saum toj no

cov nyees khawm [kab] [kab ntawv] = {

{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', ' C '}, {'*',' 0 ','#',' D '}};

byte rowP [kab] = {13, 12, 11, 10}; // kab pins ntawm tus keyboard

byte columnsP [kab ntawv] = {9, 8, 7, 6}; // kab pins ntawm tus keyboard

Keypad pad = Keypad (uaKeymap (cov nyees khawm), rowP, kab P, kab, kab, kab); // tsim cov keyboard

void teeb tsa () {

Serial.begin (9600); }

void voj () {

khawm khawm Pressed = pad.getKey (); // tau txais daim npav los ntawm cov keyboard yog tias (khawm Nyem) // qhia lub pob twg tau nyem rau ntawm lub keyboard {Serial.println (buttonPressed); }}

Kauj ruam 2: Ntxiv Micro Servo

Ntxiv Micro Servo
Ntxiv Micro Servo
Ntxiv Micro Servo
Ntxiv Micro Servo

Tam sim no cia ntxiv servo motor. Qhov no yog qhov yooj yim ntxiv rau peb txoj haujlwm tam sim no txij li lub micro server tsuas muaj peb lub xov hlau.

  • Cov xaim xim av mus rau txoj kev tsheb nqaj hlau ntawm lub khob cij
  • Liab mus rau Txoj Kev tsheb nqaj hlau
  • Txiv kab ntxwv mus rau Pin 3 ntawm Arduino. Nco ntsoov lub micro server yuav tsum muaj tus pin PWM ntawm Arduino. Qhov no yog vim los ntawm servo siv TIMER2

Tam sim no cia tsuas yog ua kom ntseeg tau tias peb txuas lub micro servo txoj cai thiab nws txav mus

#include #include "Servo.h"

const byte kab = 4; // plaub kab txij li cov keypad puv lawm

const byte txhua = 4; // plaub kab, tib yam li saum toj no

cov nyees khawm [kab] [kab ntawv] = {

{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', ' C '}, {'*',' 0 ','#',' D '}};

byte rowP [kab] = {13, 12, 11, 10}; // kab pins ntawm tus keyboard

byte columnsP [kab ntawv] = {9, 8, 7, 6}; // kab pins ntawm tus keyboard

Keypad pad = Keypad (uaKeymap (cov nyees khawm), rowP, kab P, kab, kab, kab); // tsim cov keyboard

Servo tam sim noServo; // 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 () {

Serial.begin (9600); currentServo.attach (3); // txuas cov servo ntawm tus pin 9 rau cov khoom siv servo

}

void voj () {

khawm khawm Pressed = pad.getKey (); // tau txais daim npav los ntawm cov keyboard yog tias (khawm Nyem) // qhia lub pob twg tau nyem rau ntawm lub keyboard {Serial.println (buttonPressed); }

currentServo.write (95);

}

Kauj Ruam 3: Hloov Kho Txoj Cai los Siv Cov Keypad ntawm Servo

Paub tias peb yuav hloov kho peb cov cai kom thaum peb nias lub pob tshwj xeeb ntawm cov keyboard, servo txav mus rau txoj haujlwm tshwj xeeb. Ib yam tseem ceeb ua ntej. Qhov chaw pabcuam servo rau 0 yog qhov txawv. Txij li thaum kuv muaj kev sib hloov ua haujlwm tas li, thaum twg nws tau ze rau 0, servo nyuam qhuav pib tig. Tus lej kuv muab tso rau hauv cov cai tau qis li kuv tuaj yeem mus yam tsis muaj qhov tshwm sim. Txawm li cas los xij, nov yog kuv tus lej kawg:

#ncig #ncig

const byte kab = 4; // plaub kab txij li cov keypad puv lawm

const byte txhua = 4; // plaub kab, tib yam li saum toj no

cov nyees khawm [kab] [kab ntawv] = {

{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', ' C '}, {'*',' 0 ','#',' D '}};

byte rowP [kab] = {13, 12, 11, 10}; // kab pins ntawm tus keyboard

byte columnsP [kab ntawv] = {9, 8, 7, 6}; // kab pins ntawm tus keyboard

Keypad pad = Keypad (uaKeymap (cov nyees khawm), rowP, kab P, kab, kab, kab); // tsim cov keyboard

Servo myServo; //

void teeb tsa () {

Serial.begin (9600); myServo.attach (5); // txuas cov servo ntawm tus pin 9 rau cov khoom siv servo}

void voj () {

char tseem ceeb = pad.getKey (); // tau txais tus lej los ntawm cov keyboard yog (qhov tseem ceeb == '0') {myServo.write (11); Serial.println ("0"); ncua (15); } yog (qhov tseem ceeb == '1') {myServo.write (12); Serial.println ("1"); ncua (15); } yog (qhov tseem ceeb == '2') {myServo.write (24); Serial.println ("2"); ncua (15); } yog (qhov tseem ceeb == '3') {myServo.write (36); Serial.println ("3"); ncua (15); }

yog (qhov tseem ceeb == '4')

{myServo.write (48); Serial.println ("4"); ncua (15); }

yog (qhov tseem ceeb == '5')

{myServo.write (60); Serial.println ("5"); ncua (15); }

yog (qhov tseem ceeb == '6')

{myServo.write (72); Serial.println ("6"); ncua (15); }

yog (qhov tseem ceeb == '7')

{myServo.write (84); Serial.println ("7"); ncua (15); }

yog (qhov tseem ceeb == '8')

{myServo.write (96); Serial.println ("8"); ncua (15); }

yog (qhov tseem ceeb == '9')

{myServo.write (108); Serial.println ("9"); ncua (15); }

yog (qhov tseem ceeb == '*')

{myServo.write (120); Serial.println ("*"); ncua (15); }

yog (qhov tseem ceeb == '#')

{myServo.write (132); Serial.println ("#"); ncua (15); }

yog (qhov tseem ceeb == 'A')

{myServo.write (146); Serial.println ("A"); ncua (15); }

yog (qhov tseem ceeb == 'B')

{myServo.write (158); Serial.println ("B"); ncua (15); }

yog (qhov tseem ceeb == 'C')

{myServo.write (170); Serial.println ("C"); ncua (15); }

yog (qhov tseem ceeb == 'D')

{myServo.write (180); Serial.println ("D"); ncua (15); }}

Pom zoo: