Help with my project

So I'm tryna make a school project,that uses a servo and an ultrasonic sensor to make a sonar,with a toy gun attached,so when the sonar detects a thing, it'll send the coordinates to the toy gun servo,and move the servo to the coordinates and fire the gun.So the problem is how do I mount the gun to the servo and how do I reload it and fire it automatically?

Read, search, study like we all did. When you have a wiring diagram, code and it partially works someone may give you a pointer

Yea I know the code and everything,but I don't have a 3d printer to print a mount and a rod that automatically shoots a gun

If the 3d printer is the issue, you could CAD model the files and send it to a company to print it and ship the part to you.

Will that be expensive?

depends on the size of the parts, materials and the company but I don't think too expensive, maybe around 20 or 25 usd? Im not too sure since i've never used a company. But if your school has a 3d printer or a friend maybe ask them first, as it would be a lot easier.

And how do you think this problem can be solved on an internet forum? :slight_smile:

Well, you've described a few different aspects to this project and it's your task to break the vision down into small steps that you can build and test individually, before assembling the final product.

  • Sub-project #1: get an servo working with Arduino. Remember to power the servo SEPARATELY from the Arduino and make sure the grounds are connected. Try any example sketch from the Servo library.

  • Sub-project #2: Get distance values printed to the Serial monitor using an ultrasonic sensor. There are example sketches in Tim Eckel's New Ping Library here (but just search up "NewPing" in the Arduino IDE Tools > Manage Libraries and let the IDE install the library for you)
    https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home

  • Sub-project #3: Spend some time working out the mechanics of the project. That's up to you since there are lots of ways to attach things to things. Servos have mounts for screws, that's the best way to rigidly attach them to things. Strong Velcro is an ok option, hot glue is another but mechanically fastening them to things as designed is the best.

What gun? How does it reload normally?

So when the sensor detects a thing, it's detecting the distance away from the sensor up to about 4-5 meters. That's not exactly "coordinates"; that's just telling you if something is in range of the sensor. Either fire or don't fire.

Do you mean like an automated turret that rotates the whole gun to aim at whatever it detects?

If so, you have two options:

  • an array of sensors forming a semi-circle across the range of the servo. When one detects something (say the extreme left hand sensor) the Arduino tells the servo to rotate in that direction.
  • the whole mechanism rotates on a constantly sweeping servo and if the one single sensor "sees" something in range, the servo stops rotating and the gun is fired.

What is the device you're going to use to fire the gun?

Refer post #2

1 Like

screws, elastic, hotglue, double-sized tape, wire... describe "gun"

Really?

Cool project! You can mount the toy gun using a bracket, like how paintball markers are fixed for automated turrets. For firing, use a relay or small motor, similar to electronic triggers in paintball guns. Reloading may need a spring or motor setup. Good luck!