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

Uncompiled, untested.

#include <NewPing.h>

const byte ENA=5;//connected to arduino's port 5 (output pwm)
const byte IN1=2;//connected to arduino's port 2
const byte IN2=3;//connected to arduino's port 3
const byte ENB=6;//connected to arduino's port 5 (output pwm)
const byte IN3=4;//connected to arduino's port 4
const byte IN4=7;//connected to arduino's port 7

const byte TRIGGER_PIN =  13;  // Arduino pin tied to trigger pin on the ultrasonic sensor.
const byte ECHO_PIN    = 12;  // 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.

void setup ()
{
  pinMode(ENA,OUTPUT);//output
  pinMode(ENB,OUTPUT);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  digitalWrite(ENA,LOW);
  digitalWrite(ENB,LOW);//stop driving
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);//setting motorA's direction
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);//setting motorB's direction
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}
void loop ()
{
  analogWrite (ENA,255);//start driving motorA
  analogWrite (ENB,255);//start driving motorB
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // 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)
  Serial.println("cm");
}

Mr AWOL the code is compiled without error.but it show ultrasonic readings on serial monitor and spinning motors .it isn’t respond to ultrasonic readings.how to fix this?

manju123:
Mr AWOL the code is compiled without error.but it show ultrasonic readings on serial monitor and spinning motors .it isn’t respond to ultrasonic readings.how to fix this?

That’s left as An Exercise For The Reader

i give you this to learn your own ways , i see you understand a little bit ,
so try to figure this out ,

also you use analog write and digital write , they do diferent jobs ,
digital is high and low , equels to 0 and 5 volt ,
analog you can do 0 or 255 , equels , 0 to 5 volt , or high and low ,
depents also if its 8 bit or 10 bits , then it wil be 0 - 1024
but you can use analog write also in diferent values ,
diferent voltages , so diferent motor speeds ,
i cant see your robot , but i tryed to visualise , :astonished:
you can use serial input for doing a thing ,
and read the comments ,

#include <NewPing.h>

const byte ENA=5;//connected to arduino's port 5 (output pwm)
const byte IN1=2;//connected to arduino's port 2
const byte IN2=3;//connected to arduino's port 3
const byte ENB=6;//connected to arduino's port 5 (output pwm)
const byte IN3=4;//connected to arduino's port 4
const byte IN4=7;//connected to arduino's port 7

