how do i wait for a pin to become HIGH

in the setup i want to halt the program and wait until a pin is set to HIGH the pin i am looking at to watch is val

i cant do anything else until unit is on val=high

is there a way to wait for this?

how can i do this

  val = digitalRead(RI);   // read the input pin
  Serial.print("Value of val= ");

if (val == 0) {
   Serial.println ("Unit Turned Off");// Turn on unit
   digitalWrite(PWR, HIGH);
   delay(3000);
   digitalWrite(PWR, LOW);
} else {
   Serial.println("Unit is tuned On");// Do Nothing
}

use a while cycle, it will continue to cycle untill the condition is matched why are you powering it on and off after the delay?

PWR,Pin this is soft power switch for the module, you can pull it to high level for at least 2s to power up or power down the module.

the value pin this pin will tell you whether the module is on and is there any calls and messages received. It will be pulled to high level when the module is on. And it will change to low for 120ms when a call or message is received.

i have come up with this reading the voltage from the pin of the GSM card i worked out that when the card id powered off the voltage drops to 0.2v and when it’s on the voltage goes between 1.6 and 1.8

    ReadIfOn();
    Serial.print("Value of val= ");
    Serial.println(val);
  if (val < 1.6) {
   Serial.println ("Unit Turned Off");// Turn on unit
   digitalWrite(FONA_PWR, HIGH);
   delay(3000);
   digitalWrite(FONA_PWR, LOW);
                                 while(val< 1.6){
                                  Serial.println("waiting");
                                  Serial.print("Value of val= ");
                                  Serial.println(val);
                                  delay(2000);
                                  ReadIfOn();
                                }
} else {
   Serial.println("Unit is tuned On Doing Nothing");// Do Nothing
}

  Serial.println("Setup DONE!");
  
}

void ReadIfOn(){
        // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float Volt = sensorValue * (3.6 / 1023.0);
  val = Volt;
  
  // print out the value you read:
  Serial.print("Value Of Volt = ");
  Serial.println(Volt);
  Serial.print("Value Of Val = ");
  Serial.println(val);
  
}

its seems to work but the pin is showing various voltage readings it’s supposed to pull LOW when the unit is off but sometimes when it’s off i’m still getting readings of 1.8 and im confused

If you are content for the Arduino to do nothing else while waiting for the pin to go HIGH you can just use a simple WHILE like this

while(digitalRead(pinNum) == LOW) {
}

…R

mikewitney: i have come up with this reading the voltage from the pin of the GSM card i worked out that when the card id powered off the voltage drops to 0.2v and when it's on the voltage goes between 1.6 and 1.8

its seems to work but the pin is showing various voltage readings it's supposed to pull LOW when the unit is off but sometimes when it's off i'm still getting readings of 1.8 and im confused

digital pins tend to float. To ensure it goes to 0v add a large resistor like a 1mohm to ground and that will pull the pin all the way to 0.