Thursday, January 15, 2015

Electronics Final: Robotic Car

Robotic Car
By; Warren and Dane

So our project was to wire and program an electric car to respond to infared signals allowing it to move forwards, move backwards, turn left, turn right and stop and start. At first we created a randomized program which caused the car to move randomly around the room. However, this part was not included in our final design. Here is a video of the car in action:
This video here explains the wiring of the infared sensor and the motors:




#include <IRremote.h>      // include database for infared receiver
int INA = 4;                       //set up pin numbers for direction of motors and speed of motors
int PWMA = 5;
int INB = 7;
int PWMB = 6;
int RECV_PIN = 11;         // input number for infared receiver

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  pinMode(INA,OUTPUT);      // motor 1 output
  pinMode(INB,OUTPUT);      // motor 2 output
  analogWrite(PWMA,255);    // motor 1 speed
  analogWrite(PWMB,255);    // motor 2 speed
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {                       // recieve results
    if (results.value == 0xFF807F)                  // if infared recieves the forward button code do this code
     {
      Serial.println("forward");                  
      digitalWrite(INA,HIGH);                        // both motors move forward
      digitalWrite(INB,HIGH);
      delay (200);
      irrecv.resume();                                       // recieve another input
      while (results.value == 0xFFFFFFF)     // while the sensor continues to recieve same input........
      {
        digitalWrite(INA,HIGH);                   // continue moving forward
        digitalWrite(INB,HIGH);
        irrecv.resume();                                      
      }
      
    }
    if (results.value == 0xFF8877)                      // if infared recieves the right button code do this code
    {
      Serial.println("right");
      digitalWrite(INA,LOW);                       // causes car to turn right
      digitalWrite(INB,HIGH);
      delay (200);
      irrecv.resume();                                         // recieve another input
      while (results.value == 0xFFFFFFF)     // while the sensor continues to recieve same input........
      {
        digitalWrite(INA,LOW);                         // continue turning right
        digitalWrite(INB,HIGH);
       
      }
      
    }
    if (results.value == 0xFF906F)    // if infared recieves the backward button code do this code
    {
      Serial.println("backwards");
      digitalWrite(INA,LOW);                 // causes car to drive backwards
      digitalWrite(INB,LOW);
      delay (200);
      irrecv.resume();                                 // recieve another input
      while (results.value == 0xFFFFFFF)   // while the sensor continues to recieve same input........
      {
        digitalWrite(INA,LOW);       // continue moving backwards
        digitalWrite(INB,LOW);
        
         irrecv.resume();
      }
      
    }
    if (results.value == 0xFF9867)       // if infared recieves the left button code do this code
    {
      Serial.println("left");
      digitalWrite(INA,HIGH);                  // causes car to turn left
      digitalWrite(INB,LOW);
      irrecv.resume();                                             // recieve another input
      delay (200);
      while (results.value == 0xFFFFFFF)    // while the sensor continues to recieve same input........
      {
        digitalWrite(INA,HIGH);                 // continue turning left
        digitalWrite(INB,LOW);
      }
      
    }
    if (results.value == 0xFF48B7)//stop     // if infared recieves the power button code do this code
    {
      Serial.println("stop");
      digitalWrite(PWMA,LOW);               // put motor speed to 0
      digitalWrite(PWMB,LOW);
    }
    if (results.value == 0xFF6897)//start    // if infared recieves the input button code do this code
    {
      Serial.println("start");
      digitalWrite(PWMA,HIGH);                 // put motor speed to 255
      digitalWrite(PWMB,HIGH);
    }
      Serial.println(results.value, HEX);         // show the input values in the serial monitor
      irrecv.resume();                                      // recieve another input
    }
  
  delay(100);
}









No comments:

Post a Comment