Analog Threshold TTL

Analog Threshold TTL

Output a TTL signal based on a threshold relative to an analog signal, PLUS MORE

This is a project for a particular use case, but we are posting it because it may be helpful to users/researchers beyond this particular set of requirements. Globally, three general ‘circuits’ are combined, each with their own functionality. See what these can do for your research:

  1. Non-Inverting Summing Amplifier: Just as it sounds, you can use this to add two or more analog signals together and have a protected output. That’s great and all, but a hidden power of this circuit is simply adding a boring old DC offset to an alternating analog signal. Why is this so cool? Well, most simple Analog to Digital Converters (ADC) (example: Arduino!) cannot accept negative voltages (at least without the whole, you know, starting another fire in the lab). So with this DC offset included, you can shift (in real-time) a signal that goes negative sometimes to one that is positive all the times, and input the shifted signal into lots of other systems (ADCs, Arduino boards, etc)!
  2. A Comparator Amp: Yup, compare two signals relative to each other, then output a digital signal. That is, when one signal is above another, you can output a digital (TTL, should you choose) signal. We chose to make this system really simple: With the use of an oscilloscope, you can set a threshold relative to some point on the original signal simply by turning a knob. When the original signal is higher than that threshold, a TTL output signal is sent out as high.
  3. Boolean Operations with an Arduino: This is a system to take two input TTL signals, do some math on them, and generate another TTL signal based on that outcome. For example, you can have the Arduino output a high TTL signal only when both input TTLs are high. It’s really simple, but makes sense in our particular use case.

For our particular use case, a researcher was taking some amazing 2-photon images of the brain, but saw some terrible distortion occur during particular parts of a heartbeat (crazy, right?). Well, they wanted to stop the imaging process (turn off the scanning laser) during some part of the heartbeat to preserve photobleaching, then start back up when the blood isn’t all ‘flowing and expanding the brain’. So this system was designed to take an ECG signal, apply some relative threshold, output an ECG TTL signal based on that, combine it with the laser on/off TTL, and output a combined signal to the laser when both input TTLs were present.

Know Your Signal: ONE Core Electrical Engineering Certification

  • Ground (GND): what we typically measure a voltage from; a reference point. You can use a true ground (by hammering a metal stake in the ground or electrically connecting to a water system) or, less optimally, a virtual ground in systems like a non-inverting amplifier (really, any point in a circuit can be called ground and all voltages can be compared against this point). It is a good idea to ground separate systems together.
  • Voltage (V): the potential to do work. We did work to move electrons from a neutral system relative to some other part of the system (typically ground), creating voltage. Modern electronics often ‘talk’ using a constant voltage (ex: TTL communication is 5V on/off).
  • Current (A): the actual movement of electrons. When electrons flow, work can be done. Some electronics require constant current systems, like LED’s, tissue lesions, etc.
  • Direct Current (DC): typically one set voltage, like a power supply. The current always flows in one direction, and for a given resistance value, the current will therefore always be set at a constant value as well.
  • Digital Signal: A signal, representing information, that is transmitted from one point to another with a set voltage, as either high (ex: 5 V for a TTL) or low (0 V for TTL). Often this signal can be represented as one (high) or zero (low).
  • Analog Signal: A signal that is transmitted with varying voltage. Sensors measure real world information often with varying voltages (ex: temperature gauges). These signals can be always positive relative to GND, or they may sometimes dip negative.
  • Digital to Analog Converters (DAC) and Analog to Digital Converts (ADC): Well, you guessed it, these are how to go between Digital and Analog Signals (often with loss of information). Arduino’s often have ADCs and sometimes have DACs.
  • Alternating Analog Signals: Analog signals that are known to go negative relative to GND. Typically, it is a bad idea to try and input a negative signal into an ADC, as circuits will fry!
  • Alternating Digital Signals: That…isn’t digital. What are you doing?

General Description and Schematic

