# Auto and up down

**URL:** <https://forum.arduino.cc/t/auto-and-up-down/1277854>\
**Category:** Programming\
**Created:** [July 3, 2024, 8:28am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854 "2024-07-03T08:28:34Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![arduino\_first](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/arduino_first/32/1282083_2.png) [@arduino\_first](https://forum.arduino.cc/u/arduino_first)\
**Post date:** [July 3, 2024, 8:28am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/1 "2024-07-03T08:28:34Z")

</div>

Good morning i am new with the arduino and i have a problem with this code

```arduino
//Global Variables
const byte auto1 = 7; 
const byte LED = 13;
const byte LED1 = 11;
const byte LED2 = 12; 
const byte up = 5;
const byte down = 6; 

unsigned long buttonPushedMillis; // when button was released
unsigned long ledTurnedOnAt; // when led was turned on
unsigned long turnOnDelay = 10; // wait to turn on LED
unsigned long turnOffDelay = 5000; // turn off LED after this time
bool ledReady = false; // flag for when button is let go
bool ledState = false; // for LED is on or not.
int state2 = 0;
int state = 0;
int state1 = 0;
int state3 = 0;
int state4 = 0;
int state5 = 0;

void setup() {
  pinMode(auto1, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(up, INPUT);
  pinMode(down, INPUT);
  digitalWrite(LED, LOW);
  // Set input/output modes of pins
}

void loop() {

  state2 = digitalRead(auto1);
  if (state2 == LOW) {
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, HIGH);
  }

  else {

    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);
    loop1();
    state2 = digitalRead(auto1);
    state1 = digitalRead(down);

    if ((state2 == HIGH) && (state1 == HIGH)) {
      loop2();
    }
    state4 = digitalRead(up);
    state2 = digitalRead(auto1);
    if ((state4 == HIGH) && (state3 == HIGH)) {
      loop3();
    }

  }

}

void loop1() {
  // get the time at the start of this loop()
  unsigned long currentMillis = millis();

  // check the button
  if (digitalRead(auto1) == LOW) {
    // update the time when button was pushed
    buttonPushedMillis = currentMillis;
    ledReady = true;
  }

  // make sure this code isn't checked until after button has been let go
  if (ledReady) {
    //this is typical millis code here:
    if ((unsigned long)(currentMillis - buttonPushedMillis) >= turnOnDelay) {
      // okay, enough time has passed since the button was let go.
      digitalWrite(LED, HIGH);
      // setup our next "state"
      ledState = true;
      // save when the LED turned on
      ledTurnedOnAt = currentMillis;
      // wait for next button press
      ledReady = false;
    }
  }

  // see if we are watching for the time to turn off LED
  if (ledState) {
    // okay, led on, check for now long
    if ((unsigned long)(currentMillis - ledTurnedOnAt) >= turnOffDelay) {
      ledState = false;
      digitalWrite(LED, LOW);
    }
  }
}

void loop2() {
  state1 = digitalRead(down);
  state3 = digitalRead(auto1);
  if ((state1 == HIGH) && (state2 == HIGH)) {
    digitalWrite(LED1, HIGH);
  }
  else {
    digitalWrite(LED1, LOW);
  }
}

void loop3() {
  state5 = digitalRead(up);
  state2 = digitalRead(auto1);
  if ((state5 == HIGH) && (state2 == HIGH)) {
    digitalWrite(LED, HIGH);
  }
  else {
    digitalWrite(LED, LOW);
  }
}

```

i have 3 buttons and 3 leds -1 up -2 down and- 3 auto when i press the auto the yellow and blue is HIGH thats what i want and when i press the auto again the up led is HIGH and close again and its going to manual up down but the manual is not working.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 3, 2024, 8:37am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/2 "2024-07-03T08:37:15Z")

</div>

Welcome to the forum

