Shake Self-balancing and Light Following Robot

Self-balancing and Light Following Robot

     Shake is a robot inspired from a Segway (You can google it if you haven’t heard it yet). He is a self-balancing and light following robot. Most of the balancing robots use Gyrometers or Accelerometers or even both for a very good accuracy but since I don’t have enough funds to have them I decided to use Light Dependent Resistors.

     The concept of its action is the same with the line follower mobile robot. When the light is received by the LDR then it tells the robot that it is near to the floor. Two LDRs are used on its front and back. When the back LDR doesn’t receive any light then the robot will move forward. When the front LDR doesn’t receive any light then the robot will move backward. It is stable when both LDRs are receiving light.

Shake only follows light when he is in a stable mode. If he is not balanced, he will stabilize himself

I provided the schematic and the code below.

He has 3 circuit boards.

Main controller board

Sensor board for Balancing

Sensor board for Light Following is also the same above just remove the 120 ohms resistors and LEDs since you will provide your own light source.

Code

<em>void main() {
 portb = 0x00;
 trisa = 0x0f;
 trisb = 0x00;
 while(1){
 if (porta.f0 == 0){
 if (porta.f1 == 0){ //00
 if (porta.f2 == 0){
 if (porta.f3 == 0){ //0000
 portb = 0x00;
 }
 else if (porta.f3 == 1){ //0001
 portb = 0x60; //move left
 }
 }
 else if (porta.f2 == 1){
 if (porta.f3 == 0){ //0010
 portb = 0x90; //move right
 }
 else if (porta.f3 == 1){ //0011
 portb = 0x50; //move forward
 }
 }
 }
 else if (porta.f1 == 1){ //01
 portb = 0x50; //move forward
 }
 }</em>

else if (porta.f0 == 1){
 if (porta.f1 == 0){ //10
 portb = 0xa0; //move backward
 }
 else if (porta.f1 == 1){ //11
 if (porta.f2 == 0){
 if (porta.f3 == 0){ //1100
 portb = 0x00;
 }
 else if (porta.f3 == 1){ //1101
 portb = 0x60; //move left
 }
 }
 else if (porta.f2 == 1){
 if (porta.f3 == 0){ //1110
 portb = 0x90; //move right

}
 else if (porta.f3 == 1){ //1111
 portb = 0x00; //move forward
 }
 }
 }
 }
 }
 }

You can download the rest of the files on my box at the right side of this blog.

Before copying the code please give credits to me or inform me that you will be using my code by leaving a comment below.

Some images taken:

Video:

Advertisements

9 responses to “Shake Self-balancing and Light Following Robot

    • Hi dav, First of all it will be hard to understand them if it is your first time to do this but of course you can still make this but I guess it will take you time. I assume that you already know how to build robots like these. If not, you should start first on the easiest projects like line following robots.

      J1 to J8 of the main board are all terminal blocks. This is how they look:
      Terminal Block

      J3 is connected to the output produced by the LDR on the balancing board (used to balance the robot).

      J4 is connected to the output produced by the LDR on the light following board (used to follow the light).

      J5 is connected to the 9v power supply which powers the circuitries.

      J6 is connected to 4 1.5v battery which powers the motor.

      J7 is connected to the power supply board of the balancing board while J8 is connected to the power supply board of the light following board.

      J1 is connected to the first motor
      J2 is connected to the 2nd motor

      *Note (This is the tricky part)
      Before connecting J1 and J2 to the motor, you should determine first their rotation if it’s clockwise or counterclockwise. Make the robot run first then if it’s not moving to the right direction then just switch the pins you connected to the motor. The proper moving direction of the robot is that when the robot is falling forward, it should also move forward. If it is falling the opposite way, it should move backward. This will keep the robot balanced.

      Ask questions if it is still not clear to you 😀

  1. Hi, I DID EVERYTHİNG YOU SAID BUT I COULD NOT MAKE IT WORK. JUST ONE OF THE LDR SENSORS WORK, THE OTHER ONES DONT. AM I MISSING SOMETHING? I TRIED MANY TIMES BUT I GOT NO RESULT. DID YOU DO SOMETHİNG ELSE DIFFERENT FROM THE ISIS PROGRAM WHICH YOU PUT IN THE PICTURE? AND THE C PROGRAM IS CORRECT?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s