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.