> [@arduino\_first](#):
>
> this code

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'  
  
Use [color = red] **code tags** [/color] (the \< CODE/ \> icon above the compose window)&nbsp;to make it easier to read and copy for examination   
  
[https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum)

In my experience the easiest way to tidy up the code and add the code tags is as follows  
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [July 3, 2024, 9:18am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/4 "2024-07-03T09:18:59Z")

</div>

Hi, @UKHeliBob  
Getting this:

# Oops! That page doesn’t exist or is private.

here, for your link. But I can navigate to that forum page, so it's your link that's bad, I think.

---

<div class="post-metadata">

**Author:** ![kolaha](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kolaha/32/966427_2.png) [@kolaha](https://forum.arduino.cc/u/kolaha)\
**Post date:** [July 3, 2024, 9:21am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/5 "2024-07-03T09:21:59Z")

</div>

```arduino
//Global Variables
const byte LED = 13;
const byte LED1 = 11;
const byte LED2 = 12;
const byte up = 5;
const byte down = 6;
const byte auto1 = 7;

unsigned long turnOffDelay = 5000; // turn off LED after this time

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(up, INPUT_PULLUP);
  pinMode(down, INPUT_PULLUP);
  pinMode(auto1, INPUT_PULLUP);
}

void loop() {
  static bool isAuto = false;

  if (digitalRead(auto1) == LOW && isAuto == false) {
    isAuto = true;
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, HIGH);
  }

  if (digitalRead(auto1) && isAuto ) {
    isAuto = false;
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);
    digitalWrite(LED, HIGH);
    delay(turnOffDelay);
    digitalWrite(LED, LOW);
  }
}

```

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [July 3, 2024, 9:24am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/6 "2024-07-03T09:24:50Z")

</div>

@arduino_first Welcome to the Forum! You'll find lots of helpers here, but we're highly focussed on 'technical', which means we thrive on details, completeness, and clarity.

Highly suggest you go to the Category "programming Questions", and read the suggested "How to get...".

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/681310/1):
>
> Welcome to the Arduino forum! A guide explaining how to get the best out of this forum is available at the link below. Please read it:

---

<div class="post-metadata">

**Author:** ![arduino\_first](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/arduino_first/32/1282083_2.png) [@arduino\_first](https://forum.arduino.cc/u/arduino_first)\
**Post date:** [July 3, 2024, 9:25am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/7 "2024-07-03T09:25:11Z")

</div>

it didnt work when the up ligh turns off i wnat to use it manually

---

<div class="post-metadata">

**Author:** ![kolaha](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kolaha/32/966427_2.png) [@kolaha](https://forum.arduino.cc/u/kolaha)\
**Post date:** [July 3, 2024, 9:30am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/8 "2024-07-03T09:30:09Z")

</div>

what manually? what should happen when you press up/down?

---

<div class="post-metadata">

**Author:** ![arduino\_first](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/arduino_first/32/1282083_2.png) [@arduino\_first](https://forum.arduino.cc/u/arduino_first)\
**Post date:** [July 3, 2024, 9:35am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/9 "2024-07-03T09:35:46Z")

</div>

up LED =HIGH when i stop pressing the button LOW and down LED1=HIGH and when i stop pressing it LOW

---

<div class="post-metadata">

**Author:** ![kolaha](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kolaha/32/966427_2.png) [@kolaha](https://forum.arduino.cc/u/kolaha)\
**Post date:** [July 3, 2024, 9:47am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/10 "2024-07-03T09:47:07Z")

</div>

up - led, down button change led1, what do led2?

---

<div class="post-metadata">

**Author:** ![arduino\_first](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/arduino_first/32/1282083_2.png) [@arduino\_first](https://forum.arduino.cc/u/arduino_first)\
**Post date:** [July 3, 2024, 9:51am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/11 "2024-07-03T09:51:09Z")

</div>

led= up, led1=down,auto1=led2

---

<div class="post-metadata">

**Author:** ![kolaha](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kolaha/32/966427_2.png) [@kolaha](https://forum.arduino.cc/u/kolaha)\
**Post date:** [July 3, 2024, 10:00am UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/12 "2024-07-03T10:00:25Z")

</div>

```arduino
//Global Variables
const byte LED = 13;
const byte LED1 = 11;
const byte LED2 = 12;
const byte up = 5;
const byte down = 6;
const byte auto1 = 7;

unsigned long turnOffDelay = 5000; // turn off LED after this time

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(up, INPUT_PULLUP);
  pinMode(down, INPUT_PULLUP);
  pinMode(auto1, INPUT_PULLUP);
}

void loop() {
  static bool isAuto = false;
  if (isAuto == false) {
    digitalWrite(LED, digitalRead(up) == LOW);
    digitalWrite(LED1, digitalRead(down) == LOW);
    if (digitalRead(auto1) == LOW ) {
      isAuto = true;
      digitalWrite(LED1, HIGH);
      digitalWrite(LED2, HIGH);
    }
  }
  if (digitalRead(auto1) && isAuto ) {
    isAuto = false;
    digitalWrite(LED2, HIGH);
    delay(turnOffDelay);
    digitalWrite(LED2, LOW);
    digitalWrite(LED1, LOW);
    digitalWrite(LED, LOW);
  }
  delay(50);
}

```

---

<div class="post-metadata">

**Author:** ![arduino\_first](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/arduino_first/32/1282083_2.png) [@arduino\_first](https://forum.arduino.cc/u/arduino_first)\
**Post date:** [July 4, 2024, 3:20pm UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/13 "2024-07-04T15:20:10Z")

</div>

Sorry for the delay it didnt work i will send you pictures but with my code installed the only thing is the up is not working

 ![IMG_20240704_181338_264](https://europe1.discourse-cdn.com/arduino/original/4X/8/1/2/812779df2a1da4cfab857a7aacb08d2032e49bef.jpeg)  
 ![IMG_20240704_181401_311](https://europe1.discourse-cdn.com/arduino/original/4X/4/b/4/4b48d2b1d876bd3ab4f24a16d419bcab7de95e47.jpeg)  
 ![IMG_20240704_181355_906](https://europe1.discourse-cdn.com/arduino/original/4X/e/b/f/ebfcb94ba9df433ef4db91e160d44cc186fede0a.jpeg)

---

<div class="post-metadata">

**Author:** ![arduino\_first](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/arduino_first/32/1282083_2.png) [@arduino\_first](https://forum.arduino.cc/u/arduino_first)\
**Post date:** [July 4, 2024, 3:21pm UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/14 "2024-07-04T15:21:28Z")

</div>

![IMG_20240704_181345_942](https://europe1.discourse-cdn.com/arduino/original/4X/9/c/8/9c81ba3f2693ffce1bdfaadf53419f1c935b8501.jpeg)  
 ![IMG_20240704_181350_887](https://europe1.discourse-cdn.com/arduino/original/4X/5/b/e/5befd8e060200f1fb814a1615930c529d7e693da.jpeg)

---

<div class="post-metadata">

**Author:** ![arduino\_first](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/arduino_first/32/1282083_2.png) [@arduino\_first](https://forum.arduino.cc/u/arduino_first)\
**Post date:** [July 4, 2024, 3:22pm UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/15 "2024-07-04T15:22:43Z")

</div>

Blue is auto, down is yellow, and up is green ,blue and yellow must work together when you change it to manual the up is enabled and turns off after some time and then you can use the manual only the up manual is not working

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 4, 2024, 3:28pm UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/16 "2024-07-04T15:28:34Z")

</div>

Pictures like that are really a waste of time. It is difficult to see where all the connections to the board go, the polarity of the LEDs and the logical connection between the code and the mess of wiring

A schematic of the project, even it is hand drawn, would be much easier to follow, particularly if it is laid out as normal with the GND line at the bottom, 5v or 3.3V at the top and with all components and pin numbers clearly labelled

---

<div class="post-metadata">

**Author:** ![kolaha](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kolaha/32/966427_2.png) [@kolaha](https://forum.arduino.cc/u/kolaha)\
**Post date:** [July 4, 2024, 4:25pm UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/19 "2024-07-04T16:25:48Z")

</div>

use [easyeda.com](http://easyeda.com)

---

<div class="post-metadata">

**Author:** ![arduino\_first](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/arduino_first/32/1282083_2.png) [@arduino\_first](https://forum.arduino.cc/u/arduino_first)\
**Post date:** [July 4, 2024, 4:31pm UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/20 "2024-07-04T16:31:58Z")

</div>

![up down auto](https://europe1.discourse-cdn.com/arduino/original/4X/7/3/7/737c916263685d57500f53fa81f81a4707fdbf50.png)

i will send it from glorious jofo and i will make it on easyda

---

<div class="post-metadata">

**Author:** ![arduino\_first](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/arduino_first/32/1282083_2.png) [@arduino\_first](https://forum.arduino.cc/u/arduino_first)\
**Post date:** [July 4, 2024, 4:32pm UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/21 "2024-07-04T16:32:40Z")

</div>

because i cant upload pdf for now

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 31, 2024, 4:32pm UTC](https://forum.arduino.cc/t/auto-and-up-down/1277854/22 "2024-12-31T16:32:52Z")

</div>

Closed on December 31, 2024, 4:32pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
