How to output to a pin from serial.port

This sketch outputs to serial monitor I want to output the voltage to a to a pwm pin.
I can't figure this out.
Program just takes a 0 - 5 v in and maps it to 2.5 v to 5.0v

// map input voltage + or - switch with encoder direction or motor voltage
//float ledPin = 5;
//float outputVoltage;
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(ledPin,OUTPUT);
}

void loop() {
float inputVoltage = analogRead(A0) * (5.0 / 1023.0); // Read input voltage (0-5V)

// Map input voltage from 0-5V to 2.5-5V
float outputVoltage = map(inputVoltage * 1000, 0, 5000, 2500, 5000) / 1000.0; // Map to millivolts and back to volts

Serial.print("Input Voltage: ");

Serial.print(inputVoltage);
Serial.print("V, Mapped Voltage: ");
Serial.print(outputVoltage);

Serial.println("V");

Thanks
Ken

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

For You and for us, please read and practise this link: How to get the best out of this forum - Using Arduino / IDE 1.x - Arduino Forum

Please read the Arduino/reference to find out how the map function can be use. This way will not do what You want.

Depending on the controller the syntax is "analogWrite( pinNumber, value);" where max value is 255 for some controllers, higher for others.
Make sure to use a pin that provides PWM.

"Duty cycle." because the voltage only will be GND or VCC.

https://docs.arduino.cc/learn/microcontrollers/analog-output/

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.