Arduino Tutorial #10 Ultrasonic sensor as a counter with Arduino

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024
  • Arduino Tutorial #10 Ultrasonic sensor as a counter with arduino
    Scroll down for code.....
    Please like & Subscribe for more videos
    If you want to support my video please buy any product through my amazon affiliate link. I will receive a commission, at no extra cost to you.
    LIST OF COMPONENT (affiliate links)
    amzn.to/2fvSRJq (Arduino)
    amzn.to/2vmUlLw (Ultrasonic sensor)
    amzn.to/2wxPmWz (Breadboard)
    amzn.to/2vJ3lvo (Jumper wire)
    #define trigPin 13
    #define echoPin 12
    int counter = 0;
    int currentState = 0;
    int previousState = 0;
    void setup() {
    Serial.begin (9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    }
    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;
    //instead of parenthesis () put angle bracket as TH-cam description does not allow angle bracket
    if (distance (= 10){
    currentState = 1;
    }
    else {
    currentState = 0;
    }
    delay(100);
    if(currentState != previousState){
    if(currentState == 1){
    counter = counter + 1;
    Serial.println(counter);
    }
    }
    }

ความคิดเห็น • 31

  • @dhmy82
    @dhmy82 ปีที่แล้ว +1

    Do we need battery in this project?

  • @santiagoabregu691
    @santiagoabregu691 11 หลายเดือนก่อน

    good job hermano!!!! bendiciones a la familia- Bless You

  • @gflaig9131
    @gflaig9131 4 ปีที่แล้ว

    I like the Off the ranch music at the beginning 🤣

  • @EthanChang-m3t
    @EthanChang-m3t ปีที่แล้ว

    Thank you for sharing this knowing! I was wondering how I can increase the distance to 10ft?

  • @cristianosoares2574
    @cristianosoares2574 5 ปีที่แล้ว +6

    if the object stays in front of the sensor it will continue counting, can you give me a lead to resolve this issue?

    • @ansithreddy
      @ansithreddy 4 ปีที่แล้ว +3

      even i have the same problem

    • @anujsaini9353
      @anujsaini9353 4 ปีที่แล้ว

      @@ansithreddy IR & uLTRASONICS SESNSOR can't help for the desire result. For that 3D depth camera can help.

    • @anujsaini9353
      @anujsaini9353 4 ปีที่แล้ว

      I'm also working with the same kind of project. Hope soon I will resolve it.

    • @SaleemMukhtiar32
      @SaleemMukhtiar32 2 ปีที่แล้ว

      @@anujsaini9353 have you resolved

  • @saglamserkann
    @saglamserkann 5 ปีที่แล้ว

    Thank you bro!

  • @malayparvadiya6043
    @malayparvadiya6043 ปีที่แล้ว

    How to restart counter after 100..??

  • @regiamonche4678
    @regiamonche4678 6 ปีที่แล้ว +1

    👍🏻👍🏻👍🏻👍🏻 working

  • @rabiibrahimi
    @rabiibrahimi 6 ปีที่แล้ว

    Hi Serdar
    thanks for sharing this amazing tutorial, iwas wondering if you know how we can use this sensor to count visitors in and out. is it possible to use just this sensor to count visitors who enters a room and who leaves the room?
    many thanks

    • @RoboticaDIY
      @RoboticaDIY  6 ปีที่แล้ว

      Rabii Brahimi only using single sensor it is not possible, because we cant detect it is entering or leaving. but by using two sensor it is possible to detect visitors who enters or leaves the room. you can watch this video i have already made for visitor counter th-cam.com/video/TI6mx3jtoY0/w-d-xo.html

    • @rabiibrahimi
      @rabiibrahimi 6 ปีที่แล้ว

      Hi Many thanks the other tutorial is fantastic although i am confused how to use the code because i will not be using any LCD i just want to check if an object pass by 1st and 2nd sensors it should count 1 otherwise it should count -1 if the other way around. the reason why i asked you previousely if this could be done with one sensor because of this video th-cam.com/video/FmI34Y2t1pM/w-d-xo.html the guy is using only on sensor but he didn't share anything about the code and didn't even care to reply to people comments :(
      I really appreciate your help and how you share knowledge with others :)

    • @RoboticaDIY
      @RoboticaDIY  6 ปีที่แล้ว

      Hi, i got it what he is doing. I think he is making difference between visitor entering and leaving by distance. I will post same video soon with code.
      and you can change lcd.begin() to Serial.begin(9600), and also change lcd.print to Serial.println(variable). so that you can see counting on your serial monitor.

    • @rabiibrahimi
      @rabiibrahimi 6 ปีที่แล้ว

      Many thanks
      looking forward to seeing the next video with one sensor :)

    • @RoboticaDIY
      @RoboticaDIY  6 ปีที่แล้ว +1

      th-cam.com/video/AZrYysD6QsI/w-d-xo.html

  • @uptownnj
    @uptownnj 6 ปีที่แล้ว

    THANKS FOR THE VIDEO YOU THE BEST

    • @uptownnj
      @uptownnj 6 ปีที่แล้ว

      CODE IS NOT WORKING HELP PLEASE

    • @RoboticaDIY
      @RoboticaDIY  6 ปีที่แล้ว +1

      @ Serdar Kocan sometimes copy & paste causes error. please try to write this code by watching it on my website.

    • @uptownnj
      @uptownnj 6 ปีที่แล้ว

      thanks for quick reply I just fixed it Now i have another quesion if you help that will be a lot to me How to change the frequency Because if i hold the object more than 1 second It counts more than 5-6 times I want the sensor count 1 not more than 1 THANKS

    • @RoboticaDIY
      @RoboticaDIY  6 ปีที่แล้ว +1

      @ Serdar Kocan increase delay time. if you want to hold up to 1 second then increase delay time from "delay(100)" to "delay(1000)". do some trial and error to find best suitable delay time for your project.

  • @luchienling
    @luchienling 5 ปีที่แล้ว

    Thank boss^^

  • @anujsaini9353
    @anujsaini9353 4 ปีที่แล้ว

    it's a poor coding.

  • @kishorekumars2058
    @kishorekumars2058 5 ปีที่แล้ว

    I done this but circuit is not working

    • @RoboticaDIY
      @RoboticaDIY  5 ปีที่แล้ว

      @Kishore S, first of all check you ultrasonic is connected properly or not and also check jumper wire is not faulty. it should work.

    • @kishorekumars2058
      @kishorekumars2058 5 ปีที่แล้ว

      @@RoboticaDIY yeah! It's working thank you

    • @okosasztal
      @okosasztal 4 ปีที่แล้ว

      @@RoboticaDIY Hello! May i have your email address please? Thank you!

  • @kishorekumars2058
    @kishorekumars2058 5 ปีที่แล้ว

    Can you explain clearly