The following example helps you to understand the stuff better. Suppose the slider of the potentiometer is adjusted so that the voltage at its slider is 3V. Since the slider terminal is connected to A0 pin, the voltage at A0 pin will be also 3V. analogRead function in arduino reads the voltage (between 0 to 5V) at the analog input pin,converts it in to a digital value between 0 and 1023 and stores it in a variable. Since the analog input voltage here is 3 volts the digital reading will be 3/(5/1023) which is equal to 613. This 613 will be saved to variable t2 (low time). Then t2 is subtracted from 1000 and the result which is 387 is stored in variable t1 (high time). Then digital pin will be switched on for t1 uS and switched off for t2 uS and the cycle is repeated. The result will be a square wave with high time = 387 uS and low time = 613 uS and the time period will be always 1000uS. The duty cycle of this wave form will be (387/(387+613))*100 which is equal to 38.7%. The wave form will look something like what is shown below. int pwm = 12; // assigns pin 12 to variable pwm int pot = A0; // assigns analog input A0 to variable pot int t1 = 0; // declares variable t1 int t2 = 0; // declares variable t2 void setup() // setup loop { pinMode(pwm, OUTPUT); // declares pin 12 as output pinMode(pot, INPUT); // declares pin A0 as input } void loop() { t2= analogRead(pot); // reads the voltage at A0 and saves in t2 t1= 1000-t2; // subtracts t2 from 1000 ans saves the result in t1 digitalWrite(pwm, HIGH); // sets pin 12 HIGH delayMicroseconds(t1); // waits for t1 uS (high time) digitalWrite(pwm, LOW); // sets pin 12 LOW delayMicroseconds(t2); // waits for t2 uS (low time) }