text:
Unable to upload to arduino
I am coding my arduino for an upcoming robot competition. I have managed to upload my code and run it on my arduino once or twice, however now I am unable to upload code. I now receive the following message:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

I have unplugged USB, pushed the reset button, checked all the settings (ports, programmer, etc), unplugged the arduino and even tried running basic code such as Blink. I've been searching for hours and now I'm not sure what to do. I am getting no response and I'm finding this really frustrating. Does anyone have any advice as to how to resolve this issue?

Are you absolutely sure you checked the port and chose the right one? Sometimes if you unplug an arduino and then connect it back again it might choose different port.


text:
Arduino Uno R3 HID with HC-06 BT module
Im trying to make a macro pad using Arduino Uno r3 and 4x4 matrix (cherry blue clone) . I know using a pro micro is better than uno cause there isn't HID compatibility in uno but since i already have one , i want to work with this . I have already tested the macro pad after compiling and flashing a keyboard.hex file . But wondering if i buy a bt module like HC-06 (which is about 3.2$ here ) would that be able to send inputs even aftar flashing ? I have like basics coding knowledge so i have no clue what flashing actually would do to the module so . Anyone know would making that macro pad BT compatible    be possible or not ?

It is unclear to me, where you flashed what, so I will describe some basics.
The Uno cannot act as a keyboard/HID device, since the microcontroller on it (the Atmega328p) doesn't have native USB capability. For connecting to USB the Uno has a USB-to-Serial chip on it (actually another microcontroller, the Atmega32u4 I think). So with the Uno you only have a serial connection, unless you hack the Atmega32u4 and program it with your own firmware (firmware is a term for software, that runs very near to the hardware, in this case directly on the microcontroller, in contrast to normal software running on an operating system on a computer; so in the middle between hard- and software, thus firmware).
Flashing is the same as programming a microcontroller. It has this name, because the program is saved in flash memory on the microcontroller (that is a specific type of memory technology; the same technology, that USB sticks use for storing your data). Flashing the HC-06 means programming it with a different firmware.
All bluetooth devices use the same base technology (thought to be clear, BLE is a different technology). The role of the device depends on the characteristic/profile, that it exposes to the host. There are profiles for HID, Serial, Audio, ... .
The HC-06 is a bluetooth slave device, which acts as a bluetooth-serial-bridge (like the Atmega32u4 acts as a USB-serial-bridge). But this is a software limitation. The HC-06 has standard bluetooth hardware, but the firmware on it just gives you the Serial profile (in fact a HC-06 is mostly the same like the master device HC-05, just different firmware and corresponding breakout boards can break out other pins). So by flashing (programming) it with a different firmware, you can get different profiles. If you find a firmware, that gives you HID functionality, you can flash that to the HC-06 and use it. Though this is a bit hacky I think (haven't done it myself), so it might be a bit too much for a beginner.
Bluetooth Slave/Master: The bluetooth protocol uses fixed roles for the two connected devices. One is the master and one is the slave. The master controls, if the communication is really happening. For example a bluetooth headset is a slave device. You cannot connect the bluetooth headset to your bluetooth keyboard, because both are slave devices. You always need one master and one slave. The HC-05 is basically the same module as the HC-06, but it's firmware enables it do be master or slave (configurable by you). So some devices support both modes, but still in any specific connection they can only have one of the modes (need to either master OR slave at any time).

Anyone know would making that macro pad BT compatible be possible or not ?

Possible, yes. But I suggest you invest in buying a ready to use bluetooth HID controller (immediately found this one from adafruit, though you might might cheaper versions). That will be way easier, than directly jumping into flashing a HC-06. Though that is still a possible path to go.
Another way to go would be to just use the serial functionality and write a small program for your PC, which reads from the Serial interface and issues key strokes according to the serial data. Then you don't need to reflash the HC-06.

Thank you chrisl for the valuable answer . I understand what you were saying .. somewhat . The thing is im from a third world country and there aren't any products from adafruit . Actually tinypico was a really good choice for my project but if i wanted to get one from AliExpress i would have to pay 20$+ on just shipping so the cost is too much .

You can search for other product than the one from Adafruit. That was just the first, that came up, when I quickly searched for it. If there are no better/cheaper modules available for you, you need to compromise. Either going the steep learning curve to learn reflashing the HC-06 or by writing the program for your PC, that handles serial input.

" I understand what you were saying .. somewhat" - Can you pinpoint, what you are not understanding completely? Then I can try to improve my answer in that direction.

I didn't understood master-slave relation in the BT module . Its because i haven't done any research in that matter . So instead of bothering you i just wanted to do some study on that matter :) again ,thank you very much for your answers , now i know what i need to look into

I added a short paragraph about this to the answer. For now I leave the rest for you to research :D If you think my answer is correct, then you can accept it. That marks the question as correctly answered.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
How can I run Hello World using Serial Monitor in Tinkercad Arduino simulator?
I want to achieve printing Hello World in the serial monitor using Tinkercad to simulate Arduino.
Here is a very simple example code for real Arduino.
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Hello World!");
}

void loop() {
  // put your main code here, to run repeatedly:

}

However, putting an Uno board, typing this code, and clicking "Start Simulation" in Tinkercad doesn't show the Hello World message.
Is it doable? If so how?
For real Arduino, you need to select Arduino serial port and open Serial Monitor. But I can't find such an option for Tinkercad. I can't find Serial Monitor in Thinkercad.
My real purpose is to use Serial Monitor output to test code snippets. Right now I don't have real Arduino board with me, so I thought a simulator would be ideal. If I can easily check the values of variables, it doesn't have to be Serial Monitor.
Sorry if this is not a place to ask questions about simulators.

Did you open the Serial Monitor?

Can you provide a public link to your tinkercad simulation?

Does this answer your question? How to simulate Arduino?

I mean where would you expect it to print Hello World ... On the Serial Monitor, right? So first open it by clicking on the Serial Monitor button at the bottom of the code tab in Tinkercad.
I tried your code and it works perfectly fine.

Haha! Thanks a lot, this kind of things is easy if you know where to look, but hard if you don't.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Code for ESP32 without Development Board
I'm very new to microcontrollers. I'd like to start developing for the esp32, as it has integrated wifi & bluetooth for quite cheap. This being said, i don't have a board yet. Is there a way i can emulate an esp32 board, so i can start programming and debugging my code?
As i'm very new, any advice is welcome.
Thanks

I don't think there are a lot of websites or software that allow you to emulate a microcontroller, to my knowledge I know a site called circuito.io that has a lot of options for components and code but does not actually emulate, or you could try tinkercad.com and it supports emulation of a few boards, but I'm not too sure about esp32

I see. I will make sure to check them out. Thanks for the hint :)

https://stackoverflow.com/questions/67330695/is-there-any-simulator-for-esp32-s2-or-esp32-chips similar question which can be merged

Welcome to Arduino Stack exchange. There are a lot of discussions and half-completed, or project-specific models available for the ESP32 simulator. My sincere advice is to go ahead and buy real hardware. By the time you take to set up the simulators (download the repo, set environment variables, connect GDB debugger or other), you would have received the ESP32 hardware itself.
Why you should go for real hardware?

An emulator can never match the timing of real ESP32 hardware. if you
have any timing-related issue, you cannot fix it using an ESP32 emulator
Real issues in hardware (bounce/debounce of switches, surge current and brownout voltages, rise time and reflections etc - won't appear in the ESP32 simulators
EMC issues due to floating inputs, Port pin current limits or even self-heating of components are not considered in most the simulators
A code running on the emulator can't always run on the real hardware without modifications, especially when it involved multiple threads and priorities

Still, other options are available online but it depends on your comfort

ESP32 Simulator by Wokwi - The ESP32 Simulator is currently in preview (affiliation disclosure)

ESP32 simulator from mireq - ESP-IDF contains a small amount of hardware-specific code, FreeRTOS and few multi-platform libraries. This project uses FreeRTOS port for POSIX, LWIP for TCP/IP layer and mbedtls for cryptography functions.
In addition, several useful APIs from esp-idf are implemented eg. logging. With this project, you can write a program, which will be runnable and testable on Linux.

ESP32 machine emulator - The purpose of this package is to enable you to test-drive (TDD) your MicroPython code in an IDE running on your computer. It seems a lot of people are test-driving python, but not many are test-driving MicroPython. That’s understandable, since many MicroPython projects are simple, and emulating real hardware in a test environment is difficult.

Bridges - Pretend your PC a Raspberry Pi or an ESP32 to connect I2C / SPI / GPIO / UART peripherals.

Note You should also check when is the last time the projects were updated. The latest ones and active ones are always a better choice as they are expected to have better usability, and stable simulations.

A few screenshots from Wokwi ESP32 Simulator

If you are new to microcontrollers then start with basic arduino code and components.  Since the esp chips can be coded with the Arduino framework it will be an almost seemless transition from Arduino board to ESP board.  Build some circuits on tinkercad.com, write some code, and simulate them. Once you have those basics down hopefully your esp board will have arrived and you can start building your project.


text:
How to send int array with ESP8266 http post request?
I'm reading RFID cards' UID with an ESP8266 and trying to send that information to my web server hosted on a Raspberry Pi. I'm currently storing the UID in an int array, but the http.POST(); function takes a string input. I tried adding each UID digit together, but that doesn't work either.
How would you go about sending the uid in the request?
My code:
    /*
    Created by TheCircuit
*/

#define SS_PIN 4  //D2
#define RST_PIN 5 //D1

#include <SPI.h>
#include <MFRC522.h>

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

const char* ssid = "****";
const char* password = "****";
const char* serverName = "****";
int RELAY = 2; //D6

int UIDs[1][4] = {
  {83, 111, 39, 47}
};

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

void setup()
{
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522

  pinMode(RELAY, OUTPUT);
  digitalWrite(RELAY, HIGH);

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
}

boolean compareUIDs(int a[4], int b[4]) {
  for (int i = 0; i < 4; i++) {
    if (a[i] != b[i]) return false;
  }

  return true;
}

void loop()
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }

  // mfrc522.PICC_DumpToSerial(&(mfrc522.uid));

  int UID[4];
  for (int i = 0; i < 4; i++) {
    UID[i] = mfrc522.uid.uidByte[i];
  }

  Serial.print(UID[0]);
  Serial.print(" ");
  Serial.print(UID[1]);
  Serial.print(" ");
  Serial.print(UID[2]);
  Serial.print(" ");
  Serial.print(UID[3]);
  Serial.println();

  for (int i = 0; i < sizeof(UIDs); i++) {
    boolean success = compareUIDs(UIDs[i], UID);
    if (success) {
      Serial.println("ACCESS GRANTED");
      digitalWrite(RELAY, LOW);

      if (WiFi.status() == WL_CONNECTED) {
        HTTPClient http;

        // Your Domain name with URL path or IP address with path
        http.begin(serverName);

        // Specify content-type header
        http.addHeader("Content-Type", "application/json");

        int httpResponseCode = http.POST("UID GOES HERE");

        Serial.print("HTTP Response code: ");
        Serial.println(httpResponseCode);

        // Free resources
        http.end();
      }

      delay(2000);
      digitalWrite(RELAY, HIGH);
      return;
    }
  }
}

