The root of this behavior is that when the program runs delay() function - nothing else could run (digitalwrites, checks, conditions, etc.) until the delay() time is passed.

The effective solution for this is avioding the delay() function, and getting the same results (without the side-effect) using timers (like millis()) or other ways.

Googling "How to avoid delay()" will give you lot of information about how-to do it, one example can be found here: Arduino Playground - How and Why to avoid delay() function.

Good luck with that, and enjoy your programming experience!

Answer from Offer on Stack Exchange
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
How to program parallel action using Arduino UNO - Programming - Arduino Forum
January 7, 2020 - Dears, I have issue with programming a code which make two action to be executed in parallel. For example: Four LED's working sequentially using delay, during that sequence I should turn on another LED at any time when a push button pressed and turn off that LED once the push button released.
๐ŸŒ
The Robotics Back-End
roboticsbackend.com โ€บ home โ€บ how to do multitasking with arduino
How To Do Multitasking With Arduino - The Robotics Back-End
April 25, 2023 - The โ€œbrainโ€ of an Arduino board is a microcontroller (ATmega328 for Arduino Uno). A microcontroller has only one core, and is only capable of executing one instruction at a time. So, if you decide to make a pause inside a function, then all your program is stuck waiting. Every time you write something, you have to think about its impact on the whole code.
Discussions

led - How can an Arduino do multiple actions in parallel without interfering with each other? - Arduino Stack Exchange
I am working with my son (9) and we are having a great time learning. But, we've run into a problem and could use your help. We have two separate loops that we want to run without interfering with... More on arduino.stackexchange.com
๐ŸŒ arduino.stackexchange.com
January 1, 2020
How to call multiples functions within the loop{ } and have them execute in parallel
You can't have them execute in parallel. Arduino boards mostly have only one CPU core and no operating system to allow multiple threads or processes to share the same core ยท But you can make it appear that the functions are operating in parallel to a human. To do that, you have to write your ... More on forum.arduino.cc
๐ŸŒ forum.arduino.cc
19
0
October 2, 2021
How to run multiple for loop parallelly in arduino?
I want to run 2 for loop at the same time, it would be great to hear some solutions. More on forum.arduino.cc
๐ŸŒ forum.arduino.cc
19
0
October 6, 2022
Parallel I/O
I loath to post this so called question because frankly, as a very smart friend of mine one said (paraphrased) .. it's impossible to answer a question incorrectly asked. And I'm not entirely certain what to ask. Still first week. I can define an individual pin as in or out, and read or write ... More on forum.arduino.cc
๐ŸŒ forum.arduino.cc
0
0
December 21, 2020
๐ŸŒ
Quora
quora.com โ€บ How-do-I-do-parallel-programming-for-Arduino
How to do parallel programming for Arduino - Quora
If you have two programs, one that ... a real parallel situation. Of course, itโ€™s still doing one thing at a time but because the timer work and your context-switching is correct, you can start experimenting with scheduling strategies depending on your use. Most basic of which is round-robin scheduling. ... Software to detect plagiarized code. Find matches for code plagiarism across billions of sources on the web or if it was wrote by ChatGPT. ... Author of "Far Inside The Arduino", 45 years ...
Top answer
1 of 5
2

The root of this behavior is that when the program runs delay() function - nothing else could run (digitalwrites, checks, conditions, etc.) until the delay() time is passed.

The effective solution for this is avioding the delay() function, and getting the same results (without the side-effect) using timers (like millis()) or other ways.

Googling "How to avoid delay()" will give you lot of information about how-to do it, one example can be found here: Arduino Playground - How and Why to avoid delay() function.

Good luck with that, and enjoy your programming experience!

2 of 5
1

we found some other code that helped us avoid the delay() functions. Now we are able to use the timestamp "Millis" to run our blinking lights AND have another if statement running the photocell & third LED.

Making progress! Thanks for the suggestions! Here is the code and it works great to turn the LED on and off based on the photocell, and have the other LED's flashing on their own.

const int photoCell =0;
const int ledPin = 13;
const int led2Pin = 12;
const int led3Pin = 11;
int lightCal;
int lightVal;
int ledState = LOW;
int led2State = HIGH;
long previousMillis = 0;
long interval = 250;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  lightCal=analogRead(photoCell);
}

void loop() {
unsigned long currentMillis = millis();
lightVal = analogRead(photoCell);

if(currentMillis - previousMillis >= interval) 
{
  previousMillis = currentMillis;
  if (ledState == LOW)
  ledState = HIGH;
  else
  ledState = LOW;
  if (ledState == LOW)
  led2State = HIGH;
  else
  led2State = LOW;

  digitalWrite(ledPin, ledState);
  digitalWrite(led2Pin, led2State);
}
if (lightVal < lightCal - 50)
{
  digitalWrite(led3Pin, HIGH);
}
else {
  digitalWrite(led3Pin, LOW);
}
}
๐ŸŒ
Instructables
instructables.com โ€บ circuits โ€บ arduino
How to Run Several Tasks on an Arduino? : 6 Steps (with Pictures) - Instructables
December 1, 2021 - How to Run Several Tasks on an Arduino?: A common problem encountered by new Arduino users is to run concurrent tasks. A microcontroller can execute only one instruction at a time, but you may want it to run several tasks in parallel, such as lighting an LED, reading a sensor, printing on โ€ฆ
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
How to call multiples functions within the loop{ } and have them execute in parallel - Programming - Arduino Forum
October 2, 2021 - You can't have them execute in parallel. Arduino boards mostly have only one CPU core and no operating system to allow multiple threads or processes to share the same core ยท But you can make it appear that the functions are operating in parallel ...
Find elsewhere
๐ŸŒ
Arduino
docs.arduino.cc โ€บ hacking โ€บ hardware โ€บ ParallelProgrammer
Arduino
We value our legacy, so we make sure to never get rid of our older documentation. In this page, you can find information for all our retired boards, shields, kits and other legacy products. To access The Arduino Playground, our legacy community wiki, you can go to playground.arduino.cc.
๐ŸŒ
CodePal
codepal.ai โ€บ code generator โ€บ arduino parallel input and output code
Arduino Parallel Input and Output Code - CodePal
October 20, 2023 - To begin, define the number of input and output pins using the variables numInputPins and numOutputPins. In this example, we have 8 input pins and 8 output pins. Next, create arrays inputPins and outputPins to store the pin numbers for inputs ...
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
Parallel I/O - Programming - Arduino Forum
December 21, 2020 - I loath to post this so called question because frankly, as a very smart friend of mine one said (paraphrased) .. it's impossible to answer a question incorrectly asked. And I'm not entirely certain what to ask. Still first week. I can define an individual pin as in or out, and read or write ...
๐ŸŒ
Arduino
docs.arduino.cc โ€บ retired โ€บ hacking โ€บ hardware โ€บ ParallelProgrammer
Parallel Port Programmer
We value our legacy, so we make sure to never get rid of our older documentation. In this page, you can find information for all our retired boards, shields, kits and other legacy products. To access The Arduino Playground, our legacy community wiki, you can go to playground.arduino.cc.
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ general guidance
Parallel actions with Arduino - General Guidance - Arduino Forum
February 22, 2021 - Hey guys, My project is a basic home temperature monitor with a NodeMCU, a BME280 sensor, and an OLED screen. For a while I was happy to log the data to Thingspeak and update the OLED at the same time. However, having tโ€ฆ
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ using arduino โ€บ project guidance
Execution of two codes in parallel - Project Guidance - Arduino Forum
August 13, 2019 - Hi, I am a beginner in Arduino Through Arduino, I am trying to operate solenoid valves (ON/OFF operation) in a sequential manner separated with delay timing. 7 valves are there & entire valve ON & OFF operation will take about 3 minutes time. However i need to have an abort switch which when I press, the valve ON & OFF operation should stop execution and come out. i.e in parallel two things have to happen 1. execution of valve ON & OFF commands (through digital pins ). 2. Checking whether abor...
๐ŸŒ
Circuitstate
circuitstate.com โ€บ tutorials โ€บ how-to-write-parallel-multitasking-applications-for-esp32-using-freertos-arduino
How to Write Parallel Multitasking Applications for ESP32 using FreeRTOS & Arduino - CIRCUITSTATE Electronics
August 16, 2025 - That means we can run multiple parallel RTOS tasks on the same core without any worries, just like how we run loop() and loop2() on the same core. When you write an Arduino application for ESP32, FreeRTOS is used in the underlying layers to schedule your tasks without you even knowing.
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
How to run Two codes at same time - Programming - Arduino Forum
May 26, 2023 - I have a MKR 1010 and want to run tqo diffrent functions in it. Rhe main problem is that i do not want to get too much delays from both the codes. So i need to figure out a way to run two codes in parallel. Help me in thโ€ฆ
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
Running Multiple task parallel - Programming - Arduino Forum
March 16, 2020 - Hello guys, I want to run 4 task parallel i.e 1st task should run after every 5 sec. 2nd runs after 1st task but it lasts for 40 to 50 sec, 3rd will run every 5 sec response of 1st and 2nd task is quick 13032020.zip (9.91 KB)