Amy’s Microtome Counter

Yesterday something awesome happened: Amy (one of the other postdocs in the lab) came to me with an idea for a piece of kit that would help her in the lab. She found that when she was cutting brain sections on the microtome, she would sometimes zone out and forget which plate she was up to. Her request was for a microtome section counter.

The idea was to have something that would light up an indicator of which plate she needed to put the next section into. It would also require a sensor of some kind that would be activated each time she placed a section. We quickly came up with a workable idea that would use an IR sensor, and the user would sweep their hand close to the sensor after each brain section was added.

This project is just asking for an Arduino, so first thing I did was sketch out some code:

// Specify pin connections
int IR = 2;
int LED1 = 3;
int LED2 = 4;
int LED3 = 5;
int LED4 = 6;
int toggle = 7;

// Specify other variables
int count = 0;            // Counter
int maxcount = 4;         // Number of plates to count
long delayTime = 500;     // Delay time to prevent multiple activations
long lastTime = 0;        // Time stamp from last activation

void setup() {

// Specify pin setup
pinMode(IR, INPUT_PULLUP);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(toggle, INPUT_PULLUP);

}

void loop() {

// Toggle to select number of plates being used
if(digitalRead(toggle) == LOW){
  maxcount = 3;
}
else{
  maxcount = 4;
}

// Detection by IR sensor 
if (digitalRead(IR) == LOW){
  if(millis() - delayTime > lastTime){    // Have you exceeded time since last activation?
    count++;                              // Add to counter
    lastTime = millis();                  // Specify timestamp of IR activation
  }
}

// Overflow counter back to start
if (count >= maxcount){              
  count = 0;
}

// Switch on each LED in turn depending on counter
if(count == 0){
  digitalWrite(LED1,HIGH);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,LOW);
  digitalWrite(LED4,LOW);
}

if(count == 1){
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,HIGH);
  digitalWrite(LED3,LOW);
  digitalWrite(LED4,LOW);
}

if(count == 2){
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,HIGH);
  digitalWrite(LED4,LOW);
}

if(count == 3){
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,LOW);
  digitalWrite(LED4,HIGH);
}

// Reset timer overflow
if(millis() - lastTime < 0){
  lastTime = millis() - lastTime;
}

}

The electronics is fairly straightforward:

Amy's microtome section counter schematic.

A small amount of assembly later, and we had a working prototype:

Microtome sectioning counter
Amy’s microtome counter

Amy has promised to test it. I’ll let you guys know how it goes.

Technology and the 3 R’s

A contemporary approach to the refinement of animal research highlights the importance of technology and the 3 R’s:

“Employing new in vivo technologies that can benefit animal welfare and science including methods to minimise pain and distress as well as to deliver enhancements in animal care, housing, handling, training and use”1

This definition fits well with my experience of animals in research – the less you stress your animals while running experiments, the better your data will be, and technology is an important way to reduce your impact on the animal whilst also improving your metrics.

My history with technology

As an example, for my PhD I wanted to investigate control of the cardiovascular system in a transgenic mouse model. I won’t go in to details here, but suffice to say it had a weird hypermetabolic phenotype which we thought would also impact the sympathetic control of the cardiovascular system. But how best to go about measuring this?

Let’s say you went to your GP with a suspected blood pressure issue, what would the doctor do? Most likely sit you down and measure your blood pressure with a plethysmograph (the cuff that goes on your arm and inflates) and your heart rate by counting beats. This was actually the first method I tried in my mice – we had a mouse-sized plethysmograph that works on the tail of the animal; it also comes with tubes to hold the mice steady while performing the experiment.

You don’t need to be a scientific researcher to realise that confining a mouse in a restricted holder like this will stress them out, even after repeated sessions of acclimatisation. And what happens when you’re stressed? Increased heart rate and blood pressure, which by definition makes this technique less than optimal.

However, it is possible to get decent data from such a system, so long as you bear in the mind the limitations when planning studies and drawing conclusions. As it happens, my transgenic mice that I used in this study were much smaller than the wildtypes, and as such I was unable to get reliable readings.

But, we really wanted to record blood pressure in this mouse model, so next step was to attempt a more invasive method to get a direct reading of blood pressure. This is possible, although technically very challenging in mice, by inserting a thin plastic tube into a major blood vessel and getting a direct readout of the pressure from inside the artery.

Obviously, you can’t go inserting a catheter into the artery of an awake mouse, so I anaesthetised my transgenics and learned how to insert the blood pressure catheter into the mouse’s carotid artery. We did get lovely blood pressure readings from this study, with the predictable caveat that it was performed in anaesthetised animals, and there aren’t many things in this world more likely to impact your cardiovascular system than being anaesthetised!

As it happens, we used a certain (old-school, not used in humans) anaesthetic known to have minimal impacts on the cardiovascular system. However, we knew we wouldn’t be able to publish the results without getting some kind of readings in an awake animal. This is where technology comes into the story, in the form of implantable telemetry.

It goes without saying that telemetry, while a great technological solution, is also technically quite challenging as well as prohibitively expensive. As such, and especially given that I was naïve to these methods, I opted for the easier biopotential transmitter to record ECG. Once I’d figured the experiments out and was able to get good heart rate recordings in awake freely moving mice, they formed the pinnacle of my PhD, and enabled us to publish the results.

In an ideal world, we would have used blood pressure telemetry (heart rate alone can give ambiguous results), but I think we made the correct decision at the time. One of my colleagues recently used the blood pressure telemeters, and had a terrible time of it – they’re just that much more difficult, especially the surgery.

Technology is important

Anyway, my takeaway message today relates the importance of technology and the 3 R’s for minimising the stress and harm done to animals in your experiments while simultaneously maximising the quality and impact of data you produce. I recently submitted a grant application to the NC3R’s with exactly this stated goal – to use my fibre-free optogenetics technology in vivo, to show that it has a marked benefit to animals in optogenetics studies, leading to a refinement, as outlined in the 3R’s.

1. Clark Br J Nutri 120(S1), S1-S7 (2018) The 3Rs in research: a contemporary approach to replacement, reduction and refinement

Feeling Warm and Fuzzy

I have previously talked about developing a touch-free timer for use in surgery. The goal was to better enable a single researcher to maintain sterility during animal surgeries. I really think this is a genuine unmet need in the research world, and widespread adoption of touch-free surgery kit would be extremely beneficial, both to the researchers and to the animals.

Anyway, with the plan to expand my touch-free surgery range, I figured the next piece of kit should be a heat mat for keeping rodents warm in surgery. And again, I wanted something that can be controlled by touch-free sensors. Helpfully, Pi Hut sell a small, flexible heating pad:

Looking at the specs, it uses ~1 A of power, which is far more than we can safely run from an Arduino digital pin. In order to do this, we make use of a component called a MOSFET, which is a special kind of transistor used to amplify circuits. A MOSFET lets you use a digital signal (eg. an Arduino output pin) to fully switch a separate circuit (eg. a fully powered heat mat).

Therefore, using a MOSFET, I can control the power going to the heat mat by the digital output of the Arduino. I’ve mentioned pulse width modulation (PWM) before, and it is perfectly suited to this application. PWM will let me digitally control the amount of power going through the heat mat. And, best of all, because it’s digitally controlled, I can shift the PWM up/down with IR proximity sensors.

But, how to display the power going through the heat mat? For this, I again turned to Pi Hut, who sell a 10-segment LED bar:

Each LED in the bar is individually controlled, which means that I can set the Arduino to display an indication of the power going through the heat mat, on a scale of 1-10. Bringing it all together in a 3D printed housing, I have power up and power down proximity sensors, a power indicator bar, and a flexible heat mat that warms quickly to the extent determined by the user:

Touch-free heat mat for keeping rodents warm in surgery.

I have used this heat mat in surgery myself, and it worked really well. It heated up super quick and I could change the power of the heat mat to the temperature needed by the mouse. This piece of kit is indispensible for keeping rodents warm in surgery.

The one thing that I think it missing is an actual reading of the mouse’s temperature – I kept having to feel the surgery bed to check the temperature, which kind of defeats the purpose of being touch-free.

So, my next plan for this piece of kit is to add in a temperature sensor (whether a standalone one or one that runs through the Arduino, I have yet to figure out). Stay tuned for updates.

A Better Timer

This is a quick update to my previous blog post, where I explained making a touch-free surgery timer. Unfortunately, I found that it just wasn’t working well – as I explained previously, the low voltage used by that timer (1.5 V from a single AA battery) was not enough to make multiple IR sensors respond to the proximity of a finger.

After some brain-storming for how to fix this issue with sensing, I came to the conclusion that I really needed to start from scratch with a new (higher voltage) timer. I therefore scoured the internet for a timer with the following features:

  • Runs at 3-5 volts (ie. two or three 1.5 V batteries), but not from button batteries (they don’t have much capacity, so would drain too quickly)
  • Stopwatch and countdown timer functions
  • Controlled by limited number of pushbuttons (ideally Start/Stop and Reset for stopwatch, then “add minute” button to set up timer)
  • Has big light-up numbers for easy checking of timing

Finally, I found a timer that hit all my requirements, and only cost around £20 on Amazon (turns out the kind of timer I wanted with simple controls and big light-up numbers is targeted to children and the elderly):

So, I cracked the timer open, soldered in IR proximity sensors to the Start/Stop, Reset and Minute buttons, and found they worked great – I could control the timer by moving my finger to within 10 mm or so. Turns out there was some dead space inside the case, which meant that I could drill holes in the side and mount the sensors on the inside. I also added in a cutoff toggle switch to cut the power to the IR LED’s to prevent battery drain.

All in all, I’m really pleased with the new timer: I left it in the surgery room, and it’s going down brilliantly with the other lab members who’ve tried it.

How to Track a Mouse

Our old locomotor tracking

One of my projects is investigating a population of neurones that controls mouse locomotor activity and food intake. In the past I have used either implantable telemetry or IR beam break cages to quantify the mice’s movement. But the telemeters, even when they’re functioning well, don’t give particularly good quantification of mouse locomotor activity, which leaves the beam break cages.

For anyone that doesn’t know, these cages are set up to have a couple of IR beams that cross the cage. Whenever the beam is broken (ie. the mouse gets in the way), this is registered by the computer. It’s quite an effective (although crude) method to quantify mouse activity. And it does so completely non-invasively. However, our current IR beam break cages have a number of drawbacks that make them unattractive:

  • They only work with some of the older open cages, and don’t work at all if the mice have any bedding in the cage (it blocks the beams)
  • The beam break cages we have available in the facility, which actually belong to one of the other lecturers (although she is happy for us to use them), are a decade or two old and were built by a previous postdoc – as such they have suffered some degradation over the years and only have partial functionality left

Anyone who reads my blog will already know what I’m about to say – with these issues I’ve raised, I decided to try and build my own set of beam break cages.

Setting up beam breaks

Right, so first step was to find some IR LED’s and sensors that I could pair across 20-30 cm of a mouse’s cage. I’ve used things like this in the past, so I know you can detect an IR signal using an LED in the ~900 nm range and a phototransistor (Figure 1A).

Luckily, I had some sat around, so I hooked them up to an Arduino, but could only detect the IR signal up to around 5 cm distance. This is obviously not enough, so after some detective work, I found some “IR Beam Break Sensors” from PiHut (Figure 1B). If those didn’t work, it would require some more complex electrical engineering to make it work. Apparently you need to use modulated signals to be sensitive enough to work over multiple metres.

Fortunately, the IR sensors from PiHut worked a treat, up to about 40 cm, which is more than enough for my purposes. The next issue was how to fix the sensors in a way that they would remain aligned in a pairing across the cage.

Aligning the sensors

For this I turned to my trusted 3D printer. After borrowing an IVC from the animal facility, I figured I could make hanging holders that would hook onto the side ridges (Figure 2).

