Introduction: Automatic Digital Microscope

Tuberculosis is a worldwide endemic disease with a high mortality rate, approximately 5 million people die each year. Despite being a disease completely curable, WHO data reveal that it is still being the third cause of mortality in the world. In the last decades, modern diagnostic methods have been developed, which diagnose the disease with a high sensitivity rate and in a few hours. However, developing countries cannot implement these new methods due to economic reasons, missing specialists and hard implementation in remote areas. For this reason, we are focusing on developing a set of embedded devices that modify and strengthen common laboratory instrumentation coupling mechanisms, circuits, microprocessors, SoCs and software with the finality of the automation of TB diagnostic.

In this set of instructions we are going to teach you how to build the automatic digital microscope. Remember that the automation devices that we have designed are customized to work with an Olympus CH2O optical microscope.

This composes the main device developed in our project "Automatic Digital Microscope" at To find out more updates on this project follow us at:

Step 1: Hardware - Automating Motion

Let's start building the automation pieces of the microscope's axis. The files that you will need are in the file section of the project's page.

Step 2: Hardware - Automating Motion (Z Axis)

We are going to start with the z axis. Print all the files that start with "z_axis". After you print them, you should have two gears, a box and two half circles.

First, we are going to attach the smaller gear to the step motor. You will need a small hammer to press the gear so it fits in the motor's gear.

Then, attach the bigger gear to the micro metric gear of the microscope. For this task you may use any strong glue that you find. It should be easy.

Next, we are going to put the motor inside the box. If your printer hasn't printed very well the box, you can use a milling machine to tune the inside until the motor fits.

Now, we are going to attach the motor to the microscope. Grab the longest half circle. You will see that it has holes, use them to merge the half circle with the motor's box. You can use 3M standard screws.

Then, take the half circle bottom and align it with the other half circle in the way it encloses the back part of the microscope's wheels. Use 3M screws to hold them.

Step 3: Hardware - Automating Motion (X & Y Axis)

You will see that the box is able to move around the microscope's circle. It works in the same way if you move it around. But, we prefer to keep it looking up so it holds itself.

XY Axis Now, we are going to build the automation devices for the X and Y axis. As we did with the z axis, start printing all the .stl files that say X or Y Axis (including the ones that have XY axis together). When your printer is done, you should have 4 gears, a cylinder, a double face box, two long brackets, two L corners and a weird holo piece (Motor Holders).

We will start by attaching the smaller gears to the motors. As we did in the z axis use a small hammer to help you. Once they are attached, we will proceed to put the motors inside the double face box. The motors are of the same size. Thus, it does not matter where you put them. If they don't fit, use a milling machine to tune the box's interior until the motors fit.

Then, we will build the motor holder. Start aligning the long holders' holes with the weird piece's holes. Use screws to join them.

Then, place two L corners to the upper edge of the long holders and use screws to attach them.

Next, align the holes of the double face box with the missing holes of the long holders. Join them using 3M screws.

Now, we are going to add the microscope's gears. Both are of the same size, so it does not matter which you use first. Take one and insert it in the microscope's movement piece. Insert it until it reaches its upper limit.

Then, take the cylinder and place it inside the x's axis movement piece. If it does not fit, use a milling machine to tune it. Once it is inside, you can take the other gear and attach it to the cylinder. Both gears should fit very well.

Finally, take the big part that holds the motors and push it softly until it fits the side of the microscope's moving stage. If the gears are not aligned, just move them.

Step 4: Hardware - Automating Motion (X, Y, Z Axis Assembly Video!)

Here you have some videos about the building of the Automation Devices:

Step 5: Electronics - Ilumination

In this step we are going to add a ring of white leds to the microscope. This piece is very important because it will greatly enhance the microscope's images.

This piece is very easy to build as you will realize. Go to the file section and download the two files that say ring of leds (part 1 and part 2). Print them.

You should have a circle with 21 holes and a cylinder with an open face.

We are going to start with the circle with 21 holes. Buy 21 bright white leds and place them in the holes of the circle. Next, use the folllowing diagram shown to solder them.

Using 36 ohm of resistance will require 300mA which is kind of high for the leds. I recommend adding a current divider to lower the current. Our prototype is working fine with 160 mA, besides it consumes less current from the battery.

Once the leds are soldered, place them so they don't touch each other. Then, add the second part of the ring of leds. This other part is a cap that should be glued to the circle. It has two holes for two feeding cables.

Step 6: Electronics - End Stops

In this step, we are going to add endstops to all 3 axes. This is important to set home so that the microscope knows where its home exactly and for it to recalibrate itself each time. In short, it is a point of reference which will be usefull for automatically mantain the microscope calibrated.

First, we will start by locating the Home to each axis of the microscope. If you dont know where it is, just move each axis manually until it cant turn no more. This point will serve as a home reference, all movements and positioning from now on will be referenced to this particular spot.

Next, we will start by getting 3 endstops. Since the microscope was not designed for this, try to find some small switches like the ones shown in the picture or ones that will fit in the place selected for home. To know where should they fit, try to fit the switch where it would be pressed when the microscope is on home of that particular axis. Repeat this for all 3 axes. You can also help yourself to understand the idea by looking at the picture on top, it shows the three spots where we placed all individual endstops.

Finally, soldier some long wires to its terminals. How long wires? You have to think where are you going to put all the electronics for this is the place the wires must reach.

Step 7: Electronics - WebCam

Webcam Coupling Device

Now we are moving into the webcam coupling device. This one is incredibly easy to build.

We are using a genious eface2025 usb camera. But you dont need to get this specific camera, as a matter of fact, any usb camera will work. This is because will be using VGA resolution since it is good enough and using a greater resolution would make things much slower.

First, download the .stl named webcam holder from the file section. Print it.

Next, place your webcam in the big hole and use a couple of screws to secure the webcam in the 3D printed piece. If your camera does not fit try to stick it in however you can but maintaining a right angle, but try not to move either forward or backward. The piece is ready to be used with the microscope, just place it inside one of the microscope's oculars and check the image. If the image is not in focus or it does not look good, pull the ocular until it fits entirely in the piece. We have calculated the exact distance to have a great image so don't worry. If you can't pull it, use a milling machine to tune the sides of the device.

Step 8: Electronics - Getting All Micros + Shield

In this step, we are going to add the hardware so the device can work alone or remotely controlled by someone.

For this step you will need:

- Arduino UNO or similar

- Raspberry pi3 B+ (probably wont work with less powerfull computers)

- Pololu a4988

- A voltage elevator lm2596

- Tools and materials to make a PCB (dont know how to do one? here's a great tutorial on it!)

You will have to build the pcb otherwise youll end up with lots of cables and protoboards laying arround everywhere. Download the attached files and make the PCB, find all modules listed, a bunch of wires and you can go on.

Step 9: Electronics - Microcontrollers

You have two options now. First, in our case our microscope's electronics were completly obsolete, thats why we decided to REMOVE all electronics and use that same space for our new electronics. Or Second, you can set all electronics aside in an enclosure if you think your microscopes built in electronics are still somewhat valuable and usefull.

In our case we did the first one, so before we start, you should remove all the electronics that the microscope has at the bottom. It is a very easy task, use a star screwdriver to remove the circuit and the covering surface. Be careful when removing the PCB. Make sure the microscope is disconnected because it works with a lot of current, i forgot about this and electrocuted myself. Be careful.

Once the bottom is empty, we are able to add the electronics and micros. There are many ways in which you can hold the stuff. We are using little pieces of acrylic glued to the bottom as a firm floor. Then, we are using screws to hold the micros.

Let's start with the Arduino Uno. There is not a lot of space down there, so you might want to buy small cables or shorten the ones you have. We shortened an Arduino Cable so it could connect via USB to the raspberry pi 3. First, we used a screw to hold the Arduino Uno to the acrylic floor.

Then, add the pololu stepper drivers to the motor shield. And this is where you will connect all cables from steppers, endstops and lighting following the diagram shown. Now stick the shield to the arduino and finally connect its communication cable.

Next, add the Raspberry pi 3. Use a screw to hold it in the acrylic floor and connect the income USB fro the Arduino Uno.

Next, we are making the electronic connections. Start by adding a mini USB cable to the Raspberry pi 3. Then, add a couple of wires to feed the motor shield.

Next, we will add the voltage elevator required to work with the motors. Test it and set it to elevate from 5[v] to 12[v]. Use a screw to attach it to the acrylic floor.

Now that we have everything in the bottom of the microscope, we can start soldering. Solder the connections as the listed diagram depicts.

We are almost ready to start the microscope! Let's add the powersource which will be a 10A powerbank. Place it in the middle of the microscope and cut a couple of USB cables to attach the feeding cable of the Raspberry pi 3 and the 5[v] feeding of the voltage elevator. If you dont have one , or dont want to use one, just use any 10A 5V power source.

Step 10: The Code! - Arduino

Upload the code to the arduino.

Step 11: The Code! - Raspberry Pt1 - Autofocus and Auto Sweeping

There are still a lot of improvements to do. For now, here's a sample code that so far works pretty well. The videos demonstrate the autofocus effectiveness. If you want to see a sweep example, then check the Hackaday Prize 2016 video. There you will find a deligthful demonstration.

Refer to the following links to check the autofocus of the microscope, INSTRUCTABLES HAS A BUG and does not let me upload the videos to this step.

Other files are on github:

Step 12: The Code! - Raspberry Pt2 - Detection Algorithm

There are three main codes that detect Tuberculosis bacillli. The first one is a simple computer vision algorithm. The second one uses a logistic regression classifier as a pixel discriminant. The third one uses the second classifier, but adds a shape descriptor classifier as well.

For now, we will give you the Computer Vision algorithm, if anyone wants to contribute. Please contact us at the Hackaday page. There is some very interesting ideas with these. Deep Learning seems to be the best way.

Check the github where the classifiers are also uploaded:

Here are some videos of the way we were working with the classifier:

Step 13: Test the Automatic Digital Microscope