Motor circuit with AND control

Hi.
I am trying to transfer code from PBASIC to work on the Arduino - using High School examination questions to get them to move from flow charts/PBASIC to using the Arduino Uno.

I have the following circuit and code:

int guard = 7;
int switchPin = 6;
int motorPin = 9;

void setup(){
pinMode(guard,INPUT);
pinMode(switchPin,INPUT);
pinMode(motorPin,OUTPUT);
}

void loop(){
if (digitalRead(guard==HIGH)&&digitalRead(switchPin==HIGH)) //&&

{

digitalWrite(motorPin,HIGH);
delay(500);
digitalWrite(motorPin,LOW);
delay(1000);
}
else {

digitalWrite(motorPin,LOW);
}

}

The problem seems to be that the switches are being ignored. The motor works the way that it should but should only start when both switches are HIGH.

Any tips?

Thank you in advance

Debs

Int 2 platform lowering.pdf (245 KB)

Fix the switch wiring.

Mark

Look closely at your digitalReads - you're reading pin zero

Hi,
Read the switches then do the test, will make for a more readable sketch.

Tom.... :slight_smile:

thankyou. Problem was with my digitalReads. The switches seemed to be fine. It's all working properly now, which is great.

Debs