Qanday qilib Arduino yordamida odamni boshqaradigan robot qilish mumkin: 3 qadam
Qanday qilib Arduino yordamida odamni boshqaradigan robot qilish mumkin: 3 qadam
Anonim
Qanday qilib Arduino yordamida odamni ergashtiradigan robot qilish kerak
Qanday qilib Arduino yordamida odamni ergashtiradigan robot qilish kerak

Odam robotga ergashadi va odamni ta'qib qiladi

1 -qadam: Asboblarni oling

Asboblarni oling
Asboblarni oling
Asboblarni oling
Asboblarni oling
Asboblarni oling
Asboblarni oling

Quyidagi vositalarni oling: Ultrasonik sensor SensorArduino uno 4 g'ildirakli dvigatellar Servo Batareya va akkumulyator qutisi Dvigatel haydovchisi Jumper simlari Shassis

2 -qadam: ulanish

Ulanmoqda
Ulanmoqda
Ulanmoqda
Ulanmoqda
Ulanmoqda
Ulanmoqda
Ulanmoqda
Ulanmoqda

Har bir uskunani motor haydovchisiga ulang. Dvigatel drayverini arduino -ga ulang.

3 -qadam: kod

Kod
Kod

#kiritish#kiritish#kiritish#O'ng A2 ni belgilash#chapni belgilash A3#TRIGGER_PIN A1 ni belgilash#ECHO_PIN A0 ni belgilash#MAX_DISTANCE 100NewPing sonar (TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); AF_DCMotor Motor1 (1, MOTOR12_MOTOR12_1); AF_DCMotor Motor3 (3, MOTOR34_1KHZ); AF_DCMotor Motor4 (4, MOTOR34_1KHZ); Servo myservo; int pos = 0; void setup () {// bir marta ishga tushirish uchun sozlash kodini shu erga qo'ying: Serial.begin (9600); myservo.attach (10); {for (pos = 90; pos <= 180; pos += 1) {myservo.write (pos); kechikish (15);} uchun (pos = 180; pos> = 0; pos- = 1) {myservo.write (pos); kechikish (15);} uchun (pos = 0; pos <= 90; pos += 1) {myservo.write (pos); delay (15);}} pinMode (RIGHT, INPUT); pinMode (LEFT, INPUT);} void loop () {// qayta ishga tushirish uchun asosiy kodingizni shu erga qo'ying: delay (50); belgisiz int masofasi = sonar.ping_cm (); Serial.print ("masofa"); Serial.println (masofa); int O'ng_Valu = digitalRead (O'ng); int Chap_Value = digitalRead (LEFT); Serial.print ("O'ng"); Serial.println (O'ng_Qiymat); Serial.print ("SOL"); Serial.println (Chap_Qiymat); agar ((O'ng_Qiymat == 1) && (masofa> = 10 va masofa <= 30) && (Chap_Qiymat == 1))) {Motor1.setSpeed (120); Dvigatel1. ishga tushirish (oldinga); Motor2.setSpeed (120); Motor2.run (oldinga); Motor3.setSpeed (120); Motor3.run (oldinga); Motor4.setSpeed (120); Motor4.run (FORWARD);} if if ((Right_Value == 0) && (Left_Value == 1)) {Motor1.setSpeed (200); Dvigatel1.run (oldinga); Motor2.setSpeed (200); Motor2.run (oldinga); Motor3.setSpeed (100); Motor3.run (orqaga); Motor4.setSpeed (100); Motor4.run (BACKWARD);} if if ((Right_Value == 1) && (Left_Value == 0)) {Motor1.setSpeed (100); Motor1.run (Orqaga); Motor2.setSpeed (100); Motor2.run (orqaga); Motor3.setSpeed (200); Motor3.run (oldinga); Motor4.setSpeed (200); Motor4.run (FORWARD);} if if ((Right_Value == 1) && (Left_Value == 1)) {Motor1.setSpeed (0); Dvigatel1. ishga tushirish (RELEASE); Motor2.setSpeed (0); Motor2.run (RELEASE); Motor3.setSpeed (0); Motor3. ishga tushirish (RELEASE); Motor4.setSpeed (0); Motor4.run (RELEASE);} if if (masofa> 1 && masofa <10) {Motor1.setSpeed (0); Dvigatel1. ishga tushirish (RELEASE); Motor2.setSpeed (0); Motor2. ishga tushirish (RELEASE); Motor3.setSpeed (0); Motor3. ishga tushirish (RELEASE); Motor4.setSpeed (0); Motor4.run (RELEASE); }}

Tavsiya: