A LEGOTM dynamic force “macroscope”

10.1119/10.0001700.1We describe the design, construction, and operation of a LEGOTM model of a dynamic force microscope, using magnetic forces as an analog of interatomic interactions. The macroscope provides key insights into the operating principles of frequency modulated non-contact atomic force microscopy—currently the scanning probe technique of choice for maximal (i.e., submolecular) spatial resolution—and is, therefore, particularly suited as a project or demonstration for nanoscience education at the undergraduate or postgraduate level.


I. INTRODUCTION
Scanning probe microscopy, 1 a technique that not only underpins the entire field of nanoscience but plays an increasingly central role in virtually every area of condensed matter physics, saw a step change in capability a decade ago with pioneering acquisition, by Gross et al., of images of the chemical architecture of a single molecule. 2 This type of ultrahigh resolution probe microscopy, which is now almost de rigueur for imaging at the atomic and molecular levels, involves operating the atomic force microscope (AFM) in the dynamic (or "non-contact") mode, generally using a quartz tuning fork sensor in the qPlus configuration introduced by Giessibl. 3 In this dynamic mode, shifts in the oscillation frequency of a tine of the tuning fork, to which is glued an atomically sharp tip, are used to probe tip-sample interactions. A recent review article 4 provides a comprehensive overview of the very many advances in nanoscale, surface, and atomic/ molecular physics (and physical chemistry) that have been made possible via the combination of the dynamic force mode with the qPlus sensor.
The widespread use and application of dynamic force microscopy (DFM) in state-of-the-art condensed matter science makes its inclusion in undergraduate and postgraduate courses essential if students are to receive a thorough grounding in the core techniques used in the field. Moreover, and equally importantly, the physics of the damped, driven, harmonic oscillator is at the core of DFM. This makes the technique a particularly exciting application of the theory of resonance that undergraduate physicists typically meet in their first year but which, of course, also connects to virtually every area they subsequently cover in their degree course. Outside of the university environment, "real world" demonstrations of otherwise difficult-to-visualize physics are exceptionally important in bringing the subject to life for public engagement and outreach activities.
Although a number of ingenious implementations of macroscopic analogs/working models of atomic force microscopes (AFMs) have previously been developed and discussed, [5][6][7][8] including LEGO-based variants, [9][10][11] these have each focused on contact mode force microscopy, where the static bending of a cantilever is used to measure tip-sample interactions. Reimer et al. 12 took the LEGO design concept much further and developed an elegant analog of a magnetic force microscope, using a microphone to detect the variations in resonant frequency of a scanning cantilever. Although the oscillation of the cantilever in the design by Reimer et al. was monitored and controlled in an innovative manner, their feedback strategy was very different from that of the phase-locked loop (PLL) technology that underpins the frequency modulation mode of operation of modern DFMs.
We have instead designed and constructed a complete analog of a DFM, incorporating the frequency modulation (FM) mode of operation that is widely used for (ultra)high resolution imaging via the use of a cantilever driven on-resonance and whose oscillation frequency is tracked via a phaselocked loop, with feedback control of the oscillation amplitude of the cantilever. The macroscope can also be operated in the amplitude modulation (AM) mode, and we compare and contrast the AM and FM techniques. In addition to generating images (of "buried" magnets), we have measured force curves for magnetic dipole-dipole interactions which follow the well-established inverse square dependence on separation that one would expect. Our LEGO DFM exploits precisely the same physical measurement principles as its state-of-the-art ultrahigh vacuum, low temperature counterparts but at a much lower bandwidth (tens of Hz rather than tens of kHz), on a much larger length scale ($centimeters rather than sub-nanometers), and, of course, at many orders of magnitude lower cost.

