arduino uno, L298N, HC SR04 and HC06 issue

I am trying to build an obstacle avoiding smart car. The components i use are Arduino Uno, L298N, 2 DC motors, HC SR04 (ultrasonic) and HC-06 (bluetooth). I am using the "Bluetooth RC car" app available in the playstore.

Problem : The car works when HC06 is connected and responds to commands. Problem occurs when i put a HC SR04 (pin 2 and pin 3 of arduino for trigger and echo) to read the obstacle distance. The forward command does not respond at all.

I tried the newping library just with the arduino board and it does read the distances and prints it back to the serial monitor. so the HCSR 04 sensor is fine. Here is the code i am using, please advise where i am wrong here. Please note i am using a single power source - 9V battery

#include <NewPing.h>

#define in1 5 //L298n Motor Driver pins.
#define in2 6
#define in3 10
#define in4 11

#define trig 2 // acy
#define echo 3 // acy
#define MAX_DISTANCE 300 // acy
#define COLL_DIST 75 // collision distance threshold 75 cms
#define LED 13

int command; //Int to store app command state.
int Speed = 204; // 0 - 255.
int Speedsec;
int buttonState = 0;
int lastButtonState = 0;
int Turnradius = 0; int brakeTime = 45;
int brkonoff = 1;
int curDist = 0;

NewPing sonar(trig, echo, MAX_DISTANCE); // acy

void setup() {
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(LED, OUTPUT); //Set the LED pin.
Serial.begin(9600); //Set the baud rate to your Bluetooth module.


void loop() {
if (Serial.available() > 0) {
command =;
Stop(); //Initialize with motors stoped.
switch (command) {
case 'F':

void forward() {
curDist = readPing(); //acy
Serial.print("Current Distance Read ping fx ::");
curDist = sonar.ping_cm(); /// to try sonar ping
serial.print("Current Distance sonar library ::");
if (curDist > COLL_DIST) //acy
{ // acy
analogWrite(in1, Speed);
analogWrite(in3, Speed);
} // acy
else // acy
{ // acy
analogWrite(in1, 0); // acy
analogWrite(in3, 0); // acy
} //acy