These worked great, with the only issue that the mice tended to move their bedding around and block the direct beams. A very simple solution to this problem was to use strong neodymium magnets to “pin” the tube/bedding at one end of the cage, out of the way of the sensor beams.

Right, so now I had 2 pairs of sensors successfully attached to each mouse cage, next I needed to actually track the data in some way.

Tracking data using Arduino

It turns out that tallying IR beam crosses is easy peasy using an Arduino. The only annoyance being having to duplicate the code 24 times (ie. 2 sensors each for 12 cages). But, I still need to get the data out of the Arduino. I figured I could either hook up an SD card reader and write the data to a removable card, or hook up to a PC and download the data directly.

As I was already connecting the Arduino to my laptop, I tried that first. A little Google sleuthing found me an open source (ie. free) “terminal” program, that will happily log data that comes in over a “COM” port, such as is used by the Arduino. It was actually really easy to set up, and will log the IR beam break data in a CSV (comma separated values) format, that can be directly opened by Excel.

For ease of later data analysis, I made the program log the data in 10 second intervals. However, it will be easy to change that depending on the experimental paradigm eg. 1 or even 10 minute intervals for longer term studies over days or weeks.

Just to prove how well the system works, you can see a massive increase in activity following injection of caffeine (Figure 3A). You also get fantastic circadian activity if you record for longer time periods (Figure 3B).

Where to get it from

As always, I am making this system available on my shop, far cheaper than any commercially available system. Obviously I’ll include a copy of the data logging software with instructions of how to use it. Anyone who wants to measure mouse locomotor activity easily and cheaply, check it out.

Edit 5/5/22: I have now uploaded details of how to make this kit to Hackaday, so head over there if you want to try and build it yourself.

Doing Away With Fibre

My interest in wireless optogenetics has come up a couple of times. In fact, I’ll start with a quick correction: I prefer to call it fibre-free optogenetics, after multiple people mistook my wireless system I was designing as meaning controlled via Bluetooth or WiFi. Which it ain’t. And, for me at least, the whole point of going “wireless” is to do away with the optic fibres, which really embody all the issues and difficulties with in vivo optogenetics:

  • Impacts to the animal – the need to have the animals in an open cage, with an open lid and a sterile environment to prevent damage to the fibres. Also, they tend to be stiff, having severe behavioural impacts.
  • Loss of optical power – the optic fibres require additional optical connections, which inevitably leads to light loss, and therefore difficulties obtaining a high enough brightness.
  • Expensive and fragile – not much more to say, other than we have spent thousands of pounds maintaining the optic fibres for our optogenetics system. This may be more than is typical, but I think that’s because the Plexon fibres we use are very fine and lightweight – I have used more durable ones that were even worse for the mouse behaviour because of the added stiffness.

The most important reason to do away with the optic fibres, as far as I’m concerned, is the impact to the animal. Quite apart from minding the 3R’s with regards to animal welfare, tethering will inevitably cause stress, which is detrimental to the data you can acquire (Figure 1). In fact, it is to the NC3R’s that I am applying for funding to take my fibre-free opto system to the next level.

There is of course the added bonus with wireless optogenetics that you can do optogenetic stimulation in otherwise impossible setups. For example, I am very keen to use my fibre-free opto’s in our calorimetry system to measure energy expenditure in response to opto stim. This is done in an air-tight sealed container, which to my knowledge this has never been done with optogenetic stimulation in the brain.

After a fair bit of research, I have found 4 commercially available wireless in vivo optogenetics systems (Figure 2).

Helios by Plexon and Teleopto by Amuza are both very similar, except that the Helios headstage attaches to “normal” implants, whereas Teleopto make their own custom implants. Both require you to point an IR remote at the headstage constantly (ie. the flashing stops if the signal stops). Fi-Wi from Doric connects over radio signal to drive opto flashing; similar to Teleopto they use custom implants. Neurolux is a very different system to the other three, and uses electromagnetic induction to remotely power the implants. Hence the Neurolux implants are tiny and custom (the LED is actually on the end of the fibre that gets implanted).

