Pages: [1]   Go Down
Author Topic: Arduino smart car  (Read 1839 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My Arduino smart car,
control is via WII nunchuk and nrf24l01+

http://youtu.be/3_f8sF2zc5s

code:
Code:
/*

 */
 #include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10

 
const int AIA = 30;  // (pwm) pin 9 connected to pin A-IA
const int AIB = 31;  // (pwm) pin 5 connected to pin A-IB
const int BIA = 33; // (pwm) pin 10 connected to pin B-IA  
const int BIB = 34;  // (pwm) pin 6 connected to pin B-IB

const int CIA = 35;  // (pwm) pin 9 connected to pin c-Ic
const int CIB = 36;  // (pwm) pin 5 connected to pin c-Ic
const int DIA = 37; // (pwm) pin 10 connected to pin d-Id  
const int DIB = 38;  // (pwm) pin 6 connected to pin d-Id
 
byte speed = 255;  // change this (0-255) to control the speed of the motors
 
 const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
int led = 13;
int mydata[2];
    
    RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
  
 
 
void setup() {
  
     mydata[0]=0;
     pinMode(led, OUTPUT);
    Serial.begin(9600);
      radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();;

    
  
  pinMode(AIA, OUTPUT); // set pins to output
  pinMode(AIB, OUTPUT);
  pinMode(BIA, OUTPUT);
  pinMode(BIB, OUTPUT);
  
   pinMode(CIA, OUTPUT); // set pins to output
  pinMode(CIB, OUTPUT);
  pinMode(DIA, OUTPUT);
  pinMode(DIB, OUTPUT);
  stopnow();
}
 
void loop() {
  
  mydata[0]=0;
   if ( radio.available() )
  {
    // Read the data payload until we've received everything
    bool done = false;
    while (!done)
    {
      // Fetch the data payload
   done = radio.read( mydata, sizeof(mydata) );
  
      Serial.print(" mydata: ");

      Serial.println(mydata[0]);
      
      
 //     Serial.print(" Y = ");      
   //   Serial.println(joystick[1]);
       digitalWrite(led, HIGH);  
   //  delay(100);
    }
    
    
  }
  
  
  else
  {    
  //    Serial.println("No radio available");
       digitalWrite(led, LOW);
   //    delay(100);
  }

if (mydata[0]==1) forward();
if (mydata[0]==2) backward();
if (mydata[0]==3) left();
if (mydata[0]==4) right();
if (mydata[0]==0) stopnow();

delay(40);


}
 
 void stopnow()
{
  analogWrite(AIA, 0);
  analogWrite(AIB, 0);
  analogWrite(BIA, 0);
  analogWrite(BIB, 0);
  
    analogWrite(CIA, 0);
  analogWrite(CIB, 0);
  analogWrite(DIA, 0);
  analogWrite(DIB, 0);
}
 
 
 
void backward()
{
  analogWrite(AIA, speed);//left top
  analogWrite(AIB, 0);
analogWrite(BIA, speed);//right top
 analogWrite(BIB, 0);
  
  analogWrite(CIA, 0);
 analogWrite(CIB, speed);
 analogWrite(DIA, 0);
  analogWrite(DIB, speed);
  
  
}
 
void forward()
{
 analogWrite(AIA, 0);//left top
  analogWrite(AIB, speed);
analogWrite(BIA, 0);//right top
 analogWrite(BIB, speed);
  
  analogWrite(CIA, speed);
 analogWrite(CIB, 0);
 analogWrite(DIA, speed);
  analogWrite(DIB, 0);
  
}
 
void left()
{
  analogWrite(AIA, speed);
  analogWrite(AIB, 0);
  analogWrite(BIA, 0);
  analogWrite(BIB, speed);
  
  
  analogWrite(CIA, 0);
 analogWrite(CIB, speed);
 analogWrite(DIA, speed);
  analogWrite(DIB, 0);
  
}
 
void right()
{
 analogWrite(AIA, 0);
  analogWrite(AIB, speed);
  analogWrite(BIA, speed);
  analogWrite(BIB, 0);
  
  
  analogWrite(CIA, speed);
 analogWrite(CIB, 0);
 analogWrite(DIA, 0);
  analogWrite(DIB, speed);
}

« Last Edit: June 06, 2014, 04:28:32 am by marco_arduino » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13917
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well done!
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Scotland
Offline Offline
Edison Member
*
Karma: 26
Posts: 1343
Have you had your Arduino fix today?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice.
Logged

Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i need faster motors.
Logged

Portugal
Offline Offline
Edison Member
*
Karma: 45
Posts: 1335
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

marco_arduino, did you had seen this thread?
Logged

Greece
Offline Offline
Sr. Member
****
Karma: 14
Posts: 416
Arduino fan
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

nice work ...  smiley-grin
Logged

z.p

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Made out well . you can upgrade it.
Logged


Pages: [1]   Go Up
Jump to: