serious guidance required for a motion sensor (sort of) device

currently doing a group project, and i have no previous programming experience at all.
I have been trying to teach myself by going through quiet a bit of example and tutorial and try changing the value and understand the program. but when trying putting lots of different codes by combining lots of different if and else together and always getting error etc,

So i need to make a program, which will detect movement, using a very basic vibration switch, which will only give a result 0 or 1 (off or on) and to have two counters (one of the bits that i am very struggle to get it work) one for timer (in second), and one for how many value of “1” received (which will be our actcounter). The vibration switch will be getting value every 1 sec and if the value is greater than 0, it will perform an action. and if actcounter >1800, it will delay (3600 - counter) ← (i am not 100% sure about it myself). Then if counter >3600, it will have another if and else statement

This is the program i try to write, based on my notes and self taught, so expect to have many mistakes and silly things

byte counter;
byte actcounter;

void setup() {
pinMode(0, INPUT); // sets digital pin 0 as an input
pinMode(8, OUTPUT); //Green LED
pinMode(9, OUTPUT);
pinMode(6, OUTPUT); //RED LED
pinMode(7, OUTPUT);

digitalWrite(8, LOW); // as pin 8 is our led cathode, this pulls the voltage to gnd
digitalWrite(6, LOW);

;
}

void loop() {
if(digitalRead(0)>0) // check if the input is HIGH (i.e. == 1)
{
digitalWrite(8, HIGH);
actcounter++;
}
else if { // otherwise…
digitalWrite(6,HIGH); // switch LED on
}
delay(1000); // wait for 1 second
else if (actcounter>=1800){
delay(3600-counter);
}
else if (counter>=3600){
counter==0
digitalWrite(8,LOW);
}
else{
counter++
digitalWrite(6, High);
delay(100);
digitalWrite(6, LOW);
}
}

this is some of the error i get
e.g. final.cpp: In function ‘void loop()’:
final:23: error: expected (' before '{' token final:27: error: 'else' without a previous 'if' final:32: error: expected ;’ before ‘digitalWrite’
final:36: error: expected `;’ before ‘}’ token

please would anyone guide me to the right direction

Post your code using the # code button.
Do you have an arduino?

Your braces } don't seem to match up to well with the code and 3600 is greater than 1800.

Like I said repost your code but first try to build up your if statement bit by bit, compiling each time and correcting any errors.

"Else if" what?

Lay your code out properly. Put each { and } on a separate line and indent the lines in between them. This makes it visually obvious how they are supposed to pair up, and make it much easier to see where you have got them mismatched.

I think the else if{ is pretty obvious

yes i do have the audrino with me gonna start a new one n test each little bits to get it work

byte counter;
byte actcounter;

void setup() {
pinMode(2, INPUT); //pin 2 as input
pinMode(8, OUTPUT); //Green LED
pinMode(9, OUTPUT);
pinMode(6, OUTPUT); //RED LED
pinMode(7, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(6, LOW);
int counter = 0;
int actcounter = 0;
}

void loop(){
if(digitalRead(2)>0){
digitalWrite(7, LOW);
digitalWrite(9, HIGH);
actcounter++;
}
else{
digitalWrite(9, LOW);
digitalWrite(7, HIGH);
}
delay(1000);
if(actcounter>1800){
delay(3600-counter);
}
else
{
//do thing B
}
if (counter>=3600){
counter=0;
digitalWrite(9, LOW);
}
else
{
digitalWrite(7, HIGH);
delay(100);
digitalWrite(7, LOW);
delay(100);
digitalWrite(7, HIGH);
delay(100);
digitalWrite(7, LOW);
counter++;
}

}

i have tidy up the program, no problem in uploading,
but currently not doing what i want.
when switch is not pressed/vibrate the RED red (pin 7) just keep on flashing. when it is pressed/ vibrate the green LED will come on but red led still flashing

actcounter is never, ever going to reach 1800.
Nor is counter going to get past 255.

an suggestion that i can have counter that can count for an hour
I want it to take data from the switch every second or even 1/4 sec , and if number of data (number of 1 since the vibration only has either 0 or 1) is greater than 1800, it will then delay (3600 - counter)
the counter will counter every seconds

change the top bit to
int counter = 0;
int actcounter =0;
?

Yup, make 'em "int"s

right thats changed.
i still don’t understand why it keep on flashing the red led when i am not doing amything to the switch…

whitepanda:
i still don't understand why it keep on flashing the red led when i am not doing amything to the switch....

Well assuming pin 7 has the red led on it (Comments to the contrary), this code:

if (counter>=3600){
    counter=0;
    digitalWrite(9, LOW);
  }
  else
  {
    digitalWrite(7, HIGH);
    delay(100);
    digitalWrite(7, LOW);
    delay(100);
    digitalWrite(7, HIGH);
    delay(100);
    digitalWrite(7, LOW);
    counter++;
  }

runs on every iteration of the loop, irrespective of whether you did anything with the switch or not, which would account for the behaviour you see.

so my program completely ignore the middle part?

Can you elaborate a bit on what you want the system to do?

If counter < 3600 you are going to be flashing pin 7 on and off.
As soon as counter gets to 3600 you set it to 0 so it will, more or less instantly start flashing pin 7 on and off.

Since I am not the best to explain stuff, so i draw the flow chart

the system is kind of a motion sensor, it will monitor movement using a vibration switch (very very sensitive), and taking data probably every 1 second and give feedback with Green LED and red led at the same time, Green mean yes there is movement, Red mean no. After an hour it will give an overall feedback. e.g. lets say there were 3600 data in an hour, and if the number of YES(s) are 1800 or more it will turn LED off and repeat the program over again. otherwise red led will flash for few times and repeat the program

in the flowchart the digitalread(0) should be digitalread(2)>0

any one got any idea?

Flowcharts are a good idea. Look at the bottom of yours, counter will almost always be less than 3600 so the program will almost always be going up the right hand side and flashing the red LED. When counter get to 3600 it will go up the left hand side once and zero counter, then start going up the right hand side again. It is always going to look like the red LED is flashing.

The design seems odd - what is the delay(3600-counter) for? Also, it seems as though if you're not watching the device very closely, you will miss the hourly led flashing report. Would it make sense to have another led to indicate whether there was activity detected on more than half the sensor reads in the hour? Or in other words - what is this device supposed to be used for?