Questions tagged [loop]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
5
votes
3answers
783 views

How do I make another action repeat inside a loop?

So, I've just started programming Arduino (and also in general), so I'm doing basic things, like switching on and off LED's. I've made them light in a sequence and then turning them off (in the same ...
2
votes
2answers
81 views

Stuck In While Loop

So I'm a beginner at Arduino and I have to light up an LED grid to show digits from 0-9. I wrote a bit of code (with the help of some people) and it's like 90% done but there's this ONE problem. I ...
1
vote
1answer
44 views

Detect button press in a loop

I am designing simple "Simon Says game" using Arduino. Simon says is a game in which a LED pattern is played and user has to mimic the pattern. There are 10 Rounds. First Round = 1 led, ...
0
votes
1answer
69 views

How fast does the Arduino execute code?

I am using the Arduino Nano every. Take this example where I am measuring two things A and B. Loop{// this loop runs once every second //Read A,B //Change something using analogueWrite which ...
0
votes
1answer
25 views

Run computation only on request over serial

An Arduino Nano is set up to perform A/D conversions and send results out over Serial. Currently the code structure is like loop() { delayUntilNextTargetTime(); measure(); ...
2
votes
1answer
91 views

Error trying to simulate temperature dynamically

I'm trying to simulate dynamic temperature using a small set of data with ESP32. I've just realized that the relay doesn't change the status if there is some variation of the temperature upper or ...
1
vote
1answer
505 views

Why is this extremely simple code not working?

I have a problem with a for loop, and Serial.print("Its Working") does not appear. Seems simple, I've done it before, now for whatever reason, its not working anymore void setup() { // put ...
2
votes
3answers
59 views

How do I make my piezo buzzer only hum once without repetition?

I have a problem with getting my buzzer to only do the tones I programmed in once. I know I have to add some sort of code but I'm relatively new to this so I don't really know. I want it to start ...
1
vote
2answers
205 views

How do I pause a loop just once?

I´m trying to make a pause in a loop, but just for the first time it loops. The next loops i would like the program to NOT do the pause. Just once time, each time a button is pressed. Does anybody ...
0
votes
0answers
39 views

I am trying to print items in a structure on aruino and am getting this error on compliation

I am writing a code to measure some sensor values, store them in a struct and print them after a limit. I am using Arduino 1.8.11, programming a DOIT ESP32 DEVKIT V1 Here is my code #include <...
2
votes
1answer
98 views

Any advice on how to repeat the song 6 times instead of infinitely?

//Here is my code so far int speakerPin = 9; int length = 28; char notes[] = "GGAGcB GGAGdc GGxecBA yyecdc"; int beats[] = { 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8,8, 16, 1, 2,2,8,8,8,8,16, 1,...
1
vote
1answer
31 views

Rotating Servo Motor using Arduino

Using arduino, I'm trying to rotate a 360 servo that will move clockwise 5 seconds,pause and counterclockwise for 5 seconds and then completely stop. However, my servo just continuously keeps on ...
0
votes
1answer
27 views

I have three pushbuttons where only one can be pushed at a time and want to set a variable for this. How?

Basically I have three push buttons that correspond to pins 1 to 3 and want to set an efficient code that sets a certain variable into the index whose digitalRead is equal to one. Let us assume that ...
-1
votes
1answer
78 views

Arduino Loop stops running as soon as power is turned on

I am using the MU Vision sensor which is supposed to drive a stepper motor. The MU Vision sensor code works. The moment I turn on the power for the stepper motor power supply, the code stops. I have ...
0
votes
1answer
34 views

How can I stop my servo looping when my sensor doesn't detect movement?

I have this project with my Arduino UNO where I want my servo motor SG90 to go full speed to 180 degrees when the PIR sensor sends HIGH value and go slowly back to zero when the value is LOW. I have ...
1
vote
0answers
29 views

How to make my sensor reads when i pressed the button

Hi I'm making a digital fare meter, I have a problem in how my sensor reads when I'd pressed the button(single tap). I need the sensor to read once I pressed the button because when I press the button ...
1
vote
0answers
41 views

Setting a fixed receiver frequency RDA5807m

I am using the receiver RDA5807m, but I do NOT need to switch the frequency and other parameters during operation. I noticed that the module continues to work when the programming pins are ...
0
votes
0answers
57 views

Infared: some controllers send code into infinite loop

I have a piece of code that captures input from infrared and spits it out to the serial port. When I use it with a simple controller that comes with a typical kit, it receives the infrared code just ...
0
votes
0answers
46 views

How to get delay after millis and stop the relay

thats my flowchart for my code void loop() { //-------------Fungsi Read sensor----------- sensorAll(); hasilec = (ppmcensor - inputec); ph = (phcensor - inputph); // hasilec = random(...
0
votes
1answer
67 views

how to stop the relay after it is getting on and let the sensor get the result

I want to provide a delay in the following iteration reading so that the sensor can read the condition after the pump starts. void loop() { //-------------Fungsi Read sensor----------- // ...
2
votes
3answers
67 views

How can I have different routines fire off at different intervals

So i'm making an interface that will have a digital clock....once a secondd.. i'd like to do other things at different intervals but if I delay(1000) then I have to wait that second which is now the ...
1
vote
0answers
31 views

how to control 2 sensor and 3 relay with fuzzy

i'm using fuzzy to decide how long the relay on pump on and i got some trouble for it he just looping on relay how should i do thats my code //---------Fuzzy 2.1 prelauch---------- //-----iNPUT ...
1
vote
1answer
78 views

Storing and sequencing output value (arduino)

I am new to Arduino programming, after days and nights trying to use array,for loop and googling a lot of article, I still unable to find the way how to store each weighing output value from int ...
1
vote
0answers
33 views

My circuit is being goofy with regards to my PIR sensor

Here is the code I've written so far. I am making a circuit with a couple of motors and 3 sensors. My plan is for the PIR Motion sensor, distance sensor, and photoresistor to tell the motors to stop ...
2
votes
0answers
43 views

Two LED Patterns Task Controlled by GUI

I am very new to Arduino and coding/programing. I set a task for myself to make a simple circuit of 5 LEDs controlled by pins 2, 4, 8, 11, 12. I want to be able to make two different pattern for the ...
2
votes
1answer
33 views

Input state is stuck HIGH when function called using input also uses same input to call another function

I'm writing a choose-your-own-adventure style project for a class project. My Arduino Uno is set up with a 16-digit LCD display and two pushbuttons with pulldown resistors. I'm wanting each function ...
1
vote
1answer
66 views

Looking to optimize this code and add a loop

So I want to optimize this code and add a loop to the two red LEDs. The process is green LED is flashing, press button, yellow LED blink for 3 secs and then alternate flashing between the two red LEDs ...
1
vote
1answer
40 views

Cutting neopixel routine code short

I've been working on a level meter with a neopixel strip (WS2812). The code is very simple: reading a potentiometer, mapping the input and showing the output in the led strip. So far, so good. The ...
1
vote
1answer
95 views

For Loop function to iterate through outputs after interrupt

I would like help to continuously loop over my output pins after each sleep cycle. I am trying to increment through each output pin during each successive interrupt. Introducing this myIteration ...
1
vote
4answers
2k views

Arduino Object Oriented Programming

Can anyone send me a link tutorial about Arduino Object Oriented Programming? I want to learn Arduino, I am just a beginner.
0
votes
1answer
67 views

Wifi strength Automation . Help. Noobie here

#include <ESP8266WiFi.h> const char *SSID = "mr_lazy_boei"; const char *pass = "usalusal"; WiFiClient client; // Relay pin number int ignition=2; int self=0; // Return ...
1
vote
1answer
214 views

Mega 2560 does not play audio file when I want. It plays when the first condition is met, but not the other

Okay, so I am making a jewelry box for my niece that will spin a necklace holder with a stepper motor, play an audio file and turn on LED lights. I am using an Arduino MEGA 2560. The flow is this: ...
1
vote
3answers
1k views

Why are the Do While loops not stopping?

Ive been staring at this for a while now and I am going cross-eyed. I am writing a simply program to change colors of a 3 color LED. It is working, but then I noticed the LED would sometimes flash. ...
1
vote
0answers
43 views

Code is not looping correctly when running on battery

static const int dry = 570; static const int wet = 225; static const int RELAY = 2; static const unsigned long DELAY_1_S = 1000; static const unsigned long DELAY_1_MINUTE = DELAY_1_S * 60; static ...
1
vote
1answer
75 views

Breaking out of the arduino fingerprint enroll loop

I am using the Arduino's Adafruit Finger Sensor library, and it has an example to enroll a fingerprint. I want it to enroll one print and exit/break out of the loop because it currently enrolls a user,...
1
vote
1answer
28 views

Check if any of loop's insides returns 1 and hold it until the whole loop is 0 again

I'm new to this, so, please, don't crucify me. I have a function that checks if an entry in multilevel array is in a certain range. Using FOR loop I check the whole array with this function, which ...
1
vote
0answers
155 views

Looping a defined function to show live variables printed on OLED screen

I have started a thread on the Arduino forum. If someone could have a look at the thread and give me some help either here or there that would be great. (I don't want to have to add all the ...
1
vote
1answer
51 views

Is it possible to exit a loop on the change of an input state?

I would like to exit a particular loop if the state of an input changes from LOW to HIGH. This is the current loop: void brakeFade() { pixels.clear(); pixels.setBrightness(255); pixels.fill(16711680, ...
0
votes
1answer
59 views

Exit from for function after detecting obstacles

#include <HCSR04.h> int red = 13; int green = 12; int blue = 11; int trigger = 9; int echo = 8; int halt; void setup(){ pinMode(red, OUTPUT); pinMode(green, OUTPUT); pinMode(blue, OUTPUT)...
-1
votes
1answer
112 views

Infinite loop serial.readString()

Ok, this is my code: int rosso = 13; int verde = 12; int blu = 11; int count = 0; String command_on, command_off; String s; String enough = "stop"; void setup(){ pinMode(rosso, OUTPUT); pinMode(...
0
votes
1answer
89 views

Stopping the program after 1 second

I am a Beginner in Arduino Programming. I am working on a project where I control A DC motor with IR sensor and arduino. Until here it is fine. But I want the Motor to stop after one second even ...
1
vote
3answers
87 views

Writing elegant applications for Arduino

Coming from a C background, I was taught that tight loops that just burn CPU aren't desirable. Is there any programming style guides on Arduino? Is it common practice to just let loop iterate as a ...
1
vote
3answers
76 views

How long does my digital pulse need to be for it to be read?

I have the following really simple code. On every iteration it'll read the first pin, and if it's high - do some serial IO. Then do the same with the second pin. Nice and simple, works during my tests....
0
votes
1answer
26 views

Do Loop query not stopping

I am new to Arduino programming and I would like to ask a question. Firstly apologies if this has been answered before and I understand if it gets locked if this has been answered elsewhere. I am ...
0
votes
1answer
77 views

Stuck in While loop!

I am using 4 LDR To track the sun for solar panels. Not using servos, but linear actuators(a little irrelevant but just to give scope) my code gets stuck in this while loop as soon as it enters it, ...
0
votes
2answers
166 views

Is there a way to make a function take an exact number of clock cycles?

Is it possible to use something like a compiler directive to pad a function with do nothing instructions so that as you add lines of code or take them away it always executes in the same amount of ...
-1
votes
2answers
189 views

How do I run a function every 10th time through a loop?

I currently have a function that poles all my sensors every time through it's loop, but I want to pole one of the sensors only every 10th time. Currently there is a 10 millisecond delay at the ...
0
votes
0answers
677 views

Break a while loop with a push button (AccelStepper.h)

Disclaimer: This is my first Arduino project. Background: I am building a "rapunzel tower" lantern for my daughter: the witch pays a visit to Rapunzel meanwhile my daughter can read a book (or still ...
1
vote
0answers
62 views

While Loop does not stop when condition is false

Here's the code: void loop() { while (1 == 1) { ObsLeft(); while (SeeLeft < 50 || SeeLeft == 50) { Urong(); ObsLeft(); if (SeeLeft > 50) { Hinto; ...
0
votes
2answers
373 views

problem with decrement in a loop

I am trying to write a sketch wherein the led brightness increases in increments of 15 until it reaches 255. At that point I want to make decrements of 15 until it reaches 0. The increment part of the ...