const byte TRIGGER_PIN =  13;  // Arduino pin tied to trigger pin on the ultrasonic sensor.
const byte ECHO_PIN    = 12;  // Arduino pin tied to echo pin on the ultrasonic sensor.
const int MAX_DISTANCE = 400; // 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 response = 2000; // here you set your centimeters ,, in digital values ,, not cm ,, look in serial print !
int cm ;
void setup ()
{
  pinMode(ENA,OUTPUT);//output
  pinMode(ENB,OUTPUT);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  digitalWrite(ENA,LOW);
  digitalWrite(ENB,LOW);//stop driving
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);//setting motorA's direction
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);//setting motorB's direction  what kind of directions ??
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}
void loop ()
{
int val = Serial.read() - '0'; // deduct ascii value of '0' to find numeric value of sent number
if (val ==1) analogWrite (ENA,255),analogWrite (ENB,255);
if (val ==2) analogWrite (ENA,0),analogWrite (ENB,0);
if (val ==3) digitalWrite (ENB,HIGH),digitalWrite (ENB,HIGH);
if (val ==4) digitalWrite(ENA,LOW),digitalWrite (ENB,LOW);
if (val ==5) analogWrite (ENA,125),analogWrite (ENB,125); // here i use another value ,, gives different voltage so your motor wil run on other speeds ,,if its analog motor 
if (val ==6) analogWrite (ENA,80),analogWrite (ENB,80);
// i ad some serial inputs ,, 1 2 3 4 ,, when you send this to arduino it wil do the task behind it ,,
// i changed the outputs to digital write , high and low to show you what you can change !

  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  int cm = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  Serial.print("SENSOR CM");
  Serial.print(cm / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  Serial.println(" cm");
  Serial.print("SENSOR DIGITAL VALUES");
  Serial.print(cm / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  Serial.println("THIS IS THE RESPONSE VALUES YOU USE FOR SETTING CONST RESPONSE ABOVE");
// here  it do a task if cm below and above then the setup value INT RESPOSNE ,, 
  if (cm > response){
  analogWrite (ENA,255);//start driving motorA  // are this your motors ??
  analogWrite (ENB,255);//start driving motorB   
  Serial.print("NOTHING SENSED BELLOW RESPONSE ");
  }
  else if (cm < response){
  Serial.print("SOMETHING SENSED BELLOW RESPONSE ");
  analogWrite (ENA,0);//stop driving motorA  // are this your motors ??
  analogWrite (ENB,0);//stop driving motorB
}
}

if you are a expert , then this was done in the same time i smoke a sigaret ,
so why the bad comments ,
this saved me one sigarete , he gave me 2 more hours to live , :grin:

Mr Dexterbot Thank you for the code, it’s now stop hitting on walls. but it’s not reverse or do any thing when wall met.now I’m working on trying to fix it.thank you for the help you gave me on past few days…

and about your bad habit, please at least use some anti nicotine drop on cigarette to minimize the nicotine effect to you to save your life a bit.better if you can avoid that habit.may be your life isn’t valuable to you :frowning: but newbies like us want people like you.so try to save more hours of your life. :slight_smile:

newbies , on this forum maybe ,lol

i also use the stuff you use in a quadcopter program but on a different way ,
about reversing the motors ,
you have to make a picture of your robot and conections ,
maybe when i have time i can edit some lines ,
:roll_eyes:

i think you have t look at a HIGH and LOW , this wil change directions ,
so normal when its high go forward , low backward ,
let me know !

I’ll give you good explanation what happen to this sensor in next comment :smiley: .but briefly, you can see that what happen to sensor :drooling_face: in red circle.I’ll post my progress ASAP I received my new sensor :slight_smile: .

fix it ,, put some solder on it ,, ! :grin:

Mr dexterbot as you said solder drop on sensor and when I try to wipe it with hot iron without using sucker :smiley: , the part was melt and the components there were plugged off :drooling_face: :drooling_face: :drooling_face: .
new sensor received today :slight_smile: and I have fix it to robot and try it with old code that work up to stop in front of obstacle.But I have no idea how to make this reverse when obstacle detected.please help me to solve this issue

you have to test the serial inputs commands i made ,
and try this give me respons ,
maybe i wil be able to help on skype if you realy get nuts :grin:

#include <NewPing.h>

const byte ENA=5;//connected to arduino's port 5 (output pwm)
const byte IN1=2;//connected to arduino's port 2
const byte IN2=3;//connected to arduino's port 3
const byte ENB=6;//connected to arduino's port 5 (output pwm)
const byte IN3=4;//connected to arduino's port 4
const byte IN4=7;//connected to arduino's port 7

const byte TRIGGER_PIN =  13;  // Arduino pin tied to trigger pin on the ultrasonic sensor.
const byte ECHO_PIN    = 12;  // Arduino pin tied to echo pin on the ultrasonic sensor.
const int MAX_DISTANCE = 400; // 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 response = 2000; // here you set your centimeters ,, in digital values ,, not cm ,, look in serial print !
int cm ;
void setup ()
{
  pinMode(ENA,OUTPUT);//output
  pinMode(ENB,OUTPUT);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  digitalWrite(ENA,LOW);
  digitalWrite(ENB,LOW);//stop driving
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);//setting motorA's direction
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);//setting motorB's direction  what kind of directions ??
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}
void loop ()
{
int val = Serial.read() - '0'; // deduct ascii value of '0' to find numeric value of sent number
if (val ==1) analogWrite (ENA,255),analogWrite (ENB,255);
if (val ==2) analogWrite (ENA,0),analogWrite (ENB,0);
if (val ==3) digitalWrite (ENB,HIGH),digitalWrite (ENB,HIGH);
if (val ==4) digitalWrite(ENA,LOW),digitalWrite (ENB,LOW);
if (val ==5) analogWrite (ENA,125),analogWrite (ENB,125); // here i use another value ,, gives different voltage so your motor wil run on other speeds ,,if its analog motor 
if (val ==6) analogWrite (ENA,80),analogWrite (ENB,80);
// i ad some serial inputs ,, 1 2 3 4 ,, when you send this to arduino it wil do the task behind it ,,
// i changed the outputs to digital write , high and low to show you what you can change !

  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  int cm = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  Serial.print("SENSOR CM");
  Serial.print(cm / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  Serial.println(" cm");
  Serial.print("SENSOR DIGITAL VALUES");
  Serial.print(cm / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  Serial.println("THIS IS THE RESPONSE VALUES YOU USE FOR SETTING CONST RESPONSE ABOVE");
// here  it do a task if cm below and above then the setup value INT RESPOSNE ,, 
  if (cm > response){
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);//setting motorA's direction
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);//setting motorB's direction  what kind of directions ??
  analogWrite (ENA,255);//start driving motorA  // are this your motors ??
  analogWrite (ENB,255);//start driving motorB   
  Serial.print("NOTHING SENSED BELLOW RESPONSE ");
  }
  else if (cm < response){
  Serial.print("SOMETHING SENSED BELLOW RESPONSE ");
  analogWrite (ENA,0);//stop driving motorA  // are this your motors ??
  analogWrite (ENB,0);//stop driving motorB
  digitalWrite(IN1,HIGH);
  digitalWrite(IN2,LOW);//setting motorA's direction
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,HIGH);//setting motorB's direction  what kind of directions ??
  analogWrite (ENA,255);//start driving motorA  // are this your motors ??
  analogWrite (ENB,155);//start driving motorB   
  delay (50);
  analogWrite (ENA,0);//stop driving motorA  // are this your motors ??
  analogWrite (ENB,0);//stop driving motorB
 }
}

did you stil have the old sensor ,, i can fix it ,,, for the price of a postcard

for a price of post card?..... yha! it's worth :D .but I have already burned it out :drooling_face: .not only the part that plugged off.other remain parts around that place were burn due to heat of iron.seems I have keep it too much time on sensor :~

you can use the piezo to build your own ! ,, :D

did you check the sketch i made ,, i seen the picture , i try to make it so when it detect it stops ,, turns ,, and go back ,, let me know if this works ,, other wise i wil make a sketch you can test the inputs true serial inputs ,,, i wil make a tool you can test the motors , wich way they turns and so ,, then i can write you some coole eperiment sketches to do some stuff :grin: i can make high tech robots ,, E,T wil modify the diddler ! ]:D

Moderator edit FOR LANGUAGE.

MIND YOUR LANGUAGE.

Wow Mr dexterbot it works great.but it’s stuck on narrow angles (~300).I have seen this kind of robots with servo motor mounted sensor. I think the need to do so is to avoid such sucks without using 2-3 sensors to cover the area.I’ll post a video ASAP I correct the issue…thank you for the long super help :slight_smile:

no this is not the problem , the problem is the software i made ,, i now start 2 understand the robot , i can change those things in totaly diferent commands ,, :grin: maybe if you have a usb cable i can make a tool like a remote ,, then i now for sure you can give me the right info i need ,, i wil start building it today , ok ! 8)

the hard thing to understand for you is this ! you are used when a motor get + and - it wil turn a certain way ,, but your config wil make use of switched + and - to reverse the motor drives ,,, this is the first thing hard to understand ,,but a good way to do so ! second is did the value change of analog voltage changed the rotation speed ? or do you need high and low ,, means 0 or 5 volt ,,, to run 1 kind of speed ,, i think the first one ,, you can change the speed , i wil make a simpel tool , you can connect to your usb robot and test some of those things ok ! there are 2 options ,, u control robot true pc , and pc has special functions reacting on things ,, or a stand alone robot ,, or both ,,,, but you need some kind of wireless tx rx i wil make some control tool ,, give me 2 days ,, :D

about that TX & RX,I have Turnigy 9X that using to my RC's .I'll try to combine arduino with my Tx & Rx

