Motor drive shield and distance sensor PROBLEM

Hello everyone,

I recently bought and motor drive shield with L293D(http://www.ebay.com/itm/370668454866?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649). My problem is that its only one free PWM in this shield. To work the distance sensor needs two PWMs one for the echo and the other for the trigger. Do you have any idea how i can solve this issue.

Thanks in advance

There are two ways to solve this. First, try using the SoftPWM library.

http://forum.arduino.cc/index.php/topic,19451.0.html

This will let you make any pin into a PWM pin, though it will use Timer2 and thus stop two of the hardware PWM pins from working. This isn't as good as hardware PWM, but DC motors shouldn't care.

Alternatively, you could try a different sensor. There are many that only need one pin, and even that pin does not have to be a PWM pin. I believe the Parallax ping sensor and its clones are this way.

hello again,

So in my case how i will set for example the analog pin as an PWM or Digital pins as PWM. I checked from the library examples and they are mentioning only for already PWM pin in the board.If someone can provide me the 2 line code needed to set 1 analog pin as a PWM and one Digital pin as PWM.

Thanks in advance.

I am not totaly sure it will work for analog pins, but for digital pins just take their example code and wherever you see a 13 replace it with the digital pin number you want to use. (Avoid 1 and 0 as they are used for serial communication and have other lingering issues with the library)

#include <SoftPWM.h>

void setup()
{
  // Initialize
  SoftPWMBegin();

  // Create and set pin 13 to 0 (off)
  SoftPWMSet(13, 0);

  // Set fade time for pin 13 to 100 ms fade-up time, and 500 ms fade-down time
  SoftPWMSetFadeTime(13, 100, 500);
}

void loop()
{
  // Turn on - set to 100%
  SoftPWMSetPercent(13, 100);

  // Wait for LED to turn on - you could do other tasks here
  delay(100);

  // Turn off - set to 0%
  SoftPWMSetPercent(13, 0);

  // Wait for LED to turn off
  delay(500);
}