Arduino uzaktan kumandalı araba

Joystick_araba ares dosyaları

kutuphane dosyaları

joystick kod:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

 

#define CE_PIN 9
#define CSN_PIN 10
#define x_axis A1 // x axis
#define y_axis A0 //y axis

 

 

const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int data[2];

void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
}

void loop()
{

data[0] = analogRead(x_axis);
data[1] = analogRead(y_axis);
radio.write( data, sizeof(data) );

//HATA AYIKLAMA (DEBUG)
Serial.print(analogRead(x_axis));
Serial.println(” “);
Serial.print(analogRead(A1));
Serial.println(” “);
//Serial.print(digitalRead(BUTON));
}

araba kod:

//Yasin Demir Joystick_kontrollü_araba
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int data[2];
int in1 = 6; //Sağ Motor
int in2 = 7;
int in3 = 2; //Sol Motor
int in4 = 4;
int sag_PWM = 5;
int sol_PWM = 3;
void setup()
{
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
pinMode(sag_PWM, OUTPUT);
pinMode(sol_PWM, OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();;
}

 

void loop() {
if ( radio.available() ) //Eğer sinyal algılarsan.
{
int y = data[1];
int x = data[0];
radio.read( data, sizeof(data) );
if (y >= 400 && y <= 600) { //DUR
digitalWrite(in1 , LOW);
digitalWrite(in2 , LOW);
digitalWrite(in3 , LOW);
digitalWrite(in4 , LOW);
analogWrite(sag_PWM, 0);
analogWrite(sol_PWM, 0);
}
if (y >= 800 && y <= 1023) { //İLERİ
digitalWrite(in1 , LOW);
digitalWrite(in2 , HIGH);
digitalWrite(in3 , LOW);
digitalWrite(in4 , HIGH);
analogWrite(sag_PWM, 185);
analogWrite(sol_PWM, 185);
}
if (y >= 0 && y <= 450) { //GERİ
digitalWrite(in1 , HIGH);
digitalWrite(in2 , LOW);
digitalWrite(in3 , HIGH);
digitalWrite(in4 , LOW);
analogWrite(sag_PWM, 185);
analogWrite(sol_PWM, 185);
}
if (x >= 0 && x <= 450) { //SOL_İLERİ
digitalWrite(in1 , LOW);
digitalWrite(in2 , HIGH);
digitalWrite(in3 , LOW);
digitalWrite(in4 , HIGH);
analogWrite(sag_PWM, 225);
analogWrite(sol_PWM, 100);
}
if (x >= 600 && x <= 1023) { //SAĞ_İlERİ
digitalWrite(in1 , LOW);
digitalWrite(in2 , HIGH);
digitalWrite(in3 , LOW);
digitalWrite(in4 , HIGH);
analogWrite(sag_PWM, 100);
analogWrite(sol_PWM, 190);
}
}
}

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak.