digitalWrite question (solved)

I am writing a sketch where I need a pin (pin 5 7) to go to LOW under a certain condition. I am using it as a ‘relay’ to control another board which does its thing when I ground the signal. I was hoping to be able to ground the signal through the pin and not use another part.

Problem is, pin 5 7 seems to go LOW at the start of the program and ‘stays’ there. So it triggers my other board when I first reset the sketch but not when the IF condition has been met.

Here is the code -

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  bmp085Calibration();
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressurex = bmp085GetPressure(bmp085ReadUP());
  pressureCall = (pressurex - 20);
  Serial.print(pressurex);
  Serial.println();
  Serial.print(pressureCall);
  pinMode(13, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop()
{
   
  pressure = bmp085GetPressure(bmp085ReadUP());
     Serial.print("Temperature: ");
  Serial.print(temperature, DEC);
  Serial.println(" *0.1 deg C");
  Serial.print("Pressure: ");
  Serial.print(pressure, DEC);
  Serial.println(" Pa");
  Serial.println();
  delay(1000);
  altitude = (float)44330 * (1 - pow(((float) pressure/p0), 0.190295));
  Serial.print("Altitude: ");
  Serial.print(altitude, 2);
  Serial.println(" m"); 
  if (pressure < pressureCall)
   {
    digitalWrite(13, HIGH);
    digitalWrite(7, LOW);
    Serial.println();
    Serial.print("You Are High!");
    while(1);
  }

}

Any ideas?

Your code mentions pin 7 and pin 13, but not pin 5...

I presume you forgot to set the output state to HIGH before enabling it:

  digitalWrite (pin, HIGH) ;
  pinMode (pin, OUTPUT) ;

I see no code that mentions pin 5 in any way?!?

I see no code that declares temperature, or pressure, or...

I don't see any CODE TAGS either. :0

hee hee apart from that - spot on!

mmcp42:
I see no code that mentions pin 5 in any way?!?

My goof - meant Pin 7

I don’t want it set to HIGH is if I can avoid it.

But I think I figured it out with this -

Instead of setting pinMode in setup I put it in the routine after the condition

Here is the updated code - (by the way this is just a snippet of the whole code)

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  bmp085Calibration();
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressurex = bmp085GetPressure(bmp085ReadUP());
  pressureCall = (pressurex - 20);
  Serial.print(pressurex);
  Serial.println();
  Serial.print(pressureCall);
  pinMode(13, OUTPUT);
  }

void loop()
{
   
  pressure = bmp085GetPressure(bmp085ReadUP());
     Serial.print("Temperature: ");
  Serial.print(temperature, DEC);
  Serial.println(" *0.1 deg C");
  Serial.print("Pressure: ");
  Serial.print(pressure, DEC);
  Serial.println(" Pa");
  Serial.println();
  delay(1000);
  altitude = (float)44330 * (1 - pow(((float) pressure/p0), 0.190295));
  Serial.print("Altitude: ");
  Serial.print(altitude, 2);
  Serial.println(" m"); 
  if (pressure < pressureCall)
   {
    digitalWrite(13, HIGH);
    pinMode(7, OUTPUT);
    digitalWrite(7, LOW);
    Serial.println();
    Serial.print("You Are High!");
    while(1);
  }

}

AWOL: I see no code that declares temperature, or pressure, or...

I don't see any CODE TAGS either. :0

This was just a bit of the code... //sorry to raise your ire with the lack of CODE TAGS

so put [ code] in front of it [ /code] at the end of it

Don't worry, I've added them.

AWOL: Don't worry, I've added them.

Thanks. Newbie goof...