II. THEORY OF DYNAMIC FORCE MICROSCOPY
DFM uses both mechanical and electrical resonance to precisely measure and track tip-sample interactions. Atomic force microscopy of this type is, thus, an ideal example of state-of-the-art application of the core principles of resonance. Given the intended undergraduate and postgraduate audiences for this paper, we outline the fundamental principles of mechanical resonance in the following. A much more detailed analysis is provided in Giessibl's influential 2003 review. 13 A cantilever, 14 or tine of a quartz tuning fork, 4 is driven to oscillate either by mechanical or electrical excitation. (Mechanical excitation is the much more frequent choice in the highest resolution modern DFM measurements.) A difference in force gradient shifts the resonant frequency (see below), while dissipation of energy affects the amplitude of the oscillation. An important aspect of the frequency modulation mode of operation (see Sec. II B) is that the conservative and non-conservative forces underlying these changes in frequency and amplitude can be separated.
The tip/cantilever system can be modeled as a simple harmonic oscillator: a point mass m attached to a cantilever with spring constant k 0 . Ignoring tip-sample interactions, the resonant frequency of this system is given by (1) The dependence of cantilever oscillation amplitude A on driving frequency x is given by a Lorentzian function where A 0 is a constant and Q is the quality factor of the oscillator. Q is defined by where c is the damping constant of the system and Dx fwhm is the full width half maximum of the resonance curve (see Fig. 1).
Considering the tip-sample force F(z) and an oscillating driving force of frequency x and amplitude F 0 results in the equation of motion where c is a damping constant, d is the equilibrium distance of the tip above the sample, z is the tip-sample distance, and t is time. For small oscillations around z ¼ d, the time dependence of z can be modeled as z ! z 0 þ z 0 ðtÞ, where z 0 is the equilibrium position. This gives and when substituted into Eq. (4) gives which is the equation for a damped driven oscillator with spring constant This new spring constant results in a system with resonant frequency dependent on the force gradient with the relation With this relation, the force gradient of the tip-sample interaction can be calculated from the resonant frequency shift of the cantilever 13 There are then two principal methods for measuring this frequency shift in atomic force microscopes: amplitude modulation and frequency modulation.

A. Amplitude modulation
Amplitude modulation involves driving the cantilever at a fixed operating frequency, slightly offset from the resonant frequency of the cantilever in free space. The change in resonant frequency can then be calculated based on the amplitude change at a fixed frequency using the relation where A 0 is the oscillation amplitude in free space. In practice, however, a feedback loop is used to maintain a constant amplitude from which an image is generated, with little direct analysis of the underpinning frequency shift due, in part, to the complicating contributions of dissipation. It is clear from Eq. (10) that a high Q gives a greater DA, so increasing the quality factor results in higher precision measurements. 15 Figure 2 shows this change in amplitude between two resonance curves with different resonant frequencies. While a high value for Q results in higher precision measurements, it also results in increased relaxation time for the system since Q / 1=c (see Eq. (3)); this can significantly limit the speed at which an image can be acquired with AM force microscopy.

B. Frequency modulation
For the damped-driven oscillating system described by Eq. (6), it can be shown 16 that the phase lag w of the oscillator compared to the driving signal is given by As x tends to x 0 , the phase lag becomes Frequency modulation mode makes use of this phase lag relation to keep the cantilever on resonance using a phase locked loop (PLL). This maintains the driving oscillation 90 offset from the measured oscillation. The resonant frequency obtained is then measured and used to calculate the force gradient (Eq. (9)). The phase lag's relationship to the driving frequency is shown in Fig. 3.

C. Energy dissipation
As a cantilever oscillates, energy is dissipated in a number of ways. There is some energy dissipation intrinsic to the cantilever itself and some dissipation to the surrounding medium (whether gas, liquid or near-vacuum). Much more importantly in the context of DFM, the work done by the cantilever against the tip-sample force also results in energy dissipation. Measuring energy dissipation can be a valuable tool in examining a material's properties, and can sometimes produce high contrast images, 17 although, as is always the case with any scanning probe measurement, it is important to recognize that dissipation can often arise from relaxation processes occurring at the tip rather than in the sample. 21 The cantilever oscillation amplitude is kept constant by a feedback loop controlling the driving oscillation's amplitude. To calculate the energy dissipation due to the tipsample force alone, the energy dissipation of the cantilever in free space was measured and subtracted from the energy dissipation above the sample. Keeping the phase-lag between the driving oscillation and the cantilever oscillation constant (using the frequency feedback loop described in Subsection III E 4.) ensures that there is no extra dissipation due to phase discrepancies. By employing a frequency feedback loop and amplitude feedback loop simultaneously, an energy dissipation scan can be generated at the same time as a frequency shift scan.

III. MECHANICAL DESIGN AND CONSTRUCTION
Our aim was to produce a model DFM using the LEGO Mindstorms NXT robotics kit and low-cost electronics. (See the supplementary material 22 for a list of parts and an estimate of costs.) Although the NXT controller is ideal for controlling motors, it does not have built-in capability for data collection or offer much flexibility with regard to the input and output of signals of various functional forms. We, therefore, also introduced a programable microcontroller, the Arduino Uno, 18 for signal acquisition, output, and control.
Dynamic force microscopy requires three primary tasks to be carried out in parallel: the cantilever oscillation needs to be driven, its response measured, and the position of the cantilever (and its integrated tip) with respect to the sample surface controlled in the x, y, and z directions. In this section, we describe our approach to mechanically implementing each of these aspects. Section IV focuses on the electronics and software.

A. Cantilever
The cantilever was a fiberboard strip approximately 230 mm long, 5 mm wide, and 1.6 mm thick. This was secured on one end to a LEGO base, using the flexibility of the LEGO Technic pieces to hold the cantilever in compression. Multiple base designs were tested, and a simple block design was deemed to be the most stable (Fig. 4). The DFM tip was formed by attaching two small neodymium magnets to the end of the cantilever furthest from the base. This allowed the cantilever to react to magnetic forces, analogous to atomic forces in a real AFM.
In order to drive the oscillation of the cantilever, another small neodymium magnet was attached to the cantilever approximately 50 mm from the secured end of the cantilever. A solenoid is held directly under this magnet, allowing the cantilever to be driven by applying an oscillating electrical signal to the solenoid. To measure the oscillation of the cantilever, a piezoelectric disk 20 mm diameter was glued to the top of the cantilever. As the cantilever oscillates, the piezoelectric crystal is deformed, creating an oscillating voltage across the terminals.

B. Sample
Our macroscope makes use of magnets to emulate the atomic forces exploited in a real AFM. Therefore, it was necessary for the sample to be constructed using magnets. To  allow for easy changes in the design of the sample, neodymium magnets, 5 mm in diameter and 3 mm thick, were inserted into the holes in the base of 2 Â 2 LEGO bricks and held in place by friction. These bricks can be rearranged on a base plate to create a number of patterns to be scanned. Figure 5 shows the magnet placement inside the bricks and an example of a sample layout.

C. Sample translation stage
The sample stage is constructed entirely using LEGO, making use of three LEGO NXT motors to control the movement. These each have a built-in encoder that can measure the current angle of rotation to a precision of 1 .
In order to reduce disturbance of the oscillating cantilever, it was decided that the sample should move instead of the cantilever. The mechanism for each of the horizontal planes (X and Y) is similar: two long LEGO rails slide over a base built from smooth LEGO Technic pieces. The motor for each of these planes is positioned above the rails and has a 40-tooth gear attached. These gears interface with "gear racks" on the LEGO rails to slide the rails along. The gear racks have 10 teeth per four LEGO "studs." Therefore, with a 40 tooth gear, a full 360 turn results in a linear movement of 16 studs, with a precision of 0.04 studs (0.32 mm). In reality, the precision of the system is much less than this due to the flexibility of the LEGO pieces.
The vertical z-axis mechanism was designed to sit on top of the horizontal axes and move the sample bed up and down with high precision. This was achieved using a LEGO worm gear interfaced with a vertical gear rack. Rotating the worm gear by 360 moves the sample bed vertically by just one gear tooth. This gives a theoretical precision of 0.001 studs (0.01 mm). As with the horizontal axes, the actual precision is significantly less than this. The design of the x-y and z platforms are illustrated schematically in Figs. 6 and 7, respectively, with a photo of the fully assembled structure shown in Fig. 8.

D. Electronics and software
The measurement and stable driving of the cantilever oscillations were deemed to be beyond the capabilities of the LEGO NXT system; therefore, a more flexible programable micro-controller was used: the Arduino Uno. 18 In the following, we discuss the measurement, interfacing, and communication protocols we implemented in order to realize analogs of the phase-locked loop (PLL) frequency tracking, amplitude control, and z feedback of a dynamic force microscope.

