STEMpedia
Published © CC BY

Remote Controlled Shopping Cart Using evive

This project will show you how to upgrade your regular shopping cart to an RC shopping cart.

IntermediateFull instructions provided3,670
Remote Controlled Shopping Cart Using evive

Things used in this project

Hardware components

evive
STEMpedia evive
×1
Arduino Mega 2560
Arduino Mega 2560
×1
DC motor (generic)
×1
Transmitter
×1
Receiver
×1

Software apps and online services

Arduino IDE
Arduino IDE
STEMpedia Gamepad

Story

Read more

Schematics

Fritzing Diagram for RC Trolley

Code

Arduino Code for RC Trolley

Arduino
#define NEUTRAL_THROTTLE 1500

#define motor1_enable 44
#define motor2_enable 45
#define motor1_dir1 28
#define motor1_dir2 29
#define motor2_dir1 30
#define motor2_dir2 31

#define channel1 2
#define channel2 3
#define channel3 18
#define channel4 19
#define channel5 20
#define channel6 21

volatile int nThrottleIn1 = NEUTRAL_THROTTLE;
volatile unsigned long ulStartPeriod1 = 0;
volatile boolean bNewThrottleSignal1 = false;

volatile int nThrottleIn2 = NEUTRAL_THROTTLE;
volatile unsigned long ulStartPeriod2 = 0;
volatile boolean bNewThrottleSignal2 = false;

volatile int nThrottleIn3 = NEUTRAL_THROTTLE;
volatile unsigned long ulStartPeriod3 = 0;
volatile boolean bNewThrottleSignal3 = false;

volatile int nThrottleIn4 = NEUTRAL_THROTTLE;
volatile unsigned long ulStartPeriod4 = 0;
volatile boolean bNewThrottleSignal4 = false;

volatile int nThrottleIn5 = NEUTRAL_THROTTLE;
volatile unsigned long ulStartPeriod5 = 0;
volatile boolean bNewThrottleSignal5 = false;

volatile int nThrottleIn6 = NEUTRAL_THROTTLE;
volatile unsigned long ulStartPeriod6 = 0;
volatile boolean bNewThrottleSignal6 = false;

void setup()
   {
     //put your setup code here, to run once:

    pinMode(2, INPUT_PULLUP);
    pinMode(3, INPUT_PULLUP);
    pinMode(18, INPUT_PULLUP);
    pinMode(19, INPUT_PULLUP);
    pinMode(20, INPUT_PULLUP);
    pinMode(21, INPUT_PULLUP);

    pinMode(motor1_enable,OUTPUT);
    pinMode(motor2_enable,OUTPUT);
    pinMode(motor1_dir1,OUTPUT);
    pinMode(motor2_dir1,OUTPUT);
    pinMode(motor1_dir2,OUTPUT);
    pinMode(motor2_dir2,OUTPUT);


    attachInterrupt(digitalPinToInterrupt(2), calcInput1, CHANGE);
    attachInterrupt(digitalPinToInterrupt(3), calcInput2, CHANGE);
    attachInterrupt(digitalPinToInterrupt(18), calcInput3, CHANGE);
    attachInterrupt(digitalPinToInterrupt(19), calcInput4, CHANGE);
    attachInterrupt(digitalPinToInterrupt(20), calcInput5, CHANGE);
    attachInterrupt(digitalPinToInterrupt(21), calcInput6, CHANGE);

    Serial.begin(9600);

  }

void loop() 
  {
     // put your main code here, to run repeatedly:

     if (bNewThrottleSignal3)
        {
  
        if(nThrottleIn3<1200)
           {
              Stop();
              Serial.println("stop");
     
           }
        else if(nThrottleIn3>1201)
           {
               nThrottleIn3 = map(nThrottleIn3 , 1130, 1908, 0, 255);
               analogWrite(motor1_enable, nThrottleIn3);
               analogWrite(motor2_enable, nThrottleIn3);
               nThrottleIn3 = map(nThrottleIn3 , 0, 255, 1130, 1908);
               Serial.println(nThrottleIn3);
           }
            bNewThrottleSignal3 = false;
         }

   if (bNewThrottleSignal1)
        {
             bNewThrottleSignal1 = false;
           if (nThrottleIn1 < 1200 && nThrottleIn3 >1200)
               {
                  left();
                  Serial.println("left");
               }
          else if (nThrottleIn1 > 1750 && nThrottleIn3 >1200)
              {
                  right();
                 Serial.println("right");
              }
          
        
        }

  if (bNewThrottleSignal2)
         {
           bNewThrottleSignal2 = false;
             if (nThrottleIn2 > 1750 && nThrottleIn3 >1200)
                {
                    forward();
                   Serial.println("forward");
                }
            else if (nThrottleIn2 < 1200 && nThrottleIn3 >1200)
               {
                  backward();
      Serial.println("back");
    }
   
  }

   if(1400<nThrottleIn1<1600 && 1400<nThrottleIn2<1600)
   {
    Stop();
   }



}



void calcInput1()
{
  // if the pin is high, its the start of an interrupt
  if (digitalRead(channel1) == HIGH)
  {
    ulStartPeriod1 = micros();
  }
  else
  {
    // if the pin is low, its the falling edge of the pulse so now we can calculate the pulse duration by subtracting the
    // start time ulStartPeriod from the current time returned by micros()
    if (ulStartPeriod1 && (bNewThrottleSignal1 == false))
    {
      nThrottleIn1 = (int)(micros() - ulStartPeriod1);
      ulStartPeriod1 = 0;

      // tell loop we have a new signal on the throttle channel
      // we will not update nThrottleIn until loop sets
      // bNewThrottleSignal back to false
      bNewThrottleSignal1 = true;
    }
  }

}


void calcInput2()
{
  if (digitalRead(channel2) == HIGH)
  {
    ulStartPeriod2 = micros();
  }
  else
  {
    if (ulStartPeriod2 && (bNewThrottleSignal2 == false))
    {
      nThrottleIn2 = (int)(micros() - ulStartPeriod2);
      ulStartPeriod2 = 0;
      bNewThrottleSignal2 = true;
    }
  }

}


void calcInput3()
{
  if (digitalRead(channel3) == HIGH)
  {
    ulStartPeriod3 = micros();
  }
  else
  {
    if (ulStartPeriod3 && (bNewThrottleSignal3 == false))
    {
      nThrottleIn3 = (int)(micros() - ulStartPeriod3);
      ulStartPeriod3 = 0;
      bNewThrottleSignal3 = true;
    }
  }

}


void calcInput4()
{
 
  if (digitalRead(channel4) == HIGH)
  {
    ulStartPeriod4 = micros();
  }
  else
  {
    if (ulStartPeriod4 && (bNewThrottleSignal4 == false))
    {
      nThrottleIn4 = (int)(micros() - ulStartPeriod4);
      ulStartPeriod4 = 0;
      bNewThrottleSignal4 = true;
    }
  }

}


void calcInput5()
{
 
  if (digitalRead(channel5) == HIGH)
  {
    ulStartPeriod5 = micros();
  }
  else
  {
   
    if (ulStartPeriod5 && (bNewThrottleSignal5 == false))
    {
      nThrottleIn5 = (int)(micros() - ulStartPeriod5);
      ulStartPeriod5 = 0;
      bNewThrottleSignal5 = true;
    }
  }

}


void calcInput6()
{
  if (digitalRead(channel6) == HIGH)
  {
    ulStartPeriod6 = micros();
  }
  else
  {
    
    if (ulStartPeriod6 && (bNewThrottleSignal6 == false))
    {
      nThrottleIn6 = (int)(micros() - ulStartPeriod6);
      ulStartPeriod6 = 0;
      bNewThrottleSignal6 = true;
    }
  }

}

void forward()
{
  digitalWrite(28,HIGH);
  digitalWrite(29,LOW);
  digitalWrite(30,HIGH);
  digitalWrite(31,LOW);
  delay(30);
}
void backward()
{
  digitalWrite(28,LOW);
  digitalWrite(29,HIGH);
  digitalWrite(30,LOW);
  digitalWrite(31,HIGH);
  delay(30);
}
void left()
{
   digitalWrite(28,HIGH);
  digitalWrite(29,LOW);
  digitalWrite(30,LOW);
  digitalWrite(31,HIGH);
  delay(30);
}
void right()
{
   digitalWrite(28,LOW);
  digitalWrite(29,HIGH);
  digitalWrite(30,HIGH);
  digitalWrite(31,LOW);
  delay(30);
}
void Stop()
{
   digitalWrite(28,LOW);
  digitalWrite(29,LOW);
  digitalWrite(30,LOW);
  digitalWrite(31,LOW);
  delay(30);
}

evive Library

C/C++
No preview (download only).

Credits

STEMpedia

STEMpedia

42 projects • 168 followers
STEMpedia blends theory with experiential learning by offering state-of-the-art technology, projects, tutorials, courses, and much more.

Comments