Cannot give binary number to arduino and display the value at the same time

Good day,

what I'm doing with my project now is giving a binary 4bits value to my DAC circuit to determine the value of voltage.

the code that i used for determine voltage from 4bits binary number is

void setup() 
{


  pinMode(0, OUTPUT);  //from D0,D1,D2,D3
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT); 
  pinMode(3, OUTPUT);

  
}
void loop() 
{

  digitalWrite(0, LOW);     // this is a binary value for 0 0 0 0 
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);

  

}

and when i want to display the value of voltage that i get from my binary number i use this code

void setup() 
{

  Serial.begin(9600);

  pinMode(0, OUTPUT); 
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT); 
  pinMode(3, OUTPUT);

  
}
void loop() 
{

  digitalWrite(0, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);

  int sensorValue01 = analogRead(A0);
  float voltage01 = sensorValue01 * (5.0 / 1024.0)+0.09;
  Serial.print("Final Temperature Voltage =  ");
  Serial.println(voltage01);
  
  delay(1000);

}

i can show the voltage value that but when i give the binary output to show the voltage at the same time, its not working. :frowning:

any help? much appreciated

Serial.begin(9600);

  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
// and in loop()
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);

If you want to use serial to output to serial monitor, don’t use pins 0 and 1 (hardware serial pins on most Arduino compatible boards).

thanks for reply! :slight_smile:

so you mean i need to start using code from pin 2?

example

 pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
// and in loop()
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);

so you mean i need to start using code from pin 2?

Yes. Use pins 2, 3, 4, 5 (or any pins that are not 0 or 1). Move the DAC inputs to those pins and set those pins to OUTPUT with pinMode.

like that?

No. digitalWrite the 4 bits to the pins that are now connected to the DAC.

is working now thank you ! much appreciated! :wink:

i just wondering if u can help me with this,

i wanna make if voltage in range of 1.949 to 3.155 = temperature in range

if voltage < 1.949 = temperature is too cold

if voltage > 3.155 = temperature is to hot.

i am using this code to do this, which is if else statement,

if (sensorValue01 >= 1.94 && sensorValue01 <= 3.16)
    {
      Serial.print("Baby in great temperature range");
    }

but i dont know how to continue for the rest :frowning:

if (sensorValue01 >= 1.94 && sensorValue01 <= 3.16)
    {
      Serial.print("Baby in great temperature range");
    }
else if(sensorValue01 < 1.94)
    {
       Serial.print("Too cold!");
     }
 else  // not cold, not just right, must be too hot
     {
        Serial.print("Too hot!");
     }

See https://www.arduino.cc/en/Reference/Else