Need info Sketch for 2WD, L9110s, ultra sonic sensor without servo and next deve

Dear,

I am newbie here, I need sketch for 2WD avoidance car for L9110s, ultra sonic sensor without servo. This is for 2WD car avoidance

And how to develop the 2WD, adding bluetooth ect. Can you give the links for that development? Especially for beginner.

Many thanks

Hi !

Here you can find a lot of information to understand how it's works: Google

Here I wrote a simple code for L9110s motor driver from this tutorials :

  1. https://brainy-bits.com/tutorials/l9110s/
  2. How to use the HG7881 (L9110) Dual Channel Motor Driver Module
#include <NewPing.h>

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     13  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

// L9110 connections
#define L9110_B_IA 10 // Pin D10 --> Motor B Input A (Left wheel)
#define L9110_B_IB 11 // Pin D11 --> Motor B Input B (Left wheel)
#define L9110_A_IA 5 // Pin D10 --> Motor A Input A (Right wheel)
#define L9110_A_IB 6 // Pin D11 --> Motor A Input B (Right wheel)
// Motor Speed & Direction
#define MOTOR_B_PWM L9110_B_IA // Motor B PWM Speed 
#define MOTOR_B_DIR L9110_B_IB // Motor B Direction
#define MOTOR_A_PWM L9110_A_IA // Motor A PWM Speed 
#define MOTOR_A_DIR L9110_A_IB // Motor A Direction

#define MOTOR_SPEED 180 // set speed from 0-255 (PWM) 
#define MOTOR_SPEED_STOP 0 // stop 0(PWM) 


NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {

  if (sonar.ping_cm() < 15 && sonar.ping_cm() > 1) { //if distance less then 15 cm and greater then 1 cm (to exclude error 0) turn back left
    leftMode();
  } else { // else go forward
    moveMode();
  }

  Serial.print("Ping: "); // Print ping on serial monitor
  Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");
}

void moveMode (void) {

  // Move forward
  digitalWrite( MOTOR_B_DIR, HIGH ); // direction = forward
  analogWrite( MOTOR_B_PWM, MOTOR_SPEED  ); // PWM speed = 180
  digitalWrite( MOTOR_A_DIR, HIGH ); // direction = forward
  analogWrite( MOTOR_A_PWM, MOTOR_SPEED  ); // PWM speed = 180

}

void leftMode(void) {

  // Move backLeft
  digitalWrite( MOTOR_B_DIR, LOW ); // direction = backward
  analogWrite( MOTOR_B_PWM, MOTOR_SPEED  ); // PWM speed = 180
  digitalWrite( MOTOR_A_DIR, LOW ); // direction = backward
  analogWrite( MOTOR_A_PWM, MOTOR_SPEED_STOP ); // PWM speed = 0
}

Thanks for the info, it is clearer now.

But when I compile the file, it shows:

Arduino: 1.6.3 (Windows 7), Board: "Arduino Uno"

mobil.ino:2:21: fatal error: NewPing.h: No such file or directory

compilation terminated.

Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

I have add NewPing.h from other source but it shows that message.

Really need info for this problem.

I have installed new version of NewPing.h . it works in compiling.

But i creates sound ngiiingggg, and the car is only one tyre that move

dodik:
I have installed new version of NewPing.h . it works in compiling.

But i creates sound ngiiingggg, and the car is only one tyre that move

Something wrong with your schematic connection! Show your schematic!

This is the schematic,

Motor A + and - (left)

Motor B + and - (right)

B_IA pin 10
B_IB pin 11

A_IA pin 5
A_IB pin 6

GND l9110s pin GND
VCC l9110s pin VIN

Ultrasonic
GND pin GND
VCC pin 5V
Echo pin 13
Trig pin 12

Thanks

dodik:
Motor A + and - (left)

Motor B + and - (right)

B_IA pin 10
B_IB pin 11

A_IA pin 5
A_IB pin 6

B motor should be LEFT and A should be RIGHT !

VCC l9110s pin VIN

What? VCC should connect arduino 5V pin not VIN. VIN is to power up your controller, not for 5V out !

AND I don't know which motors are you using?

Important thing is right motor driver and motor connections.

I connect VCC and GND (l9110s) to power, and Arduino to jack power (separate battery). But it doesn't work. I change the sensor, but it is the same. Not work. I assume the NewPing.h , I download from the Arduino Playground - HomePage. But it should be compatible (version 1.7)

I try this sketch, it moves. But without ultrasonic. Thanks.

/*

L9110 motor driver controlling 2 small DC motors
*/

const int AIA = 5; // (pwm) pin 5 connected to pin A-IA
const int AIB = 6; // (pwm) pin 6 connected to pin A-IB
const int BIA = 10; // (pwm) pin 10 connected to pin B-IA
const int BIB = 11; // (pwm) pin 11 connected to pin B-IB

byte speed = 255; // change this (0-255) to control the speed of the motors

void setup() {
pinMode(AIA, OUTPUT); // set pins to output
pinMode(AIB, OUTPUT);
pinMode(BIA, OUTPUT);
pinMode(BIB, OUTPUT);
}

void loop() {
forward();
delay(1000);
backward();
delay(1000);
left();
delay(1000);
right();
delay(1000);
}

void backward()
{
analogWrite(AIA, 0);
analogWrite(AIB, speed);
analogWrite(BIA, 0);
analogWrite(BIB, speed);
}

void forward()
{
analogWrite(AIA, speed);
analogWrite(AIB, 0);
analogWrite(BIA, speed);
analogWrite(BIB, 0);
}

void left()
{
analogWrite(AIA, speed);
analogWrite(AIB, 0);
analogWrite(BIA, 0);
analogWrite(BIB, speed);
}

void right()
{
analogWrite(AIA, 0);
analogWrite(AIB, speed);
analogWrite(BIA, speed);
analogWrite(BIB, 0);
}

if you want to add code, please use code tags Your code!!! :wink:

If your code works, this must works too !

/*
 http://www.bajdi.com
 L9110 motor driver controlling 2 small DC motors 
 */

#include <NewPing.h>

const int TRIGGER_PIN = 12;  // Arduino pin tied to trigger pin on the ultrasonic sensor.
const int ECHO_PIN = 13;  // Arduino pin tied to echo pin on the ultrasonic sensor.
const int MAX_DISTANCE = 200; // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

const int AIA = 5;  // (pwm) pin 5 connected to pin A-IA 
const int AIB = 6;  // (pwm) pin 6 connected to pin A-IB 
const int BIA = 10; // (pwm) pin 10 connected to pin B-IA  
const int BIB = 11;  // (pwm) pin 11 connected to pin B-IB 

byte speed = 255;  // change this (0-255) to control the speed of the motors 


void setup() {
  pinMode(AIA, OUTPUT); // set pins to output
  pinMode(AIB, OUTPUT);
  pinMode(BIA, OUTPUT);
  pinMode(BIB, OUTPUT);

}

void loop() if (sonar.ping_cm() < 15 && sonar.ping_cm() > 1) { //if distance less then 15 cm and greater then 1 cm (to exclude error 0) turn back left
  left(); 
} else { // else go forward 
  forward();
}

void forward()
{
  analogWrite(AIA, speed);
  analogWrite(AIB, 0);
  analogWrite(BIA, speed);
  analogWrite(BIB, 0);
}

void left()
{
  analogWrite(AIA, speed);
  analogWrite(AIB, 0);
  analogWrite(BIA, 0);
  analogWrite(BIB, speed);
}