صنع سيارة والتحكم بها بالاردوينو





كيف نصنع سيارة نتحكم بها من خلال اي جهاز تحكم مع الاردوينو 



الهدف من المشروع هو خلق جو من المتعة والتعلم

المكونات واللوازم

اردوينو نانو
لوح تجارب
DvDاقراص 
Dc 6v محرك
بطارية
L293d
Servo motor
اسلاك التوصيل
IR sensor

لوح تجارب


Dc motor 6v

Arduino nano
L293D


IR sensor


Servo motor


DvD


Batre 9v

اسلاك التوصيل


طريقة التوصيل 






كود البرمجة

//ABOUBAKER ELAZOUM
#include <Servo.h>
#include <IRremote.h>
//Include header files to control servo motor and IR sensor

IRrecv irrecv(2);  //Mapping the digital pin which is connected to IR sensor(pin no.8)
decode_results results; //Variable to save recieved IR sign
Servo myServo;  //Variable to use servo motor
const int MOTOR_R_R = 5;  //Right motor red line
const int MOTOR_R_B = 6;  //Right motor black line
const int MOTOR_L_R = 10; //Left motor red line 
const int MOTOR_L_B = 11; //Left motor black line

void setup()
{
  irrecv.enableIRIn();  //Enable IR sensor
  myServo.attach(9);  //Use pin no.9 to control servo motor
  pinMode(MOTOR_R_R, OUTPUT); //DC motor pin output setting
  pinMode(MOTOR_R_B, OUTPUT);
  pinMode(MOTOR_L_R, OUTPUT);
  pinMode(MOTOR_L_B, OUTPUT);
}

void loop()
{
  if (irrecv.decode(&results)) //Interpret IR sign
  {
    switch (results.value)
    {
      
      case 0xFFA25D
:  //case 4(Left)
        analogWrite(MOTOR_R_R, 255);
        analogWrite(MOTOR_R_B, 0);
        analogWrite(MOTOR_L_R, 0);
        analogWrite(MOTOR_L_B, 255);
        break;
      case 0xFF629D
        :  //cFD20DFase 5(Stop)
        analogWrite(MOTOR_R_R, 0);
        analogWrite(MOTOR_R_B, 0);
        analogWrite(MOTOR_L_R, 0);
        analogWrite(MOTOR_L_B, 0);
        break;
      case 0xFFE21D
        :  //case 6(Right)
        analogWrite(MOTOR_R_R, 0);
        analogWrite(MOTOR_R_B, 255);
        analogWrite(MOTOR_L_R, 255);
        analogWrite(MOTOR_L_B, 0);
        break;
      case 0xFF22DD
        :  //case 8(Back)
        analogWrite(MOTOR_R_R, 0);
        analogWrite(MOTOR_R_B, 255);
        analogWrite(MOTOR_L_R, 0);
        analogWrite(MOTOR_L_B, 255);
        break;
      case 0xFF02FD

        :  //case 0(Kick)
        myServo.write(70);
        delay(900);
        myServo.write(90);
        break;
       case 0xFF18E7
        :  //case 0(Kick)
        myServo.write(110);
        delay(900);
        myServo.write(90);
        break;
    }
    delay(30);  //Delay 0.03sec
    irrecv.resume();  //Reset to recieve next sign
  }
}




تعليقات