I have collated a summary table of the various systems, including a number of parameters (Table 1). Included is the cost to buy a complete setup to stimulate 1 mouse at a time, which usually comes with a few implants. However, I was unable to find out the irradiance available from the Plexon Helios system, despite asking the sales people for those details.

Overall, the Doric system seems the best of the bunch; despite being the heaviest it is very compact and produces by far the highest irradiance. In fact, it provides higher irradiance than the system I’ve been developing, which comes out around 150 mW/mm2. Stay tuned, and I’ll be talking more about my system in the coming months.

1. Won et al., Nat Biomed Eng (2021) Wireless and battery-free technologies for nanoengineering.

One Tiny Step for Man

I’ve been working on the next in my EasyTTL series. Whereas my previous iteration had additional functions and output, this time I had a single goal: make a portable optogenetics TTL driver. This means making it as small as possible and, most importantly, battery powered.

While it is possible to run an Arduino off a battery source, they are pretty big and relatively power hungry. So, I wanted to find a smaller microcontroller to use for this purpose. It is, of course, possible to design a circuit from scratch to use a microcontroller, but that is a huge amount of effort. I would only want to go to those lengths if I had a good reason, like I needed to fit it into a miniscule space, or I was intending to make hundreds.

Fortunately, others have thought the same, and helpfully produced microcontroller breakout boards. Essentially this puts the chip on a board with easily accessible pins and all the control circuitry you need for easy programming via USB, with power regulation etc. I won’t go into all the available microcontroller boards, there are loads out there.

I picked the Adafruit Trinket (Figure 1), because it is small and can be programmed using Arduino IDE, which means I don’t even need to learn any new programming languages. You can think of it as a tiny Arduino, perfect for making a simple and portable optogenetics TTL driver.

The biggest drawback of the Trinket, or any smaller and more basic microcontroller, is that I lose functions; in particular there are fewer I/O pins to connect my switches and dials to. Whereas the Arduino Uno has 14 digital I/O pins, the Trinket only has 4. Now, I obviously need the TTL output and a switch to turn the flashing on/off. I also like to have an LED indicator of the TTL being switched on, which leaves a single pin to control the flashing frequency, on times etc.

With the restriction of a single available pin to control the flashing, I can put in a toggle switch to allow the user to choose between two stimulation paradigms. I will therefore just program my two “favourites”, ie. those that I see most often in the literature or that I am most likely to use myself in the lab:

  • 10 ms flash on-time; 10 Hz frequency
  • 10 ms flash on-time; 20 Hz frequency for 1 second, then off for 3 seconds

My loyal readers will know about my dislike of the 20 Hz and higher frequencies, but as you see them so often in the literature it felt remiss not to include. So anyway, I programmed the Trinket, connected it to switches etc, and hooked the output up to an oscilloscope (Figure 2).

The timing is very good, although it runs about 100 µs fast for a 10 ms pulse, giving it a timing accuracy of 99 %. While this isn’t as good as the Arduino, it is still great, and to be honest is far better than you would ever need for an optogenetics study, either in vivo or in vitro.

Next, I printed a housing unit for the Trinket and a 9 V battery, and I also included a slide switch to cut the power and prevent battery drain when not in use. I think it looks quite smart (Figure 3).

I can’t wait to turn up somewhere with this little box, and hook it up to drive a laser or LED in an optogenetics study.

No Touchy!

This came about when I was thinking about how to improve my surgery technique, in particular sterility. Not that I or people I’ve taught have ever had issues with infection, but maintaining good sterile technique can be difficult, and it certainly makes many routine tasks challenging. And, unlike “real” surgeons, who have a team of underlings to aid in their surgery, we researchers often undertake ours alone, or at most with a single technical helper.

