Mundarija:

Arduino yordamida aqlli robotni qanday qilish kerak: 4 qadam
Arduino yordamida aqlli robotni qanday qilish kerak: 4 qadam

Video: Arduino yordamida aqlli robotni qanday qilish kerak: 4 qadam

Video: Arduino yordamida aqlli robotni qanday qilish kerak: 4 qadam
Video: Birgalikda robot-mashina yasaymizmi? 2024, Noyabr
Anonim
Image
Image

Salom,

Men arduino ishlab chiqaruvchisiman va bu darslikda sizga arduino yordamida aqlli robot yasashni ko'rsataman.

Agar sizga mening darsligim yoqqan bo'lsa, arduino ishlab chiqaruvchisi deb nomlangan youtube kanalimni qo'llab -quvvatlashni o'ylab ko'ring

Ta'minotlar

Sizga kerak bo'lgan narsalar:

1) arduino bilan

2) ultratovush sensori

3) Bo motor

4) g'ildiraklar

5) muzqaymoq tayoqchalari

6) 9V batareya

1 -qadam: Ulanishlar

HAMMA KOMPONENTLARNI JOYIDA GLUE
HAMMA KOMPONENTLARNI JOYIDA GLUE

Endi barcha materiallarni olgandan so'ng, siz hamma narsani yuqorida ko'rsatilgan sxemaga muvofiq ulashni boshlashingiz kerak

2 -qadam: BARCHA KOMPONENTLARNI O'RNATISH

OK,

Endi yuqoridagi rasmda ko'rsatilgandek hamma narsani joyiga ulang

3 -qadam: DASTURLASH

Endi,

taxtani quyida berilgan kod bilan dasturlashni boshlang

// ARDUINO MOSHINALARDAN TUG'ILADI //// Kodni yuklashdan oldin kerakli kutubxonani o'rnatishingiz kerak // // AFMotor kutubxonasi https://learn.adafruit.com/adafruit-motor-shield/library-install // // NewPing kutubxonasi https://github.com/livetronic/Arduino-NewPing// // Servo kutubxonasi https://github.com/arduino-libraries/Servo.git // // Kutubxonalarni o'rnatish uchun eskizga o'ting >> Qo'shish Kutubxona >>. ZIP faylini qo'shish >> Yuqoridagi havolalardan Yuklangan ZIP fayllarini tanlang //

#qo'shing

#qo'shing

#qo'shing

#ta'rif TRIG_PIN A0

#ECHO_PIN A1 ni belgilang #MAX_DISTANCE 200 ni aniqlang

#define MAX_SPEED 150 // shahar motorlarining tezligini belgilaydi

#MAX_SPEED_OFFSETni aniqlang 20

NewPing sonar (TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

AF_DCMotor dvigatel1 (1, MOTOR12_1KHZ);

// AF_DCMotor dvigateli2 (2, MOTOR12_1KHZ); // AF_DCMotor motor3 (3, MOTOR34_1KHZ); AF_DCMotor dvigateli4 (4, MOTOR34_1KHZ); Xizmat ko'rsatish xizmati;

boolean goForward = false;

int masofa = 100; int speedSet = 0;

bo'sh o'rnatish () {

myservo.attach (10);

myservo.write (115); kechikish (1000); masofa = readPing (); kechikish (100); masofa = readPing (); kechikish (100); masofa = readPing (); kechikish (100); masofa = readPing (); kechikish (100); }

void loop () {

int masofaR = 0; int masofaL = 0; kechikish (40); if (masofa <= 15) {moveStop (); kechikish (100); moveBackward (); kechikish (300); moveStop (); kechikish (200); masofaR = qarashRight (); kechikish (300); masofaL = qarashLeft (); kechikish (300);

agar (masofaR> = masofaL)

{ O'ng tomonga buriling(); moveStop (); } boshqa {turnLeft (); moveStop (); }} boshqa {moveForward (); } masofa = readPing (); }

int lookRight ()

{myservo.write (50); kechikish (650); int masofasi = readPing (); kechikish (100); myservo.write (115); qaytish masofasi; }

int lookLeft ()

{myservo.write (170); kechikish (650); int masofasi = readPing (); kechikish (100); myservo.write (115); qaytish masofasi; kechikish (100); }

int readPing () {

kechikish (70); int sm = sonar.ping_cm (); agar (sm == 0) {sm = 250; } qaytarish sm; }

void moveStop () {

motor1. ishga tushirish (RELEASE); //motor2.run (RELEASE); //motor3.run (RELEASE); motor4. ishga tushirish (RELEASE); } void moveForward () {bekor

agar (! Oldinga ketadi)

{goForward = rost; motor1.yugurish (OLDINGA); //motor2.run (OLDINGA); //motor3.run (OLDINGA); motor4.run (oldinga); uchun (speedSet = 0; speedSet <MAX_SPEED; speedSet += 2) // batareyalarni tezda yuklamaslik uchun tezlikni asta -sekin oshiring {motor1.setSpeed (speedSet); //motor2.setSpeed(speedSet); //motor3.setSpeed(speedSet); motor4.setSpeed (speedSet); kechikish (5); }}}

bekor harakatBackward () {

goForward = false; motor1. ishga tushirish (orqaga); //motor2.run(AQQA); //motor3.run(AQQA); motor4. ishga tushirish (orqaga); uchun (speedSet = 0; speedSet <MAX_SPEED; speedSet += 2) // batareyalarni tez yuklamaslik uchun tezlikni asta -sekin oshiring {motor1.setSpeed (speedSet); //motor2.setSpeed(speedSet); //motor3.setSpeed(speedSet); motor4.setSpeed (speedSet); kechikish (5); }}

void turnRight () {

motor1. ishga tushirish (orqaga); //motor2.run(AQQA); //motor3.run (OLDINGA); motor4.run (oldinga); kechikish (350); motor1. ishga tushirish (OLDINGA); //motor2.run (OLDINGA); //motor3.run (OLDINGA); motor4.run (oldinga); } bekor TurnLeft () {motor1.run (OLGA); //motor2.run (OLDINGA); //motor3.run(AQQA); motor4. ishga tushirish (orqaga); kechikish (350); motor1. ishga tushirish (OLDINGA); //motor2.run (OLDINGA); //motor3.run (OLDINGA); motor4.run (oldinga); }

Tavsiya: