Project Guidance required......pleasez help

Good Morning All,

I'm in a 2nd year college student making project to set time duration in minutes to turn ON and OFF of MOTOR.

IM stuck in this please help.

Want learn and explore more in coding and arduino use.

Below is my code where im using led right now later i will add motor.

please reply anyone who can guide me.

int button1 =5;
  int button2 =6;
  int led =4;
  int Time=0;
  void setup() {
    // put your setup code here, to run once:
  
    Serial.print(9600);
    pinMode(button1,INPUT);
    pinMode(button2,INPUT);
    pinMode(led,OUTPUT);
  
  }
  
  void loop() {
    // put your main code here, to run repeatedly:
  
    int Onbutton=digitalRead(button1);
    
    int Offbutton=digitalRead(button2);
    
    if(Onbutton==HIGH)
    {
      Time++;
      digitalWrite(led,HIGH);
      Serial.print("led ON");
      Serial.print(Time); 
    }
  
    if(Offbutton==HIGH)
    {
      Time--;
      digitalWrite(led,LOW);
      Serial.print("led OFF");
      Serial.print(Time); 
    }
  
  }

You haven't said what the problem is, but I going to guess:
a) floating input
b) You're doing things while the button is pressed, not when the button becomes pressed.

Thanks Awol Sir for reply.

Problem I'm facing is when i press button1 it should increment the time per minute and set time for motor to run and then when i press button2 it should decrement time per minute to Off motor.

Automatically it should then ON and OFF the motor till the time arduino have power.

I think there's a state change example provided in the IDE.

But how to add minute time to ON AND OFF MOTOR.

When the state of a switch changes, increment or decrement a variable, depending on which switch has changed state.

Is it Ok SIR.

int button1 =5;
  int button2 =6;
  int led =4;
  int Time=0;

  int lastButtonState=0;
  void setup() {
    // put your setup code here, to run once:
  
    Serial.print(9600);
    pinMode(button1,INPUT);
    pinMode(button2,INPUT);
    pinMode(led,OUTPUT);
  
  }
  
  void loop() {
    // put your main code here, to run repeatedly:
  
    int Onbutton=digitalRead(button1);
    
    int Offbutton=digitalRead(button2);
    
   if (Onbutton != lastButtonState)
    {
      if (Onbutton == HIGH)
      {
      Time++;
      digitalWrite(led,HIGH);
      Serial.print("led ON");
      Serial.print(Time); 
    }
    }
  lastButtonState=Onbutton;
  
    if (Offbutton != lastButtonState)
    {
      if (Offbutton == HIGH)
      {
    
      Time--;
      digitalWrite(led,LOW);
      Serial.print("led OFF");
      Serial.print(Time); 
    }
  
  }
  lastButtonState=Offbutton;
    }

No it is not OK.
How have you wired the buttons. You should wire them between input and ground and use the INPUT_PULLUP in the setup.

Next you need a last state variable for each of the buttons you can not shair them.

Given the title of this section the title of this thread is some what silly.

Grummy_Mike i wish you could help me.

Im new in coding ..

please help.

Mike is helping - what are you doing?

I really dont get Mike what he said...

Im reading some article where i can get some hint....

But not yet got what i required...

My only point is how motor will sense that following minutes is set to ON and OFF.

means any timer function or library i have used for that?

Sorry for trouble but i want to learn this how to do it.

Mike wrote that you can't share a "lastButtonState" - the code must have a last state for each switch.

Thanks sir got it.