Arduino code:

#define trigPin 13

#define echoPin 12

#define motor 7

#define buzzer 6

void setup()
{
pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(motor, OUTPUT);

pinMode(buzzer,OUTPUT);

}

void loop()

{

long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

if (distance < 70)     // This is where checking the distance you can change the value

{

digitalWrite(motor,HIGH);    // When the the distance below 100cm

digitalWrite(buzzer,HIGH);

} else

{

digitalWrite(motor,LOW);     // when greater than 100cm

digitalWrite(buzzer,LOW);

} delay(500);

}

Post a Comment

16 Comments

  1. Sir please give Arduino code away 4 mtr

    ReplyDelete
  2. what is the motor variable in this project stand for? Please help!!

    ReplyDelete
  3. Sir I am not able to understand pls anyone explain me it's urgent it's my project
    Pls provide eme your WhatsApp number and guide me pls I want help

    ReplyDelete
  4. Sir in which app we have to do this and how

    ReplyDelete
  5. Sir I can't understand that please explain me 🥺🥺

    ReplyDelete
  6. Sir I want to make just opposite of this project can you make for me please 🙏

    ReplyDelete
  7. Sir I am getting error like this

    Arduino: 1.8.17 Hourly Build 2021/09/06 02:33 (Windows 10), Board: "Arduino Uno"











    sketch_sep19a:63:19: error: stray '\302' in program
    if (distance < 70)     // This is where checking the distance you can change the value
    ^
    sketch_sep19a:63:20: error: stray '\240' in program
    if (distance < 70)     // This is where checking the distance you can change the value
    ^
    sketch_sep19a:63:22: error: stray '\302' in program
    if (distance < 70)     // This is where checking the distance you can change the value
    ^
    sketch_sep19a:63:23: error: stray '\240' in program
    if (distance < 70)     // This is where checking the distance you can change the value
    ^
    sketch_sep19a:63:25: error: stray '\302' in program
    if (distance < 70)     // This is where checking the distance you can change the value
    ^
    sketch_sep19a:63:26: error: stray '\240' in program
    if (distance < 70)     // This is where checking the distance you can change the value
    ^
    sketch_sep19a:69:26: error: stray '\302' in program
    digitalWrite(motor,HIGH);    // When the the distance below 100cm
    ^
    sketch_sep19a:69:27: error: stray '\240' in program
    digitalWrite(motor,HIGH);    // When the the distance below 100cm
    ^
    sketch_sep19a:69:29: error: stray '\302' in program
    digitalWrite(motor,HIGH);    // When the the distance below 100cm
    ^
    sketch_sep19a:69:30: error: stray '\240' in program
    digitalWrite(motor,HIGH);    // When the the distance below 100cm
    ^
    sketch_sep19a:81:25: error: stray '\302' in program
    digitalWrite(motor,LOW);     // when greater than 100cm
    ^
    sketch_sep19a:81:26: error: stray '\240' in program
    digitalWrite(motor,LOW);     // when greater than 100cm
    ^
    sketch_sep19a:81:28: error: stray '\302' in program
    digitalWrite(motor,LOW);     // when greater than 100cm
    ^
    sketch_sep19a:81:29: error: stray '\240' in program
    digitalWrite(motor,LOW);     // when greater than 100cm
    ^
    sketch_sep19a:81:31: error: stray '\302' in program
    digitalWrite(motor,LOW);     // when greater than 100cm
    ^
    sketch_sep19a:81:32: error: stray '\240' in program
    digitalWrite(motor,LOW);     // when greater than 100cm
    ^
    C:\Users\DELL\AppData\Local\Temp\arduino_modified_sketch_25701\sketch_sep19a.ino: In function 'void setup()':
    sketch_sep19a:16:1: error: a function-definition is not allowed here before '{' token
    {
    ^
    sketch_sep19a:36:1: error: a function-definition is not allowed here before '{' token
    {
    ^
    sketch_sep19a:92:13: error: a function-definition is not allowed here before '{' token
    void loop() {
    ^
    sketch_sep19a:95:1: error: expected '}' at end of input
    }
    ^
    exit status 1
    stray '\302' in program


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

    Pls say why

    ReplyDelete
  8. Sir its is working ,i have done my programming and there is no any mistake

    ReplyDelete