The entire system can be built for very little money (under $100) using just a few simple electronic components. See below for the build instructions; but first, we’ll go through each of the three circuits and show how you can modify them for your needs.


Non-Inverting Summing Amplifier

You can find a general guide for summing amplifiers here.


For this example, V1 (our alternating analog signal) is added to V2 (our offset voltage to make V1 no longer alternating). Because our V1 just happens to be +/- 5V, we can use a 5V signal to add to V1 to make it always positive. It just so happens that the Arduino beetle can be powered by a USB cable, and therefore its positive voltage will be a very reliable 5V offset. If you are not using a 5V Arduino and don’t want to use a second power supply, you can get 5V from the current 12V power supply by using a voltage divider, as shown in the schematic; this is the only condition where R2 may be required. So, to obtain the offset of 5V, use either the Arduino, or the voltage divider (I show your choice as a switch in the lower-left corner in the schematic, but again, just choose one).

The voltage that powers the op amp (V3) must be higher than the input voltage (V1) or clipping will occur.

Fun note: The two resistors that connect to pin 2 (negative) on the op amp are the same, and therefore the op amp has unity gain. You could play with this to add a gain to the system here…

The output (V4) is a summation of V1 and V2. For this example, it is now a + 10V Analog Signal.

Comparator Amplifier

You can see a general reference for comparing amplifiers here.


For this example, we are taking the output of the Non-Inverting Summing Amp (V4, a positive 10V signal) and comparing that against some relative threshold voltage (V5). To get this threshold voltage, we can again use a voltage divider. A potentiometer is a variable resistor, and thus we are able to vary the resistance, and therefore the voltage, of V5. The output, on pin 7 of the LM358, is a digital signal: high when V4 is higher than V5, and low when not. You can invert this high/low output state, if needed, simply by inverting the inputs to the positive and negative on the op amp. This output is positive 12V when high and 0V when low. This is too high of a voltage to input into our Arduino (which accepts 5V digital signals), so we again use a voltage divider to get the appropriate voltage. For ease, we use only one resistor in the design. This results in a signal that is not 5V (come on, do the math to figure out what it is, it’s only a set of parallel resistors in a voltage divider). So what gives? Welp, learn about TTL Logic Levels here, and know that it is close enough for our Arduino.

Oh, fine, I'll steal their photo to make your life easier

All voltages herein (V4, V5, and V6) are simply relative. It is recommended that you hook up these signals to an oscilloscope as you adjust your potentiometer to simply view the signals relative to each other. You could also get all fancy and have the threshold signal come in from some other system. Or (TODO) you could input your shifted output from above (V4) to the Arduino, calculate the signal properties (Min and Max), and output a threshold based on this (example: 80% of the last 10 averaged Max minus Min). BUT if you go this route, be sure not to simply output a threshold on a PWM pin! As with LED’s, by turning down the PWM duty cycle, it may appear to your eye that you are lowering the intensity, but that is only because your eye averages over the duty cycle. In fact, the signal is still digital and is not (without other circuit components) an analog signal appropriate for setting a threshold!

The output (V6) is a near 5V TTL signal.

TTL Boolean Logic with an Arduino


We chose to use a Beetle for our Arduino, because they are very inexpensive, small, fit onto a breadboard well, and are just so gosh darn cute. When you solder in jumpers to put this into a breadboard, you can skip or cut every other jumper pin to make it fit. We could utilize analog components to do digital logic, or just use the simple Beetle. And we could do some bitwise logic (same link) to do this, or we could use some real simple if statements.

For this example we take the TTL that controls the on/off of a laser and combine it with the TTL output from our V6 TTL signal. We send out a third TTL that is high only when both input TTLs are high. Code can be found here. Be sure to set your Arduino Board as Arduino Leonardo for programming purposes.