You encode it in some string format that the website at the remote end is expecting. Either as a HTTP parameter list, or as a JSON array string, or whatever is needed.

@Majenko could you give me a link or short explanation to get started on that one?

It looks like you've already decided on (or had imposed on you) JSON.  So the simplest method is to use ArduinoJSON (https://arduinojson.org/) to create the JSON string for you.

my StreamLib has CStringBuilder to print to string same way as you print to Serial

you could send it as an integer ... that UID in your code is 536f272f

You could use the (awesome) ArduinoJSON library, but likely overkill for this app. I found it more useful to parse JSON than to construct it.
You could simply print to a buffer and the POST that:
char payload[MAX_PAYLOAD];
sprintf(payload, "{\"uid1\":%d,\"uid2\":%d,\"uid3\":%d,\"uid4\":%d}", UID[0], UID[1], UID[2], UID[3]);

http.POST(payload);

You would #define MAX_PAYLOAD with a value that will be sufficient to hold all the information.
Notice that sprintf allows you to use any formatting options you want (e.g. hexadecimal, etc).
If you wanted to send it as an array:
sprintf(payload, "{\"uid\":[%d,%d,%d,%d]}", UID[0], UID[1], UID[2], UID[3]);


text:
How do I synch the Arduino PID library with an external timer for turn-rate control?
I have been trying to use the Arduino PID library for controlling the rate of turn (in deg/sec) of a wall-following robot.
The robot's operating system uses TIMER5 on an Arduino MEGA2560 to update a number of time-sensitive parameters (heading, front/back/left/right distances, etc) which are used throughout the code. For turn rate control, the difference between the current and previous headings (appropriately modified for 0/180 transitions) is multiplied by 10 to get deg/sec, and then this value is the 'input' to a PID. The PID output is a speed control to the wheels to achieve the desired turn rate setpoint.
Unfortunately, the current Arduino PID library has an internal timer (that can be changed, but not disabled) which has it's own idea of time.  In addition, the PID library's internal timer isn't available to the outside world - it is only used in PID::Compute().
The typical code configuration for using a PID is something like the following:
loop()
{
    //lots of other stuff
    if(TIMER5 ISR has been triggered)
    {
        //compute turn rate = 10*delta_heading
    }

    if(myPID.Compute()) //the internal timer is used inside this function
    {
       //use the PID output to control something (like wheel speeds)
    }
}

loop() runs at max speed, but myPID.Compute() only generates a new output when the internal PID timer elapses (otherwise it returns immediately without doing anything).  However, the turn rate input is being computed on a different schedule, leading to unpredictable behavior.
A possible solution is:
loop()
{
    //lots of other stuff

    if(myPID.Compute()) //the internal timer is used inside this function
    {
        New_Hdg_Val = GetNewHdgVal();
        turn_rate = ComputeTurnRate(New_Hdg_Val, Prev_Hdg_Val);
        Prev_Hdg_Val = New_Hdg_Val;

       //use the PID output to control something (like wheel speeds)
    }
}

So now the turn rate is computed on the same time intervals as PID::Compute(), which looks OK, as long as the timer value being used by the PID is the same as the TIMER5 ISR value being used by the rest of the program; clunky, inelegant, but maybe OK.
Unfortunately, because the PID computes a new output value inside PID::Compute(), the new value computation comes BEFORE the turn rate computation, which means the turn rate being used to produce the new output uses turn rate information that is AT LEAST 100mSec out of date (assuming the default 100mSec PID sample time setting) - ouch!!
So, how do others use the Arduino PID library in systems with an external (to the PID library) timing source?

I don't know how others use the PID Lib ;-). Without having thougt much about the problem: How about computing the turn rate in each loop cycle? Outside of the  the if(myPID.Compute()) block. Does it cause a problem, if it is computed before every myPID.Compute call? You waste a small amount of computing time, but you got the most actual values for the turn rate.

Peter, I certainly could do that. The computation is trivial, but getting the heading measurement from the MPU6050 is not, and there isn't any guarantee that a (blocking) MPU6050 measurement won't start just before the PID's internal timer would have elapsed, meaning that now the PID::Compute() cycles aren't periodic anymore.  This is a big problem because the internal PID math assumes periodicity.

I don't think reading the MPU is a problem. Even if you read all values from it (I don't know if that's the case) you can reach a sampling rate of 100 HZ. That means max. 10 ms per read out. And if you need the value for the compute() you have to read the MPU before the PID executes, so it blocks the PID in any way.  The Compute Method of the PID works with millis() and a sample interval of 100 msec by default. If that starts max. 10  msec later, who cares? And, you do "lots of other stuff" in the loop function before it. How much time does that need?  ;-)

I looked into the code of the compute method, and honestly I  am not very impressed of it. The author needs constant time intervals, because he uses a trick to save a division and a multiplication (derivative, integral). But now every delay in the loop can result in errors in the integral and derivative.  He claims that industrial controller run best within constant intervals.  But an industrial controller runs  on a real time systems that garantees fix intervals. And the Arduino loop  provides no real time feature. Especially, if there is a lot of other stuff performed.

If I would need a PID controller, I would write my own version. The author links to a piece of code I would prefer to use.  http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/  (but without the "time interval"  improvements)

You sync it by calling the myPID.Compute() function in your external timer handler function.  If your loop function is lengthy, move your time-critical functions to a timer handler.

I use TIMER5 on the Mega 2560 to run everything that is time-sensitive, including PID calculations.  I use a custom PID_calcs function that mimics the internal workings of PID.Compute(), and PID_calcs is called each time TIMER5 is fired, guaranteeing equal time intervals.


text:
CD rom stepper getting warm
I'm trying to run a SPS-15RF stepper motor from an old cd rom drive. I'm using a CNC shield and a4988 driver with a 6v power supply. The motion is smooth and fine. I know it has 18 pulse/revolution and works with 5v but It gets quite unexpectedly hot. It feels that it can burn my fingers if I keep it running.
What is wrong with it? is it related to micro-stepping or sth else!?

Those motors are not designed to be constantly driven. They are designed to move to one position and then "release" (that is, the power is removed and active driving ceases).

there are many DIY projects on the web, using these motors for CNC applications which are somehow constant driven! there should be a solution.

Maybe you need to trim down the motor current at the driver. When the motor gets hot at continous use with the normal current, you could lower it, so that it doesn't get hot anymore

don't forget to "release" - disable driver when not actively moving (pin is called EN)

@chrisl How can I trim down the motor current?

Normally a stepper driver gas a little potentiometer on it, that you can rotate with a small screwdriver. That is used to set the motor current

Ok. I got it. current limit=Vref*2.5


text:
Does natural outdoors wind affect the readings of an ultrasonic sensor significantly?
I am thinking of using an ultrasonic sensor outdoors, and am wondering if the presence of wind (say up to 20km/h) would significantly impact the accuracy of the readings, or would this not be a large concern?
Thanks.

why would "natural" and "outdoors" make a difference? ... it is air movement ... run some tests using a hair dryer

Ah that's true, I added outdoor to give an idea of the wind speeds I'm considering. Your idea with using a hair dryer is pretty good, I'll give that a shot, thanks!

google ultrasonic anemometer

you did not say what you are measuring with the ultrasonic sensor, or how it is configured ... if it is a distance sensor module with the emitter and detector beside each other, then my gut feeling tells me that wind from directly in front, or directly in back would not make much difference ... any side to side air movement would increase the length of the sound travel .... i could easily be very wrong on this

As speed of sound is around 1235 km/h at 25°C, it' won't do so much difference for 20km/h (in the same direction as measurement) - it's under 2%

@KIIV i think that wind in same direction would not affect it much, because the sound propagation would speed up in one direction and slow down in the other direction

@jsotola true, completely forgot about that


text:
Get LFN from SFN with SDFat
I am trying to optimize the memory usage of my ESP8266 arduino sketch by using 8.3 SFN folder names internally, but LFN when needed for user output. Unfortunately when opening a folder by using the SFN, getName also returns the SFN:
sdfat::SdFile _currentFolder;
_currentFolder.open("BLUBBE~1");
char foldername[100];
_currentFolder.getName(foldername, sizeof(foldername));

results in "BLUBBE~1" while
sdfat::SdFile _currentFolder;
_currentFolder.open("blubberblub");
char foldername[100];
_currentFolder.getName(foldername, sizeof(foldername));

results in "blubberblub" (and getSFN would return "BLUBBE~1"). Is there any chance to open the folder using the SFN "BLUBBE~1", but get the LFN ("blubberblub") later on?


text:
How to edit this IR sensor code to COINSLOT sensor
The project is Like a secured PiggyBank but it will count the coins inside it.
Im using a coin sensor at default it has 5v, then goes to zer if inserted with a coin.
I have 2 codes The one was form my old project then second one was a coinslot code got in youtube.
Im hoping someone can guide me where to deelte some codes, then add it at one lsit of code.
Behavior of the project
-Start > Display Total : Amount > if I will unlock the solenoid it will display Welcome "NAME" .
Hope you can get my Idea. Some of code inside of the solenoid was not perfect sorry for that I just get it from scrath without proper knowledge.
This is code for FINGERPRINT TO SOLENOID LOCK
#include <Adafruit_Fingerprint.h>    //Libraries needed
#include <SoftwareSerial.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27          //LCD i2c stuff
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

int in2 = 4;

int But1=8;  // In order to add a push button I got the 5v from the pin 8 instead of "5v" arduino pin
int But2=9;

String Names[] = { "RAVEN", "Surtr", "Tech",}; //Those are the names affected to the fingertemplates IDs
                                                 //The first on which is Names[0] : Yassine has the ID 1 in the fingerprint sensor

SoftwareSerial mySerial(2, 3);                  //Fingerprint sensor wiring RX 3, TX 2
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); //LCD declaring

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);                    //Fingerprint sensor declaring

void setup()
{
  pinMode(in2, OUTPUT);
  digitalWrite(in2, HIGH);
  pinMode(But1, OUTPUT);    //Push button stuff, I made the pin 8 permanent LOW level
  digitalWrite(But1,LOW);
  pinMode(But2,INPUT_PULLUP);     //And I read the button state on pin 9

  Serial.begin(9600);               //Serial begin incase you need to see something on the serial monitor
  finger.begin(57600);              //Sensor baude rate
  lcd.begin (16,2);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home();
  finger.getTemplateCount();        //Counts the number of templates stored in the sensor flash memory
  delay(2000);
  introScreen();
}

void loop()
{
  int result = getFingerprintIDez();  //This function keeps looping and waiting for a fingerprint to be put on the sensor
  //delay(50);
  bool Button1=digitalRead(But2);  //Reading the state of the pushbutton
  if(Button1==LOW or result >= 0){
    //If the button is pressed it opens the doorlock as the button is meant to be inside
    OpenDoor();
    introScreen();
  }
}

void introScreen()
{
    lcd.clear();
    lcd.print("Place finger");
}

//Main function taken from the "fingerprint" example and modified
//Only the modifications are commented
int getFingerprintIDez() {
  uint8_t p = finger.getImage();        //Image scanning
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();               //Converting
  if (p != FINGERPRINT_OK)  return -1;

  lcd.clear();                     //And here we write a message or take an action for the denied template
  p = finger.fingerFastSearch();     //Looking for matches in the internal memory
  if (p != FINGERPRINT_OK){          //if the searching fails it means that the template isn't registered
    lcd.print("Access denied");
    delay(2000);
    introScreen();
    return -1;
  }
            //If we found a match we proceed in the function

  lcd.print("Welcome");                  //Printing a message for the recognized template
  lcd.setCursor(2,1);
  lcd.print(Names[finger.fingerID-1]); //Then print the name we gave it and the -1 is to remove the shift as the ID starts from "1" but the array from "0"
  return finger.fingerID;
}

/*The two following functions depends on your locking system
 *mine has a DC motor that should turn in both ways for opening and closing
 *that's why I'm using H bridge, you could have a solenoid with a transistor
 *then you'll need only opening sequence but controlling the transistor
 *as the closing is spring loaded...
 */

void OpenDoor(){
  digitalWrite(in2, LOW); // turn on motor
  delay(5000);
  digitalWrite(in2, HIGH); // turn off motor
}

This code is for COINSLOT
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#define coinSlot 6

LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the I2C bus address for an unmodified module

int coinCount = 0;
int coinSlotSignal;
int requiredCoins = 1;
boolean coinInserted = false;

void setup() {
  Serial.begin(9600);
 pinMode(coinSlot, INPUT_PULLUP);

 lcd.setBacklightPin(3,POSITIVE);
 lcd.setBacklight(LOW); // You can turn the backlight off by setting it to LOW instead of HIGH
 lcd.begin(16, 2);
lcd.write(EEPROM.read(5));
}

void loop() {
  while(!coinInserted){
  coinSlotSignal = digitalRead(coinSlot);
  if(coinSlotSignal < 1) {
    coinCount += 1;
    coinInserted = true;
EEPROM.write(0,coinCount);
Serial.println(EEPROM.read(0));

lcd.setCursor(0,0);
lcd.print("TOTAL:");
lcd.setCursor(0,1);
lcd.print(coinCount);
}
  }

while(coinInserted) {
  coinSlotSignal = digitalRead(coinSlot);
  if(coinSlotSignal >0) {
    coinInserted = false;

  }
}
if(coinCount >= requiredCoins) {
  delay(1500);
}
}

you cannot have two void setup() ... put codes from both into one ... same with void loop()

please fix the indentation of your code ... it will be much easier to follow the code flow and it will make it more difficult to make mistakes

why does PROJECT BEHAVIOR say nothing about the coinslot? ... is coinslot part of the project or not? ... it also does not say anything about the lock solenoid ....... not a very good description of the project behavior .... a clear, detailed description of the project behavior usually translates into code almost directly

I have 2 separated project codes sir but I got the coinslot code in google, Im hoping that how to sink 2 coses at 1 to run the project

It's unclear what the issue is. If the coin slot device has a logic output based on an internal sensor then hook that output up to the Arduino and process it like any other logic input--what's the specific problem?

I don't know how to sink the 2 project code in to 1 code :(

I read the article sir and try to sink the code but its giving a short of a problem that I cant find why its causing it but try to see the error code it keep on saying that "expected unqualified-id before 'while'


text:
Can't enable face detection on esp32 cam : CORRUPT HEAP: Bad head at 0x3ffe2eb4. Expected 0xabba1234 got 0x00000008 abort()
I was trying to make esp32 face recognition using the esp32 camera web server example in arduino ,
and everything works fine untill i press on face detection the frame is frozen , module restarted and put this error to serial monitor :

CORRUPT HEAP: Bad head at 0x3ffe2eb4. Expected 0xabba1234 got 0x00000008
abort() was called at PC 0x4008a64d on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x4008df7c:0x3ffe1c30 0x4008e1f5:0x3ffe1c50 0x4008a64d:0x3ffe1c70
0x4008a779:0x3ffe1ca0 0x400f97cb:0x3ffe1cc0 0x400f5a61:0x3ffe1f80 0x400f59f0:0x3ffe1fd0
0x40093545:0x3ffe2000 0x40082976:0x3ffe2020 0x4008a545:0x3ffe2040 0x4000bec7:0x3ffe2060
0x400d1bc9:0x3ffe2080 0x401194f5:0x3ffe2230 0x40119bfd:0x3ffe2260 0x40119cb5:0x3ffe22f0
0x4011a088:0x3ffe2310 0x40118774:0x3ffe2330 0x401187cb:0x3ffe2370 0x4008fe86:0x3ffe2390

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4

I tried erasing flash bt it made the same error again
I am using Arduino IDE 1.8.12 , esp32-cam
operating at 5 volts from the programmer (also tried other external power supplies)
and these are the pictures of settings : (also used wrover kit in programming settings with huge app >3mb)
Chip name

ESP32 Cam

FTDI Programmer

AI THINKER

Settings

I want to make a face recognition door lock , if this doesn't work could anyone refer me to how can I get facial recognition on esp32 cam with any other way?

I don't have enough reputation to be able to add a comment, but using the answer from Andrew Hart I was able to resolve this.  For completeness of this thread in case the linked solution ever disappears:
Locate these sections from the app_httpd.cpp:
if (net_boxes){
    detected = true;
    if(recognition_enabled){
        face_id = run_face_recognition(image_matrix, net_boxes);
    }
    draw_face_boxes(image_matrix, net_boxes, face_id);
    free(net_boxes->score);
    free(net_boxes->box);
    free(net_boxes->landmark);
    free(net_boxes);

and
fr_recognize = esp_timer_get_time();
draw_face_boxes(image_matrix, net_boxes, face_id);
free(net_boxes->score);
free(net_boxes->box);
free(net_boxes->landmark);
free(net_boxes);

replace the 4 free's in each block with dl_lib_free.

The above free(...) -> dl_lib_free(...) replacements fixed the issue for me. This was done on the 2.0.0 board version in the Arduino IDE. I was able to revert to 1.0.4 and find myself in a working state, but performance was definitely worse (where 1.5 frames/s being good performance). Don't forget to re-enroll if you shave your beard... Not that I couldn't unlock a cabinet because of this or anything.

Rollback your ESP32 board driver to 1.04. works for me ;-)

Thanks!! this worked for me!!!

I ran into this issue with the same setup. This Github issue seems identical to ours, and applying the fix in this comment quickly resolved it for me: https://github.com/espressif/arduino-esp32/issues/5128#issuecomment-851785970. Good luck!

Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.


text:
HTTPS GET request working on esp32 but not on esp8266
I'm trying to port my esp32 program to esp8266, and i've come across a problem where i can't get a response from a HTTPS GET request on esp8266, but on my esp32 the same code works fine.
The function i'm using looks like this:
void GetHTTP()
{
  if (WiFi.status() == WL_CONNECTED)
  {
    HTTPClient http;
    http.begin(requestURL);
    int httpCode = http.GET();
    if (httpCode > 0)
    {
      requestData = http.getString();
      GenerateTable();
      //GetDelimiterCount(requestData, delimiterStart);
    }
    http.end();
  }
}

I've also tried running my request with the esp8266 "BasicHttpsClient" and "BasicHttpClient", and in both cases the program returns the error: "connection failed" from https.errorToString(httpCode).s_str()
or http code "-1" without any API specific error codes.
I'm requesting from Trafiklab's realtime infromation v4 API And
the request looks somewhat like this:

https://api.sl.se/api2/realtimedeparturesV4.json?

I've omitted the API key and parameters i use from this URL. The response is also correct when requested by any browser.
Could this be something to do with SSL? I'm completely out of clues as to what the differences between esp32's and esp8266's http-client libraries might be. I'm also using the latest version of the ESP8266 Boards libraries (2.7.4).

see the examples of the ESP8266HttpClient library

I did. I mentioned that in my initial post.

look again. focus on the first parameter of http.begin in BasicHttpsClient

I ended up using

ESP8266WiFi.h

instead of

ESP8266WiFiMulti.h

This fixed both my original code and the basic HTTPS example. I still don't understand what difference it made though.


text:
Using a leds driver ic with arduino
I have an ic (CT1642 1442) it's a led driver 8 bit, i want to use it with my arduino nano and i don't have any idea how to use it.
If someone can help me ill be thankfull.

https://github.com/arkroan/CT1642, https://forum.allaboutcircuits.com/threads/how-to-use-an-ct1642-or-sm1642-led-driver-with-key-scan-arduino-project.116955/, https://arduino-projects-free.blogspot.com/2020/07/fd1642-ct1642-sm1642-et6227.html, etc. You'll likely need to be a bit more specific with what exactly you're working with (bare chip? Board with that chip?) and what you want to do with it.

Start by getting the datasheet for the ic and read through it.

@lurker No, start by learning to read Chinese - then get the datasheet and read it...


text:
Problem with floating of AnalogRead
For a university Lab course i have to realize a UPS unit with a internal LiPo battery . The unit uses as battery charger a buck converter
I have only a problem with the battery charger (buck converter). Few weeks before i verify the code and it works without problem. Now i can notice that the analog value that i read are floating too much and this represents a problem for the Constant Current (CC) and Constant Voltage (CV) phases of the battery charge process.
I found that this problem happens when plug arduino  after i have started the PC, while it doesn't happen when i plug the USB cable of arduino and then start the PC. It seems to be a problem with the ground of arduino.
the circuit scheme is the following one:

and what i obtain is that:

as you can see i have a strange increase of all the voltage that i read with the analog pin of arduino. The code is correct since before this week it works well, but if necessary i will upload it.
the 10Ohm resistor is placed in the buck converter only to measure the chargin current that i calculate as:
charging_current=(analogRead(A1)-analogRead(A2))*5.00/1023.00
The battery must be charged at constant current equal to 50mA until the battery voltage became equal to 4.10V, after that value the battery must be charged at constant voltage equal to 4.20V until the charging current became smaller than 10/5mA.
Notice that i try also to make more acquisition for each voltage: i made 8 measurement and then i calculate the average value, but the result doesn't change.

Please add information about which measurement are floating and what the actual and expected ranges are.

The measurement that are flosting are the voltsge that i masured on the network, on the battery and on the resistor... So all the vale that i read from analogo PIN of Arduino...the network voltage should be around 6V while the resistor voltage and the battery voltage should grow up while the battery charges... The start from 3.40V and the should reach about 4.20V

I can't make head nor tail of that fritzy thing. Please provide a proper schematic that we can follow.

I try to give you more detail information about the problem and i post a schematic of the battery charger. The other componente are ok so i can focus on the buck converter

I would expect some fluctuation, based one where in the PWM cycle you are doing the measurement. That is, based on whether the mosfet is turned on or not.

there are same fluctuation but sometime they are very smaller, like 40mV other time they are very big, like 100/150mV. On other thing that i note right now while i was testing the circuit, is that if i move the usb cable the voltage read frome the 3 pin (A0,A1 e A2) changes a lot, like 1V....this is due to the fact that the cable that i'm using isn't a cable of good quality?

Do you have an oscilloscope to measure waveforms? Then do this, please. And you might like to use an output of your Aduino to mark the times you read the analog inputs. Trace these, too.

i don't have an oscilloscope....

put caps in parallel with the voltage divider resistors, start around 100u. Also, you can expect a few levels of noise on a built-in ADC no matter what. Use an external ADC for more accurate + precise readings.


text:
ESP8266 Webserver does not respond
I am trying to reach the webserver running in my Wemos D1 Mini compatible board.
I am trying one esp8266 example using Arduino examples "WifiManualServer" code below.
I have replaced the SSI and password for my wifi network in the lines
#define STASSID "my wifi ssid"
#define STAPSK  "my secret"

/*
    This sketch demonstrates how to set up a simple HTTP-like server.
    The server will set a GPIO pin depending on the request
      http://server_ip/gpio/0 will set the GPIO2 low,
      http://server_ip/gpio/1 will set the GPIO2 high
    server_ip is the IP address of the ESP8266 module, will be
    printed to Serial when the module is connected.
*/

#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "my wifi ssid"
#define STAPSK  "my secret"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
  Serial.begin(115200);

  // prepare LED
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, 0);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print(F("Connecting to "));
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println();
  Serial.println(F("WiFi connected"));

  // Start the server
  server.begin();
  Serial.println(F("Server started"));

  // Print the IP address
  Serial.println(WiFi.localIP());
  server = WiFiServer(80);
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  Serial.println(F("new client"));

  client.setTimeout(5000); // default is 1000

  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(F("request: "));
  Serial.println(req);

  // Match the request
  int val;
  if (req.indexOf(F("/gpio/0")) != -1) {
    val = 0;
  } else if (req.indexOf(F("/gpio/1")) != -1) {
    val = 1;
  } else {
    Serial.println(F("invalid request"));
    val = digitalRead(LED_BUILTIN);
  }

  // Set LED according to the request
  digitalWrite(LED_BUILTIN, val);

  // read/ignore the rest of the request
  // do not client.flush(): it is for output only, see below
  while (client.available()) {
    // byte by byte is not very efficient
    client.read();
  }

  // Send the response to the client
  // it is OK for multiple small client.print/write,
  // because nagle algorithm will group them into one single packet
  client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n\r\nGPIO is now "));
  client.print((val) ? F("high") : F("low"));
  client.print(F("

Click here to switch LED GPIO on, or here to switch LED GPIO off."));

  // The client will actually be *flushed* then disconnected
  // when the function returns and 'client' object is destroyed (out-of-scope)
  // flush = ensure written data are received by the other side
  Serial.println(F("Disconnecting from client"));
}

Once I compile and upload the sketch, the sketch is able to connect to my wifi network.
The following is the output in the serial monitor.
20:45:12.633 -> Connecting to <text replaced xxxxxxx>
20:45:13.247 -> ........
20:45:17.551 -> WiFi connected
20:45:17.551 -> Server started
20:45:17.551 -> 192.168.0.39

I am able to verify the client connection in my wifi routers network management UI.
The espboard is connected and assigned the IP as in the output (192.168.0.39).
When I launch browser and try to get http://192.168.0.39/gpio/0, the request times out.
from my windows 10 pc, tried ping on 192.168.0.39, the Request timed out.
From the sketch I see the following lines in the loop() function:
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  Serial.println(F("new client"));

The execution never reached the line Serial.println(F("new client"));.
I had tried inserting the line server = WiFiServer(80); after the wifi connection is established.
Please share your thoughts on why the server.available() is not successful?

Is your windows 10 PC on the same subnet? Does your WiFi router impose WiFi Isolation?

remove the line server = WiFiServer(80);

I think you have to call server.on() somewhere so the server does actually serve an url. Which library do you use btw (there is nothing behind #include for me)?

@SimSon, this is not ESP8266WebServer library

@Juraj, thanks for the suggestion. I have now removed the line server = WiFiServer(80). The issue is resovled. The server is now reachable. Thanks your help.


text:
Using 4x1 MUX to control a servo
I was supposed to first create a 4x1 MUX using AND and NOT gates. The 4 input data lines (io,i1,i2,i3) were 4 PWM pins from the arduino (3,5,6,9), with analogWrite() values as 100,150,200,250 respectively, and the selection lines were taken from two slide switches.

int i0=100;
int i1=150;
int i2=200;
int i3=250;

void setup()
{
  pinMode(5, OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(3,OUTPUT);

  analogWrite(3,i0);
  analogWrite(5,i1);
  analogWrite(6,i2);
  analogWrite(9,i3);

  Serial.begin(9600);
}

void loop()
{

}

Simulation link: https://www.tinkercad.com/things/cRZNvuwhZYV
The voltmeter + is connected to the output of the MUX. Both selection lines are HIGH, so the output is i3, which has the pWM value 250. So the voltage should be (250/255)*5, i.e about 4.9 V, which is what the meter shows. (The servo is present but not connected.)
The voltmeter values are in accordance for all the 4 possible combinations. In short, the 4x1 MUX is working perfectly.
(it was important for me to clarify this as otherwise people might have thought of the MUX implementation as the problem with my lsubsequent circuit , and with the messy wiring, it would've been impossible to confirm whether or not this is the case. However, as I have clearly shown, the problem is NOT with the MUX).
Next, I tried to control the servo using this MUX. I connected the servo control pin to the MUX output:

#include<Servo.h>
Servo s1;
Servo s2;
Servo s3;
Servo s4;

int i0=100;
int i1=150;
int i2=200;
int i3=250;

void setup()
{
  pinMode(3,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(9,OUTPUT);

  analogWrite(3,i0);
  analogWrite(5,i1);
  analogWrite(6,i2);
  analogWrite(9,i3);

  s1.attach(3);
  s2.attach(5);
  s3.attach(6);
  s4.attach(9);

  Serial.begin(9600);
}

void loop()
{

 s1.write((i0*180)/255);
 s2.write((i1*180)/255);
 s3.write((i2*180)/255);
 s4.write((i3*180)/255);
}

For instance, I thought if both switches were on, then the output is i3,(which was coming from pin 9), so
only s4.attach(9); and s4.write((i3*180)/255); will work. (As, it is apparent that the control pin is connected to pin 9 in this case).
The servo does move around when I change the switches to on off combinations, however,something drastic has happened to the voltmeter values, which tells me that my code is messing with the MUX output. The output voltages fluctuate rapidly between 97 and 180 mV.
What exactly have I done wrong, and how exactly am I supposed to control the Servo, then?

Honestly I would think that none of the codes really work, at least at a real Arduino (don't know, how tinkercad is handling this). Calling analogWrite() or Servo.write() repeatedly in loop() without  anything to slow it down would restart the PWM wave again and agian. Please try to put these lines into setup() instead. Maybe tinkercad handles analogWrite() and the servo library differently.

one of the main things that you are doing wrong is using a voltmeter to measure a pulse train ... an oscilloscope is the appropriate instrument for that

@chrisl I changed the codes, the problem still persists. Any idea why? and any idea what exactly can I do to control the servo properly?

@jsotola what difference will that make? (I ask this politely ofcourse) The voltmeter is showing the correct values for the MUX, which means my MUX is working properly, that's all I wanted to confirm. When I add the servo, is when the voltmeter goes beserk, so something is probably wrong with the handling of my servo... I am not sure why using an oscilloscope will fix that

is it possible to control the servo with only one servo object?

What is the purpose of both analogWrite() and Servo::write() using the same pin? Do you need the former at all?

well the analogWrite() serves as data inputs to the MUX... You may be right that using the same pin may be causing the trouble.. But then what code do you recommend?


text:
How to get 2 loop functions to cooperate?
I have a OLED SSD1306 & DS3231 RTC, 2 buttons to set the time & date. My project is to display a scrolling text at the top of the OLED, the RTC time in the middle, the day & date on the last line. My issue is I can't get the scrolling text & the time to run right when in the loop together, individually they work normal. When they are together, the scrolling text is fine, but the time is static, its not displaying the current RTC. Then after 1 loop cycle the time seconds text become jumbled, then after a 2nd cycle the minutes & seconds become jumbled. I have tried putting display.clearDisplay(); display.display(); at the end of the loop, doing this fixes the time from becoming jumbled by clearing the buffer before the next cycle, but does not fix the time from being static. How can I get the time to not be static anymore? Any help would be greatly appreciated. Here is my sketch:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define button1    9                       // Button B1 is connected to Arduino pin 9
#define button2    8                       // Button B2 is connected to Arduino pin 8

void setup(void) {
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  delay(1000);

  // by default, the high voltage from the 3.3v line
  display.begin(SSD1306_SWITCHCAPVCC, 0x3c);  // initialize with the I2C address
  // init done

  // Clear the display buffer.
  display.clearDisplay();
  display.display();

  display.setTextColor(WHITE, BLACK);
}

char Time[]     = "  :  :  ";
char Calendar[] = "  /  /20  ";
byte i, second, minute, hour, day, month, date, year;

void display_day(){
  switch(day){
    case 1:  draw_text(0, 50, " SUNDAY  ", 1); break; //(Column,Row,Data to be displayed,Font size)
    case 2:  draw_text(0, 50, " MONDAY  ", 1); break; //(Column,Row,Data to be displayed,Font size)
    case 3:  draw_text(0, 50, " TUESDAY ", 1); break; //(Column,Row,Data to be displayed,Font size)
    case 4:  draw_text(0, 50, "WEDNESDAY", 1); break; //(Column,Row,Data to be displayed,Font size)
    case 5:  draw_text(0, 50, "THURSDAY ", 1); break; //(Column,Row,Data to be displayed,Font size)
    case 6:  draw_text(0, 50, " FRIDAY  ", 1); break; //(Column,Row,Data to be displayed,Font size)
    default: draw_text(0, 50, "SATURDAY ", 1); //(Column,Row,Data to be displayed,Font size)
  }
}

void DS3231_display(){
  // Convert BCD to decimal
  second = (second >> 4) * 10 + (second & 0x0F);
  minute = (minute >> 4) * 10 + (minute & 0x0F);
  hour   = (hour >> 4)   * 10 + (hour & 0x0F);
  month  = (month >> 4)  * 10 + (month & 0x0F);
  date   = (date >> 4)   * 10 + (date & 0x0F);
  year   = (year >> 4)   * 10 + (year & 0x0F);
  // End conversion

  Time[7]     = second % 10 + 48;
  Time[6]     = second / 10 + 48;
  Time[4]     = minute % 10 + 48;
  Time[3]     = minute / 10 + 48;
  Time[1]     = hour   % 10 + 48;
  Time[0]     = hour   / 10 + 48;
  Calendar[9] = year   % 10 + 48;
  Calendar[8] = year   / 10 + 48;
  Calendar[4] = date   % 10 + 48;
  Calendar[3] = date   / 10 + 48;
  Calendar[1] = month  % 10 + 48;
  Calendar[0] = month  / 10 + 48;

//Print text
  draw_text(60, 50, Calendar, 1); // Display the date (format: mm/dd/yyyy)
  draw_text(15, 25, Time, 2); // Display the time
}

void blink_parameter(){
  byte j = 0;
  while(j < 10 && digitalRead(button1) && digitalRead(button2)){
    j++;
    delay(25);
  }
}

byte edit(byte x_pos, byte y_pos, byte parameter){
  char text[3];
  sprintf(text,"%02u", parameter);
  while(!digitalRead(button1));                      // Wait until button B1 released
  while(true){
    while(!digitalRead(button2)){                    // If button B2 is pressed
      parameter++;
      if(i == 0 && parameter > 12)                   // If month > 12 ==> month = 1
        parameter = 1;
      if(i == 1 && parameter > 31)                   // If date > 31 ==> date = 1
        parameter = 1;
      if(i == 2 && parameter > 99)                   // If year > 99 ==> year = 0
        parameter = 0;
      if(i == 3 && parameter > 23)                   // If hours > 23 ==> hours = 0
        parameter = 0;
      if(i == 4 && parameter > 59)                   // If minutes > 59 ==> minutes = 0
        parameter = 0;
      sprintf(text,"%02u", parameter);
      draw_text(x_pos, y_pos, text, 1);
      delay(200);                                    // Wait 200ms
    }
    draw_text(x_pos, y_pos, "  ", 1);
    blink_parameter();
    draw_text(x_pos, y_pos, text, 1);
    blink_parameter();
    if(!digitalRead(button1)){                       // If button B1 is pressed
      i++;                                           // Increment 'i' for the next parameter
      return parameter;                              // Return parameter value and exit
    }
  }
}

void draw_text(byte x_pos, byte y_pos, char *text, byte text_size) {
  display.setCursor(x_pos, y_pos);
  display.setTextSize(text_size);
  display.print(text);
  display.display();
}

void scroll_text(){
  draw_text(0, 0, "The Pumpkin Express", 1);
  display.display();
  display.startscrollright(0x00, 0x00);
  delay(8500);
  display.stopscroll();
  delay(4000);
  }

void loop() {

  if(!digitalRead(button1)){                         // If button B1 is pressed
    i = 0;
    while(!digitalRead(button1));                    // Wait for button B1 release
    while(true){
      while(!digitalRead(button2)){                  // While button B2 pressed
        day++;                                       // Increment day
        if(day > 7) day = 1;
        display_day();                               // Call display_day function
        delay(200);                                  // Wait 200 ms
      }
      draw_text(0, 50, "         ", 1);
      blink_parameter();                             // Call blink_parameter function
      display_day();                                 // Call display_day function
      blink_parameter();                             // Call blink_parameter function
      if(!digitalRead(button1))                      // If button B1 is pressed
        break;
    }
    //set position of text when editing on button press
    month  = edit(60, 50, month);                    // Edit month
    date   = edit(80, 50, date);                      // Edit date
    year   = edit(110,50, year);                    // Edit year
    hour   = edit(14, 25, hour);                     // Edit hours
    minute = edit(50, 25, minute);                   // Edit minutes

    // Convert decimal to BCD
    minute = ((minute / 10) << 4) + (minute % 10);
    hour = ((hour / 10)  << 4) + (hour % 10);
    date = ((date / 10) <<  4) + (date % 10);
    month = ((month / 10)  << 4) + (month % 10);
    year = ((year / 10)  << 4) + (year % 10);
    // End conversion

    // Write data to DS3231 RTC
    Wire.beginTransmission(0x68);               // Start I2C protocol with DS3231 address
    Wire.write(0);                              // Send register address
    Wire.write(0);                              // Reset seconds and start oscillator
    Wire.write(minute);                         // Write minute
    Wire.write(hour);                           // Write hour
    Wire.write(day);                            // Write day
    Wire.write(month);                          // Write month
    Wire.write(date);                           // Write date
    Wire.write(year);                           // Write year
    Wire.endTransmission();                     // Stop transmission and release the I2C bus
    delay(200);                                 // Wait 200ms
  }

  Wire.beginTransmission(0x68);                 // Start I2C protocol with DS3231 address
  Wire.write(0);                                // Send register address
  Wire.endTransmission(false);                  // I2C restart
  Wire.requestFrom(0x68, 7);                    // Request 7 bytes from DS3231 and release I2C bus at end of reading
  second = Wire.read();                         // Read seconds from register 0
  minute = Wire.read();                         // Read minutes from register 1
  hour   = Wire.read();                         // Read hour from register 2
  day    = Wire.read();                         // Read day from register 3
  month  = Wire.read();                         // Read month from register 4
  date   = Wire.read();                         // Read date from register 5
  year   = Wire.read();                         // Read year from register 6
  Wire.beginTransmission(0x68);                 // Start I2C protocol with DS3231 address
  Wire.write(0x11);                             // Send register address
  Wire.endTransmission(false);                  // I2C restart
  Wire.requestFrom(0x68, 2);                    // Request 2 bytes from DS3231 and release I2C bus at end of reading

  DS3231_display();                             // Display time & calendar
  display_day();                                // Display date

  scroll_text();                                // Display scrolling text
              // If i dont use the clear buffers(next 2 line codes), on the
             //next loop cycle the seconds & minute text becomes jumbled
  //display.clearDisplay();
  //display.display();

  delay(50);                                    // Wait 50ms
}

it is not surprising, your scroll_text() function stops the program execution for 12.5 seconds

Thx for the suggestions, I changed the title to my post, & I tried commented out the delays and start & stop in my void scrolling_text(); the text is not scrolling, but is glitching, & the time is all jumbled

The reason for the delays in the void scrolling_text(); is because I want the text to scroll 1 lap around, pause to display the text, then the scrolling starts back up again. Just like the LCD screen on a train when it is displaying the next train stop

maybe what you need is a unified display function ... the scroll function does not do any displaying .. it only sets a character buffer ... the time function also does no displaying ... it sets the value of a time variable ... the display function uses the values in the character buffer, and in the time variable, and puts them on the screen

So are you saying I should create a new void called void display_text(); & in it put: draw_text(60, 50, Calendar, 1);  draw_text(15, 25, Time, 2); draw_text(0, 0, "The Pumpkin Express", 1); ?

possibly something like that ... it does not have to be in its own function .. it can be part of loop() ... whatever way you like to organize your code

"is there a way to isolate those delays...?" The processor can only do one thing at a time so if is delaying(), everything else it has to do is being held up, not just the contents of the function containing the delay(). [Responding here in anticipation of you editing your "answer" into the question.

So I tried creating a new void with all 3 draw_text’s, both the calendar & time would not work outside the void DS3231_display(). So I figured out my problem is the delays in the void scrolling_text() is some how being read as part of the whole sketch. I thought creating a void would prevent that & only run it when it is called. Is there a way of coding to prevent one void delays from effecting the whole program, like is there a way to isolate those delays, or have the program only read the delays only when it is executing the display.scrollleft(0x00,0x00);?

JRobert, are you saying I cant have the scrolling text in my sketch, because the Arduino cant handle it while executing the rest of the sketch? The reason for the delay's, is because I want the OLED to scroll the text, then pause the text to show it fully on the display, then scroll again, rinse & repeat. The reason the first delay is 8500, is because that is how long it takes the text to completely scroll out of view.

@Stiglitz Unclear what's meant by "the delays in the void scrolling_text() is somehow being read as part of the whole sketch." A delay delays: it stops the world (except for interrupts)--nothing else will happen during a delay, it's delaying (except interrupts). If you don't want the sketch to delay in a way that stops the world then you'll need to delay differently. The Blink Without Delay may be what you're ultimately asking for.

The answer to your title question, "How to get 2 loop functions to cooperate?" is: You can't, because your program can't have two functions with the same name. What you'd need to do instead is redesign your program, keeping in mind the MCU can only do one thing at a time, although you could break up each of several jobs into pieces and interleave them fast enough that we slow humans won't notice.
My approach, when I have a question like this, is to temporarily put aside what I know about coding and about MCUs, and just focus on how to do the job. I list the sub-tasks my code needs to do but without thinking too much about how to do them. Write them down, in the order they required doing, in any note-taking style that suits you.
Now break down each one of those sub-tasks into its sub-tasks. Repeat, until you understand how to code each one. Then you'll know enough to start writing the code.
Update:
@NathanJiang is correct. The solution is not to make two loop() functions (because the language doesn't support that), but to decide how to interleave pieces of each job within 1 function, in such a way that they each appear to operate smoothly and don't interfere with each other. Especially, neither one must call delay(), which stops your code doing anything for the duration. If some piece isn't ready to be done yet, your code must move on to other pieces and do which ever of those is ready. This keeps it checking each piece over and over again, rapidly, doing what is ready and skipping what is not.

What do you mean I have 2 functions with the same name? All 3 functions have different names, scroll_text(), display_day(), & DS3231_display(). the reason for my title, is because I am having an issue with scroll_text() & DS3231_display() making my program glitch when both are running in the sketch. I can get them to run fine individually.

I believe that @JRobert means that you cannot have two functions both with the name loop.

The way to get functions to cooperate with each other is to re-code them so they don't waste time and pass control back and forth as quickly as possible.  You do this by using the BlinkWithoutDelay trick to re-write the "blocking" code to be non-blocking and trust in loop() to hand back control to your function in a reasonable amount of time.
For instance take this function that @jsotola identified as a performance killer:
void scroll_text(){
  draw_text(0, 0, "The Pumpkin Express", 1);
  display.display();
  display.startscrollright(0x00, 0x00);
  delay(8500);
  display.stopscroll();
  delay(4000);
  }

It really doesn't need to monopolize the processor for 12500 microseconds--Instead it could just check the time and turn scrolling on and off every so often, and quickly pass control back to the loop() for reading and updating the clock.
I don't have your hardware or setup, so here's some untested code:
void scroll_text(){
  // some local state variables to remember where we are
  static bool isInitialized = false; // maybe a global if re-initializing is needed.
  static bool isScrolling = false;
  static unsigned long interval = 1;
  static unsigned long last = -interval;
  unsigned long now = millis();
  if (now - last >= interval ) { // time to do something
    last = now;
    if( !isInitialized ){
      draw_text(0, 0, "The Pumpkin Express", 1);
      display.display();
      isIinitialized = true;
    }
    if ( !isScrolling ) {
        isScrolling = true;
        display.startscrollright(0x00, 0x00);
        // delay(8500);  // use BWOD trick instead
        interval = 8500;
     } else { // isScrolling
       isScrolling = false;
       display.stopscroll();
       //delay(4000);
       interval = 4000;
     }
  }

This drop-in scroll_text() function can be called many time times per millisecond and will mostly do nothing and return control immediately.  But when it realizes the time is right, it will update its own state variables and the output states.
By replacing the scroll_text() function with a non-blocking form, it speeds up loop() by 12.5 seconds per loop.  Doing similar replacement of processor-sapping delay()s could further improve responsiveness.  However it is a big mind shift to stop using serial, blocking code and shift to events.  Every time you see a delay(), a while(...), or a for() loop, think about whether you really need to trap the processor inside of that loop, or what data you would need in order to skip it for now and come back to it next time through the main event loop().
I think the next step would be to wrap the reading of the reading the the DS3231 with the BWOD trick -- you only need to read the clock once per 1000ms and you could save hundreds of instructions per loop().


text:
Turning off a LED
I am trying to make 2 alarms for 2 different times using 2 LED's which should turn on when the time corresponds to the set time and then if a pushbutton is pressed, the LED should turn off. For the first alarm, the first LED can be turn off with the pushbutton, instead for the second alarm, the second LED is turning on, but if the pushbutton is pressed is will not turn off, even though is the same code. What can I do to turn off the second LED?
#include <RTClib.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int nowHr, nowMin, nowSec;
RTC_DS3231 rtc;

int h1 = 15;
int m1 = 51;
int h2 = 15;
int m2 = 52 ;
int pin_buton1 = 8;
int stop_buton =9;
int state_stop_buton = 0;

int led1_pin = 6;
int state_led = LOW;
int pushpressed = 0;

int led2_pin = 7;
int state_led2 = LOW;

void setup()
{

  Wire.begin();
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  rtc.adjust(DateTime(2021, 03, 27, 15, 50, 50));

  lcd.backlight();
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Welcome To Our");
  lcd.setCursor(0, 1);
  lcd.print("device");

  pinMode(pin_buton1, INPUT);
  pinMode(stop_buton, INPUT);
  pinMode(led1_pin, OUTPUT);
  pinMode(led2_pin, OUTPUT);
  delay(2000);
  Serial.begin(9600);
}

void loop() {
  timeScreen();
  first_alarm();
  stopPins();
  second_alarm();
  stopPins2();

  state_stop_buton = digitalRead(stop_buton);

}

void timeScreen() {

  DateTime now = rtc.now();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Time:");
  lcd.setCursor(6, 0);
  lcd.print(nowHr = now.hour(), DEC);
  lcd.print(":");
  lcd.print(nowMin = now.minute(), DEC);
  lcd.print(":");
  lcd.print(nowSec = now.second(), DEC);
  lcd.setCursor(0, 1);
  lcd.print("Date: ");
  lcd.print(now.day(), DEC);
  lcd.print("/");
  lcd.print(now.month(), DEC);
  lcd.print("/");
  lcd.print(now.year(), DEC);
  delay(500);

}

void stopPins() {
  if (state_stop_buton == 1) {

    pushpressed =1;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("first message ");
    lcd.setCursor(0, 1);
    lcd.print("was read");
    delay(1200);
    lcd.clear();
  }
}

void startBuzz() {

  if (pushpressed == 0) {

    if (state_led == LOW) {
      state_led = HIGH;
      digitalWrite(led1_pin, state_led);

    }
  }
  else if (pushpressed == 1) {

    state_led = LOW;
    digitalWrite(led1_pin, state_led);
  }
}

void first_alarm() {
  DateTime t = rtc.now();
  if (int(t.hour()) == h1 && int(t.minute()) == m1) {

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("first ");
    lcd.setCursor(0, 1);
    lcd.print("text");
    startBuzz();
    delay(5000);

  }
}

//

void stopPins2() {
  if (state_stop_buton == 1) {

    pushpressed = 1;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("second message ");
    lcd.setCursor(0, 1);
    lcd.print("was read ");
    delay(1200);
    lcd.clear();
  }
}

void startBuzz2() {

  if (pushpressed == 1) {

    if (state_led2 == LOW) {
      state_led2 = HIGH;
      digitalWrite(led2_pin, state_led2);

    }
  }
  else  if (pushpressed == 0 ) {
    state_led2 = LOW;
   digitalWrite(led2_pin, state_led2);
 }
}

void second_alarm() {
  DateTime t = rtc.now();
  if (int(t.hour()) == h2 && int(t.minute()) == m2   ) {

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("second");
    lcd.setCursor(0, 1);
    lcd.print("text");
    startBuzz2();
    delay(5000);

  }
}

1. pushpressed gets set, but never reset.
It's set in stopPins() and stopPins2() if the input is HIGH. Since it's never reset back to zero, once it's been set, the logic in startBuzz and startBuzz2 will follow a single pass. You've created a latched switch.

General Stuff

2. Inconsistent naming: makes reading code harder
Pick snake_case or camelCase or smashitalltogether (not recommended) and stick with it :) Same goes for the "types" of variables: some things are named xxx pin xxx, some are named xxx state xxx, some aren't. It's clearer when same-things are named-same.
3. Duplication: makes understanding code harder
Along with the naming, the (essentially) duplicated code makes tracking down problems harder, as you've noticed trying to debug this problem. There are a ton of ways to go about shrinking the code down to make it understandable. The nutshells are to identify the differences in similar code, and to do less at once.
(And if you want to take it to its logical conclusion, wrapping up each alarm in a class would eliminate all duplication and most function parameters :)

Annoying Diversion of Explanation

Let's look at startBuzz and startBuzz2.
void startBuzz() {
  if (pushpressed == 0) {
    if (state_led == LOW) {
      state_led = HIGH;
      digitalWrite(led1_pin, state_led);
    }
  } else if (pushpressed == 1) {
    state_led = LOW;
    digitalWrite(led1_pin, state_led);
  }
}

void startBuzz2() {
  if (pushpressed == 1) {
    if (state_led2 == LOW) {
      state_led2 = HIGH;
      digitalWrite(led2_pin, state_led2);
    }
  } else if (pushpressed == 0) {
    state_led2 = LOW;
    digitalWrite(led2_pin, state_led2);
  }
}

The only things different here are the LED pin, and the LED state. Let's normalize our naming so things become clear, using startBuzz as the example. We'll also assume pushPressed can only be 0 or 1 (HIGH or LOW):
void startBuzz() {
  if (pushPressed == LOW) {
    if (led1State == LOW) {
      led1State = HIGH;
      digitalWrite(led1Pin, led1State);
    }
  } else {
    led1State = LOW;
    digitalWrite(led1Pin, led1State);
  }
}

We can make this work for either LED by doing two things: taking in the pin and current state, and returning the new state. Why return the new state instead of setting it here? It makes the mainline code easier (and avoids passing a reference).
void startBuzz(int ledPin, int ledState) {
  int newLedState = ledState;

  if (pushPressed == LOW) {
    if (ledState == LOW) {
      newLedState = HIGH;
      digitalWrite(ledPin, newLedState);
    }
  } else {
    newLedState = LOW;
    digitalWrite(ledPin, newLedState);
  }

  return newLedState;
}

Then when we call startBuzz or startBuzz2 we replace the current code with:
led1State = startBuzz(led1Pin, led1State);

We're not done.
Since we keep the original ledState we can remove the duplicated calls to digitalWrite; at worst we'll have a superfluous write when pushPressed != LOW && ledState != HIGH.
Since all conditions except one lead to a LOW value we don't even need to keep the original state. And since it's two conditions to flip it HIGH we can combine those. And if we pull out the digitalWrite we're really just calculating the next state--that doesn't rely on the LED pin.
void getNextLedState(int ledState) {
  return (pushPressed == LOW && ledState == LOW) ? HIGH : LOW;
}

And the callsites look like this:
led1State = getNextLedState(led1State);
digitalWrite(led1Pin, led1State);

Similarly for the alarms: create a function called checkAlarm that takes in hrs and mins and returns a boolean. In the loop call checkAlarm(h1, m1) and if true, call runAlarm1(). (Even that could be shrunk further, but you get the idea.) stopPins differs only in the strings written to the LCD. And so on.

Well that turned into a lot of words. This is what happens when I'm in the middle of writing book.

thank you very much for you response, I think I have to read several times your instructions and then apply them. Good luck with you book!

@biancaaa I'll make a similar circuit and post my code somewhere and post a link. Not soon enough to help you, bit hey :)

sorry if i bother you , but i followed your advice about reseting the stop button, but i can't handle it. Before the end of void startBuzz i wrote "pushpressed = 0;", but it is still not working @Dave Newton

@Biancaaa Maybe post your current code in a gist or here; I can take a look in an hour or two.

'
void startBuzz() {
if (pushpressed == 0) {
if (ledState == LOW) {
  ledState = HIGH;
}
digitalWrite(ledPin, ledState);

}
else if (pushpressed == 1) {
ledState = LOW;
digitalWrite(ledPin, ledState);

}
pushpressed = 0;
}
'

so, this is the edit which i made in the code. I am new in this domain (arduino), but I will pay attention to the advices you explained above about the functions. If i set pushpressed to 0 in function startBuzz, the led for the first alarm will not turn off definitive when the pushbutton is pressed, instead, the second led for the second alarm can be turn off when the same pushbutton is pressed.


text:
Communication code between nrf24l01's suddenly not working. Hardware is fine
I specifically had saved code for the purpose of checking the connection, but it doesn't seem to work anymore.
All the examples from this simple tutorial work, so it can't be a hardware issue.
Maybe someone can find a reason why the code wouldn't work? It returns radio.available() as false
//Transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
float valueTransmit;
float valueRecieved;

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(addresses[1]); // 00002
  radio.openReadingPipe(1, addresses[0]); // 00001
  radio.setPALevel(RF24_PA_LOW);
  valueTransmit = 0
}
void loop() {
  radio.stopListening();
  radio.write(&valueTransmit, sizeof(valueTransmit));
  delay(5);

  radio.startListening();
  if (radio.available() ) {
      radio.read( &valueRecieved, sizeof(valueRecieved) );
  Serial.print(valueRecieved);
  valueTransmit = valueRecieved + 0.01;
  }
}

//Reciever
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
float valueTransmit;
float valueRecieved;

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(addresses[0]); // 00001
  radio.openReadingPipe(1, addresses[1]); // 00002
  radio.setPALevel(RF24_PA_LOW);
}
void loop() {
  radio.startListening();
  if (radio.available() ) {
    radio.read( &valueRecieved, sizeof(valueRecieved) );
    Serial.print(valueRecieved);
    valueTransmit = valueRecieved + 1;
  }

  radio.stopListening();
  radio.write(&valueTransmit, sizeof(valueTransmit));
  delay(5);

}

suddenly not working means that it was working and it failed without any changes ... is that what happened?

@jsotola Honestly it's been a while since I wrote that code, so can't be too sure. But I remember being happy to finally see it working and pasting it into a notepad. If I did any changes, it was just to make it flow/look better.

Also, I had tried to edit the tutorial example code to work with just integers and adding up numbers and made this to show what I changed. That also made it stop working and I couldn't figure out why. It's not like I changed anything critical, just the data that it sends.


text:
LED sometimes don't turn off when a button is pressed
I'm still very new to this but I've put together some code that when a button is pressed, my servo runs continuously, a second button rotates it the other way and a third cancels everything.
A red or green comes on depending on the rotation and this can be one using an IR receiver also.
Issue I'm having is that randomly, 1/5 of the time, the red or green LED does not turn off. I can manually kill it using the third cancel button or just press it a couple times until it turns off as it should on the next push of the button.
Cant work out where im going wrong.
I also find my IR remote works maybe 60% of the time. Any help would be greatly appreciated.
#include <Servo.h>
Servo servo1;
int servoPin = 9;
#include "IRremote.h"

/*----- Variables, Pins -----*/

int receiver = 12; // Signal Pin of IR receiver to Arduino Digital Pin 6
int RledPin = 5;
int GledPin = 3;
int buttonApin = 7;
int buttonBpin = 8;
int buttonCpin = 4;
unsigned long elapsedTime;
unsigned long onTime;

/*-----( Declare objects )-----*/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4

IRrecv irrecv(receiver);    // create instance of 'irrecv'
decode_results results;     // create instance of 'decode_results'

void setup()
{
  irrecv.enableIRIn(); // Start the receiver
  servo1.attach(servoPin);
  servo1.write(90);
  pinMode(RledPin, OUTPUT);
  pinMode(GledPin, OUTPUT);
  pinMode(buttonApin, INPUT_PULLUP);
  pinMode(buttonBpin, INPUT_PULLUP);
  pinMode(buttonCpin, INPUT_PULLUP);

}

void loop(){

if (digitalRead(buttonApin) == LOW)   // Switch is closed to start LED timer
         {
          digitalWrite(RledPin, HIGH);  // Red LED comes On
          digitalWrite(GledPin, LOW);  // Green LED Goes Off
          servo1.attach(servoPin); //Servo is activated
          servo1.write(0);  //Servo turns on clockwise
            onTime = millis();  //time set
          }

      if(onTime > 0 && millis() - onTime > 1500)  //time limit target
            {
            servo1.write(90); //Servo stops
            servo1.detach(); //servo deactivated
            delay(500); //used to sync the servo stop with the LED off
            digitalWrite(RledPin, LOW);  // LED goes off
              onTime = 0;  //time reset
            }

if (digitalRead(buttonCpin) == LOW)   // Switch is closed to start LED timer
         {
          digitalWrite(GledPin, HIGH);  // Green LED comes On
          digitalWrite(RledPin, LOW);  // RED LED Goes Off
          servo1.attach(servoPin); //Servo is activated
          servo1.write(180);  //Servo turns on anti-clockwise
            onTime = millis();  //time set
          }

      if(onTime > 0 && millis() - onTime > 1500)  //time limit target
            {
            servo1.write(90); //Servo stops
            servo1.detach(); //servo deactivated
            delay(500);
            digitalWrite(GledPin, LOW);
              onTime = 0;  //time reset
            }

if (digitalRead(buttonBpin) == LOW) //Deactivation Sequence KILL SWITCH
  {
    digitalWrite(RledPin, LOW);
    digitalWrite(GledPin, LOW);
    servo1.write(90);
    servo1.detach();
      onTime = 0;  //time reset
  }

  if (irrecv.decode(&results)) // have we received an IR signal?

  {
    switch(results.value)

    {

      case 0xFFE01F: // DOWN button pressed
                      {
          digitalWrite(RledPin, HIGH);  // Red LED comes On
          digitalWrite(GledPin, LOW);  // Green LED Goes Off
          servo1.attach(servoPin); //Servo is activated
          servo1.write(0);  //Servo turns on clockwise
          onTime = millis();  //time set
          }

          if(onTime > 0 && millis() - onTime > 2000)  //time limit target
            {
            servo1.write(90); //Servo stops
            servo1.detach(); //servo deactivated
            digitalWrite(RledPin, LOW);  // LED goes off
             onTime = 0;  //time reset
            }
            break;

      case 0xFF906F: // UP button pressed
                      {
          digitalWrite(GledPin, HIGH);  // Green LED comes On
          digitalWrite(RledPin, LOW);  // RED LED Goes Off
          servo1.attach(servoPin); //Servo is activated
          servo1.write(180);  //Servo turns on anticlockwise
          onTime = millis();  //time set
          }

      if(onTime > 0 && millis() - onTime > 2000)  //time limit target
            {
            servo1.write(90); //Servo stops
            servo1.detach(); //servo deactivated
            digitalWrite(GledPin, LOW);  // LED goes off
             onTime = 0;  //time reset
            }
            break;

      case 0xFF02FD: // PAUSE button pressed
                      servo1.write(90);
                      servo1.detach();
                      digitalWrite(GledPin, LOW);
                      digitalWrite(GledPin, LOW);
                      break;

    }

      irrecv.resume(); // receive the next value

  }
}/* --end main loop -- */

insert a layer of separation between the button press and the resulting action ... do same with IR codes .... pressing a button results is a flag variable being set doRed = true; ...... case 0xFFE01F: does the same thing .... neither of these do anything else, just set a flag and continue on ..... further down in loop(), act on the state of the flag if (doRed) {

Please adopt an indenting style and stick to it. Your source is barely readable. Many problems reveal themselves by consistent indentation.

Insert some debugging outputs to see what exactly happens in your program.

Are you debouncing the buttons in hardware? If not, you need to debounce them in software using a debouncer. This will remove the random glitches as the switch contacts bounce when they change over.

@jsotola Thanks for the reply, sorry to sound silly but when you say add a layer of separation, what does that mean?

@tim Thanks for the suggestion, I ave read articles mentioning debouncers but don't know anything about them. I will go away and look into it, thank you.

@NathanCooper ... not separated if button is pressed, then turn on LED.... separated if button is pressed, then set a flag .... if flag is set, then turn on LED .... multiple events can set the flag ... only one function checks the flag and activates the LED

Found the answer!
I added serial print to every line and realised that my kill process after the time elapsed was switching between the red led and green led.
I didn't need the if time elapsed function many times, just once. Deleted that portion and it worked perfectly. Seems to have fixed the IR troubles too.
Working code:

#include <Servo.h>
Servo servo1;
int servoPin = 9;
#include "IRremote.h"

/*----- Variables, Pins -----*/

int receiver = 12; // Signal Pin of IR receiver to Arduino Digital Pin 6
int RledPin = 5;
int GledPin = 3;
int buttonApin = 7;
int buttonBpin = 8;
int buttonCpin = 4;
unsigned long elapsedTime;
unsigned long onTime;

/*-----( Declare objects )-----*/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4

IRrecv irrecv(receiver);    // create instance of 'irrecv'
decode_results results;     // create instance of 'decode_results'

void setup()
{
  irrecv.enableIRIn(); // Start the receiver
  servo1.attach(servoPin);
  servo1.write(90);
  pinMode(RledPin, OUTPUT);
  pinMode(GledPin, OUTPUT);
  pinMode(buttonApin, INPUT_PULLUP);
  pinMode(buttonBpin, INPUT_PULLUP);
  pinMode(buttonCpin, INPUT_PULLUP);
  Serial.begin(9600);
  pinMode(LED_BUILTIN, HIGH);

}

void loop(){

if (digitalRead(buttonApin) == LOW)   // Switch is closed to start LED timer
         {
          digitalWrite(RledPin, HIGH);  // Red LED comes On
          Serial.println("RED comes on");
          digitalWrite(GledPin, LOW);  // Green LED Goes Off
          Serial.println("green off");
          servo1.attach(servoPin); //Servo is activated
          Serial.println("red servo attach");
          servo1.write(0);  //Servo turns on clockwise
          Serial.println("red servo spins");
            onTime = millis();  //time set
         }

if(onTime > 0 && millis() - onTime > 1500)  //time limit target
            {
            servo1.write(90); //Servo stops
            Serial.println("servo stops spinning");
            digitalWrite(RledPin, LOW);  // LED goes off
            digitalWrite(GledPin, LOW);  // LED goes off
            Serial.println("red RED goes off");
            delay(500);
            Serial.println("delay");
            servo1.detach(); //servo deactivated
            Serial.println("servo Rled dettach");
              onTime = 0;  //time reset

         }
if (digitalRead(buttonCpin) == LOW)   // Switch is closed to start LED timer
         {
          digitalWrite(GledPin, HIGH);  // Green LED comes On
          Serial.println("green comes on");
          digitalWrite(RledPin, LOW);  // RED LED Goes Off
          Serial.println("RED goes off");
          servo1.attach(servoPin); //Servo is activated
          Serial.println("green servo attached");
          servo1.write(180);  //Servo turns on clockwise
          Serial.println("green servo spins");
            onTime = millis();  //time set
         }

if (digitalRead(buttonBpin) == LOW) //Dectivation Sequence KILL SWITCH
  {
    digitalWrite(RledPin, LOW);
    Serial.println("total red off");
    digitalWrite(GledPin, LOW);
    Serial.println("total green off");
    servo1.write(90);
    Serial.println("total servo off");
    servo1.detach();
    Serial.println("total detach");
      onTime = 0;  //time reset
  }

  if (irrecv.decode(&results)) // have we received an IR signal?

  {
    switch(results.value)

    {

      case 0xFFE01F: // DOWN button pressed
                      {
          digitalWrite(RledPin, HIGH);  // Red LED comes On
          digitalWrite(GledPin, LOW);  // Green LED Goes Off
          servo1.attach(servoPin); //Servo is activated
          servo1.write(0);  //Servo turns on clockwise
          onTime = millis();  //time set
          }
          break;

      case 0xFF906F: // UP button pressed
                      {
          digitalWrite(GledPin, HIGH);  // Green LED comes On
          digitalWrite(RledPin, LOW);  // RED LED Goes Off
          servo1.attach(servoPin); //Servo is activated
          servo1.write(180);  //Servo turns on clockwise
          onTime = millis();  //time set
          }
          break;

      case 0xFF02FD: // PAUSE button pressed
          servo1.write(90);
          digitalWrite(GledPin, LOW);
          digitalWrite(GledPin, LOW);
          delay(500);
          servo1.detach();
          break;
    }

      irrecv.resume(); // receive the next value

  }
}/* --end main loop -- */


text:
FingerPrint Scanner wont detect any input (fingerprint image)
Hi good day to all I have a project that , it will lock the solenoid using the fingerprint then I have hook up a coinslot that will count the coins inside the vault its like a secured piggybank.
Project objective

it must display the coin total :
If fingerprint is access it will unlock the solenoid
then goes back to total of coins

The problem is its just showing total of coins inserte but the fingerprint wont detect any image id taken from enrrol code
#include <Adafruit_Fingerprint.h>    //Libraries needed
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#include <EEPROM.h>
#define coinSlot 9 // different pin!!! untested!!!

#define I2C_ADDR 0x27          //LCD i2c stuff
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

int in2 = 4;

String Names[] = { "RAVEN", "Surtr", "Tech",}; //Those are the names affected to the fingertemplates IDs
                                                 //The first on which is Names[0] : Yassine has the ID 1 in the fingerprint sensor

SoftwareSerial mySerial(2, 3);                  //Fingerprint sensor wiring RX 3, TX 2
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); //LCD declaring

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);                    //Fingerprint sensor declaring

int coinCount = 0;
int coinSlotSignal;
int requiredCoins = 1;
boolean coinInserted = false;

void setup()
{
  pinMode(in2, OUTPUT);
  digitalWrite(in2, HIGH);
  pinMode(coinSlot, INPUT_PULLUP);
  lcd.write(EEPROM.read(5));

  Serial.begin(9600);               //Serial begin incase you need to see something on the serial monitor
  finger.begin(57600);              //Sensor baude rate
  lcd.begin (16,2);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home();
  finger.getTemplateCount();        //Counts the number of templates stored in the sensor flash memory
  delay(2000);
}

void loop()
{
  int result = getFingerprintIDez();  //This function keeps looping and waiting for a fingerprint to be put on the sensor
    OpenDoor();

  // Coinslot
  while(!coinInserted){
    coinSlotSignal = digitalRead(coinSlot);

    if(coinSlotSignal < 1) {
      coinCount += 1;
      coinInserted = true;
      EEPROM.write(0,coinCount);
      Serial.println(EEPROM.read(0));

      lcd.setCursor(0,0);
      lcd.print("TOTAL:");
      lcd.setCursor(0,1);
      lcd.print(coinCount);
    } // if
  } // while

  while(coinInserted) {
   coinSlotSignal = digitalRead(coinSlot);
    if(coinSlotSignal >0) {
      coinInserted = false;
    }
  }

  if(coinCount >= requiredCoins) {
    delay(1500);
  }
}

//Main function taken from the "fingerprint" example and modified
//Only the modifications are commented
int getFingerprintIDez() {
  uint8_t p = finger.getImage();        //Image scanning
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();               //Converting
  if (p != FINGERPRINT_OK)  return -1;

  lcd.clear();                     //And here we write a message or take an action for the denied template
  p = finger.fingerFastSearch();     //Looking for matches in the internal memory
  if (p != FINGERPRINT_OK){          //if the searching fails it means that the template isn't registered
    lcd.print("Access denied");
    delay(2000);
    return -1;
  }
            //If we found a match we proceed in the function

  lcd.print("Welcome");                  //Printing a message for the recognized template
  lcd.setCursor(2,1);
  lcd.print(Names[finger.fingerID-1]); //Then print the name we gave it and the -1 is to remove the shift as the ID starts from "1" but the array from "0"
  return finger.fingerID;
}

/*The two following functions depends on your locking system
 *mine has a DC motor that should turn in both ways for opening and closing
 *that's why I'm using H bridge, you could have a solenoid with a transistor
 *then you'll need only opening sequence but controlling the transistor
 *as the closing is spring loaded...
 */

void OpenDoor(){
  digitalWrite(in2, LOW); // turn on motor
  delay(5000);
  digitalWrite(in2, HIGH); // turn off motor
}

what is your question?

I tried to test using enroll code it was working then If I try to upload the code it wont work in the serial monitor it sayst fingerprint not found

I cannot see, where "fingerprint not found" would be printed to Serial. Please explain, where this happens.and did you actually enroll fingerprint with a previous code? Otherwise the sensor cannot recognize any fingerprint.

hI sir thanks for the reply I already fixed the issue sir , I was having a bad balance on my Brackets , after formally formatting my code I found the issues. Thanks


text:
error: expected primary-expression before ',' token edit status 1
Im using tinkercad for my robotics class and I can't seem to figure out a solution for this problem.
Heres my codes:
#include <LiquidCrystal.h> //LCD library
#define echo 2
#define trig 3

// Gas Sensor
#define GREEN 4
#define Yellow 6
#define RED 7
#define Buzzer 5
#define Sensor A0

float duration;
float distance;

LiquidCrystal lcd(13,,12,11,10,9,8);

int sensor_Input;
float temp;

void setup()
{
  // Ultrasonic sensor
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  Serial.begin(9600);
  lcd.begin(13, 2);

  //temp
  measure_Temp();
  display_Temp();

  // Gas Sensor
  for (int i = 0; i < 6; i++)
    pinMode(i, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  // Ultrasonic Sensor
  time_Measurement();
  distance = duration * (0.0343) /2;

  display_distance();

  // Gas Sensor
  for (int i = 0; i < 6; i++)
    digitalWrite(i, LOW);

  status_Indicator();
}

void status_Indicator()
{
  // Gas Sensor
  int sensor_In = analogRead(A0);
  Serial.println(sensor_In);

  if ( sensor_In>=40 )
  {
    digitalWrite(RED, HIGH);
    digitalWrite(Buzzer, HIGH);
  }
  else if (sensor_In >=25 )
  {
    digitalWrite(Yellow, HIGH);
  }
  else
  {
    digitalWrite(GREEN, HIGH);
  }
  delay(10);
}

void time_Measurement()
{
  // Ultrasonic Sensor
  digitalWrite(trig, LOW);
  delayMicroseconds(2);

  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);

  duration = pulseIn(echo, HIGH);
}

void display_distance()
{
  lcd.clear();
    lcd.setCursor(0, 0);
  Serial.print("Distance in m: ");
  Serial.print(distance);
  Serial.println();
  lcd.print("distance in m: ");
  lcd.setCursor(5, 1);
  lcd.print(distance);
  delay(1000);
}

void measure_Temp()
{
  //Temp
  sensor_Input = analogRead(A0);
  temp = (float)sensor_Input / 1024;
  temp = temp *5;
  temp = temp - 0.5;
  temp = temp *100;
}

void display_Temp()
{
  //temp
  lcd.setCursor(0, 0);
  Serial.print("Temp. in Celcius: ");
  Serial.print(temp);
  Serial.println();
  lcd.print("Temp. in Celcius: ");
  lcd.setCursor(5, 1);
  lcd.print(temp);
  delay(500);
}

@ user77041 Please provide the full error output.

You have two commas in the command when making the lcd object:
LiquidCrystal lcd(13,,12,11,10,9,8);

Probably just a typo, delete the comma and you should be good to go.
LiquidCrystal lcd(13,12,11,10,9,8);