Communication
The Arduino Uno communicated with the NXT system using the I 2 C (Inter-Integrated Circuit) protocol. 19 This protocol operates over two wires (plus ground) and facilitates Fig. 4. Schematic diagram and photograph of the cantilever assembly. master-slave communication. The NXT controller, as the master device in the system, initiated all communication with the Arduino. That communication could take the form of a request for information, or a command. In our case, all communication took place using single precision floats. The I 2 C bus of the NXT required two pull-up resistors to pull the data lines up to 4.5 V. This simple circuit is shown in Fig. 9.

Driving solenoid
In order to drive the solenoid, one of the Arduino's pulse width modulation (PWM) outputs was used. PWM is a method for producing arbitrary waveforms using only a digital (on/off) output and operates by running a clock at a fixed frequency (in our case, this was approximately 63 kHz). It then varies the duty cycle of the output. By smoothing this output using capacitors in a digital-to-analogue converter (DAC) circuit, it is possible to create a very smooth output. The output from an Arduino-controlled DAC is of very low-impedance, so a power amplifier was used between the DAC and the solenoid. One of the channels from an ST L272M power op-amp chip was used, powered by the single rail 5 V supply of the Arduino. The output from the Arduino DAC must be between 0 V and 5 V, oscillating around 2.5 V. Therefore, the output from the amplifier was capacitively coupled to the solenoid such that the voltage oscillated around 0 V. The circuit used to drive the solenoid is shown in Fig. 10.

Measuring oscillations
The piezoelectric crystal attached to the cantilever produces an oscillating voltage signal as the cantilever moves. By default, the Arduino can measure input voltages between 0 V and 5 V. To more precisely measure the low voltages produced by the piezoelectric crystal, we used the analogue reference pin to set the upper limit of the measurement lower than 5 V. This reference was set using a potentiometer to allow quick adjustments.
In order for the entire signal to be measured, the Arduino input voltage must be greater than 0 V. Therefore, one side of the piezoelectric crystal was tied to one half of the analogue reference voltage using a potential divider. This meant that the Arduino input voltage oscillated around the center of the measurable range. The full circuit used to connect the piezoelectric crystal to the Arduino is shown in Fig. 11.

Circuit board
The three circuits described above were combined onto a single stripboard designed to mount on top of the Arduino. This arrangement is commonly referred to as an "Arduino shield." The piezoelectric crystal, solenoid, and I 2 C link were connected using standard header pins. Three LEDs were added to spare digital pins on the Arduino, to indicate the current mode of the software.

E. Software (Arduino)
The Arduino software was written in Cþþ, as is required by the Arduino firmware. The code was modularized into four classes: • I 2 C comms: manages communication between the Arduino and the NXT. • Signal generator: produces the sinusoidal signal to drive the solenoid. • Oscilloscope: measures the incoming signal from the piezoelectric crystal, calculating phase, amplitude, and frequency. • Feedback: provides frequency and amplitude feedback loops which can be enabled/disabled as needed.
The full code for these classes can be found in supplementary material. 22 A brief description of each is provided in the following.

I 2 C comms
When initialized, this class enables the I 2 C bus and monitors for received messages from the NXT. One function deals with incoming commands, and another deals with incoming requests for information. Both types of message normally result in function calls to other classes within the software.

Signal generator
When the signal generator class initializes, it calculates 256 values of a single sine wave cycle, i.e., a sine look-up Fig. 9. Circuit schematic for I 2 C connection to Arduino.   11. The circuit used to connect the piezoelectric crystal to the Arduino's analogue input and control its input range using the analogue reference pin. table, and stores this in memory to save recalculating constantly.
Two of the Arduino's three built-in timers were used. Timer 1 was put into PWM mode, outputting its signal on pin 9. Timer 2 was set up with a 32Â prescaler, meaning that a counter was incremented at a rate of 500 kHz (32Â slower than the Arduino's 16 MHz processor speed). When the counter reaches the OCR (output compare register), the ISR (interrupt service routine) function is called. This is scheduled as an interrupt function, so it is given the highest priority on the processor. This helps to keep the timing as accurate as possible.
The ISR function simply takes the next value in the sine wave array and sets the PWM duty cycle accordingly. To change the frequency of the output wave, the OCR value is varied between 1 and 255. The frequency f of the resultant wave is given by where f inc is the frequency of the timer and L is the length of the precalculated sin wave array. Since OCR must be an integer, only discrete values of frequency are allowed. The gap between allowed frequency values is typically around 0.1 Hz, which can be a significant limitation of this architecture. Our signal generator class provides functions for setting and getting three parameters of the wave: frequency, amplitude, and phase.

