What is this TTL/PWM stuff about?

The reason for writing this article is the post about me building a laser engraver. I decided to make this an article of its own, because it might be interesting enough for other purposes.


Digging in a bit further when investigating why my laser module claims to support both TTL and PWM (how two?) I found that TTL is just a digital signal with 5 volt being HIGH and 0 volt being LOW.

Well, that’s actually oversimplifying things, in reality there are some thresholds like anything up to 0,4 volt being LOW and anything above 2,4 volts being HIGH or something along those lines according to wikipedia. At least conceptually however, 0 volt is LOW and 5 volt is HIGH.

Translating this to a laser it would mean that providing it with 0 volts would have it turned off and providing it with 5 volts would turn it on.


PWM is a way to modulate intensity using a digital signal when controlling for example an LED or a motor or something else I haven’t imagined. It will definitely not work for all devices, but motors and LED’s are good examples of what works.

Basically PWM allows you to drive the brightness of an LED or the speed of a motor. It does so using a digital signal that is turned LOW or HIGH over time and hence you could say that it uses TTL (at least when the voltage is 5 volt, for other voltages I guess it is not TTL in a pure sense?).

If we want an LED to be completely lit we will supply it the HIGH voltage. When we want it completely turned off we supply the LOW voltage (0 volt). If we want to control the brightness we give a signal that varies between LOW and HIGH over time. So if we want a brightness of 50% that means we give it a signal that is LOW 50% of the time and HIGH the other 50% of the time. This works because we repeat this really fast. The process of turning it on and off is in a very small time frame.

To illustrate what PWM does I have created a simulation using tinkercad. It shows an LED fading from off to on. On the right side of the LED it shows the signal on a simulated oscilloscope, which is a square wave. ezgif-3-3b780b172ec6

By ranging the width of the block in the square wave we control the amount of time it is LOW or HIGH and thus when it is on or off. By doing this really fast we can control brightness, speed or other stuff I haven’t imagined.

The code for the Arduino is:

int led_port = 9;   // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 1; // how many points to fade the LED by

void setup() {
  pinMode(led_port, OUTPUT);

void loop() {
  analogWrite(led_port, brightness);

  brightness = brightness + fadeAmount;
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;


Leave a Reply

Your email address will not be published.