here try this i made ,
i wil explain later ok :sweat_smile:

https://www.mediafire.com/?pg8wduz9noqre6k
use sketch bellow , i forgot to take out the testing cm in the rar file

you need usb conected , you wil like it :smiley:
and you can do some stuff , XD

#include <NewPing.h>

const byte ENA=5;//connected to arduino's port 5 (output pwm)
const byte IN1=2;//connected to arduino's port 2
const byte IN2=3;//connected to arduino's port 3
const byte ENB=6;//connected to arduino's port 5 (output pwm)
const byte IN3=4;//connected to arduino's port 4
const byte IN4=7;//connected to arduino's port 7

const byte TRIGGER_PIN =  13;  // Arduino pin tied to trigger pin on the ultrasonic sensor.
const byte ECHO_PIN    = 12;  // Arduino pin tied to echo pin on the ultrasonic sensor.
const int MAX_DISTANCE = 500; // 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.

int response ; 
int cm ;  
int pls,memo,mem,rate,mode,sensor1,valm;
void setup ()
{
  pinMode(ENA,OUTPUT);//output
  pinMode(ENB,OUTPUT);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  digitalWrite(ENA,LOW);
  digitalWrite(ENB,LOW);//stop driving
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);//setting motorA's direction
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);//setting motorB's direction  what kind of directions ??
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
  analogWrite (ENA,0);//stop driving motorA  forward
  analogWrite (ENB,0);//stop driving motorB  forward 
  response = 2500;
  rate = 255 ; // high speed
  mem = 0;

}
void loop ()
{

  Serial.print((char)1); 
  Serial.print (cm);
  Serial.print((char)2);
  Serial.print (sensor1);
  Serial.print((char)3);
  Serial.print (mode);  // mode
  Serial.print((char)4);
  Serial.print (rate); 
  Serial.print((char)5);
  Serial.print (" CUSTOM ROBOT TOOL  ");
  Serial.print((char)6);
  Serial.print (response);
  Serial.print((char)7);
  int val = Serial.read() - '0'; // deduct ascii value of '0' to find numeric value of sent number
  delay (30);
  //cm = sonar.ping(); 
  if(cm >0)sensor1 = cm;
  sensor1 = cm/ US_ROUNDTRIP_CM; 
  rate =constrain(rate,0,255);
  response =constrain(response,0,10000);
  if(response > cm)mem =1;
  if(response < cm)mem =2;
  if(response < cm)mem =2;
  if (val == 22 ){
    memo = 10;
    mode = 55;
  }  
  if (val == 37 ){
    rate = rate + 1;
  }
  if (val == 20 ){
    rate = rate - 1;
  }
  if (val == 30 ){
    response = response + 1;
  }
  if (val == 18 ){
    response = response - 1;
  }
  if (val == 35 ){
    mode = 10; 
    analogWrite (ENA,0);//stop driving motorA  forward
    analogWrite (ENB,0);//stop driving motorB  forward 
  }
  if (val ==7 ){
    memo =1 ;
    mode = 101;
  }
  if (val ==1){ 
    mode = 1;
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,HIGH);
    digitalWrite(IN3,HIGH); // forward // 
    digitalWrite(IN4,LOW);
    analogWrite (ENA,rate);//start driving motorA  forward
    analogWrite (ENB,rate);//start driving motorB  forward 
    delay (100);
    analogWrite (ENA,0),analogWrite (ENB,0);
  }
  if (val ==2){ 
    mode = 2;
    digitalWrite(IN1,HIGH);
    digitalWrite(IN2,LOW);//setting motorA's direction
    digitalWrite(IN3,LOW);
    digitalWrite(IN4,HIGH);//setting motorB's direction  what kind of directions ??
    analogWrite (ENA,rate);//start driving motorA  // are this your motors ??
    analogWrite (ENB,rate);//start driving motorB   
    delay (100);
    analogWrite (ENA,0),analogWrite (ENB,0);
  }
  if (val ==3){
    mode = 3;
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,HIGH);
    digitalWrite(IN3,HIGH); // forward // 
    digitalWrite(IN4,LOW);
    analogWrite (ENA,0);//start driving motorA  forward
    analogWrite (ENB,rate);//start driving motorB  forward 
    delay (20);
    analogWrite (ENA,0),analogWrite (ENB,0);
  }
  if (val ==4){ 
    mode = 4;
    digitalWrite(IN1,HIGH);
    digitalWrite(IN2,LOW);//setting motorA's direction
    digitalWrite(IN3,LOW);
    digitalWrite(IN4,HIGH);
    analogWrite (ENA,0);//start driving motorA  forward
    analogWrite (ENB,rate);//start driving motorB  forward 
    delay (20);
    analogWrite (ENA,0),analogWrite (ENB,0);
  }
  if (val ==5){ 
    mode = 5;
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,HIGH);
    digitalWrite(IN3,HIGH); // forward // 
    digitalWrite(IN4,LOW);
    analogWrite (ENA,rate);//start driving motorA  forward
    analogWrite (ENB,0);//start driving motorB  forward 
    delay (20);
    analogWrite (ENA,0),analogWrite (ENB,0);
  } 
  if (val ==6){
    mode = 6;
    digitalWrite(IN1,HIGH);
    digitalWrite(IN2,LOW);//setting motorA's direction
    digitalWrite(IN3,LOW);
    digitalWrite(IN4,HIGH);
    analogWrite (ENA,rate);//start driving motorA  forward
    analogWrite (ENB,0);//start driving motorB  forward 
    delay (20);
    analogWrite (ENA,0),analogWrite (ENB,0);
  } 
  if (mem == 1 && memo ==1){
    mode = 777;
    // memo = 1234;
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,HIGH);//setting motorA's direction
    digitalWrite(IN3,HIGH);
    digitalWrite(IN4,LOW);//setting motorB's direction  what kind of directions ??
    analogWrite (ENA,rate);//start driving motorA  // are this your motors ??
    analogWrite (ENB,rate);//start driving motorB 
    return ;//
  }
  if (mem == 2 && memo ==1){
    mode = 666;  //detect 
    // memo = 5434;
    analogWrite (ENA,0);//stop driving motorA  // are this your motors ??
    analogWrite (ENB,0);//stop driving motorB
    digitalWrite(IN1,HIGH);
    digitalWrite(IN2,LOW);//setting motorA's direction
    digitalWrite(IN3,LOW);
    digitalWrite(IN4,HIGH);//setting motorB's direction  what kind of directions ??
    analogWrite (ENA,rate);//start driving motorA  // are this your motors ??
    analogWrite (ENB,rate);//start driving motorB   
    // delay (300);
    analogWrite (ENA,0);//stop driving motorA  // are this your motors ??
    analogWrite (ENB,0);//stop driving motorB
    return;//
  }
  if (val == 9 ){
    mode = 9;  
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,HIGH);//setting motorA's direction
    digitalWrite(IN3,HIGH);
    digitalWrite(IN4,LOW);//setting motorB's direction  what kind of directions ??
    analogWrite (ENA,0);//start driving motorA  // are this your motors ??
    analogWrite (ENB,rate);//start driving motorB 
    delay (100);
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,HIGH);//setting motorA's direction
    digitalWrite(IN3,HIGH);
    digitalWrite(IN4,LOW);//setting motorB's direction  what kind of directions ??
    analogWrite (ENA,rate);//start driving motorA  // are this your motors ??
    analogWrite (ENB,0);//start driving motorB 
    delay (100);
  }
}

you can change motor speed , range for finder , manual and automatic ,
i wil make it different if you know how ut works , make a movie :smiley:
i forgot some things , butt i am bit tired , wil make it better when i have spare time :drooling_face:

custum.JPG

i updated the version , i was so sleepy i forgot some things , so download the latests one , sketch is included .,

give me some feedback so i can adjust stuf !!!

:grin:

robotv2.rar + sketch

Mr Dexterbot,Sorry for the muteness of my side :drooling_face:I’m working on passing my semester exams these days :grin: .I’ll back ASAP my work is done :smiley: