Titl sensor with buzzer and led output

Good afternoon guys. I am new with Xod and I have to solve a project. I want to connect a tilt sensor that after 10 changement of status will give a signal to a buzzer, and after 5 movements will give another signal to a led. How could I project this on Xod? Thsnk you so much.

I assume the tilt sensor provides an analog signal that can be read via analog-read node. That can feed into a pulse-on-change node that feeds a count node. Compare the current count using greater node to provide an indication when the buzzer and/or led should turn on.

You can use the simulator to test your logic if you use a tweak-number node as your tilt-sensor and watch nodes as your buzzer and led.

There is a problem with this simple solution, though. Any analog input is likely to fluctuate slightly all the time, so pulse-on-change will probably pulse a lot more than you want it to. One possible solution for that is to feed the analog-read to format-number to round the sensor output to the specified number of digits (probably between 1 & 3; most likely 1 or 2) and ignore smaller fluctuations, then have format-number feed the pulse-on-change node. This won’t help if the small fluctuation happens to be between 0.1999999 and 0.20000 or similar, but it provides a quick 1st attempt before moving on to a better solution. The debounce node might also be of help to ignore small fluctuations, but I think it is also only a partial solution (and it would probably be better to just check tilt sensor less frequently).

A full solution might require comparing current value to previous value and only counting change if difference is big enough (but that is quite a bit more complicated). For that, you would need a buffer node to remember the previous value, pulses to update the previous value, and code to compare current and previous. All a good addition, but probably not something you should be attempting on the 1st try before you have the basics working. You would need to experiment with your particular tilt sensor to know how much of a change is important for your application.

Thank you very much. I bought the sensor and I will play with it from wednesday. I need to put it on a dumbell for a project, so every 10 repetitions it will make a sound. I hope the tilt sensor it’s a good sensor for this project.

Interesting. The tilt sensor won’t know it is moving up & down if it is on the dumbbell (assuming you do not twist the bar as you go up & down). I guess you could strap the sensor to your upper arm (or put it on a stick with a fixed pivot and resting on the dumbbell so its angle changes as dumbbell goes up & down). Either way, you can determine fixed values for the tilt sensor in up & down positions and only trigger when you reach that value instead of worrying about previous values, etc.

If you want to trigger buzzer every 10 reps, you will probably want to use modulo function to determine every 10th (beep if count >0 AND (count modulo 10)=0). A delay node can be used to control length of beep from buzzer.

Thank you Gweimer. Tomorrow I will have the sensor. So I can show you the xod codes to see if something is missing.
As I am really new with Arduino I need to improve myself.

How can I make an output after 10 movements of the tilt sensor?

First step will be to determine what value returned by your tilt sensor indicates a “movement”. For example, any value above 0.8 might indicate that you have lifted the bar up (or maybe any value below 0.4). You need to experiment with your sensor to decide what value to use.

Let’s assume you decide to trigger on >0.8. you would link the analog-sensor-VAL pin to the left input pin of a greater node and set the right pin to 0.8. the output of that would link to a pulse-on-true node, which would link to a count node. You now have a count of how many reps you have done. There should be a modulus node. Count modulus 10 will be zero for any number divisible by 10 (i.e. every 10th rep).


Analog sensor has value 0, greater than 0.9

But the buzzer it works only at the beginning. Did I make it something wrong ?

buzzer-pulse-T pin is time to run buzzer. You probably want a static value for that, not output of modulo. If you only want buzzer ever 10 reps, you only want to pulse buzzer-pulse-TRIG pin when modulo output is zero. This means you need to use equal node to compare modulo output to zero, and trigger buzzer when it is true.

Coding per the previous paragraph will also buzz when count is zero (i.e. when you turn it on or reset the system). If that bothers you, you can add more nodes to only pulse buzzer when modulo is zero AND count > 0, but get it working without extra features like this before making it more complicated. I only mention this so you do not panic when it buzzes right away…it is a “feature”

1 Like

at the end we did this trying to create a loop and every 30 movements there will be a buzzer. The only thing is that the sensor is very sensible so it counts everytime the sensor ball touches his metal envelop.