Cov txheej txheem:

Yuav Ua Li Cas Ntse Tus Neeg Hlau Siv Arduino: 4 Kauj Ruam
Yuav Ua Li Cas Ntse Tus Neeg Hlau Siv Arduino: 4 Kauj Ruam

Video: Yuav Ua Li Cas Ntse Tus Neeg Hlau Siv Arduino: 4 Kauj Ruam

Video: Yuav Ua Li Cas Ntse Tus Neeg Hlau Siv Arduino: 4 Kauj Ruam
Video: ๐Ÿคž8 YAM COV NEEG TXAWJ NTSE ZAM TSIS UA YOG DAB TSI?๐Ÿšซ 2024, Kaum ib hlis
Anonim
Image
Image

nyob zoo,

Kuv yog tus tsim arduino thiab hauv qhov kev qhia no kuv yuav qhia koj tias yuav ua li cas thiaj ua tau ntse neeg hlau siv arduino

yog tias koj nyiam kuv cov lus qhia ces txiav txim siab txhawb nqa kuv tus youtube channel npe hu ua tus tsim arduino

Khoom siv

Tej yam koj yuav tsum tau:

1) arduino ib

2) ultrasonic sensor

3) Bo lub cev muaj zog

4) lub log

5) khov nab kuab

6) Roj teeb 9v

Kauj ruam 1: Kev sib txuas

Kuaj tag nrho cov ntsiab lus hauv qhov chaw
Kuaj tag nrho cov ntsiab lus hauv qhov chaw

Tom qab, tau txais txhua yam khoom siv tam sim no koj yuav tsum pib txuas txhua yam raws li daim duab qhia chaw hauv qab no

Kauj Ruam 2: Kuaj tag nrho cov ntsiab lus hauv qhov chaw

OK,

tam sim no txuas txhua yam hauv qhov chaw raws li qhia hauv daim duab saum toj no

Kauj ruam 3: PROGRAMMING

Tam sim no,

pib tsim lub rooj tsavxwm nrog cov lej muab hauv qab no

// ARDUINO OBSTACLE AVOIDING CAR //// Ua ntej rub tawm cov cai koj yuav tsum teeb tsa lub tsev qiv ntawv tsim nyog // // AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install // NewPing Library https://github.com/livetronic/Arduino-NewPing// // Servo Library https://github.com/arduino-libraries/Servo.git // // Txhawm rau nruab cov tsev qiv ntawv mus rau kos duab >> suav nrog Lub Tsev Qiv Ntawv >> Ntxiv. ZIP Cov Ntaub Ntawv >> Xaiv cov rub tawm ZIP cov ntaub ntawv Los ntawm cov kab ntawv saum toj no //

#suav nrog

#suav nrog

#suav nrog

#define TRIG_PIN A0

#define ECHO_PIN A1 #define MAX_DISTANCE 200

#define MAX_SPEED 150 // teeb tsa ceev ntawm DC lub cav

#define MAX_SPEED_OFFSET 20

NewPing sonar (TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

AF_DCMotor motor1 (1, MOTOR12_1KHZ);

// AF_DCMotor motor2 (2, MOTOR12_1KHZ); // AF_DCMotor motor3 (3, MOTOR34_1KHZ); AF_DCMotor motor4 (4, MOTOR34_1KHZ); Servo tswj;

boolean GoForward = tsis tseeb;

int nrug = 100; int speedSet = 0;

void teeb tsa () {

myservo.attach (10);

myservo.write (115); ncua (1000); nrug = readPing (); ncua (100); nrug = readPing (); ncua (100); nrug = readPing (); ncua (100); nrug = readPing (); ncua (100); }

void voj () {

int nrug R = 0; int nrug L = 0; ncua (40); yog (nrug <= 15) {moveStop (); ncua (100); moveBackward (); ncua (300); moveStop (); ncua (200); nrugR = lookRight (); ncua (300); distanceL = saibLeft (); ncua (300);

yog (nrug R> = nrug L)

{tig rov qab (); moveStop (); } lwm {turnLeft (); moveStop (); }} lwm tus {moveForward (); } nrug = readPing (); }

int saibRight ()

{myservo.write (50); ncua (650); int nrug = readPing (); ncua (100); myservo.write (115); rov nrug deb; }

koj zooLeft ()

{myservo.write (170); ncua (650); int nrug = readPing (); ncua (100); myservo.write (115); rov nrug deb; ncua (100); }

int readPing () {

ncua (70); int cm = sonar.ping_cm (); yog (cm == 0) {cm = 250; } rov cm; }

tsis muaj dabtsis moveStop () {

motor1.run (tso tawm); //motor2.run(RELEASE); //motor3.run(RELEASE); motor4.run (tso tawm); } tsis muaj dabtsis moveForward () {

yog tias (! goForward)

{goForward = muaj tseeb; motor1.run (FORWARD); //motor2.run(FORWARD); //motor3.run(FORWARD); motor4.run (FORWARD); rau (speedSet = 0; speedSet <MAX_SPEED; speedSet += 2) // maj mam nqa nrawm kom tsis txhob ntsaws lub roj teeb nrawm dua {motor1.setSpeed (speedSet); //motor2.setSpeed(speedSet); //motor3.setSpeed(speedSet); motor4.setSpeed (speedSet); ncua (5); }}}

void moveBackward () {

GoForward = tsis tseeb; motor1.run (rov qab); //motor2.run(BACKWARD); //motor3.run(BACKWARD); motor4.run (rov qab); rau (speedSet = 0; speedSet <MAX_SPEED; speedSet += 2) // maj mam nqa nrawm kom tsis txhob ntsaws lub roj teeb nrawm dua {motor1.setSpeed (speedSet); //motor2.setSpeed(speedSet); //motor3.setSpeed(speedSet); motor4.setSpeed (speedSet); ncua (5); }}

void turnRight () {

motor1.run (rov qab); //motor2.run(BACKWARD); //motor3.run(FORWARD); motor4.run (FORWARD); ncua (350); motor1.run (FORWARD); //motor2.run(FORWARD); //motor3.run(FORWARD); motor4.run (FORWARD); } void turnLeft () {motor1.run (FORWARD); //motor2.run(FORWARD); //motor3.run(BACKWARD); motor4.run (rov qab); ncua (350); motor1.run (FORWARD); //motor2.run(FORWARD); //motor3.run(FORWARD); motor4.run (FORWARD); }

Pom zoo: