can i use a pwm pin to power a transistor with variable voltage ?

hi guys

i tried to power a transistor with a pwm pin but when i try to measure the voltage
that it provides with another analog pin i get a lot of zeros on the serial monitor! :

void loop() {
  for(int i=0; i<255;i = i+1){
    analogWrite(pwm,i);
    vbb[i]= analogRead(Rb) ;
    delay(100);
   Serial.println(vbb[i]);
  }

my question is could the analogRead measure the pwm output as analog data or its not possible ?
could i power a transistor with this pwm and would it recognize it as a variable voltage or not ?

PWM is NOT a variable voltage. It is a pulse wave with variable mark/space. When you read it you are likely to see either 0 or 1023 depending on where exactly in the cycle you happen to catch it.

Most loads like a motor or LEDs will react as though they are being driven by a variable voltage but they are not. It is just the AVERAGE voltage that varies.

Steve

If you add a suitable capacitor and resistor to ground, you can achieve a variable voltage with a PWM source.