Are you bored? You can also build a laser tower. You know — the one that goes on bench shoots a red beam in many different directions and maybe even throws a smoke machine? Yes, one of them.

What will you need

  • Arduino
  • 2 servos
  • Laser module, such as one of this set of sensors
  • Piezo buzzer or other small output device
  • Metal wire and cable ties for fastening
  • Long female->male connection cables as well as normal connection cables

Optionally, a smoke plant is required — the laser has a low enough power, so you will not be able to see the beam without smoke, even in a dark room.


Construction plan

The main idea behind the turret is to place a laser module on top of a single servo to allow for horizontal rotation; then install this package on another 90 degree servo to allow for vertical movement. We have a piezo to provide sound effects and I’m throwing in a smoke machine for good measure.

Servo Testing

Depending on your servo, the wires may be colored differently, but in general:

  • Red is the positive wire and on both of my servos it was the center of the three — to connect to the +5V rail.
  • Brown or black is the negative that should be connected to GND on the Arduino.
  • White or orange is the signal wire to be connected to the PWM digital I/O pin (9 and 10 in the demo below).

After you connect two servos, download the following code example. I named one servo Hori to control the horizontal movement and the other Vert. Everyone should complete a full range of motion (about 60 degrees in my case).

#include  Servo vert,hori; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position void setup() { hori.attach(9); vert.attach(10); // attaches the servo on pin 9,10 to the servo objects vert.write(0); hori.write(0); } void loop() { for(pos = 0; pos < 180; pos += 10) // goes from 0 degrees to 180 degrees { // in steps of 10 degrees vert.write(pos); hori.write(pos); // tell servo to go to position in variable 'pos' delay(100); // waits 100ms for the servo to reach the position } for(pos = 180; pos>=1; pos-=10) // goes back from 180 degrees to 0 degrees { vert.write(pos); // tell servo to go to position in variable 'pos' hori.write(pos); delay(100); // waits 100ms for the servo to reach the position } } 

Everything is fine? Move on.

Laser and sound testing Pew Pew

A laser module is similar to an LED, but it has a built in resistor so we can connect it directly to a digital I/O — very easy. If you are using the same laser module as mine, » » goes to GND , S- to output 12. Modify the code example above so that output 12 outputs:

 int laser = 12; pinMode(laser,OUTPUT); 

Then blink a contact on each loop using the standard digitalWrite() method .

We’re just using PWM to drive the piezo buzzer at a comfortable audio level — you can experiment with the tone library if you like, but I want some simple noise. Connect the black wire to ground and the red wire to pin 11. Determine buzzer on the corresponding pin, set the output mode and activate using analogWrite(buzzer, 100) (or any other the number you want up to 254); and analogWrite(buzzer, 0), to turn off.

A complete code example modified to scan two servos, turn on the laser, and play an annoying sound can be found here.

All your components should work — now we need to tie it all together.

Creation of the tower

Using cable ties, attach one servo to the other; it doesn’t matter, just make sure one moves horizontally and the other moves vertically. You can remove the rotor blade and reinstall it during testing if the angle is not correct.


Use a hard modeling wire to attach the laser module to the blade of another servo, like so:

wires for the laser module

Finally, I attached the whole thing to the table leg with more cable ties and some wood.


Tower Programming

I don’t know about you, but my laser tower idea is based on countless sci-fi movies and Star Trek episodes. Invariably someone will fly past the tower, and small shots, made in the dock, will fly at a rapid pace, always milliseconds too slow, so our protagonist will not actually hit the target. This is what I’m trying to replicate, although feel free to tweak the main mode to suit your idea of ​​what a turret should do.

Here is the pseudo code I used for the main loop:

I also added a separate method fire(), to structure the code a little better. Adjust the ranges of all functions random() to speed up or slow down each parameter; or up the shots for a more energetic dance club. Scroll down for the video code in action!

 #include  Servo vert,hori; // create servo object to control a servo int pos = 0; // variable to store the servo position int laser = 12; int buzzer = 11; void setup() { hori.attach(9); vert.attach(10); // attaches the servo on pin 9 to the servo object pinMode(laser,OUTPUT); pinMode(buzzer,OUTPUT); } void loop() { int timeBetweenBursts = random(200,1000); int timeBetweenShots = random(50,200); int vertStart = random(1,180); int vertEnd = random(1,180); int horiStart = random(1,180); int horiEnd = random(1,180); int numShots = random(5,20); int vertChange = (vertEnd - vertStart) / numShots; //how much to move vertical axis by each shot int horiChange = (horiEnd - horiStart) / numShots; vert.write(vertStart);//let it get to start position first, wait a little hori.write(horiStart); delay(100); for(int shot = 0; shot 

In battle

I don't think there's a practical use for this little toy, but it's a lot of fun and there are plenty of variables to tweak to get the effect you want. Perhaps this will come in handy for a LEGO home movie?

Похожие записи