Oscilloscope
The majority of the oscilloscope class is implemented in a single function, newMeasurement. This is called as frequently as possible in an infinite loop. It is interrupted by the timers in the signal generator function, so is not necessarily called at regular intervals. The newMeasurement function reads the current voltage from the piezoelectric crystal and uses that to calculate the RMS voltage, mean voltage, and period (and, thus, frequency) of the previous cycle.
The class determines where a new wave begins by watching for a rising edge. It was found that the newMeasurement function is called approximately 2000 times per second, which gives a hypothetical frequency resolution of 0.0005 Hz.

Feedback
The feedback class has a single main function, doFeedback, which is called on every rising edge. It then calls two different functions depending on the current settings, doFrequencyFeedback or doAmplitudeFeedback. If the frequency feedback loop is enabled, doFrequencyFeedback sets the signal generator's output frequency to exactly match the oscilloscope's measured frequency. It also sets the phase of the signal generator to 90 . This is of course a very simplistic implementation of a phase-locked loop, but it proved to be more than sufficient for the low oscillation frequencies in this project.
If the amplitude feedback loop is enabled, doAmplitudeFeedback compares the oscilloscope's current RMS amplitude with a target value. It then adjusts the signal generator's output amplitude in an attempt to reach the target value. This makes use of a PID (proportional-integral-differential) controller, the implementation of which is provided by an opensource library. 20 Figure 12 is a flow chart showing the basic steps in the implementation of the feedback loops.

F. Software (LEGO NXT)
The LEGO Mindstorms NXT platform supports programing in a number of different languages, namely, NXT-G (the default), Java, and LabView. LabView was chosen for its ease of use in scientific interfacing applications. However, it would be reasonably trivial to re-implement this functionality in a freely available language such as Java since the more complex logic is managed by the Arduino Cþþ code. Using Java would better achieve the project's aim of using low cost equipment. The software was operated in direct mode, which means that all logic is executed in LabView running on the computer, and the NXT inputs/outputs are communicated over a USB connection. This allows for easy logging of data to the computer's hard drive and more processing power than the NXT itself is able to provide.

LabVIEW VIs
A number of simple LabView sub-VIs were created to allow for easy control of the NXT's motors. The most frequently used motor VI is Go To Position, which runs a motor at a given power until it reaches a given rotation. Other VIs were created to allow automatically setting each motor's upper and lower limits (as these are reset each time the NXT is rebooted). Each VI is provided in the supplementary material. 22 To communicate with the Arduino LabView sub-VIs were written for requesting information and setting parameters. These make use of LabView's built-in I 2 C VI and encapsulate all conversions between LabView float data types and the byte array that is sent to the Arduino. Notably, the order of bytes had to be reversed because the Arduino has a "little endian" architecture, whereas LabView is "big endian"-based. For each of the readable and writable Arduino parameters, an individual sub-VI was created with an associated icon to make building a more complicated VI more intuitive.

Resonance VI
A simple VI was created to enable the easy measurement of a resonance curve. It does not make any use of the NXT motors and simply controls the Arduino oscillator. It loops over each frequency in the given range, setting the Arduino signal generator to the required frequency. It then waits for a defined amount of time, before measuring the amplitude and phase from the Arduino's oscilloscope. It takes a number of data points at each frequency and records them all in a CSV file for later analysis. (Other file formats could also easily be exported in principle via this VI.)

