Array of ultra sonic sensors to turn a monitor into a touch screen display

I have an array of 6 ultra sonic sensors connected to my Arduino MEGA2560. These sensors are located at the bottom of a monitor. I am getting correct distances, and this part is working fine. I am seeking help to turn these distances into mouse movements (to turn an ordinary monitor into a touch screen display). I am new to coding, and I could use some help.

Maybe I could use a bunch of “If statements”? If so, could you provide me with an example?

Here is the working code I have. Please let me know how I should move on with this project.


Array_Of_6_Ultrasoic_Sensors.ino (3.69 KB)

Given a description of how the sensors are arranged, and their accurately measured positions on an (X,Y) coordinate system, it might be possible to work out the position of a reflecting object.

Maybe I could use a bunch of "If statements"?

No, you would use math (basic geometry) instead. Look up "trilateration".

These sensors are located at the bottom of a monitor.

It would be much better if three were along the bottom, and three along one vertical side (or, even bettter 6 in each direction).

A Mega can not act as a HID (keyboard or mouse). You need a board with native USB support

*) Arduino Leonardo, Micro, Due or Zero *) Sparkfun Pro Micro *) Pololu A-star based on 32U4 *) A teensy.

And there are probably a few more.

Alternative is to write a PC application that can take serial input (from the Mega) and translate it to mouse movements.

Besides figuring out x,y from sonic ranger, you need to detect "mouse click". Maybe attach an accelerometer that can detect knocks or taps so when you tap the screen, the accelerometer can tell arduino there was a tap.

Thanks for the quick response!

Would I be able to attach a Sparkfun Pro Micro (or any other board that can act as an HID) to my MEGA2560? How would I do so?

Or alternatively, would it be best to do something else.

I appreciate your help. :slight_smile:

How many pins do you need? That will determine which solution to look at.

But yes, You can connect one of the serial ports of the Mega to the RX1 and TX1 of the pro micro. Contrary to 328P based boards (e.g. Uno), they are separate from the USB and will not interfere.

Be aware that some boards that I mentioned are 3.3V.

Alright, I have connected 8 Ultrasonic sensors to the Mega (4 on the bottom, and 4 on the side of the moniter). So if I were to connect the Pro Micro ATmega32U4 5V 16MHz to my MEGA 2560, I would be able to use the distances to create an "x" and "y" coordinate system. (using trilateration) Then connect an accelerometer to alert the Arduino when there is a tap.

Would all this be feasible? I have a lack of understanding in this subject, so all your help is much appreciated.

Would all this be feasible?