Noob attempting Digital to Analog Conversion (DAC)

Hello,

I am fairly new to micro-controllers and have only a short background in electrical theory and terminology. So please bear with me.

I have a pH sensor that connects to the rx and tx pins on the arduino. I am using pins 2 and 3

However, I would like to output an analog voltage that correlates to the sensors read values from one of the arduino pins. This will be so that the signal can be read by a separate board I prefer to use for my project that can only handle analog inputs.

I found an example on how to do the conversion, although it is using a single input pin_3 in this case. and converting that into an analog output pin_9. In my case I have both the rx and tx pins plugged into the Arduino communicating with the sensor and desire to output the analog signal say thu pin_9. How would I go about coding my “inPin”. How does the coding need to be changed to incorporate the rx and tx values? Can I just simply use my rx pin as my “inpin” ?

I have pasted both the example code I intend to follow for the conversion and for the ph sensor itself below.

int pwmPin = 9; // output pin supporting PWM
int inPin = 3; // voltage connected to analog pin 3, e.g. a potentiometer
int val = 0; // variable to store the read value
float volt = 0; // variable to hold the voltage read
void setup()
{
pinMode(pwmPin, OUTPUT); // sets the pin as output
}
void loop()
{
val = analogRead(inPin); // read the input pin
volt =(5.0 * val) / 1023;
val = 255 * (volt / 5);
analogWrite(pwmPin, val);
}

Here is the code used for operating the pH sensor:

//This code was written to be easy to understand.
//Code efficiency was not considered.
//Modify this code as you see fit.
//This code will output data to the Arduino serial monitor.
//Type commands into the Arduino serial monitor to control the pH circuit.
//This code was written in the Arduino 1.6.5 IDE
//An Arduino UNO was used to test this code.


#include <SoftwareSerial.h>                           //we have to include the SoftwareSerial library, or else we can't use it.
#define rx 2                                          //define what pin rx is going to be.
#define tx 3                                          //define what pin tx is going to be.


SoftwareSerial myserial(rx, tx);                      //define how the soft serial port is going to work.


String inputstring = "";                              //a string to hold incoming data from the PC
String sensorstring = "";                             //a string to hold the data from the Atlas Scientific product
boolean input_stringcomplete = false;                 //have we received all the data from the PC
boolean sensor_stringcomplete = false;                //have we received all the data from the Atlas Scientific product
float ph;                                             //used to hold a floating point number that is the pH. 



void setup() {                                        //set up the hardware
  Serial.begin(9600);                                 //set baud rate for the hardware serial port_0 to 9600
  myserial.begin(9600);                               //set baud rate for software serial port_3 to 9600
  inputstring.reserve(10);                            //set aside some bytes for receiving data from the PC
  sensorstring.reserve(30);                           //set aside some bytes for receiving data from Atlas Scientific product
}


void serialEvent() {                                  //if the hardware serial port_0 receives a char
  char inchar = (char)Serial.read();                  //get the char we just received
  inputstring += inchar;                              //add it to the inputString
  if (inchar == '\r') {                               
    input_stringcomplete = true;                      //if the incoming character is a <CR>, set the flag
  }
}

void loop() {                                         //here we go...

  if (input_stringcomplete) {                         //if a string from the PC has been received in its entirety                     
    myserial.print(inputstring);                      //send that string to the Atlas Scientific product
    inputstring = "";                                 //clear the string
    input_stringcomplete = false;                     //reset the flag used to tell if we have received a completed string from the PC      
  }

  if (myserial.available() > 0) {                     //if we see that the Atlas Scientific product has sent a character.
    char inchar = (char)myserial.read();              //get the char we just received
    sensorstring += inchar;
    if (inchar == '\r') {
      sensor_stringcomplete = true;                   //if the incoming character is a <CR>, set the flag
    }
  }


  if (sensor_stringcomplete) {                        //if a string from the Atlas Scientific product has been received in its entirety
    Serial.println(sensorstring);                     //send that string to the PC's serial monitor
    ph = sensorstring.toFloat();                      //convert the string to a floating point number so it can be evaluated by the Arduino

    if (ph >= 7.0) {                                  //if the pH is greater than or equal to 7.0
      Serial.println("high");                         //print "high" this is demonstrating that the Arduino is evaluating the pH as a number and not as a string
    }

    if (ph <= 6.999) {                                //if the pH is less than or equal to 6.999
      Serial.println("low");                          //print "low" this is demonstrating that the Arduino is evaluating the pH as a number and not as a string
    }

    sensorstring = "";                                //clear the string:
    sensor_stringcomplete = false;                    //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
  }
}

Use analogWrite() for analog (PWM) output. Map the obtained pH value into the range acceptable to analogWrite().