Scanning VI
A scanning VI was created with a comprehensive user interface. This VI consists of a number of sections which run simultaneously: Parameters available for each scan, in addition to the motor limits, are as follows: • Number of points (for each axis). • X and Y move speed (speed that the X and Y motors move). • Z move speed (speed that the Z motor moves). • Relaxation time (time to wait between moving and taking data). • N samples (number of data points to take at each location). • Time between samples (amount of time to wait between each data point). • Alternate directions (option to choose whether the Y axis should move in alternate directions, or reset to zero for each X value).
To avoid having to specify the type of data to collect on each scan, every available data point is recorded simultaneously and can be selected for use when analyzing the data. The data collection portion of the VI is designed to be as simple as possible: it moves to each required data point, records all of the necessary data, and then saves it to a CSV file for later analysis.

IV. RESULTS AND DEMONSTRATIONS
To test and demonstrate the functionality of the macroscope, a number of different types of measurement were set up. Each of these was an analog to an imaging or "spectroscopy" task carried out using a real atomic force microscope. (It is often the case in the ultrahigh vacuum AFM community that force-distance curves are called force "spectra." This is not at all consistent with the conventional usage of the term "spectroscopy" as the measurement is carried out as a function of tip-sample separation rather than energy. Nonetheless, "force spectroscopy" has stuck.) It is important to note that each of these demonstrations occurred separately, and equipment was re-arranged between them. Therefore, results from different demonstrations should be considered as independent and not compared quantitatively. For example, a small movement in the cantilever mounting can result in a large change in resonant frequency.

A. Resonance frequency-phase curve
This measurement mode shows the relationship of driving/measured phase difference to oscillation amplitude, in addition to calculating a quantitative value for the cantilever's quality factor Q. Data collection took place with the cantilever tip in free space, with no sample close to the tip. Using the resonance VI described in Sec. III F 2, we performed a resonance scan over the frequency range 13-16.5 Hz, at intervals of 0.04 Hz, taking 50 data points at each frequency. The relaxation time was set to 1 s. The actual frequency after rounding (see Sec. III E 2) was recorded alongside the measured RMS oscillation amplitude.
The resultant CSV file was parsed, and mean values for the amplitude and phase were taken for each of the frequencies. An estimated error was calculated from the standard deviation for each point. The data were plotted on a graph, Fig. 13, and a least-squares algorithm was used to fit Eqs. (2) and (11) to the amplitude and phase, respectively.
For the amplitude curve, the least squares fit algorithm returned Q ¼ 50 6 4 and f 0 ¼ 14:7 6 0:1 Hz. A leastsquares fit for the phase curve returned f 0 ¼ 14:6 6 0:1 Hz. Both the amplitude and phase curve follow the behavior predicted in Fig. 3. The two values of f 0 obtained (from the amplitude-vs-frequency and phase-vs-frequency curves, respectively) also match to within measurement error. The errors on the amplitude values appear to be significantly higher for the points where the amplitude/frequency gradient is high. This error could be reduced by increasing the relaxation time between each measurement.

B. Resonant frequency shift
A shift in resonant frequency due to a tip-sample interaction is the core principle of dynamic force microscopy. We demonstrated the frequency shift by measuring a resonance curve for the cantilever in free space and again above a magnetic sample. With the sample removed, the resonance VI described in Sec. III F 2 was used to take a resonance curve over the frequency range 12-16 Hz at intervals of 0.05 Hz, taking 50 data points at each frequency. The relaxation time was set to 1 s. The actual frequency after rounding (see Sec. III E 2) was recorded alongside the measured RMS oscillation amplitude.
The same process was repeated with the tip positioned over a magnet providing a repulsive force. The resultant data were parsed, and mean values for amplitude were calculated at each frequency. Uncertainties were calculated based on the standard deviation of the amplitude measurements for each frequency. A least-squares algorithm was used to fit Eq.
(2) to the data with and without the tip-sample interaction.
The resultant values of f 0 were compared to check for a change in resonant frequency.
A graph displaying the resonant frequency shift due to the tip-sample forces is shown in Fig. 14. The resonant frequency of the cantilever in free space was found to be f 0 ¼ 11:8 6 0:1 Hz; and the resonant frequency of the cantilever over a magnetic sample was measured as f 0 ¼ 11:1 6 0:1 Hz. This makes the frequency shift Df 0 ¼ 0:7 6 0:1 Hz.

