please give me programming code if you have project with this components

I have this items purchased separately.I'd like to do this project and projects that can be do by this so if you have this or same project like this please give me programming code for it please :blush:

2 x Geared Motor 2 x Micro Servo Tyres Omni-Directional Wheel L298N Motor Driver Arduino 328 Board Ultrasonic Module Jumper Cables

Looks like an interesting variation of Duemilanove clone, lots of headers added with +5/Gnd terminals to provide signal & power. I'd start with some simpler projects; make the tires move, get a distance reading, make the ping sensor move back & forth with the servo ...

I went to your link, copied the description into Google and in about a minute found:

First Thank you for all who interesting in my matter and helping me :slight_smile: .

I have use the code in Mr econjack’s shows this error when verifying –
“Arduino: 1.5.7 (Windows 8), Board: “Arduino Uno”
sketch_aug06a.ino:6:21: fatal error: NewPing.h: No such file or directory
compilation terminated.”

Mr crossroadstold that it could use to make more simple one to move forward or backward when obstacle detected.please direct me for link that have guided steps to make it

and please tell me how to connect sensor to board.I have HC-SR04 ultrasonic sensor.I think it’s work with 5v,so please tell me to which places do I want to plug it’s four connections (according to ecojack’s code).

I know this is stupid question but I’d like to know whether is it bad to supply voltage via power socket when it plug in to PC by programming port ?

manju123: I'd like to know whether is it bad to supply voltage via power socket when it plug in to PC by programming port ?

Of course not.

It's designed especially to be powered that way.

newping ,, you have to download that libary , its a custom sonic sensor lib ,,

Mr dexterbot I have tried your examples and it work well.thank you! :slight_smile: now I’m going to use previous code that showed that error with this new library .

i wil post 2 script ,., one is for reading the normal script , lib HR-S04 ,
other uses newping ,
you conect , + to 5v - to gnd and trigger to pin 2 and echo on 3 OK

#include "HCSR04.h" // sonic sensor lib
HCSR04 ultrasonic(2, 3); //Trig pin2 , Echo pin3;  
int cm;
int sensor;
void setup() {

void loop (){
 cm = ultrasonic.Ranging(); 
  sensor = cm ; 
  Serial.println (cm);
  delay (200);

and this is whit new ping lib ,

int incoming;
int sensor;
#include <NewPing.h> 
#define TRIGGER_PIN  2  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     3  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 1000 // max sensor value 400 means 4 meter 
void setup() {

void loop (){
 incoming =;
 sensor = incoming/ US_ROUNDTRIP_CM;
  Serial.print ("cm =");
  Serial.println (sensor); 
   Serial.print ("sensor digital reading value ");
  Serial.println (incoming); 


Mr Dexterbot this error showed up when I tried to verify the code
“sketch_aug06a.ino:1:40: fatal error: HCSR04.h: No such file or directory
compilation terminated.”
but I have installed library provided by you and I have tested it too :~

no this one uses the normal libary , the other one the newlip ,

you see define , #include “HCSR04.h” meens uses this lib
other uses #include <NewPing.h> …
i think there is somethings wrong on the unziping and dropping the lib and examples
to be sure , i alway drop a folder in libarys , in programfile/arduino/examples , and in libarys ,
when you go to examples , and you see the lib examples … they have to work ,
and when the name of the folder is to big it also wont work , but you wil see an error before program boots ,
so try to drop it in examples and in libarys , this wil solve it ,

please see whether my wire connections are correct

I have tried previous steps but the ultrasonic part is working well and showing readings in serial monitor but I don’t know how to wire (to which ports) motor control board with arduino if any one can give me complete code to complete my work and please if you can tell me how to edit this to do my work it will very helpful

This is the program comes with examples in programmer under file>example>robot control>runway robot.but this made to work with arduino robot kit.I have tried to edit this to do my work but the result is more and more errors :stuck_out_tongue:

/* Runaway Robot

Play tag with your robot! With an ultrasonic
distance sensor, it’s capable of detecting and avoiding
obstacles, never bumping into walls again!

You’ll need to attach an untrasonic range finder to M1.


  • Arduino Robot
  • US range finder like Maxbotix EZ10, with analog output

created 1 May 2013
by X. Yang
modified 12 May 2013
by D. Cuartielles

This example is in the public domain

// include the robot library
#include <ArduinoRobot.h>
#include <Wire.h>
#include <SPI.h>

int sensorPin = M1; // pin is used by the sensor

void setup() {
// initialize the Robot, SD card, and display

// draw a face on the LCD screen

void loop() {
// If the robot is blocked, turn until free
while (getDistance() < 40) { // If an obstacle is less than 20cm away
setFace(false); //shows an unhappy face
Robot.motorsStop(); // stop the motors
delay(1000); // wait for a moment
Robot.turn(90); // turn to the right and try again
setFace(true); // happy face
// if there are no objects in the way, keep moving
Robot.motorsWrite(255, 255);

// return the distance in cm
float getDistance() {
// read the value from the sensor
int sensorValue = Robot.analogRead(sensorPin);
//Convert the sensor input to cm.
float distance_cm = sensorValue * 1.27;
return distance_cm;

// make a happy or sad face
void setFace(boolean onOff) {
if (onOff) {
// if true show a happy face
Robot.background(0, 0, 255);
Robot.setCursor(44, 60);
Robot.stroke(0, 255, 0);
} else {
// if false show an upset face
Robot.background(255, 0, 0);
Robot.setCursor(44, 60);
Robot.stroke(0, 255, 0);

what do you want ? and conected to what ?? you see its a robot sketch for a robot ,, or do you want to build the robot ?

Mr Dexterbot I want to make runway/obstacle avoiding ultrasonic robot.I have following :slight_smile:
2 wheel + caster wheel chassis + gear motors
L298N Motor Driver
Arduino 328 Board
HC-SR04 ultrasonic sensor.

please give me complete code please :blush: … please :blush: … please :blush: … please give me complete code please… please… please …


Mr spycatcher2k I have just asked help.I’m not pressing any one to do my work.I think you should read replies from top to bottom.I have a problem with combining code and I’m asking help for make complete code that combine both ultrasonic reading part and motor control part .that’s what I request.I have hi lite some names previously because they have helped me lot to understand how to do this and bring my work to current if you can help me on my matter please help me or just let other volunteers to share their great knowledge through this forum.

I think people would be more willing to help if they could see some effort on your part to describe the code you have written and tested, along with your observations about what it does and doesn't do.


:stuck_out_tongue_closed_eyes: ok ok Mrs spycatcher2k

ok finaly I have 2 separate codes
For motors

int ENA=5;//connected to arduino's port 5 (output pwm)
int IN1=2;//connected to arduino's port 2
int IN2=3;//connected to arduino's port 3
int ENB=6;//connected to arduino's port 5 (output pwm)
int IN3=4;//connected to arduino's port 4
int IN4=7;//connected to arduino's port 7
void setup ()
  digitalWrite(ENB,LOW);//stop driving
  digitalWrite(IN2,HIGH);//setting motorA's direction
  digitalWrite(IN4,LOW);//setting motorB's direction
void loop ()
  analogWrite (ENA,255);//start driving motorA
  analogWrite (ENB,255);//start driving motorB

For Ultrasonic sensor

// ---------------------------------------------------------------------------
// Example NewPing library sketch that does a ping about 20 times per second.
// ---------------------------------------------------------------------------

#include <NewPing.h>

#define TRIGGER_PIN  13  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     12  // 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.

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() {
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS =; // Send ping, get ping time in microseconds (uS).
  Serial.print("Ping: ");
  Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)

now please give me some help to combine this two codes together