I Need Help For My Ardunio Project(Cleaner Robot)

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!

Moderator: phalanx

Post Reply
emrereyizz
Posts: 1
Joined: Sat Dec 08, 2018 6:42 am

I Need Help For My Ardunio Project(Cleaner Robot)

Post by emrereyizz » Sat Dec 08, 2018 6:44 am

Hello my dear friends.My project consist of 2 servo 2 dc motors and 3 ultrasonic sensors.Before i added servo motor codes,my system was working smootly.But now,since i added my servo motor codes and cases,my circuit is working wrong.I mean only one servo and one dc motor is working at the same time.Can you guys PLS help to find my error .Thank you..




#include<Servo.h>
Servo servo1;
Servo servo2;

int pos=0;
// ön
const int triger_pin =2;
const int echo_pin=3;

//sağ
int triger_pin2 =4 ;
int echo_pin2 = 5;

//sol
int triger_pin3 =6;
int echo_pin3 = 7;

const int sag_i=8;
const int sag_g=9;
const int sol_i=12;
const int sol_g=13;
int sure1;
int mesafe1;
int sure2;
int mesafe2;
int sure3;
int mesafe3;

// motor 1
int enA = 10; /* Enable girişleri Arduinonun pwm girişlerine bağladık.*/

// motor 2
int enB = 11; /* Enable girişleri Arduinonun pwm girişlerine bağladık.*/






void setup() {

servo1.attach(A2);
servo2.attach(A3);
digitalWrite(A2,HIGH);
digitalWrite(A3,HIGH);
Serial.begin (9600);
pinMode(triger_pin, OUTPUT);
pinMode(echo_pin, INPUT);

pinMode(triger_pin2, OUTPUT);
pinMode(echo_pin2, INPUT);

pinMode(triger_pin3, OUTPUT);
pinMode(echo_pin3, INPUT);

pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);

}

void loop() {
/*-------------------------Servo Motorlar-----------------------*/

for(pos=0;pos<=180 ; pos+=11)
{
servo1.write(pos);
servo2.write(pos);
delay(15);
}
for(pos=180;pos>=0 ; pos-=11 )
{
servo1.write(pos);
servo2.write(pos);
delay(15);
}


/* ----------------Ön Sensör----------------------*/
digitalWrite (triger_pin, HIGH);
delayMicroseconds (1000);
digitalWrite (triger_pin, LOW);
sure1 = pulseIn (echo_pin, HIGH);
mesafe1 = (sure1/2) / 29.1;

Serial.print("On sensor:");
Serial.print(mesafe1);
Serial.print("cm");
Serial.println();

/*--------------------------------------------------*/

/*-----------------Sag Sensör-----------------------*/
digitalWrite (triger_pin2, HIGH);
delayMicroseconds (1000);
digitalWrite (triger_pin2, LOW);
sure2 = pulseIn (echo_pin2, HIGH);
mesafe2 = (sure2/2) / 29.1;

Serial.print("Sag sensor:");
Serial.print(mesafe2);
Serial.print("cm");
Serial.println();
/*--------------------------------------------------*/

/*-----------------Sol Sensör-----------------------*/
digitalWrite (triger_pin3, HIGH);
delayMicroseconds (1000);
digitalWrite (triger_pin3, LOW);
sure3 = pulseIn (echo_pin3, HIGH);
mesafe3 = (sure3/2) / 29.1;

Serial.print("Sol sensor:");
Serial.print(mesafe3);
Serial.print("cm");
Serial.println();
/*--------------------------------------------------*/

// Motorlar sabit hızda aynı yöne dönüyorlar.
// sol motor ileri
digitalWrite(sag_i, HIGH);
digitalWrite(sag_g, LOW);
// Motor 1 için 0~255 arasında bir hız değeri verelim. 255 en üst sınır
analogWrite(enA, 75);
// sağ motor ileri
digitalWrite(sol_i, HIGH);
digitalWrite(sol_g, LOW);
// Motor 2 için 0~255 arasında bir hız değeri verelim. 255 en üst sınır
analogWrite(enB, 75);


/*----------------------------------------------------------*/

if(mesafe1<30 )//ön sensör
{
//motorlar durduruluyor
digitalWrite(sag_i, LOW);
digitalWrite(sag_g, LOW);
digitalWrite(sol_i, LOW);
digitalWrite(sol_g, LOW);

delay(500);//bir üst fonksiyonun çalışma süresi

// motorlar geriye dönüyor
digitalWrite(sag_i, LOW);
digitalWrite(sag_g, HIGH);
digitalWrite(sol_i, LOW);
digitalWrite(sol_g, HIGH);

delay(500);//bir üst fonksiyonun çalışma süresi

digitalWrite(sag_i, HIGH);
digitalWrite(sag_g, LOW);
digitalWrite(sol_i, LOW);
digitalWrite(sol_g, HIGH );

delay(1000);//bir üst fonksiyonun çalışma süresi

}
/*------------------------------------------------------------*/
if(mesafe2<7 )//sağ sensör
{
//sağ motor
digitalWrite(sag_i, HIGH);
digitalWrite(sag_g, LOW);
analogWrite(enA,75);

//sol motor
digitalWrite(sol_i, LOW);
digitalWrite(sol_g, HIGH);
analogWrite(enB,75);


delay(500);
}

/*------------------------------------------------------*/
if(mesafe3<7 )//sol sensör
{

//sağ motor
digitalWrite(sag_i, LOW);
digitalWrite(sag_g, HIGH);
analogWrite(enA, 75);

//sol motor
digitalWrite(sol_i, HIGH);
digitalWrite(sol_g, LOW);
analogWrite(enB, 75);

delay(500);
}
}

BigPilot
Posts: 26
Joined: Fri Sep 23, 2005 2:04 am

Re: I Need Help For My Ardunio Project(Cleaner Robot)

Post by BigPilot » Sun Dec 09, 2018 8:41 am

First of all, I recommend you use a version control system to safe you source code changes, such as Git in combination with TortoiseGit (on Windows).

Why are you assuming it's a software problem? Did you switch the connections to the servo's and get a different result?

Post Reply