I am working on a school project for next week And I need my Arduino to 'sense' at which direction it is moved is it possible? Are there any direction sensors that 'sense' at which direction the Arduino is moving?
-
Direction relative to itself or the absolute direction (like north or south)?– chrislSep 16, 2018 at 9:20
-
@chrisl no I want the Arduino to sense that it goes up, down, right or left sry that I didn't included in the question 😓– user49556Sep 16, 2018 at 9:54
-
playground.arduino.cc/Main/MPU-6050– Juraj ♦Sep 16, 2018 at 10:26
-
@Juraj na not much help😐– user49556Sep 16, 2018 at 11:48
-
1it is, how it is done. study– Juraj ♦Sep 16, 2018 at 11:51
1 Answer
As Juraj wrote, you need an MPU, which is a module, that consists of an 3-dimensional accelerometer and a 3-dimensional gyroscope. With the first you can sense acceleration in each of the 3 dimensions (up-down, left-right, forwards-backwards), with the seconds you can sense rotation around these three directions. Sometimes (depending on the module) there is also an magnetometer included, which can be used as a compass.
Note, that you cannot sense the actual speed of a device directly, without using some external reference. With an accelerometer you have to do some maths on the data to get the speed (basically integrating). But since you just want to sense the direction, without bothering about the exact speed, you don't have to think about this.
How exactly you have to program this is out of scope for this side, since it is a rather big topic. Also it depends on the module and library you use. The link, that was provided by Juraj, is a good starting point for reading about this. There are also some further links, for example to a library for controlling the MPU-6050 (if you have one of these) at this github site.
Basically you will have to regularly measure the acceleration in all three dimensions with the MPU. If for an axis the acceleration gets greater than a threshold value, you can count this as direction. To get a more precise direction (not only directly along the axis) you will have to combine the values of the dimensions as a vector. How this is to be solved depends greatly on what you want to achieve.