Arduino chicken coop door

hello i am trying to make an Arduino coop door i am using a l298n h bridge with an ldr. here is my code, any help or ideas?

int enB = 5;
int in3 = 7;
int in4 = 6;

int laststate;

void setup() {
pinMode(enB, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
laststate == LOW;
}

void loop(){

if(analogRead(1) < 500 && laststate == LOW) {
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(4000);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(1000);
laststate == HIGH;
}
else
{
}

if(analogRead(1) > 100 && laststate == HIGH){
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(4000);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(1000);
laststate == LOW;
}
else{

}

}

What does “enB, in3 and in4” represent?
Why the empty else clauses?
What kind of motor, step or DC, required Volts and Amps?
Describe what you expect the program to do.
You should put your code in a “code box” by clicking the ( </> ) symbol at top left of the reply screen, then highlight, copy and paste your code into the box that appears.

Hi,

also, if the sketch does not work as expected, it would be nice to have a description of the issue(s) and the tests that you have done as part of your troubleshooting...

Thanks !

dan

Welcome to the Forum. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags ("</>") when posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button.

…and this does absolutely nothing:

    else
    {
      }

Twice.

    laststate == LOW;

Perform a comparison and chuck* away the result?
Nope.

    laststate = LOW;is most likely what you intended.

*Little chicken coop-related gag there :wink:

There are lots of Forum Threads about chicken coops. They may already have a solution for your problem.

...R

jcallen:
What does “enB, in3 and in4” represent?
Why the empty else clauses?
What kind of motor, step or DC, required Volts and Amps?
Describe what you expect the program to do.
You should put your code in a “code box” by clicking the ( </> ) symbol at top left of the reply screen, then highlight, copy and paste your code into the box that appears.

They are the motor ports that control the h bridge. the motor is a 6v motor with a gear box on end it is power with a 4 aa batterys. the code should open the door when the Ldr senses brightness and closes the door when dark.

@arduinokid55: If someone asks you a question on the forum, it's better that you reply on the forum, rather than reporting your reply to the moderators.

thanks im new at this

thanks im new at this

And that is why we have “sticky” posts at the start of the programming section, giving you helpful instructions.


Please use code tags.

Read this before posting a programming question

Please edit your post, select the code, and put it beween [code][/code] tags.

You can do that by hitting the “Code” icon above the posting area. It is the first icon, with the symbol: </>

How to use this forum