Cov txheej txheem:

Yuav Ua Li Cas Tib Neeg Ua Raws Li Neeg Hlau Nrog Arduino: 3 Kauj Ruam
Yuav Ua Li Cas Tib Neeg Ua Raws Li Neeg Hlau Nrog Arduino: 3 Kauj Ruam

Video: Yuav Ua Li Cas Tib Neeg Ua Raws Li Neeg Hlau Nrog Arduino: 3 Kauj Ruam

Video: Yuav Ua Li Cas Tib Neeg Ua Raws Li Neeg Hlau Nrog Arduino: 3 Kauj Ruam
Video: NOOBS PLAY CLASH ROYALE FROM START LIVE 2024, Hlis ntuj nqeg
Anonim
Yuav Ua Li Cas Tib Neeg Ua Raws Li Neeg Hlau Nrog Arduino
Yuav Ua Li Cas Tib Neeg Ua Raws Li Neeg Hlau Nrog Arduino

Tib neeg ua raws kev nkag siab neeg hlau thiab ua raws tib neeg

Kauj Ruam 1: Tau Txais Cov Cuab Yeej

Tau Txais Cov Cuab Yeej
Tau Txais Cov Cuab Yeej
Tau Txais Cov Cuab Yeej
Tau Txais Cov Cuab Yeej
Tau Txais Cov Cuab Yeej
Tau Txais Cov Cuab Yeej

Tau txais cov cuab yeej zoo li: Ultrasonic sensorSensorArduino uno 4 gear motors nrog lub logServo Roj teeb thiab roj teeb rooj plaub Lub cev tsav tsheb Jumper xov hlau Chassis

Kauj ruam 2: Txuas

Txuas
Txuas
Txuas
Txuas
Txuas
Txuas
Txuas
Txuas

Txuas txhua yam khoom siv rau tus tsav tsheb. Txuas tus tsav tsheb mus rau arduino.

Kauj ruam 3: Code

Code
Code

#suav nrog#suav nrog#suav nrog RIGHT A2#txhais LEFT A3#txhais TRIGGER_PIN A1#txhais ECHO_PIN A0#txhais MAX_DISTANCE 100NewPing sonar (TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); AF_DCMotor Motor1 (1, MOTOR12K); AF_DCMotor Motor1 (1, MOTOR12_1); AF_DCMotor Motor3 (3, MOTOR34_1KHZ); AF_DCMotor Motor4 (4, MOTOR34_1KHZ); Servo myservo; int pos = 0; void setup () {// put your setup code here, to run once: Serial.begin (9600); myservo.attach (10); {rau (pos = 90; pos <= 180; pos += 1) {myservo.write (pos); ncua (15);} rau (pos = 180; pos> = 0; pos- = 1) {myservo.write (pos); ncua (15);} rau (pos = 0; pos <= 90; pos += 1) {myservo.write (pos); ncua (15);}} pinMode (RIGHT, INPUT); pinMode (LEFT, INPUT);} void loop () {// tso koj tus lej tseem ceeb ntawm no, kom rov ua dua: ncua (50); unsigned int nrug = sonar.ping_cm (); Serial.print ("nrug"); Serial.println (nrug); int Right_Value = digitalRead (RIGHT); int Left_Value = digitalRead (LEFT); Serial.print ("RIGHT"); Serial.println (Right_Value); Serial.print ("LEFT"); Serial.println (Left_Value); yog ((Right_Value == 1) && (nrug> = 10 && nrug <= 30) && (Left_Value == 1)) {Motor1.setSpeed (120); Motor1.run (FORWARD); Motor2.setSpeed (120); Motor2.run (FORWARD); Motor3.setSpeed (120); Motor3.run (FORWARD); Motor4.setSpeed (120); Motor4.run (FORWARD);} ntxiv yog ((Right_Value == 0) && (Left_Value == 1)) {Motor1.setSpeed (200); Motor1.run (FORWARD); Motor2.setSpeed (200); Motor2.run (FORWARD); Motor3.setSpeed (100); Motor3.run (rov qab); Motor4.setSpeed (100); Motor4.run (BACKWARD);} ntxiv yog ((Right_Value == 1) && (Left_Value == 0)) {Motor1.setSpeed (100); Motor1.run (rov qab); Motor2.setSpeed (100); Motor2.run (rov qab); Motor3.setSpeed (200); Motor3.run (FORWARD); Motor4.setSpeed (200); Motor4.run (FORWARD);} lwm tus yog ((Right_Value == 1) && (Left_Value == 1)) {Motor1.setSpeed (0); Motor1.run (tso tawm); Motor2.setSpeed (0); Motor2.run (tso tawm); Motor3.setSpeed (0); Motor3.run (tso tawm); Motor4.setSpeed (0); Motor4.run (tso tawm);} lwm qhov yog (nrug> 1 && nrug <10) {Motor1.setSpeed (0); Motor1.run (tso tawm); Motor2.setSpeed (0); Motor2.run (tso tawm); Motor3.setSpeed (0); Motor3.run (tso tawm); Motor4.setSpeed (0); Motor4.run (tso tawm); }}

Pom zoo: