Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Engr Muhammad Sheraz
Published © GPL3+

Smartphone Controlled Pick and Place Robot with Code

A smartphone-controlled robotic car with an arm on it with acomplete project report, code, and circuit diagram. which can pick up to 9 gram.

IntermediateFull instructions providedOver 1 day610
Smartphone Controlled Pick and Place Robot with Code

Things used in this project

Hardware components

Raspberry Pi Complete Robotic Kit
×1
Epson Arduino Uno R3
×1
smart home HC Bluetooth Module
×1
Amazon Alexa Servo Motor
×3
Adafruit Potentiometer
×3

Software apps and online services

Amazon Alexa Official Arduino Skill
Amazon Alexa Official Arduino Skill

Hand tools and fabrication machines

Acutronic Robotics Digital Electric Soldering Iron Kit with Helping Hands
Soldering iron with Digital multimeter kit

Story

Read more

Code

Code For CAR

C/C++
int motorLpin1=2;
int motorLpin2=3;
int motorRpin1=4;
int motorRpin2=5;
int motorLpwm=10;
int motorRpwm=11;

int motorSpeed=125;
int turn=50;

void setup() {
  Serial.begin(9600);
  Serial.flush();
  pinMode(motorLpin1,OUTPUT);
  pinMode(motorLpin2,OUTPUT);
  pinMode(motorRpin1,OUTPUT);
  pinMode(motorRpin2,OUTPUT);
  pinMode(motorLpwm,OUTPUT);
  pinMode(motorRpwm,OUTPUT);
}

void loop() {
  String input="";
  while(Serial.available()){
    input+=(char)Serial.read();
    delay(5);
  }
  
  if(input=="n"){
    stp();
  }
  else if(input=="F"){
    fwd();
  }
  else if(input=="R"){
    rev();
  }
  else if(input.indexOf("TL")>-1){
    lft();
  }
  else if(input.indexOf("TR")>-1){
    rght();
  }
  else if(input!=""){
    motorSpeed=input.toInt();
  }
}

void fwd(){
  analogWrite(motorLpwm,motorSpeed);
  analogWrite(motorRpwm,motorSpeed);
  digitalWrite(motorLpin1,1);
  digitalWrite(motorLpin2,0);
  digitalWrite(motorRpin1,1);
  digitalWrite(motorRpin2,0);
}

void rev(){
  analogWrite(motorLpwm,motorSpeed);
  analogWrite(motorRpwm,motorSpeed);
  digitalWrite(motorLpin1,0);
  digitalWrite(motorLpin2,1);
  digitalWrite(motorRpin1,0);
  digitalWrite(motorRpin2,1);
}

void lft(){
  analogWrite(motorLpwm,motorSpeed-turn);
  analogWrite(motorRpwm,motorSpeed+turn);
  digitalWrite(motorLpin1,0);
  digitalWrite(motorLpin2,1);
  digitalWrite(motorRpin1,1);
  digitalWrite(motorRpin2,0);
}

void rght(){
  analogWrite(motorLpwm,motorSpeed+turn);
  analogWrite(motorRpwm,motorSpeed-turn);
  digitalWrite(motorLpin1,1);
  digitalWrite(motorLpin2,0);
  digitalWrite(motorRpin1,0);
  digitalWrite(motorRpin2,1);
}

void stp(){
  analogWrite(motorLpwm,0);
  analogWrite(motorRpwm,0);
  digitalWrite(motorLpin1,1);
  digitalWrite(motorLpin2,1);
  digitalWrite(motorRpin1,1);
  digitalWrite(motorRpin2,1);
}

Code For Robotic Arm

Arduino
-*//add servo library
#include <Servo.h>

//define our servos
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

//define our potentiometers
int pot1 = A1;
int pot2 = A2;
int pot3 = A3;
int pot4 = A4;

//variable to read the values from the analog pin (potentiometers)
int valPot1;
int valPot2;
int valPot3;
int valPot4;

void setup()
{
  //attaches our servos on pins PWM 3-5-6-9 to the servos
  servo1.attach(3);
  servo1.write(0);  //define servo1 start position
  servo2.attach(5);
  servo2.write(90); //define servo2 start position
  servo3.attach(6);
  servo3.write(90); //define servo3 start position
  servo4.attach(9);
  servo4.write(70); //define servo4 start position
}

void loop()
{
  //reads the value of potentiometers (value between 0 and 1023)

  valPot1 = analogRead(pot1);
  valPot1 = map (valPot1, 0, 1023, 0, 180); //scale it to use it with the servo (value between 0 and 180)
  servo1.write(valPot1); //set the servo position according to the scaled value

  valPot2 = analogRead(pot2);
  valPot2 = map (valPot2, 0, 1023, 0, 180);
  servo2.write(valPot2);
  
  valPot3 = analogRead(pot3);
  valPot3 = map (valPot3, 0, 1023, 0, 180);
  servo3.write(valPot3);

  valPot4 = analogRead(pot4);
  valPot4 = map (valPot4, 0, 1023, 70, 150);
  servo4.write(valPot4);
  
}

Credits

Engr Muhammad Sheraz
14 projects • 64 followers
BSc Electerical Enginer and An Expert Academic Writer https://aquabcasing.com/WhatsApp: +923057608848

Comments