kodu d,worde de yaıp dosya olarak yükledim bilginiz olsun.
//#include<Servo.h>
//Servo kalem;
//const byte sag_echo = 6;
//const byte sag_trig = 7;
//int sag_sure = 0;
//int sag_mesafe = 0;
//const byte sol_echo = 2;
//const byte sol_trig = 3;
//int sol_sure = 0;
//int sol_mesafe = 0;
const byte orta_echo = 13;
const byte orta_trig = 12;
int orta_sure = 0;
int orta_mesafe = 0;
#define SagMotorileri 4
#define SagMotorGeri 5
#define SolMotorileri 6
#define SolMotorGeri 7
#define B 11
#define EN1 9
#define EN2 3
int metal_pini = 8; // variable for reading the pushbutton status
int metal = 0;
//int in=0;//yerdeki acıso
//int cik=90;//yukardaki acısı
void setup() {
//kalem.attach(9);
pinMode(SolMotorileri, OUTPUT);
pinMode(SolMotorGeri, OUTPUT);
pinMode(SagMotorileri, OUTPUT);
pinMode(SagMotorGeri, OUTPUT);
pinMode(B, OUTPUT);
pinMode(EN1, OUTPUT);
pinMode(EN2, OUTPUT);
//pinMode(sag_echo , INPUT);
// pinMode(sag_trig , OUTPUT);
//
//pinMode(sol_echo , INPUT);
// pinMode(sol_trig , OUTPUT);
pinMode(orta_echo , INPUT);
pinMode(orta_trig , OUTPUT);
pinMode(metal_pini , INPUT);
Serial.begin(9600);
// kalem.write(cik); // ortada
}
void loop() {
metal = digitalRead(metal_pini);
bak();
if (orta_mesafe < 20 )
{
digitalWrite(SolMotorileri, LOW);
digitalWrite(SolMotorGeri, HIGH);
digitalWrite(SagMotorileri, LOW);
digitalWrite(SagMotorGeri, HIGH);
// digitalWrite(EN1, HIGH);
// digitalWrite(EN2, HIGH);
delay (300);
digitalWrite(SolMotorileri, HIGH);
digitalWrite(SolMotorGeri, LOW);
digitalWrite(SagMotorileri, LOW);
digitalWrite(SagMotorGeri, HIGH);
//digitalWrite(EN1, HIGH);
// digitalWrite(EN2, HIGH);
delay (500);
}
else
{
metal = digitalRead(metal_pini);
if (metal == LOW)
{
// digitalWrite(SolMotorileri, LOW);
// digitalWrite(SolMotorGeri, LOW);
// digitalWrite(SagMotorileri, LOW);
// digitalWrite(SagMotorGeri, LOW);
digitalWrite(B, HIGH);
delay(300);
// digitalWrite(SolMotorileri, LOW);
// digitalWrite(SolMotorGeri, HIGH);
// digitalWrite(SagMotorileri, LOW);
// digitalWrite(SagMotorGeri, HIGH);
digitalWrite(B,LOW);
delay (300);
// digitalWrite(SolMotorileri, LOW);
// digitalWrite(SolMotorGeri, HIGH);
// digitalWrite(SagMotorileri, HIGH);
// digitalWrite(SagMotorGeri, LOW);
digitalWrite(B, HIGH);
delay (300);
}
// digitalWrite(SolMotorileri, HIGH);
// digitalWrite(SolMotorGeri, LOW);
// digitalWrite(SagMotorileri, HIGH);
// digitalWrite(SagMotorGeri, LOW);
digitalWrite(B,LOW);
}
}
void bak()
{
digitalWrite(orta_trig , HIGH);
delayMicroseconds(1000);
digitalWrite(orta_trig , LOW);
orta_sure = pulseIn(orta_echo , HIGH);
orta_mesafe = (orta_sure / 2) / 28.5 ;
delay (50);
Serial.print (" orta_mesafe ");
Serial.println (orta_mesafe);
}
/sites/default/files/cevaplar/dosya/2020/file-isi_engel_0.docx