So, what kind of routine tasks do we perform during surgery that could be done without touching anything? My first thought was a timer – we do a lot of virus injections with a nanoinjector, and we time how long we inject to ensure sufficient spread of the virus before retracting the needle. After much Googling and scouring of the internet, I was unable to find any “hands-free timer” that wasn’t a 30-second hand-washing timer. So I decided to develop my own.

First step to a hands-free timer is to find a switch of some kind that can be remotely activated, a proximity sensor of some kind. I wanted something cheap and crudely effective – ie. something that triggers upon proximity of an object (likely a human finger), with a detection distance of 5-10 mm. This lead me to two likely alternatives, a capacitive plate or an infrared sensor (Figure 1).

I bought some sensors to test, hooked them up to an Arduino and found that the IR sensor worked great, but the capacitive plate was very hit-or-miss. Right, so I knew which sensor I wanted to use, but now I needed to set them up on a timer. My first thought was to use my perennial favourite, the Arduino. And I did start setting that up, but then I found an old lab timer that I thought might make a quick and easy prototype (Figure 2A).

Opening the old timer up, I found that the buttons were simple conductive latches that connected the microcontroller pin to ground. All I had to do was correctly solder in the phototransistors of my IR sensors to perform the same latch, and I could activate the “buttons”. The one snag I found was that the timer ran off a single 1.5 V battery, which wasn’t really enough to produce a strong IR signal. This meant a couple of things:

  • I could only connect two IR sensors before the drain on the battery meant they ceased to function entirely; therefore, I hooked them up to START/STOP and RESET, to give me a functional stopwatch without the other functions.
  • The low power available from a single AA battery meant that even with only 2 IR sensors connected, they have low IR strength and therefore can only detect highly IR-reflective objects. It works for metal objects and gloved hands, so should work fine in surgery.

I connected up a couple of IR sensors to the existing circuit, as well as a toggle switch to turn off the power to the sensors to prevent battery drain when not in use. I then 3D-printed a box to house everything, giving me a prototype for my Touch-Free Timer (Figure 2B).

I had assumed that the timer, being so old, would not be in production any more. However, it looks like you can still buy it from lab suppliers, so I shouldn’t have any problems producing as many as are needed.

A Mega Piece of Kit

I have exciting news for my loyal readers: I have finally completed the prototype for my EasyTTL Mega controller! This is a 4-channel optogenetics TTL driver, which I plan to use for in vivo optogenetics experiments.

I’ve mentioned parts of the development of this project before. But, for those who haven’t read the previous blog posts, the idea behind it was to make an optogenetics TTL driver that is simple and easy to use. I get so annoyed by the unnecessary complexity (and associated costs and difficulties) inherent in most neuroscience research equipment. As such, I have produced a massively simplified device that is controlled by the user with knobs (teehee) and switches.

The EasyTTL Mega (Figure 1) is a 4-channel optogenetics TTL driver built on an Arduino Mega core1. The Arduino Mega is a robust open-source microcontroller board with a massive array of I/O pins. I have given it four TTL outputs, each individually switchable by tactile toggle switches. The stimulation settings are determined by three dials: one for the flash duration, one for the frequency of stimulation and one for the brightness. The flash settings have been taken from a decade of optogenetics literature and experiments by yours truly, and covers 99% of flashing paradigms that I have seen.

My prototype 4-channel optogenetics TTL driver.

Being a good scientist, I needed to test the system, so I connected a couple of the outputs to an oscilloscope and turned on the pulsing. First, I checked the pulse durations (Figure 2), which are consistently accurate across the range.

Confirming accurate timing from my optogenetics TTL driver.

Next, I tested the range of flashing frequencies (Figure 3), which are also bang tidy.

Confirming accurate frequency timing from my optogenetics TTL driver.

Finally, I needed to check the brightness control (Figure 4). A quick note: the brightness control is based on pulse width modulation, which means that the laser or LED controller can be set to a constant current. However, the frequency of the PWM is 980 Hz for TTL outputs 1 and 2, but only 490 Hz for TTL outputs 3 and 4. What this means practically is that there will be a threshold flash duration below which the PWM makes the brightness unstable from one flash to the next, and this will be worse for the pins 3 and 4 which run a slower PWM.

