Arduino

Hi can anyone help me i'm a new student at arduino and i have a project in where i am making a barrier (servo) and it has to stay open for 30 sec and then when the barrier is closing but it picks up an item blocking the way it should open again for 30 secs aswell when the there is 10 seconds left i am thinking of adding a piezo buzzer which should make noise if anyone can help me make the code for this it will be very helpful.

In this project i am using:
ultrasonic sensor
Servo motor
Pir sensor
Piezo sensor

Thanks

What have you got so far?

Welcome

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
Posting images:
https://forum.arduino.cc/index.php?topic=519037.0

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

Have a look at how millis() is used to manage timing in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...R

This is project guidance; no code required :wink:

Do you know how to read your sensors, beep, move the servo and so on? If not start with that.

Your problem calls for a so-called finite statemachine. Once you have mastered the above, below can act as a framework; you'll need to fillin the details.

// possible states of the gate
enum GATESTATES
{
  CLOSED,
  OPENING,
  OPEN,
  CLOSING,
};

// current state
GATESTATES currentState = CLOSED;

void setup()
{
  // put your setup code here, to run once:

}

void loop()
{
  switch (currentState)
  {
    case CLOSED:
      if (somethingHappensThatNeedsGateToOpen == true)
      {
        currentState = OPENING;
      }
      break;
    case OPENING:
      if (gateHasOpened)
      {
        currentState = OPEN;
      }
      break;
    case OPEN:
      if(tenSecondsToGo)
      {
        beepIt();
      }
      if(thirtySecondHavePassed)
      {
        currentState = CLOSING;
      }
      break;
    case CLOSING:
      if (blockageDetected)
      {
        currentState = OPENING;
      }
      if (gateHasClosed)
      {
        currentState = CLOSED;
      }
      break;
  }
}