Wednesday, October 26, 2016

Building a laser-guided clock


A lot of thought went into what project I'll write my first blog post about. Here it is, the obvious choice - the laser-guided clock.

To be honest, it's not actually laser guided, that's just something to make it sound cooler. What it really is, is a stepper motor controller pan/tilt mount that houses a cheap 405nm laser, which draws on a glow-in-the-dark sticker.

You probably already saw the video. If not, scroll up and play it.
The clock has had some improvements since the video was made, but the basics are the same.

Parts

Two 28BYJ-48 Stepper motors with ULN2003 drivers


I got one set with my Arduino kit, and ordered the second one off eBay. They come cheap, but have their limitations. For a project like this, they would be perfect, if it wasn't for one small issue: the shaft has a bit of slack in it. The slack is about 5 degrees, which may seem small, but since we are dealing with a projection which is about a foot away from the laser, it's very noticable. The slack on the tilt motor won't affect the projection at all, because the weight of the laser keeps it at one end, but to fix the issue on the pan motor, I added a spring from a pen, that keeps the shaft's slack from manifesting.



You can also clearly see pan/tilt mount. I designed those pieces in SolidWorks and had them 3D printed by a local company. They fit really well and are held together nicely by M4 nuts and bolts.

The laser



A simple laser pointer I got from eBay. Boasts a whopping 5mW of power and a 405nm wavelength. It's normally powered by two AAA batteries, but I'm using the microcontrollers 3.3V output and driving it via a transistor. The transistor has its base connected to a PWM enabled GPIO pin through a resistor.



NODEmcu v2:


This is the brains. It's a really good microcontroller. Not only because it's cheap and it has WiFi, but it's also compatible with the Arduino IDE. This means that it can run the same programs in the same language, plus WiFi. Did I already mention that it has WiFi?

The code:


The code includes a webserver that you can host from your personal computer or even your personal server. If you have one. The server also requires maven to be installed.

The older model that you can see in the video was using an Arduino Nano as the MCU and was taking it's clock data from a RTC, but the one I had seemed unreliable. Also the process of configuring it via the serial port was cumbersome. When you add my idea of building a smart home with a server as a central hub, you get the approach I'm using now with the web-server acting as a front-end for config and also as a way of getting the time.

The way it draws the numbers is hard-coded. What I mean by that, is I split each digit into parts of lines and arcs, which I devised a mathematical formula for that tell the laser a point in space it has to be at. This is then trigonometrically interpreted into angular data the motors can use.