• Skip to content

Vidyasagar Academy

Trusted name in education

  • Home
  • Blog
  • Online Shop
  • Coaching
    • Online Tests
  • Contact

How to move your robot FORWARD & BACKWARD infinitely

This is the SIXTH PROGRAM in your course of FUNDAMENTALS OF ROBOTICS. To use this program, you must use our robotics kit already supplied to you.

If you do not have this kit, then you can purchase our distance learning programme in robotics or contact us to join our regular batches of robotics.

Now read the following program carefully and work as per the given instructions, to enjoy your first program in robotics.

To use this program directly for your robotic kit, copy it, create new project in AVR Studio and then paste it into the coding area. Then compile it.

/*
Level II project of ‘Moving the robot FORWARD & BACKWARD’
Applicable to ATMega8/16/32/128
Designed by: Vidyasagar Academy, Akola
Website: www.vsagar.org

*** CONNECTION DETAILS OF KIT ***
1) The 2 motors in your kit, are internally connected to PB4-PB1, as follows:
Left motor: PB4 -> (+) and PB3 -> (-)
Right motor: PB1 -> (+) and PB1 -> (-)

2) Connect two IR sensors: LS to PC3 and RS to PC0.
*/

#define F_CPU 12000000UL // defining the crystal frequency 12MHz
// given on your dev. board of ATMega8

#include <avr/io.h> // including the input-output
// to define the input output ports and pins
// this file is inside the AVR folder of AVR Studio folder

#include <util/delay.h> // including the delay file
// this file is inside the
// utilities (util) folder of AVR Studio folder

int main() // starting the main function of program

{ // main function brace opened

DDRB=0b00011110; // PB4-PB1 of PORTB are defined as output pins

while(1) // starting the infinite loop to repeat the action infinitely

{ // while loop brace opened

PORTB=0b00000000; // both motors OFF
_delay_ms(2000); // delay of 2000ms=2sec

PORTB=0b00010010; // both motors rotate FORWARD
// so your robot will move forward for 1.5sec.

_delay_ms(1500); // delay of 1500ms=1.5sec.

PORTB=0b00000000; // both motors OFF, so robot STOPS
_delay_ms(1000); // delay of 1000ms=1sec

PORTB=0b00001100; // both motors rotate BACKWARD
// so your robot will move backward for 1.5sec.

_delay_ms(1500); // delay of 1500ms=1.5sec.

// after this step the program will jump to 1st line
// and your robot will move to-and-fro

} // while loop closed

} // main function closed

/*
=== HOW TO USE AND RUN THIS PROGRAM IN YOUR KIT? ===
1) First read the program carefully. Understand the steps as taught to you.
2) Connect your kit to USB port.
3) Burn the ‘hex’ file into your kit.
4) Now keep your robot on a plane surface and switch it on.
5) Wait for 2sec. Now your robot will move forward for some time.
6) Then it will stop.
7) Now it will move in backward direction for some time.
8) In this way, it will continue to move to-and-fro for infinite times.
9) When you finish testing the program switch it OFF.
10) Is it working? Nice! You did it.
11) Now don’t forget to give your feedback.
*/

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Google+ (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)

Related Posts

Filed Under: Robotics Tagged With: Web Tutorials

Subscribe to Monthly Newsletter

Subscribe and never miss a single post you love to receive!

Join 3,628 other subscribers

Reader Interactions

Comments

  1. Carter Elvise says

    November 25, 2015 at 3:34 PM

    Can I combine more than two programs in a single program so that the robot will do different actions?

    • Admin says

      November 25, 2015 at 9:27 PM

      Yes. Of course, you can.
      Provided you have enough idea of basic coding.

  • Home
  • Google+
  • Facebook
  • Instagram
  • Twitter
  • Pinterest

Copyright © 2018 · Vidyasagar Academy, All rights reserved. Terms & Conditions