Saturday 4 March 2017

HOW TO MAKE ROBOTIC SPIDER | ROBOTIC DIY | BEST ARDUINO PROJECT






Hello everyone, Today we learn how to make a robotic spider which is inspired by natural insects.
This is Arduino based project. this tutorial is about how to code Arduino for this type of insects and how to program ultrasonic sensor to detect the objects.

COMPONENT REQUIRED:
(1)- Arduino Pro mini
(2)- 6 Servo motors
(3)- Ultrasonic sensor
(4)- Spokes

ARDUINO CODE:

#include<Servo.h>  //include servo library
Servo s1,s2,s3,s4,s5,s6; // create 6 servo objects
int cu1=100, cu2=120, cu3=110, cu4=90, cu5=60, cu6=70; // set leg angle to parellel around 90 deg
const int trigPin = 13; // assign trig pin to 13
const int echoPin = 12; // assign echo pin to 12

// defines variables
long duration;
int distance;

void setup()
{
  s1.attach(5);  // sevo object attach to pwm pin of pro mini
  s2.attach(3);
  s3.attach(11);
  s4.attach(10);
  s5.attach(9);
  s6.attach(6);

pinMode(trigPin, OUTPUT); // set trig pin as a output
pinMode(echoPin, INPUT);  // set echopin as input pin

//initial pattern angle
 s1.write(cu1-40);
 delay(15);
 s2.write(cu2);
 delay(15);
 s3.write(cu3+50);
 delay(15);
 s4.write(cu4-50);
 delay(15);
 s5.write(cu5);
 delay(15);
 s6.write(cu6+40);
 delay(15);

 delay(3000);
 s1.write(cu1);
 delay(15);
 s2.write(cu2);
 delay(15);
 s3.write(cu3);
 delay(15);
 s4.write(cu4);
 delay(15);
 s5.write(cu5);
 delay(15);
 s6.write(cu6);
 delay(15);

 delay(3000);
}

void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // trig high to get a wave for 10 microsecond
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // estimate duration of pulse high
distance= duration*0.034/2;

if(distance< 10 && distance>0 ) // condition for check distance from ultrasonic sensor
{
Servo1(-40);
Servo6(40);
Servo2(-40);
Servo5(40);
Servo3(-40);
Servo4(40);
delay(5000);

s1.write(cu1);
 delay(10);
 s2.write(cu2);
 delay(10);
 s3.write(cu3);
 delay(10);
 s4.write(cu4);
 delay(10);
 s5.write(cu5);
 delay(10);
 s6.write(cu6);
 delay(10);

delay(1500);
}

else
{
Servo1(-40);
Servo6(40);
delay(100);
Servo2(-40);
Servo5(40);
delay(100);
Servo3(-40);
Servo4(40);
delay(100);

s1.attach(5);
s2.attach(3);
s3.attach(11);
s4.attach(10);
s5.attach(9);
s6.attach(6);
s1.write(cu1);
 delay(10);
 s2.write(cu2);
 delay(10);
 s3.write(cu3);
 delay(10);
 s4.write(cu4);
 delay(10);
 s5.write(cu5);
 delay(10);
 s6.write(cu6);
 delay(10);
delay(500);
}

}

// servo functoins

void Servo1(int val)
{
  s1.attach(5);
  s1.write(cu1+val);
  delay(100);
  s1.detach();
}
void Servo2(int val)
{
  s2.attach(3);
  s2.write(cu2+val);
  delay(100);
  s2.detach();
}

void Servo3(int val)
{
  s3.attach(11);
  s3.write(cu3+val);
  delay(100);
  s3.detach();
}

void Servo4(int val)
{
  s4.attach(10);
  s4.write(cu4+val);
  delay(100);
  s4.detach();
}

void Servo5(int val)
{
  s5.attach(9);
  s5.write(cu5+val);
  delay(100);
  s5.detach();
}

void Servo6(int val)
{
  s6.attach(6);
  s6.write(cu6+val);
  delay(100);
  s6.detach();
}

No comments:

Post a Comment