Need help in a robotic project!!

Hello to all :slight_smile:
I am currently working on a wall following,obstacle avoiding bot.
It works on differential drive using two dc motors.
I am using an arduino mega2560.
For distance measurement-sharp GP2D120.
For obstacle sensing-[http://robokits.co.in/shop/index.php?main_page=product_info&products_id=45]
And L293D for motor direction control.
Now i am stuck..there are two inputs to the microcontroller from the driver circuit..I want to use PWM
for controlling the motor speed and direction..WHERE TO PUT THESE TWO INPUTS ON MY MCU??
And how do i maintain a fixed distance from the wall using the sharp sensor..this is all programming part and i am
a beginner..I am in need of some help..!!

Hey,

Btw,

wall following

You want it to follow a wall? :stuck_out_tongue:

I checked the data sheet for your moter driver.

  1. The voltage in for vcc1 is around 4.5-7v. can be connected to the arduino out
  2. vcc2 is vcc1-36v. For higher power you need to connect a transistor as a switch. eg. tip31b. To drive high power moters if i'm right.

Referring to page 9 of the data sheet, Figure 5, The EN/1A/2A should be connected to digital outs on the arduino board. you can then program em according to the function table given. for eg.

#define en 10
#define a1 11
#define a2 12

void setup() {                
  pinMode(en, OUTPUT); //connect En
  pinMode(a1, OUTPUT); //connect 1A
  pinMode(a2, OUTPUT); //connect 2A

}

void loop() {
  digitalWrite(en, HIGH);
  digitalWrite(a1, LOW);
  digitalWrite(a2, HIGH);
  
  delay(2000); //wait for 2s
  
  digitalWrite(en, HIGH);
  digitalWrite(a1, HIGH);
  digitalWrite(a2, LOW); 
  
  delay(2000);
  
}

This code should turn it left-right after 2 seconds..

Connect vcc1/vcc2/8 to 5v of arduino, Ground 4 5 12 13 of driver
if the moters are not that big. it should roughly work :slight_smile:
Hook up the diodes as shown in the circuit btw. Data sheet suggests high speed output clamp diodes but i think low power ones should work just fine as long as you are connecting 5v. THey are used to prevent the back flow of electricity cause of inductance..

Hope this helps..

Thanks for the reply.

Btw,
Quote
wall following
You want it to follow a wall?

Yeah :stuck_out_tongue:
I am using a 12V rated DC motor,powered by an external source(Li-ion battery).
+12V being connected to pin8 of the IC.Would that work?
The code given by you is helpful but I want to use PWM to control speed.
And how do I control the speed of the motors according to the Sharp sensor readings?
Like turn left,turn right,go forward or stop. :disappointed_relieved:

How do you decide that a wall isn't an obstacle, and so should not be avoided?

How do you decide that a wall isn't an obstacle, and so should not be avoided?

You see if it moves, and if it does you follow it.

http://luckylarry.co.uk/arduino-projects/control-a-dc-motor-with-arduino-and-l293d-chip/

Try this.

How do you decide that a wall isn't an obstacle, and so should not be avoided?

We do avoid the wall. :slight_smile:

http://luckylarry.co.uk/arduino-projects/control-a-dc-motor-with-arduino-and-l293d-chip/

Thanks for the link. 8)