How to use a signal to output 5v voltage?

#include "mbed.h"

AnalogIn ain(A0);
DigitalOut dout(D0);

int main() {
    while(1){
        if(ain > 0.3f){
            dout = 1;
        } else {
            dout = 0; // setup output as low
        }
        wait(0.2f);
    }
}

So this is my code, the device I’m using is nucleo-f466re. Does anyone know how I could output a 5V voltage using a signal?

Hi there,

please format your code like this

```
your code
```

You can’t set it to 5V because the ARM chips working on 3.3V. You need to use a transistor. The transistor will be controlled via your 3.3V GPIO pin and the transistor will drive 5v for your output.
Another option can be an operation amplifier or a voltage level shifter, depends on the application.

BR, Jan

1 Like

Alright, thanks for your reply!