loading

While making autonomous robot using ultrasonic sensors, we faced this problem of changing the path of robot when it bumps to a wall or object.

The solution is pretty simple, but I hope it will help someone :)

Step 1: Components Needed:

1) Aluminum Foil

2) Transistor (npn)

3) Chart paper

4) 1 kilo ohm resistor

5) Small piece of GPB.

6) Glue, Wires, Tape, Soldering Iron etc

7) And of course, the chassis of your robot

Step 2: Working With Foil

Apply a layer of foil on the front body of your robot.

Take a chart paper that will cover the foil, and paste foil on it too!

Attach a wire to both the foils.

Step 3: Finishing Up

Cut out few strips of chart paper, fold them, and use them as support to hold the other foil in front of the robot's body. Keep enough space between both the foils that they don't touch each other except when bumped.

And now the main circuit.

How does this work?

When two foils come in contact with each other, a switch should change its state, which can cause interrupt to the controller.

We give Vcc to one strip. And the other strip should be the input to a switch. Here transistor comes to the rescue. (look at the figure below) When the two strips don't touch each other, there is no input at the base of transistor, and output at the collector end is high. When contact is made, base gets +5V and transistor conducts, resulting to low output.

The output from the transistor is given to an interrupt pin on controller board (here Arduino) and in the next step you can check out our code..

Step 4: Code

We wanted our robo to go reverse and then right whenever it bumped. So this is the code:

(Written for Arduino)

#define mota1 4

#define mota2 53

#define motb1 7

#define motb2 6

#define en1 3

#define en2 5

void forward(void);

void reverse2(void);

void pause(void);

void right(void);

void setup()

{

Serial.begin(9600);

pinMode(19,INPUT);

attachInterrupt(4,bump,LOW);

pinMode(mota1,OUTPUT);

pinMode(mota2,OUTPUT);

pinMode(motb1,OUTPUT);

pinMode(motb2,OUTPUT);

pinMode(en1,OUTPUT);

pinMode(en2,OUTPUT);

}

void loop()

{

forward();

}

void bump()

{

for(long i = 0; i < 10000; i++){

pause();

}

for(long i = 0; i < 30000; i++){

reverse2();

}

for(long i = 0; i < 60000; i++){

right();

}

}

void forward()

{

analogWrite(en1,125);

analogWrite(en2,125);

digitalWrite(mota1,HIGH);

digitalWrite(mota2,LOW);

digitalWrite(motb1,HIGH);

digitalWrite(motb2,LOW);

}

void reverse2(void){

analogWrite(en1,255);

analogWrite(en2,255);

digitalWrite(mota1,LOW);

digitalWrite(mota2,HIGH);

digitalWrite(motb1,LOW);

digitalWrite(motb2,HIGH);

}

void right(void)

{

analogWrite(en1,0);

analogWrite(en2,255);

digitalWrite(mota1,HIGH);

digitalWrite(mota2,LOW);

digitalWrite(motb1,HIGH);

digitalWrite(motb2,LOW);

}

void pause()

{

analogWrite(en1,0);

analogWrite(en2,0);

}

About This Instructable

323views

10favorites

License:

Bio: Loves Electronics. Loves Books
More by JeniS1:Bump detector for robots with aluminum foil CircuiTricks : Circuits with a pencil.. 
Add instructable to: