not declared in this scope

hello

i have a problem
i am new in this filed, please help me

i don’t what’s the problem with this code, everytime i get this message “Switch_pin’ was not declared in this scope” please help me !

this is my code

void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
if ( switch_pin == HIGH) {
digitalWrite(inletValvePin,HIGH); // turn pressure valve HIGH
digitalWrite(pumpPin,HIGH); // make sure pump is on
digitalWrite(exhaustValvePin,LOW); // turn exhaust valve LOW
digitalWrite(ledPin,HIGH); // LED ON
}

if ( switch_pin == LOW) {
digitalWrite(inletValvePin,LOW); // turn pressure valve HIGH
digitalWrite(pumpPin,LOW); // pump is off
digitalWrite(exhaustValvePin,HIGH); // turn exhaust valve HIGH
digitalWrite(ledPin,LOW); // LED off
}
sensorValue = analogRead(analogInPin);

// digital value of pressure sensor voltage
voltage_mv = (sensorValue * reference_voltage_mv) / ADCFULLSCALE;

// pressure sensor voltage in mV
voltage_v = voltage_mv / 1000;

output_pressure = ( ( (voltage_v - (0.10 * (reference_voltage_mv/1000) )) * (Pmax - Pmin) ) / (0.8 * (reference_voltage_mv/1000) ) ) + Pmin;

if (sensorValue <= desiredValue) {
analogWrite(pumpPin,255); // Pump. (0 is off) and (255 is on)
digitalWrite(inletValvePin,HIGH); // open the air valve
digitalWrite(exhaustValvePin,LOW); // close the exhaust valve
}

if (sensorValue > desiredValue) {
while (analogRead(A0) > (desiredValue - tolerance) ) {
analogWrite(pumpPin,190); // reduce speed of pump
digitalWrite(inletValvePin,HIGH); // open the air valve
digitalWrite(exhaustValvePin,LOW); // close the exhaust valve
}
}
}

None of your variables are defined or declared.

Please remember to use code tags when posting code.

Please don't waste your precious time looking for this topic's duplicate; I deleted it.

  if ( switch_pin == HIGH)As a guess based on the name, you have a switch connected to an Arduino pin and want to test whether the pin is HIGH or LOW.

You should probably be using digitalRead() on the pin and testing the value returned, not the value of switch_pin itself. The value of switch_pin is not changed by your program

Before you post code here using code tags, place the cursor in the IDE's source code window and then press Ctrl-T. This will reformat your code into a common C style that's easier for us to read.

Cloud_zzx:
i don't what's the problem with this code, everytime i get this message "Switch_pin' was not declared in this scope" please help me !

Typically, at or near the top of your sketch, you assign names to various pins:

const byte switch_pin = 2;
const byte inletValvePin = 3;
const byte pumpPin = 4;
const byte exhaustValvePin = 5;
const byte ledPin = 13;
const byte analogInPin = A0;

Adding those helps but you also have a bunch of variables that are used but not defined. Unlike some languages, you have to tell the compiler what type each variable is. In many cases it is as easy as adding 'int' or 'float' in front of the firt use of the variable. For named constants like your 'reference_voltage_mv' you would typically put that up near the pin declarations.

Also if you indent the code , then you can check you have matching number of {} brackets , which tends to give none obvious compile errors and can be otherwise hard to spot