C. Force-distance relationship
Next, the dependence of force gradient on tip-sample distance-another core experimental quantity in DFM-was measured. From this, the tip-sample force was calculated. In real atomic force microscopes, these techniques may be used to map out potential energy landscapes for adsorbed atoms and molecules, and even measure the forces required to manipulate single atoms. 4 A single magnet was placed in the center of the sample bed, and the bed was manipulated manually until the magnet Fig. 13. Plot showing the relationship between the amplitude of oscillation and the phase lag between the driving and measured oscillations. The amplitude error bars are based on 1 standard deviation of the data points. Standard deviation of the phase data points is negligible and not shown. The data are fitted to Eqs. (2) and (11), respectively, using a least squares algorithm.
was exactly under the tip of the cantilever. The z-axis was retracted to its maximum distance, and the scanning VI (see Sec. III F 3) was used to collect a 1D Df 0 (z) curve. The resonant frequency at 50 different z distances was scanned (using the frequency feedback loop), over the full range of the zaxis-a total motor rotation of 2000 . At each location, 50 data points were taken, their mean was taken, and their uncertainty was estimated from the standard deviation.
From Eq. (8), the force gradient dF=dz is proportional to the change in resonant frequency Df 0 . Therefore, the force at each z position can be found from For the equally spaced measurements in this demonstration, with the first measurement being the furthest from the sample, it is sufficient to simply calculate Df 0 ðNÞ; (15) where N z is the sample number and Df 0 ðNÞ is the change in resonant frequency at sample number N. Using this relation, a plot of force against tip-sample separation was created. The result of the Df (z) scan is shown in Fig. 15. The data fit extremely well to a curve with a 1=z 2 dependence as one would expect for the interaction between two magnetic dipoles.
The process was then repeated, but this time data were taken for a grid of points on the z and x axis, with the single sample magnet at the center of the x axis. Five data points were taken at each location. A plot was produced showing contours of constant z-displacement on axes of tip-sample force and x-position. The result of this two-dimensional scan is shown in Fig. 16. It clearly shows how tip-sample force is affected by distance in both the horizontal and vertical plane. The two-dimensional scan is difficult to analyze quantitatively, but the symmetry of the plot and the consistent curve shapes for each z contour demonstrate key AFM concepts well. Despite the magnetic sample being placed exactly in the center of the sample bed, it is clear that the plot is not exactly central. This suggests some zero-error on the x axis, most likely caused by the flexibility of the LEGO structure.

D. Amplitude modulation scans
Amplitude modulation is used extensively for DFM imaging in air and under liquid, forming the basis of non-contact and tapping mode force microscopy. We used amplitude modulation to generate a color-mapped image of the magnet sample (Fig. 5) using this technique. The z-axis was adjusted such that the cantilever tip was approximately 2 cm above the sample surface. A resonance curve similar to that described in Sec. IV A was first taken for the cantilever above a non-magnetic portion of the sample, and the frequency with the steepest negative amplitude gradient was chosen as the driving frequency for the amplitude modulation scan.
Using the scanning VI, both Arduino feedback loops were disabled. The solenoid driving frequency was set to a constant 11.8 Hz, and the driving amplitude was set to maximum. A scan was then performed over a 30 Â 30 grid in the x-y plane. At each location, seven amplitude measurements were taken. The relaxation time at each location was set to 1.5 s. The resultant data were then processed: the mean amplitude for each point was calculated, and the change in   amplitude from the maximum point of the scan was calculated. This amplitude change is proportional to the force gradient (Eq. (9)). The data were subsequently plotted as a 2 D color-mapped image, Fig. 17.
Initial attempts at taking these scans used a zig-zag approach (y axis moved in alternate directions for each x value), but it was found that this caused alternate lines on the map to be offset from one another. This was due to the flexibility of the LEGO stage. In order to avoid this problem, the zig-zag option was disabled, such that the y axis reset to zero for every x value. This means that while there may still be zero errors associated with the location values, these errors are systematic and so the map presents an accurate picture of the surface topography.
Gaussian interpolation has been used between each data point to produce a smooth image. The image produced is a clear representation of the overall sample shape. Unfortunately, the individual magnets are not easily discernible from one another. Increasing the relaxation time for each point may help increase the spatial resolution of the scan. Despite this limitation, the image clearly demonstrates the principles of amplitude modulation AFM.