Component Description Value Quantity $    
R1 Resistor 100 kOhm 6 8 Sparkfun  
R2 Resistor 47 kOhm 2 0, same kit Sparkfun  
Breadboard Breadboard Solderable or not, 1 5 Sparkfun  
LM358N Op Amp 2 Channel, 32 V 1 7 Amazon  
Pot Potentiometer 2 MOhm 1 12 Amazon  
BNC1, 4-8 BNC Connectors 50 Ohm, Male 6 6 Amazon  
Arduino Arduino Beetle Arduino Leonardo 1 8 Sparkfun  
  USB Cord   1 3 Sparkfun  
  Wall Plug   1 4 Sparkfun  
  12 V Power Supply   1 7 Sparkfun  
  3D-Printed Housing Mega 1 ? ONECore  
  Wire 22 gage, single core Lots   Amazon  

Component Notes

Although the schematic may look complicated, it is pretty straightforward. If you use the Arduino to act as the 5V DC power source, there is only one resistor value, used 8 times to push voltages around, which is fun.

Also, the op amp used has two channels; so two op amps appear in the same electrical component, but span two parts of the schematic. I previously said the system was real-time, and it generally is, but this super cheap-o op amp isn’t really built for speed. There is something called the slew rate which will effect how fast you can go. There is interplay between the voltage and the frequency with which this op amp will output a good signal once given an input signal. With my testing, a 10V peak-to-peak signal sinusoidal started to fall apart above 13 kHz (the output became saw-tooth rather than sinusoidal). Heads up.


Here is another look at the hand drawn schematic, including fancy crayon coloring, because I am just that lazy/artistic. Not typical schematic labeling: Voltages are labeled throughout in circles. Connections to/from the LM358 and Arduino are labeled in squares to make your life easy.


Here is the labeling

Voltage Name (if applicable) Description (as designed) Range (if applicable, as designed) BNC Arduino beetle Color
V1 Analog In Analog, Alternating Input +/- 5 V; 10 V total Amplitude BNC1 NA White
V2 Offset Voltage to add to V1 to make Analog signal all positive 5 VDC if from Arduino, 5.81 V if from V3 NA NA NA
V3 Power Supply Powers the Op Amp, Sets V2, Sets V5 12 VDC NA NA Red
V4 Positive Analog In V1 plus V2. It is what we compare threshold against 0-12 VDC BNC4 NA Yellow
V5 Threshold Turning the potentiometer will set the threshold 0-12 VDC BNC5 NA Orange (or Red)
V6 TTL Threshold 0V when Analog is below Threshold, else 5V 0 or 5 VDC BNC6 D9 Purple
V7 TTL Input, Laser Input Originally used to drive the laser 0 or 5 VDC BNC7 D10 Black
V8 TTL Output On when V6 and V7 are both 5V, else 0V 0 or 5 VDC BNC8 D11 Blue
5VDC 5V 5VDC 5V NA + Pink
GND GND Ground Zero All - Green

And to save you the googlin’, here is the schematic of the LM358 and the pinout of the Arduino beetle:



Here is a picture of the layout.


Because that’s a rat’s nest, here is a picture of the Fritzing. I am including this picture because I am too lazy to use Fritzing the right way, and just used Gimp to overlay the Arduino beetle and some other components.

pasted image 0.png

The actual Fritzing file can be found here. It is helpful to move some components around to see connections and whatnot, but the Fritzing schematic alone should not be considered viable. Some components will not be in the Fritzing schematic (ex: Arduino Beetle), so see the photoshopped pic directly above this paragraph.

ONE Core Acknowledgement

Please acknowledge the ONE Core facility in your publications. An appropriate wording would be:

“The Optogenetics and Neural Engineering (ONE) Core at the University of Colorado School of Medicine provided engineering support for this research. The ONE Core is part of the NeuroTechnology Center, funded in part by the School of Medicine and by the National Institute of Neurological Disorders and Stroke of the National Institutes of Health under award number P30NS048154.”