I need help with my programming for "if" structure

Cant get this work when it comes to “if(digitalRead(4) == LOW)”.

The flow of the program is when digital read 3 is high, there will be an increment in the touchcounter making if(touchcounter == 1 ) to be true. Next is reading the state of (digitalRead(4) == LOW), if its true the counter will increment to the counter . if(counter == 1), the program will run. the problem im facing right now is having the program stuck at “if(digitalRead(4) ==LOW)”.

here is the full programming :

int touch = 3;
int button = 4;
int led = 12;
int touchcounter;
int counter;

void setup()
{
pinMode(4, INPUT_PULLUP);
pinMode(3, INPUT);
pinMode(12, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
counter = 0;
touchcounter = 0;

Serial.begin(9600);
}

void loop()
{
if(digitalRead(3) == HIGH)
{
touchcounter = touchcounter + 1;
delay(500);
Serial.print("touchcounter: ");
Serial.print(touchcounter);

if(touchcounter == 1)
{
if(digitalRead(4) == LOW)
{
counter = counter + 1;
delay(500);
Serial.println("push counter: ");
Serial.print(counter);

if(counter == 1)
{
int val;
int dat;
val=analogRead(0);//Connect LM35 on Analog 0
dat=(500 * val) /1024;;
Serial.print(“Temp:”); //Display the temperature on Serial monitor
Serial.print(dat);
Serial.println(“C”);
delay(500);

if(dat>25)
{
digitalWrite(12, HIGH);
}
else
{
digitalWrite(12, LOW);
}
}

if(counter == 2)
{
int val1;
val1=analogRead(1);
Serial.println(val1,DEC);
delay(100);

if(val1>500)
{
digitalWrite(12, HIGH);
}
else
{
digitalWrite(12, LOW);
}
counter = counter - 2;
}
}
}

if(touchcounter == 2)
{
digitalWrite(12, LOW);
counter = 0;
touchcounter = touchcounter - 2;
Serial.print(“System is shutdown”);
}
}
}

MYASSIGNMENT.ino (1.71 KB)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Check your analogRead(0) it should be analogRead(A0)
likewise your other analogRead

Thanks.. Tom.. :slight_smile:

You are aware that to increment the push counter, pin 3 must be high and pin 4 must be low at basically the same time (ok, you have given yourself 500 ms to take your finger of the touch and onto the button).