E. Frequency modulation scans
Frequency modulation is the mode of choice for the highest resolution imaging, spectroscopy, and manipulation DFM experiments, 4,13 and demonstrating FM operation was, therefore, the primary objective of our macroscope project. The Arduino frequency feedback loop was enabled, the driving amplitude fixed at maximum, and a 2D scan was taken over a 30 Â 30 grid in the x-y plane. At each location, 50 frequency measurements were taken. The relaxation time was set to just 0.5 s (as compared to the 1.5 s relaxation time used for AM scanning) as the frequency change was observed to occur almost instantly on the live graphs. For each location, the mean frequency was calculated, and Eq. (8) was used to calculate the force gradient at each point. The force gradient was then plotted as a 2D color-mapped image, as shown in Fig. 18. The image clearly shows the eight magnets of the sample, with much higher spatial resolution than that of the amplitude modulation scan. This demonstrates that frequency modulation is capable of producing higher contrast images than amplitude modulation, but in a fraction of the time.

F. Dissipation map
Measuring energy dissipation is a technique which, in principle, can result in high contrast images of a surface's topography 17 and can often provide key insights into tip dynamics during atomic manipulation processes. 4,21 Therefore, the final DFM measurement technique we implemented was mapping energy dissipation during FM imaging of the "N" magnet configuration, as described above. The only parameter that was changed as compared to the FM imaging described in Sec. IV E was the relaxation time, which was raised to 4.5 s per point in order to secure lower noise dissipation images. For each location, the mean driving amplitude was calculated and subtracted from the driving amplitude for the cantilever in free space. The resultant energy dissipation map was then plotted as a color mapped image, Fig. 19.
When compared to the results for frequency and amplitude modulation scans for the same sample, it is clear that although the N magnet pattern is discernable in the dissipation image, the contrast is poor and the signal to noise ratio is low. Higher contrast images with better signal to noise ratios could likely be obtained by adjusting the PID controller's parameters to improve the performance of the amplitude feedback loop.

V. CONCLUSIONS
We have designed, constructed, and tested a LEGO-based analog of a dynamic force microscope, incorporating the key measurement modes used in state-of-the-art atomic force microscopy, viz., resonant frequency and phase curves, Fig. 17. Amplitude modulation (AM) image of the N pattern of magnets shown in Fig. 5. Gaussian interpolation has been used to smooth the data. force-distance curves, amplitude modulation and frequency modulation imaging, and dissipation mapping. The macroscope is thus an important educational tool for nanoscience and condensed matter physics courses, either for operation as a ready-built demonstration model of probe microscopy or as a construction and coding project. Although our working model captures the core principles of probe microscopy (including its many quirks, foibles, and irritations), and is capable of generating low noise data and images, there are however, a number of shortcomings in the design of the model that could be improved. Key among these relate to the flexibility of the LEGO stage. This was the main source of error throughout our experiments and demonstrations, causing uncertainty in the spatial position of the tip. This could be improved by driving the X and Y axes on both sliding rails simultaneously, using two gears and a longer axle. The friction between the sliding rails and the base could also be reduced to eliminate the skipping that occurs as the axes move. To improve the spatial resolution of the system, a higher gear ratio could be used with the LEGO motors, and a smaller tip could be used on the cantilever.
With or without these improvements, however, the macroscope could be used in a range of applications, from public outreach to undergraduate teaching and learning, providing key insights into just how probe microscopy enables us to map and manipulate the atomic, molecular, and nanoscopic worlds.

AUTHORS' CONTRIBUTIONS
D.T. and H.S. contributed equally to this work.

ACKNOWLEDGMENTS
The authors gratefully acknowledge the assistance of the Third Year Undergraduate Laboratory staff in the School of Physics and Astronomy at the University of Nottingham, particularly Matt Young, throughout the project on which this paper is based. The authors also thank Dr. Chris Mellor (also at UoN Physics and Astronomy) for suggesting the force macroscope term. a)