New Homepage Forums Sensor Shields Proximity Sensor push-up counter does not stop counting

This topic contains 7 replies, has 2 voices, and was last updated by avatar Bramscho 2 years, 1 month ago. This post has been viewed 494 times

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #60923
    avatarBramscho
    Participant

    Hello,
    I have been struggling with this for months. I am trying to write a program that when a pushup is counted by the proximity counter it adds one to the total pushups value. When at 5 pushups, it will serial print a message that it is done. Whenever the 1sheeld counts one pushup meaning the proximity sensor was triggered, it does not stop counting. Any suggestions? Like I said I have been working on this for a very long time with no progress and any help is appreciated.
    Thanks

    #60956
    avatarAhmed ismail
    Keymaster

    Hey, I believe that you should contact us sooner than that we may have saved lots of your time 🙂

    Alright, your code actually has three problems:

    1- 1Sheeld is using the same UART port the Arduino using to communicate with your PC and that’s why we have two modes for the UART port, one of them while you are uploading the code (the Arduino is communicating with the PC) and the other mode is while running the project (the Arduino is communicating with the 1Sheeld)
    So, you can’t use the serial communication in your code cause it will open a channel of communication with the PC while you are using it with 1Sheeld, you didn’t notice the problem a lot this time cause you were using the same Baud rate 1Sheeld is using and you were reading from 1Sheeld and writing on the PC so the communication conflict wasn’t noticeable but that doesn’t mean that it doesn’t exist 🙂 So I have deleted all the serial related lines from the code and I replaced them with our terminal shield which can do all the serial monitor of the IDE can do but on your smartphone.

    2- You are using a relay board on pin no.1 which is the receiving pin in the UART port which is being used from 1Sheeld with pin no. 0 so I placed it on pin no. 4 instead (pins 0 &1 are reserved for 1Sheeld’s communication).

    3- The last problem which is the core problem you were asking for is the logic of the if condition you were using.
    the Arduino board processing power is so fast that it can record maybe 50 pushups while you have made only one 🙂 and the delay you were using were out of the condition so it won’t make any difference and there’s a better solution for that which is using a flag just to make sure that you have made only one push up so I have made it flase everytime you were not close to the sensor and true when you are close and it will only count when you made a real push up 🙂

    So please try out the code below and let me know how it worked:

    #60994
    avatarBramscho
    Participant

    Hello,
    I tried using your code but when I tried all it would do when I put my hand of the proximity sensor for the first time is it would count: 1, 2, 3, 4, 5 and then “Pushups Done”. I tried various versions using your code as a base and it still does not work. Any other ideas?
    Thanks a bunch,
    Bram

    #61089
    avatarAhmed ismail
    Keymaster

    Hey, yeah I believe it’s the status of the proximity sensor, could you please update the if condition to be: if (ProximitySensor.getValue() == 0 && flag == false ) in the code I sent to you and try again and let me know if it worked or not 🙂

    #61274
    avatarBramscho
    Participant

    I tried that and now it runs on its own – I do not even have to trigger the proximity sensor it counts 1-5 then says pushups done, waits a little, then does it again.

    #61329
    avatarAhmed ismail
    Keymaster

    Hey, I have tried it again and I believe that this is the optimum code so please try it and tell me how it worked for you 🙂

    #61640
    avatarBramscho
    Participant

    I do not know if there is a problem with my OneSheeld or what but it is still just counting from 1-5 displaying that message, waiting a few seconds, and then doing it again using the exact code you just sent. I don’t know what the problem is but it is very frustrating and I appreciate your continual support.
    Thanks
    Bram

    #61642
    avatarBramscho
    Participant

    I guess I spoke just too soon, I am not sure exactly what I did but now it is working. When the Arduino starts up even without activating the sensor 1 pushup is recorded, then you have to wait about 7 seconds because the sensor does not record anything, and then it will start counting 1-5 1 per pushup and then displaying the message when done. So it is working now with a few odd tweaks to still smooth out.
    thanks,
    Bram

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.