Investigating the PWM dimming function on my 4-channel optogenetics TTL driver.

Based on my recording of the PWM outputs, the dimming control is unusable for flash durations of 1 ms on all outputs, and 2 ms or less on outputs 3 and 4. Despite my earlier misgivings, I think the 2 ms flash on outputs 1 and 2 looks fine. I’ve put the EasyTTL Mega in the shop, in case anyone wants one for their own research.

1. https://store.arduino.cc/products/Arduino-mega-2560-rev3

Fine Control

I have recently been working on a more advanced version of my EasyTTL stimulator, this time including a dimming control for the TTL output. This is crucial if we wish to control our LED brightness for optogenetics.

Quick lesson on electronics: how do we adjust the brightness of an LED? The typical answer is to say “Adjust the voltage across the LED, or adjust the resistance of the circuit”, and in the simplest terms this will change the power the LED can use. But, it’s not a reliable way to do this, because of the exponential increase in light output across a narrow voltage range (Figure 1); with the LED I’ve shown here, a voltage change of 0.5 V will take you from very low current and negligible light output to maximal output. Furthermore, LED’s get hot during use, which changes their properties and makes them produce more light at the same voltage – this is not only terrible for ensuring precise brightness output, it can also lead to runaway heating and the LED burning out.

So, how do we fix this? This is really the whole point of using a TTL control device. The LED (or laser) is set up to drive a constant current (and it’s the current which determines the actual amount of light being produced), and then you pulse a controlling input to switch the light source on and off as you please. What this means is that a TTL is a very simple digital signal, on or off, with no information about the intensity of the signal.

So, what is an easy way to control an LED brightness for optogenetics? One answer is to use Pulse Width Modulation (PWM), which produces small pulses within your signal, but faster than your eye can detect. Essentially, you’re turning the LED on and off very fast (hundreds or thousands of times a second), and you control the brightness by adjusting the relative levels of on and off. More “on” and it’s brighter, more “off” and it’s dimmer. Simples.

Here’s how I’ve put PWM control into an Arduino Uno (Figure 2). It uses a potentiometer (also known as a variable resistor), but rather than connect directly to the LED output, we connect this to an analog input on the Arduino. The Arduino can then read the value of the potentiometer and using software we can drive an appropriate PWM output on our TTL signal.

See below for the code I wrote to control the circuit. We very simply set the LED as an output and the potentiometer as an analog input (read as “sensorValue”) – the reading needs to be adjusted by a factor of 4 to take into account the change in “bit” rate; essentially it reads the analog input on a different scale than it drives PWM output. Helpfully, Arduino has a built-in PWM function called “analogWrite”, which will drive a 490 Hz PWM based on your value.

Setting up a PWM manually is of course possible, but more of a pain. However, it is something I am likely to do in the future because, as the sharp-eyed among you may have noticed, 490 Hz produces PWM widths of around 1 ms, so it only works for pulses that are longer than that. In fact, I wouldn’t want to use it for pulses much shorter than 10 ms, because it will make the brightness output unstable from one pulse to the next. However, for the immediate future, I’m not overly bothered because I never use a pulse shorter than 10 ms anyway and the PWM produces fantastic brightness control at those speeds.

I hope you’ve found this post interesting, and I would absolutely recommend any readers to buy themselves an Arduino and some components and try this out, see how easy it is to control your LED brightness for optogenetics. However, if you do want an easy-to-use TTL driver for your optogenetics system but don’t want the hassle of building one yourself, I am planning to build some myself and make them available on this website at a reasonable cost.

EDIT 3/9/21: Doing some further investigations today, I found that the Arduino Mega has 980 Hz PWM control from pins 4 and 13, so I will connect 2 of the TTL outputs from my EasyTTL Mega device to those pins instead. This means that you will have access to higher resolution PWM control from TTL outputs 1 and 2, and should work well with on-times of 5 ms, and would probably be acceptable (but not perfect) for 2 ms on-times.