text:
Turning on and off two set of LEDs with two tactile buttons
I have two sets of 4 LEDs.
Set A (Led1 Led2, Led3, Led4)
Set B (Led5 Led6, Led7, Led8)
Both sets have its own tactile button:
Tactile A,
Tactile B,
Tactile A, turning on the LEDs set A and tactile B turning on the LEDs on set B.
So each time I press the tactile A, Led1 from Set A will turn on. The next press will turn on Led2 and LED1 off, then Led3 on, Led2 off, and Led4 on and led3 off.
Same for Tactile B and set B.
Tactile A will not change the set be and same tactile B.
So I came up with the below code. It works fine for Tactile A, for set A. But I am not able to turn on the set B with Tactile B. Tactile B is keep switching itself one after another the tactile B is no functioning. Each set should work with its own tactile button.

//Start -- Power supply on/off code

#include <Bounce2.h>

#define POWER_PIN 13
#define power 12

//End -- Power supply on/off code

//Start -- Switching Leds
// Leds set A
#define button 2
#define led1 8
#define led2 7
#define led3 6
#define led4 5
//Leds set B
#define tactile 3
#define led5 11
#define led6 4
#define led7 9
#define led8 10
int state = 0;      //integer to hold the current state Set A
int old = 0;        //integer to hold the last state Set A
int tactitleState = 0;      //integer to hold the current state Set B
int oldState = 0;        //integer to hold the last state Set B
int buttonPoll = 0; //integer to hold the button state for set A
int tactilePoll = 0; //integer to hold the button state for set B
//End -- Switching power

//Start -- Power supply on/off code

int powerState = LOW;
Bounce b = Bounce(); // Instantiate a Bounce object

//End -- Power supply on/off code

void setup() {
  //Start -- Power supply on/off code

  b.attach(POWER_PIN, INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
  b.interval(25); // Use a debounce interval of 25 milliseconds
  pinMode(power, OUTPUT); // Setup the LED
  digitalWrite(power, powerState); // Turn off the LED

  //End -- Power supply on/off code

  //Start -- Switching power

  pinMode(button, INPUT); //button set as input
  pinMode(led1, OUTPUT); //Output set Led1
  pinMode(led2, OUTPUT); //Output set Led2
  pinMode(led3, OUTPUT); //Output set Led3
  pinMode(led4, OUTPUT); //Output set Led4

  digitalWrite (led1, HIGH); //set state Led1
  digitalWrite (led2, HIGH); //set state Led2
  digitalWrite (led3, HIGH); //set state Led3
  digitalWrite (led4, HIGH); //set state Led4

  digitalWrite (power, HIGH); //state of the input power

  //Second relay
  pinMode(tactile, INPUT); //button set as input
  pinMode(led5, OUTPUT); //Output set Led5
  pinMode(led6, OUTPUT); //Output set Led6
  pinMode(led7, OUTPUT); //Output set Led7
  pinMode(led8, OUTPUT); //Output set Led8

  digitalWrite (led5, HIGH); //set state Led5
  digitalWrite (led6, HIGH); //set state Led6
  digitalWrite (led7, HIGH); //set state Led7
  digitalWrite (led8, HIGH); //set state Led8

  //End -- Switching power

}

void loop() {
  //Start -- Power supply on/off code
  b.update(); // Update the Bounce instance
  if ( b.fell() ) {  // Call code if button transitions from HIGH to LOW
    powerState = !powerState; // Toggle LED state
    digitalWrite(power, powerState); // Apply new LED state
  }
  //End -- Power supply on/off code

  //Start -- Switching power Set A.

  buttonPoll = digitalRead(button); //Detect the state of the button
  if (buttonPoll == 1) {              //Check if the button pressed
    delay (50);                       //Delay 50ms
    buttonPoll = digitalRead (button); //Poll button again
    if (buttonPoll == 0) {           //if it is 0 considered one press
      state = old + 1;               //increas state by 1
    }
  }
  else {
    delay (100);                    //Delay 100ms
  }
  switch (state) {     //react tot button press & state
    case 1:
      digitalWrite (led1, LOW); //led1 is on
      digitalWrite (led2, HIGH); //led2 is off
      digitalWrite (led3, HIGH); //led3 is off
      digitalWrite (led4, HIGH); //led4 is off
      old = state;
      break;
    case 2:
      digitalWrite (led1, HIGH); //led1 is off
      digitalWrite (led2, LOW); //led2 is on
      digitalWrite (led3, HIGH); //led3 is off
      digitalWrite (led4, HIGH); //led4 is off
      old = state;
      break;
    case 3:
      digitalWrite (led1, HIGH); //led1 is off
      digitalWrite (led2, HIGH); //led2 is off
      digitalWrite (led3, LOW); //led3 is on
      digitalWrite (led4, HIGH); //led4 is off
      old = state;
      break;
    case 4:
      digitalWrite (led1, HIGH); //led1 is of
      digitalWrite (led2, HIGH); //led2 is off
      digitalWrite (led3, HIGH); //led3 is off
      digitalWrite (led4, LOW); //led4 is on
      old = state;
      break;
    default:                   //if the there is no state, then all leds are off
      digitalWrite (led1, HIGH); //led1 is of
      digitalWrite (led2, HIGH); //led2 is off
      digitalWrite (led3, HIGH); //led3 is off
      digitalWrite (led4, HIGH); //led4 is off
      old = 0;   // All states are reset to 0 off
      break;
  }
  //End -- Switching  led set A
  //Start -- Switching led set B

  tactilePoll = digitalRead(tactile); //Detect the state of the button
  if (tactilePoll == 1) {              //Check if the button pressed
    delay (50);                       //Delay 50ms
    tactilePoll = digitalRead (tactile); //Poll button again
    if (tactilePoll == 0) {           //if it is 0 considered one press
      tactitleState = oldState + 1;               //increas state by 1
    }
  }
  else {
    delay (100);                    //Delay 100ms
  }
  switch (tactitleState) {     //react tot button press & state
      case 1:
      digitalWrite (led5, LOW); //led5 is on
      digitalWrite (led6, HIGH); //led6 is off
      digitalWrite (led7, HIGH); //led7 is off
      digitalWrite (led8, HIGH); //led8 is off
      oldState = tactitleState;
      break;
    case 2:
      digitalWrite (led5, HIGH); //led5 is off
      digitalWrite (led6, LOW); //led6 is on
      digitalWrite (led7, HIGH); //led7 is off
      digitalWrite (led8, HIGH); //led8 is off
      oldState = tactitleState;
      break;
    case 3:
      digitalWrite (led5, HIGH); //led5 is off
      digitalWrite (led6, HIGH); //led6 is off
      digitalWrite (led7, LOW); //led7 is on
      digitalWrite (led8, HIGH); //led8 is off
      oldState = tactitleState;
      break;
    case 4:
      digitalWrite (led5, HIGH); //led5 is off
      digitalWrite (led6, HIGH); //led6 is off
      digitalWrite (led7, HIGH); //led7 is off
      digitalWrite (led8, LOW); //led8 is on
      oldState = tactitleState;
      break;
    default:                   //if the there is no state, then all leds are off
      digitalWrite (led5, HIGH); //led5 is off
      digitalWrite (led6, HIGH); //led6 is off
      digitalWrite (led7, HIGH); //led7 is off
      digitalWrite (led8, HIGH); //led8 is off
      oldState = 0;   // All states are reset to 0 off
      break;
  }
  //End -- Switching Leds set B
}

The link doesn't seem to work without an account. You code for checking if a button is pressed is very odd, and it surprises me that it even seems to work for the A set button. How are you buttons connected? Do they have a pull-up/pull-down resistor? Might I also suggest renaming you variables something less random. For example use stateA and stateB instead of state and tactileState. Idem for buttonPoll and tactilePoll. old and oldState.

Your code is rather hard to follow.
Your code to read a button press doesn't make much sense:
  buttonPoll = digitalRead(button); //Detect the state of the button
  if (buttonPoll == 1) {              //Check if the button pressed
    delay (50);                       //Delay 50ms
    buttonPoll = digitalRead (button); //Poll button again
    if (buttonPoll == 0) {           //if it is 0 considered one press
      state = old + 1;               //increas state by 1
    }
  }
  else {
    delay (100);                    //Delay 100ms
  }

That code will, I think, only detect a button press if you press the button for exactly 50 mS. Given that you already use the Bounce library, why don't you create Bounce instances for your LED controller buttons and use those to read those buttons as well?
Next issue: you are setting your button and tactile pins to INPUT rather than INPUT_PULLUP. Do you have pulldown resistors on those? (when your input is set to INPUT mode you need pulldown resistors, and need to connect the switches to +5V. If you use INPUT_PULLUP mode you don't need any resistors, but you connect your switches to ground. They then read HIGH until you press a switch, at which point the switch connects the pin to ground and pulls it LOW.)
Next issue: You are treating a value of 1 as pressed and 0 as not pressed. You should use the constants HIGH and LOW instead. (And note that if you use INPUT_PULLUP mode for your pins, you should wire your buttons to VCC, and treat HIGH as not pressed and LOW as button pressed.)
I would suggest renaming your variables and using arrays of LED pin numbers:
int set1Button 2;
int set1LEDs[] = {8, 7, 6, 5};
int set1State = 0; //No LEDs lit

int set2Button 3;
int set2LEDs[] = {11, 4, 9, 10};
int set2State = 0; //No LEDs lit

Pressing setButton1 should advance set1State, and pushing set2Button should advance set2State.
For value 0, set all LEDs to off. any other value, set the LED at index setXState - 1 on and all others off.
This code would work for the first set of LEDs:
for (int index = 1; index <= 4; index++) {
     int value = set1State == index ? HIGH : LOW;
     digitalWrite (set1LEDs[index-1], value);
}

Small correction: If using INPUT_PULLUP, one should wire the button to ground, not to Vcc. And of course the array definition should look like in Mats edit of your question. As far as I know, the above array definition does not work in C/C++.

Chrisl, the way my answer was worded it wasn't clear that for a pin set to INPUT you need a pulldown resistor and the switch connected to +5V, but for INPUT_PULLUP mode you need to connect the switch to ground. I edited the answer to make it clearer.

I work mostly in Swift these days, and couldn't remember the C/C++ static array syntax. Thanks @Mat for fixing it.

@DuncanC, Can you please provide a full code? I tried but it is not working.

This is not a code writing service, and my partial code might not fit with the rest of your sketch. Edit your question and provide the updated code at the end, along with detailed information on how it's behaving.

Your new wiring diagram shows you as having the buttons connected to +5V. Is that correct? Are you using INPUT mode or INPUT_PULLUP mode? Are you treating a HIGH value as button pressed, or a LOW value?

@DuncanC, The button is connected to 5V, and to pin 2 and other to pin 3,. So when the button press the pin 2 or same pin 3 goes hight.

And the rest of my questions?

@DuncanC, I use INPUT mode with a resistor as shown in the pic, if it is wrong so then I will use INPUT_PULLUP mode. When the button is pressed it will act is LOW.

INPUT mode, with pull-down resistors, should work. I don't see any pull-down resistors in the picture of your circuit however.

But your button debouncing code from your original post is a mess. Why not use the Bounce library for your switches? I assume that's what it's for.

@DuncanC, since I posted this question, I started an online course in Arduino coding and C++. I almost finished the Arduino course, and it was not that much helpful. I will start another advance course on Arduino. In future, I may be able to sort this out. But right now I am too beginner. I just do this for fun and experience and it is not a business.  I googled the Bounce library and checked YouTube, I will look at how it is possible. Thanks for the directions.

I found some examples in these links:
How to Detect Short, Long, and Double Clicks with Arduino
https://youtu.be/TwM1sp2IXYI
Button De-bouncing
https://youtu.be/4NcfEwm9WBI


text:
What are patterns of bits sent to or read from GPIO pins called?
I want to call them “words”, but I’m uncertain if this is how they are referred to in documentation for the use of a header board that might plug into an ardino board.
So if you have a sequence of ONs and OFFs being read or sent from a microcontroller board are those called words?  What are they called?

What? I don't understand, what you are talking about

https://en.wikipedia.org/wiki/Word_(computer_architecture)

Bit streams or bit patterns, perhaps? Words have a different definition already, but it may fit what you are asking for, can't tell.

Also it might be called packets, messages (=> communication protocol). Depends on interface

@KIIV Frames too?  What do you mean by “depends on the interface?”

Different interfaces names similar concepts differently...

The "GP" in GPIO stands for "general-purpose", meaning that the interpretation of the signals will vary. Even changing from a 0 to a 1 might not be "a bit" depending on the specific protocol being used (e.g., edge-clocked).

Here is a simplistic diagram.
Larger than 8 bits is usually referred to as WORD.

Is one nybble input and the other nybble output in the diagram?

no,  it is not ... how did you arrive at that supposition? ... the diagram only shows that a byte consists of two nybbles ... there is no input or output implied

Consider backing away from Arduino hardware for just a moment

I want to call them “words”, but I’m uncertain ...

For most computers and processors a word is comprised of bytes and bytes are comprised of bits.  A bit is an individual 0 or 1.  That's always true.  A byte is almost always made up of 8 bits.  Why? Because it is always convenient to do things on a computer or processor in powers of 2.  That is, 2 or 4 or 8 or 16 or 32 or ... (keeps going).  And 8 is a convenient sized number of bits!  A word is usually 2 bytes or 16 bits.  But that's not always true.  For some computers it is more.
Keep in mind, so far, we are just talking about data.  Not physical GPIO pins.  When we do interface through the GPIO pins this data can be sent out in parallel or in serial form.  It really depends on how we want to interface with the world!  For instance, many Arduino projects uses a serial interface called an I2C bus to talk with peripherals such as a temperature sensor.

So if you have a sequence of ONs and OFFs being read or sent from a
microcontroller board are those called words?

This sounds like you are talking about serial data (as apposed to parallel data).

Talking about the hardware: The GPIO lines on most embedded processors are designed to interface with the world using parallel data.  You can use software and "emulate" a serial stream of data on one of the GPIO lines.  But you might not be able to send out data fast.  Instead, most embedded processors have special serial port pins which are connected to fast hardware usually called UARTs. When sending or receiving serial data, it is almost always better to use a pin connected to a UART.

Talking about the data: Again, word can mean different amounts of data on different processors. And to further complicate things, some serial protocols mix things up and end up sending out or reading data using an odd number of bits.  Which makes talking about the combined bits as a word confusing.  At this point I would just stop using the word "word" to describe the data and just call it "data".

Besides, most Arduino boards (like the Arduino Uno) use embedded processors which interface directly to peripherals such as temperature sensors over serial ports.  As such, the data format is usually spelled out by the peripheral and is (very) specific for the purpose of the peripheral (temperature sensing in this case). It is recommended to read the specifications for the peripheral and use the terminology presented there when communicating with others regarding that particular peripheral.

source: Stack Exchange

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

sort: votes


text:
Uno doesn’t get enough power from 5v barrel connector. Why?
I’m using a 5v 20a power supply run through a barrel connector into an Arduino Uno to control an LED strip. When only the barrel is connected, the green light on the Uno comes on but the yellow light lights dimly for a few milliseconds then goes dark. The light strip doesn’t light at all. When a USB is also connected, the board lights up fully (green and yellow LED) and the LED strip runs through its routine.
I’m making this as Christmas lights on a tree outside so I want it to run on the stand alone power supply. Why doesn’t the barrel work on 5v?

because it is not a 5 V barrel jack. the specs says it is for 7 to 12 V

Voltage Drop
Well, if you put 5V into your barrel jack, your UNO's onboard 5V regulator is going to drop that down to 3.5V or so.  You must have more than 5V into the regulator to get 5V out of it.  This is referred to as the regulator's "drop out" voltage.
The specs for an UNO say to power it from at least 7V for that reason.
As an experiment you can power it this way without your lights attached and measure the "5V" header to GND to see this happening.
Power Dissipation
Linear regulators like that found on the UNO are not efficient. They waste energy as heat in proportion to the current through it and voltage dropped by it.
If you provide it with 7V at the regulator and your project draws 0.5 amps from the regulator, you will try to generate 0.5A * (7V - 5V), that is 1 Watt of heat.  Your regulator can probably dissipate half that with how it's mounted on the UNO and normal ambient air temperature.
Note this situation gets worse if you put 12V (for example) into the barrel jack, as you'd be dropping 7V across the regulator.
Many linear regulators have thermal overload protection built into them.  They'll stop producing as much voltage at the output as they heat up to try to survive the event.  And that's likely what you're seeing if you're trying to power your christmas lights from the regulator.
If you want to see this yourself might try very briefly tapping the regulator with your finger; it may be blazing hot.  You might just dampen your finger and hold it near the regulator's surface to feel the heat coming off of it.
You will more than likely need to route power around the Arduino board to your lights to prevent this.

Thanks! That makes sense.

@JohnnyRollerfeet If you have 5V already, you can wire it to the 5V rail (to skip the regulator). But be avare of possible backpowering of USB hub

@JohnnyRollerfeet, you may also want to consider getting a USB breakout or take the B end off a USB cable and use that to power the board.  That will allow you to keep the using the polyfuse that the UNO has connected to its USB jack.  And it will effectively plug the USB jack while you're powering it with 5V more-or-less directly.

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


text:
Errors occured when switching from Uno to Nano Every
I wrote a code that worked perfectly on an Uno. I switched everything out to a Nano Every, and now I'm getting the following errors:
In file included from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\libraries\LiquidCrystal\src\LiquidCrystal.cpp:1:0:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\libraries\LiquidCrystal\src\LiquidCrystal.h:45:36: error: expected class-name before '{' token
 class LiquidCrystal : public Print {
                                    ^
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\libraries\LiquidCrystal\src\LiquidCrystal.h:86:9: error: 'Print' has not been declared
   using Print::write;
         ^~~~~

exit status 1

Error compiling for board Arduino Nano Every.

I'm new to programming (this is the first thing I've done that wasn't from a tutorial), so I don't understand what any of the above means.
In the Tools dropdown, I have
Board: Arduino Nano Every
Registers Emulation: None (ATMEGA4809)
Programmer: Onboard Atmel mEDBG (Uno Wifi Rev2)
Here's the code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("Charging");
  delay(750);
  lcd.print(".");
  delay(750);
  lcd.print(".");
  delay(750);
  lcd.print(".");
  delay(750);
  lcd.clear();
  lcd.print("Charged");
}

void loop() {
  const int buzzerPin = 6;
  const int switchPin = 13;
  const int buttonPin = 7;
  const int ledPin = 9;
  pinMode(switchPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  int switchState = digitalRead(switchPin);
  int buttonState = digitalRead(buttonPin);
  lcd.setCursor(0, 1);
  lcd.print("Mode: ");
  if (switchState == LOW) {
    lcd.print("Stun");
  } else {
    lcd.print("Kill");
  }
  if (buttonState == HIGH) {
    const int buzzerMax = 2000;
    const int time = 3;
    int buzzerTone;
    int totalReps = 50;
    int reps = 10;
    while (reps < totalReps) {
      buzzerTone = ((totalReps - reps) * 2 * (buzzerMax / totalReps));
      tone(buzzerPin, buzzerTone);
      analogWrite(ledPin, (255 / reps));
      delay(time);
      reps++;
      delay(time);
      if (reps == totalReps) {
        noTone(buzzerPin);
        analogWrite(ledPin, 0);
      }
    }
    lcd.clear();
    lcd.print("Charging");
    delay(333);
    lcd.print(".");
    delay(333);
    lcd.print(".");
    delay(333);
    lcd.print(".");
    delay(333);
    lcd.clear();
    lcd.print("Charged");
  }
}

Looks like you're using the Windows Store version of the IDE. That's known to be faulty in so many ways. Download the newest version from the Arduino website and update all the cores to the latest version.

it is a know issue with a workaround https://github.com/arduino/Arduino/issues/10025


text:
Writing a 32-bit register to 32 pins as fast as possible in Arduino Due
Problem:

I'm using Due's QDEC function to decode a 32bit quadrature encoder.
I need to pipe out the counter value as fast as possible to another instrument's DIO.
The rear strip is selected as digital output because it's easy to slap an IDC connector on it.

#define QA 2
#define QB 13
const unsigned int mask_QA = digitalPinToBitMask(QA);
const unsigned int mask_QB = digitalPinToBitMask(QB);

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

    // QDEC block
    REG_PIOB_PDR = mask_QA;     // activate peripheral function
    REG_PIOB_ABSR |= mask_QA;   // choose peripheral option B
    REG_PIOB_PDR = mask_QB;
    REG_PIOB_ABSR |= mask_QB;

    REG_PMC_PCER0 = (1<<27);                                // activate clock for TC0 (PID27)
    REG_TC0_CMR0 = (1 << 0) | (1 << 2) | (1<<8) | (1<<10);  // config clock
    REG_TC0_BMR = (1<<9)|(1<<8)|(1<<12);                    // activate QDEC
    REG_TC0_CCR0 = 5;                                       // enable the clock and reset counter

    //PIO BLOCK
    // mask write, the rear strip of Arduino Due
    REG_PIOA_OWER = 0x0018c808; // A 7 14 15 19 20
    REG_PIOB_OWER = 0x04204000; // B 14 21 26
    REG_PIOC_OWER = 0x000FF3FE; // C 1-9 12-19
    REG_PIOD_OWER = 0x0000064F; // D 0 1 2 3 6 9 10
}
void loop() {

  // data write
  REG_PIOA_ODSR = REG_TC0_CV0;
  REG_PIOB_ODSR = REG_TC0_CV0;
  REG_PIOC_ODSR = REG_TC0_CV0;
  REG_PIOD_ODSR = REG_TC0_CV0;
}

This code is untested as I don't have access to the hardware right now.
Basically 4 bit masks (for PIO ABCD) are created to map the 32bit REG_TC0_CV0 onto the rear strip.

Requirement:

[Priority] As little delay as possible, every clock cycle matters.
[Secondary] Output bandwidth should match the update rate of REG_TC0_CV0, which I didn't manage to find in the manual. The output should also provide a latch for the receiving equipment to sync sampling.

Question:

Would disabling peripheral functions for all 32 pins on the rear strip interfere with the core functionality that this program depends on (timer/counter etc) ?
Are there other ways that can accomplish this faster ?
I would like to use the main CPU tread for serial interface. It is possible to attach the four ODSR writing instructions to a timer ISR so it does not interfere with void loop()?

Thanks in advance !

please post a link to the quadrature encoder .... it actually makes no sense that it would require a 32 bit interface

@jsotola The quadrature encoder is from a scientific-grade brushless linear motor. I don't know the exact part number but the linear motor has the precision of 20000 counts/mm, and the max travel of the motor is 220mm. So the top count is 4400000, which requires at least 23 bits. Also the output format of REG_TC0_CV0 is 32 bits.

Define as fast as possible? once per second, a 100,000,000 times a second, both are possible but there is a upper limit to what you can do with a processor, additional hardware may be needed. More Information Please?

@Gil Thanks for your interests in my question. I have updated the question to better define "fast".

@Gil 100MHz possible ? I thought the MCK is 84MHz. However that's irrelevant as the output should be attached to ISR for when REG_TC0_CV0 became available.


text:
Why won't my motor run?
I am trying to run a small 3v motor with a Keyestudio MEGA 2560(which is the same as the Arduino MEGA 2560). I am getting a consistent 5 volts everywhere I check with a multimeter. The voltage drops to 0.01-0.05 once I connect the motor. The motor runs once it is connected directly to the Arduino's 5v output pin. The motor draws about 600mA consistently when we connect it directly to 5v.
My code is rather basic, which just sends voltage out pin 5.  I am not using any shield. controlling the speed is not my main concern here, though later on in my project I would like the motor to be able to reverse as well.
I found this circuit diagram in "Arduino for dummies," and found this same diagram on many other websites too.
void setup() {
  pinMode(5,OUTPUT);
}

void loop() {
  digitalWrite(5,HIGH);
}

simulate this circuit – Schematic created using CircuitLab

An NPN bipolar transistor requires a current to flow from base to the emitter which is then multiplied by the beta of the transistor controlling the maximum current which flows from the collector to the emitter.  A 2n2222 beta is about 100.  Let us calculate the amount of current which will be allowed to flow from the collector to the emitter of the 2n2222 transistor.  First calculate the current from the base to the emitter:
I(be) = (5.0 volts- 0.7 volts) / 1,000 ohms
I(be) = .0043 Amps

Use this current to find the maximum current flowing from the emitter to the collector:
I(ce) = 100 x I(be) = 0.430 Amp or 430mA

We see that the transistor does not provide enough current to drive a 600mA motor.
We need to reduce the value of R1 such that I(ce) is at least 600mA which means that I(be) needs to be at least 6mA.  Rearranging the earlier equation to find R1:
I(be) = (5.0 volts- 0.7 volts) / 1,000 ohms
I(be) = (5.0 volts- 0.7 volts) / R1
R1 = (5.0 volts- 0.7 volts) / I(be)
R1 = (5.0 volts- 0.7 volts) / 0.006 Amps
R1 = 716.67 ohms

However, because of the large amount of I(ce) current necessary to drive the load, we find the transistor reaching it's limits and the beta of the transistors drop apprecably:

This diagram is a little hard to understand.  And there is no curve for 600mA.  But we can get an idea of what to expect if we look at the 500mA curve.  We see that in order to get less than a volt drop across the transistor (V(ce)) we need to pump in more than 10mA (I(be)).  To get similar results for 600mA we would likely approach 20mA and now we are dangerously close to the processor pin current driving capabilities.
A common alternative is to use a Darlington Transistor configuration:

The resulting beta is essentially the product of the individual transistor's betas.
Let's do some rough calculations.  If the 2n2222 that switches the load current has a lower beta of about 10, we would need about 60mA to switch a 600mA current.  To generate 60mA through the transistor connected to the processor, we would need about 0.6mA from the processor.  That's really small and we can afford to triple it to ensure reliable operation.  So let's pick 3mA:
R1 = (5.0 volts- (2 * 0.7 volts)) / 0.003
R1 = 1200 ohm

So a 1K ohm resistor should likely work.

The DC gain of the transistor will likely be lower than that. “About 100” is an order of magnitude estimate of the typical gain at moderate currents. The gain goes down when I_C goes above 100 mA. According to this datasheet (Fig. 4), the typical gain @ (I_C = 500 mA, V_CE = 1 V) is 50, and more like 10 if you want to be well into saturation (V_CE ≈ 0.2 V).

Dang, I missed that entirely @EdgarBonet.  I'll fix the answer.  Thanks.

Ok, I fixed the solution.  I'm eager to hear your thoughts @EdgarBonet.

Wouldn't a power MOSFET be a better choice for this application, since they have very low on resistance and require almost no current to the base?

That is a good suggestion @DuncanC.  I've see both used.  Do you have a reference to a good discussion we can read?


text:
Error downloading package_esp32
I've been trying to install esp32 on Arduino IDE for days now but I keep getting 'error downloading package' message. I checked the over and over again, it's correct. I even tried installing it manually using GitGUI but it's not working. Please help me.

what's correct?

The link. I was wondering maybe I was making a mistake but I checked, there's no mistake

Describe exactly what steps you followed and any error messages you get. Otherwise we'll just have to guess. You may write "it's correct" but the fact that you can't get it to work tells me otherwise. Did you follow these instructions ?

The content of the boards manager json file the ESP32 Arduino package downloads and is well formed JSON.  There appear to be 14 distinct .zip and .tar.gz files for the core and tools files for the various platforms supported by the 1.0.4 release.  All of them download for me.  You should update your question in all the ways mentioned in comments above.

*Started the IDE, opened files>preferences, entered the link, open tools>boards>boards manager, searched for esp32 but it showed blank. I tried three types which I all found on the net
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
https://dl.espressif.com/dl/package_esp32_index.json
The error message I keep getting reads;
'Error downloading [the link I use]'

The last, https://dl.espressif.com/dl/package_esp32_index.json is what I believe to be correct and what I'd used when doing the work behind my prior comment.

What do you think could be the problem?

Also experiencing this issue, exactly as described by the OP. Anyone have a solution?


text:
Arduino Nano randomly resetting
I am currently struggling with an intermittent problem with an Arduino project.
Background
I am using a LabVIEW program to control a few pieces of hardware. One of them is a NEMA 17 stepper motor that drives a rack and pinion actuator. I am using a genuine Arduino Nano with an (official) EasyDriver motor driver to drive the NEMA 17. The Arduino listens for the state of a DI pin, and if it is pulled high it moves out the rack until a U-shaped sensor sends a high input signal at the outermost position, it then listens for that DI pin to be pulled low and retracts the rack until a proximity sensor sends a high input signal.
The Problem
I noticed that my actuator was either becoming unresponsive to the input signals from the LabVIEW DAQ, or that it was getting stuck mid actuation (motor has plenty of torque for this application). After changing up the code to print updates to the serial port, I realized that after a few cycles the Arduino resets and re-enters the Setup() function.
I changed out the Nano and it made no difference. I am using a timeout feature for the first time and I was wondering if the memory usage of this feature could be causing problems - however I commented out this part of the code and the Arduino still reset. The code is below - would really love to hear any thoughts on whether this is likely to be a hardware or software issue. I am powering the Arduino with a 7V line from a Power Supply into the Vin port. The prox sensor operates at 24V but I divide the output signal's voltage so that the input voltage is ~4.8V (I have measured this). I am using the same U-shaped sensor with a few other Arduinos and I am not seeing this issue. I have powered Arduinos with the same 7V line in the past and have also never seen them reset like this.
Let me know what you think, thank you!
 const int uSensor = 12;
const int proxSensor = 10;

const int labViewHomePin = 9;
const int labViewInputPin = 8;

const int labViewOutFeedback = 7;
const int labViewInFeedback = 6;

const int StepperStepPin = 2;
const int StepperDirectionPin = 3;
const int ENPin = 13;

enum {IdleState, ForwardState, BackwardState} State;            // this switch case is used to call the correct function that turns the motor in the desired direction

boolean rampDone = false;
boolean pusherIn = false;
boolean pusherOut = false;
boolean homingDone = false;

boolean updateGiven = false;

int motorSpeed = 300;
int rampStartSpeed = 500;
int rampStepCountNo = 800;

boolean boolInitialMove = true;
unsigned long timeInitialMove = 6000;
unsigned long startTime;
unsigned long endTime;

void setup() {
  Serial.begin(9600);
  pinMode(uSensor, INPUT);
  pinMode(proxSensor, INPUT);
  pinMode(labViewHomePin, INPUT);                                  // initialising input pins
  pinMode(labViewInputPin, INPUT);                                  // initialising input pins

  pinMode(StepperDirectionPin, OUTPUT);                             //Direction
  pinMode(StepperStepPin, OUTPUT);                                  // Step
  pinMode(ENPin, OUTPUT);                                           // Enable

  Serial.println();
  Serial.println("Setup phase called");
  Serial.println();

  pinMode(labViewInFeedback, OUTPUT);
  pinMode(labViewOutFeedback, OUTPUT);

  State = IdleState;
  digitalWrite(ENPin,HIGH);                                         // Disable the drive by default

  homingDone = false;
}

void loop() {
  if ((digitalRead(labViewHomePin) == HIGH) && (homingDone == false)) {
    Serial.println("Homing Pin High Detected");
    homingRoutine();
    homingDone = true;
    Serial.print("Homing Done = ");
    Serial.println(homingDone);
    State = IdleState;

    if(digitalRead(proxSensor) == HIGH) {
      digitalWrite(labViewInFeedback,HIGH);
      digitalWrite(labViewOutFeedback,LOW);
    }
    else if(digitalRead(uSensor) == HIGH)  {
      digitalWrite(labViewInFeedback,LOW);
      digitalWrite(labViewOutFeedback,HIGH);
    }
    else {
      digitalWrite(labViewInFeedback,LOW);
      digitalWrite(labViewOutFeedback,LOW);
    }

  }

  switch (State) {
    case IdleState:
    boolInitialMove = true;
    digitalWrite(ENPin,HIGH);

      if(updateGiven == false) {
        Serial.println("I am in IdleState");
        Serial.print("Pusher Out Boolean = ");
        Serial.println(pusherOut);
        Serial.print("Pusher In Boolean = ");
        Serial.println(pusherIn);
        Serial.print("Prox Sensor status: ");
        Serial.println(digitalRead(proxSensor));
        Serial.print("U-Sensor status: ");
        Serial.println(digitalRead(uSensor));
        updateGiven = true;
      }

      if ((digitalRead(labViewInputPin) == HIGH) && (pusherOut == false) && (homingDone == true)) {
        digitalWrite(ENPin,LOW);                                    // Enable drive
        State = ForwardState;
        Serial.println("LabVIEW High detected. Case switched to ForwardState");
        Serial.println("");
        updateGiven = false;
      }
      else if ((digitalRead(labViewInputPin) == LOW) && (pusherIn == false) && (homingDone == true)) {
        digitalWrite(ENPin,LOW);                                    // Enable drive
        State = BackwardState;
        Serial.println("LabVIEW Low detected. Case switched to BackwardState");
        Serial.println("");
        updateGiven = false;
      }
      else {
        //do nothing
      }

      if(digitalRead(uSensor) == HIGH) {
        pusherOut = true;
        pusherIn = false;
      }
      else if(digitalRead(proxSensor) == HIGH) {
        pusherOut = false;
        pusherIn = true;
      }
      else {
        //do nothing
      }

      break;

    case ForwardState:

    if(updateGiven == false) {
        Serial.println("I am in ForwardState");
        Serial.print("LabVIEW Actuate Pin = ");
        Serial.println(digitalRead(labViewHomePin));
        updateGiven = true;
      }

    if(boolInitialMove == true) {
        digitalWrite(StepperDirectionPin, LOW);
        rampUpCosineWave(rampStartSpeed, rampStepCountNo, motorSpeed);
        startTime = millis();
        endTime = startTime;
        boolInitialMove = false;
      }

      endTime = millis();
      rotateForward(motorSpeed);                                            // this calls the function ForwardState which starts pushing out the pusher

      if (digitalRead(uSensor) == HIGH) {
        digitalWrite(labViewInFeedback,LOW);
        digitalWrite(labViewOutFeedback,HIGH);
        Serial.println("U-Sensor High detected. Case switched to Idlestate");
        Serial.println("");
        updateGiven = false;

        pusherOut = true;
        pusherIn = false;
        State = IdleState;
      }
      else if((endTime-startTime) > timeInitialMove) {
        digitalWrite(ENPin,HIGH);
        digitalWrite(StepperStepPin, LOW);
        digitalWrite(StepperDirectionPin, LOW);
        digitalWrite(labViewOutFeedback,HIGH);
        digitalWrite(labViewInFeedback,HIGH);

        Serial.println("");
        Serial.println("**TIMEOUT DETECTED**");
        Serial.println("");

        State = IdleState;
      }
      break;

    case BackwardState:

    if(updateGiven == false) {
        Serial.println("I am in BackwardState");
        Serial.print("LabVIEW Actuate Pin = ");
        Serial.println(digitalRead(labViewHomePin));
        updateGiven = true;
      }

    if(boolInitialMove == true) {
        digitalWrite(StepperDirectionPin, HIGH);
        rampUpCosineWave(rampStartSpeed, rampStepCountNo, motorSpeed);
        startTime = millis();
        endTime = startTime;
        boolInitialMove = false;
      }

      endTime = millis();
      rotateBackward(motorSpeed);

      if (digitalRead(proxSensor) == HIGH) {
        digitalWrite(labViewInFeedback,HIGH);
        digitalWrite(labViewOutFeedback,LOW);                                // Disable drive
        Serial.println("Prox Sensor High detected. Case switched to Idlestate");
        Serial.println("");
        updateGiven = false;

        pusherOut = false;
        pusherIn = true;
        State = IdleState;
      }
      else if((endTime-startTime) > timeInitialMove) {
        digitalWrite(ENPin,HIGH);
        digitalWrite(StepperStepPin, LOW);
        digitalWrite(StepperDirectionPin, LOW);
        digitalWrite(labViewOutFeedback,HIGH);
        digitalWrite(labViewInFeedback,HIGH);

        Serial.println("");
        Serial.println("**TIMEOUT DETECTED**");
        Serial.println("");

        State = IdleState;
      }
      break;

  } // end switch
}

void rotateForward(int mtrSpeed) {
  digitalWrite(StepperDirectionPin, LOW);
  digitalWrite(StepperStepPin, HIGH);
  delayMicroseconds(mtrSpeed);
  digitalWrite(StepperStepPin, LOW);
}

void rotateBackward(int mtrSpeed) {
  digitalWrite(StepperDirectionPin, HIGH);
  digitalWrite(StepperStepPin, LOW);
  delayMicroseconds(mtrSpeed);
  digitalWrite(StepperStepPin, HIGH);
}

void homingRoutine() {
  digitalWrite(ENPin,LOW);
  Serial.println("Homing Routine called");
  bool firstCycle = false;
  bool secondCycle = false;
  bool thirdCycle = false;
  bool fourthCycle = false;

  while(digitalRead(uSensor) != HIGH) {
    rotateForward(rampStartSpeed);
  }
  delay(500);
  Serial.println("First home movement completed");
  while(digitalRead(proxSensor) != HIGH) {
    rotateBackward(rampStartSpeed);
  }
  delay(500);
  Serial.println("Second home movement completed");
  while(digitalRead(uSensor) != HIGH) {
    rotateForward(rampStartSpeed);
  }
  delay(500);
  Serial.println("Third home movement completed");
  while(digitalRead(proxSensor) != HIGH) {
    rotateBackward(rampStartSpeed);
  }

  delay(500);

  homingDone = true;
  pusherIn = true;
  pusherOut = false;

}

  int rampUpCosineWave(int startSpeed, int rampUpSteps, int maximumSpeed) {
  int countedSteps = 0;
  float amp = ((startSpeed-maximumSpeed)/2);
  for(int currentSpeed = startSpeed; currentSpeed > maximumSpeed; currentSpeed = (int)((amp + maximumSpeed)+(amp*(cos((PI/rampUpSteps)*countedSteps))))) {
    digitalWrite(StepperStepPin, LOW);
    delayMicroseconds(currentSpeed);
    digitalWrite(StepperStepPin, HIGH);
    countedSteps++;
  }

  return countedSteps;
}

Can you monitor the Vin and +5V lines with a scope while the stepper is running? Electric motors can make power supplies noisy and unstable.

Your meter may also have a MIN mode that tracks the minimum voltage seen since started.  It's not as good as a using a scope as Edgar suggests, but sometimes it can help.

Thank you all for your contributions. I managed to find the issue and solve the intermittent reset. I was expecting to find a hardware problem as the root cause, but just in case it was software related I wanted to check as well. It turned out to be hardware
Gil is certainly questioning the correct piece of hardware. It was indeed the wiring of the Prox sensor. I had connected both the data and power common rails to facilitate the prox sensor but on inspection, I decided to keep these separate and voltage divide the prox sensor away from the rails and instead bring a direct 4.8V line into the Arduino. Whatever noise the stepper motor was creating was unable to impact the data lines of the Arduino, and I haven't seen the issue return since.
Really appreciate the help everyone. I didn't scope the power lines to the Arduino, as the issue continued regardless of me powering the arduino through only the COM port of a PC, a combo of both the COM port and 7V to the Vin line (presume the Arduino draws from the 7V line but I am unsure) and just the 7V line. Appears to have been noise disrupting the data common rail of the Arduino.

I expect you have a lot going on with your design.  Dividing down is never a good voltage (power) supply regardless of what you measure unless you are using a good scope to measure and it is well bypassed. Consider a Buck regulator from one of the China suppliers they are just a few bucks and will stabilize your circuit. If the prox sensor draws just a few mills consider powering it with the Arduino 5 volts. Motors like other inductive devices generate lots of transinents that are both conducted and radiated, something like that may be getting into your system possibly via the prox sensor. This should get you started.


text:
Arduino expected ')' before '{' token
 for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    Serial.print(mfrc522.uid.uidByte{i} < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte{i}, HEX);
    content.concat(String(mfrc522.uid.uidByte{i} < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte{i}, HEX));
  }

I use this code to get UID of an RFID card, but the error "expected ')' before '{' token" comes out. Does anybody know how to solve this problem?

This is a simple C(++) error and not Arduino-specific. To address array elements you should use square brackets ([, ]) instead of curly brackets. Replace all instances of {i} with [i] and you will be good to go.

I’m voting to close this question because it's a trivial syntax error question.

Welcome to this site, next time use ctrl-k to align your code.
The problem is in:
Serial.print(mfrc522.uid.uidByte{i} < 0x10 ? " 0" : " ");

To get the value of an array, use [i], not {i}, thus
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");

(similar to other lines).
To give some additional hints:

Try to prevent duplicated code by storing the byte into a variable. Now you can use uidValue in the subsequent lines.
uint8_t uidValue = mfrc522.uid.uidByte[i];

Store 0x10 inside a constant.

So you get:
const uint8_t MAX_HEX_SINGLE_DIGIT_VALUE 0x0F;

for (byte i = 0; i < mfrc522.uid.size; i++)
{
    uint8_t uid_byte = mfrc522.uid.uidByte[i];
    Serial.print(uid_byte < LOW_VALUE <= MAX_HEX_SINGLE_DIGIT_VALUE ? " 0" : " ");
    Serial.print(uid_byte, HEX);
    content.concat(String(uid_byte < MAX_HEX_SINGLE_DIGIT_VALUE ? " 0" : " "));
    content.concat(String((uid_byte, HEX));
  }

I assume the Serial lines are only for debugging, otherwise you can combine them too.

Thank you very much, Michel.

If the answer helps, consider upvoting and if the answer solves your problem, also accept it.

Michel, if you answer a syntax error question, then at least without syntax errors. I thought you agreed that syntax error questions shouldn't  be answered.

@Juraj I don't have a compiler at hand ... and I will ask to move the question to StackOverflow.

they will reject a syntax error question. it is off-topic on SO

So how can the op get an answer? For a beginner programmer I can imagine it's not immediately trivial to use [] instead of {}.

to ask a question for every syntax error is not a way to learn codding. a codding course is a much better way

@Juraj .. However, at least instead of answering a duplicate question could be found. Although I hope if the OP stays interested he will do a course, or at least find out how C(++) syntax works.


text:
Is it possible to configure uboot without the "Yun Serial Terminal" sketch by using the hardware serial on pins 0 and 1 instead?
Trying to rescue a Yun with the 1.5.3 image.
It's not possible to upload the required "Yun Serial Terminal" sketch  because the device hangs at U-Boot (hence the rescue attempt).
Using putty serial with:
Pin 0 (Rx)
Pin 1 (Tx)
Baud: 250000
8N1
This capture shows the result (which is the best I can find so far).
How do I properly connect to the serial console using the GPIO pins?

Hold the MCU in RESET to prevent it interfering.


text:
Connecting multiple ultrasonic sensors(hc-sr04) to a single arduino board.(mega)
I am currently working on an alarm system using multiple sensors and one arduino board and I am getting readings from 2 of the sensors but one gives a constant zero and a constant buzzer sound even without sensing the distance...I have followed the schematics of the original project but nothing works. Here is the code

int ledred1 = 2;
int ledgreen1 = 3;
int ledorange1 = 4;
int ledred2 = 5;
int ledgreen2 = 6;
int ledorange2 = 7;
int ledred3 = 8;
int ledgreen3 = 9;
int ledorange3 = 10;

int sound = 250;

int trigPin1 = 11;
int echoPin1 = 12;

int trigPin2 = 13;
int echoPin2 = 30;

int trigPin3 = 31;
int echoPin3 = 32;

#define buzzer1 33
#define buzzer2 34
#define buzzer3 35

void setup() {
  Serial.begin (9600);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);

  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);

  pinMode(trigPin3, OUTPUT);
  pinMode(echoPin3, INPUT);

  pinMode(ledred1, OUTPUT);
  pinMode(ledred2, OUTPUT);
  pinMode(ledorange1, OUTPUT);
  pinMode(ledgreen1, OUTPUT);
  pinMode(ledgreen2, OUTPUT);
  pinMode(ledred3, OUTPUT);
  pinMode(ledgreen3, OUTPUT);
  pinMode(ledorange2, OUTPUT);
  pinMode(ledorange3, OUTPUT);

}
void firstsensor(){ // This function is for first sensor.
  int duration1, distance1;
  digitalWrite (trigPin1, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin1, LOW);
  duration1 = pulseIn (echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;

      Serial.print("1st Sensor: ");
      Serial.print(distance1);
      Serial.print("cm    ");

  if (distance1 <=200 && distance1>=100) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,HIGH);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);

    sound=250;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
     }

  if (distance1 <100&& distance1>=50) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,HIGH);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);

    sound=275;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }
        if (distance1 <50&& distance1>=0) {  // Change the number for long or short distances.
    digitalWrite (ledred1, HIGH);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);

    sound=300;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }
      if(distance1>200 || distance1<0){
    Serial.println("Out of Range");
    noTone(buzzer1);
  }
  else{
    Serial.print(distance1);
    Serial.println("cm");
    tone(buzzer1,sound);

  }
}
void secondsensor(){ // This function is for second sensor.
    int duration2, distance2;
    digitalWrite (trigPin2, HIGH);
    delayMicroseconds (10);
    digitalWrite (trigPin2, LOW);
    duration2 = pulseIn (echoPin2, HIGH);
    distance2 = (duration2/2) / 29.1;

      Serial.print("2nd Sensor: ");
      Serial.print(distance2);
      Serial.print("cm    ");

     if (distance2 <=200&& distance2>=100) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, HIGH);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);

    sound=250;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
     }

  if (distance2 <100&& distance2>=50) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,HIGH);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);

    sound=275;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }
        if (distance2 <50&& distance2>=0) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, HIGH);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);

    sound=300;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }
      if(distance2>200 || distance2<0){
    Serial.println("Out of Range");
    noTone(buzzer2);
  }
  else{
    Serial.print(distance2);
    Serial.println("cm");
    tone(buzzer2,sound);

  }
}
void thirdsensor(){ // This function is for third sensor.
    int duration3, distance3;
    digitalWrite (trigPin3, HIGH);
    delayMicroseconds (10);
    digitalWrite (trigPin3, LOW);
    duration3 = pulseIn (echoPin3, HIGH);
    distance3 = (duration3/2) / 29.1;

      Serial.print("3rd Sensor: ");
      Serial.print(distance3);
      Serial.print("cm");

     if (distance3 <=200&& distance3>=100) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, HIGH);

    sound=250;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
     }

  if (distance3 <100&& distance3>=50) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,HIGH);
    digitalWrite (ledgreen3, LOW);

    sound=275;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }
        if (distance3 <50&& distance3>=0) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);

    sound=300;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }
      if(distance3>200 || distance3<0){
    Serial.println("Out of Range");
    noTone(buzzer3);
  }
  else{
    Serial.print(distance3);
    Serial.println("cm");
    tone(buzzer3,sound);

  }
}

void loop() {
Serial.println("\n");
firstsensor();
delay(100);
secondsensor();
delay(100);
thirdsensor();
delay(100);
}

This is what I get in the serial monitor
This is the snapshot of the pin configuration

Did you try exchanging the first module with one of the others? Tripple-check all your connections? Test it out with a simple example sketch all on its own?

I would suggest that you want to really simplify your program by making a single function that can take parameters to work with different pin combinations rather than duplicating code like that.

please review your code line by line and learn what each line does .... it appears that you have not thought about program flow at all .... i am saying this because your sensor1 code manipulates led2 and led3 ... same with sensor2 and sensor3 ... also the distance checking code turns off leds that were previously turned on .... you cannot just copy and paste code without being aware of what it does

@Mat I have rebuilt the connections and tested using a simple sketch..It works.. I guess the problem is with the code

@Majenko I am currently trying to simplify the code

@jsotola Rookie mistake:( I am kindly requesting for your help in going through the lines with me since I am new to all this

This is NOT an answer to the question, but I did some (major) refactoring which make it much more clear what is happening.
I think you made some mistake within the (refactored) method Sensor::UpdateState.
File <.ino>:
#include "Sensors.h"

Sensors _sensors;

void setup() {
  Serial.begin (9600);
  _sensors.Init();
}

void loop()
{
  _sensors.Process();
}

File Sensors.h:
#ifndef SENSORS_H
#define SENSORS_H

#include "Arduino.h"
#include "Sensor.h"

class Sensors
{
  public:
    Sensors();

    void Init();
    void Process();

  private:
    static const int NR_OF_SENSORS = 3;

    Sensor _sensors[NR_OF_SENSORS];
};

#endif // SENSORS_H

File Sensors.cpp:
#include "Sensors.h"

Sensors::Sensors()
:
  //              index trigPin echoPin redLed orangeLed greenLed buzzer)
  _sensors( { Sensor(1 ,  11   ,  12   ,  2       3     ,   4    ,  33),
              Sensor(2 ,  13   ,  30   ,  5       6     ,   7    ,  34),
              Sensor(3 ,  31   ,  32   ,  8       9     ,   10   ,  35) })
{
}

void Sensors::Init()
{
  for (uint8_t index = 0; index < NR_OF_SENSORS; index++)
  {
    _sensors[index].Init();
  }
}

void Sensors::Process()
{
  for (uint8_t index = 0; index < NR_OF_SENSORS; index++)
  {
    _sensors[index].Process();
  }
}

File Sensor.h:
#ifndef SENSOR_H
#define SENSOR_H

#include "Arduino.h"

class Sensor
{
  public:
    enum EState
    {
      LOW_OUT_OF_RANGE,
      WAY_TOO_CLOSE,
      TOO_CLOSE,
      OK,
      HIGH_OUT_OF_RANGE
    };

    Sensor(uint8_t index, uint8_t trigPin, uint8_t echoPin, uint8_t redLed, uint8_t orangeLed, uint8_t greenLed, uint8_t buzzer);

    uint8_t Index    (void) { return _index;     };
    uint8_t TrigPin  (void) { return _trigPin;   };
    uint8_t EchoPin  (void) { return _echoPin;   };
    uint8_t RedLed   (void) { return _redLed;    };
    uint8_t OrangeLed(void) { return _orangeLed; };
    uint8_t GreenLed (void) { return _greenLed;  };
    uint8_t Buzzer   (void) { return _buzzer;    };

    void Init();
    void Process();

  private:
    uint8_t _index;
    uint8_t _trigPin;
    uint8_t _echoPin;
    uint8_t _redLed;
    uint8_t _orangeLed;
    uint8_t _greenLed;
    uint8_t _buzzer;
    EState _state;
    uint8_t _distance;

    void Measure();
    void UpdateState();
    void ProcessState();
    void Show(uint16_t sound, uint8_t led);
    void PrintDistance(void);
};

#endif // SENSOR_H

File Sensor.cpp:
#include "Sensor.h"

Sensor::Sensor(uint8_t index, uint8_t trigPin, uint8_t echoPin, uint8_t redLed, uint8_t orangeLed, uint8_t greenLed, uint8_t buzzer)
:
  _index(index),
  _trigPin(trigPin),
  _echoPin(echoPin),
  _redLed(redLed),
  _orangeLed(orangeLed),
  _greenLed(greenLed),
  _buzzer(buzzer),
  _state(OK),
  _distance(0)
{
}

void Sensor::Init()
{
  pinMode(TrigPin()  , OUTPUT);
  pinMode(EchoPin()  , INPUT);
  pinMode(RedLed()   , OUTPUT);
  pinMode(OrangeLed(), OUTPUT);
  pinMode(GreenLed() , OUTPUT);
}

void Sensor::Process()
{
  Measure();
  UpdateState();
  ProcessState();
  PrintDistance();
  delay(100);
}

void Sensor::Measure()
{
  digitalWrite(TrigPin(), HIGH);
  delayMicroseconds (10);
  digitalWrite(TrigPin(), LOW);
  uint16_t duration = pulseIn (EchoPin(), HIGH);
  _distance = (duration / 2) / 29.1;
}

void Sensor::UpdateState()
{
  if (_distance < 0)
  {
    _state = LOW_OUT_OF_RANGE;
  }
  else if (_distance <= 50)
  {
    _state = WAY_TOO_CLOSE;
  }
  else if (_distance <= 100)
  {
    _state = TOO_CLOSE;
  }
  else if (_distance <= 200)
  {
    _state = OK;
  }
  else
  {
    _state = HIGH_OUT_OF_RANGE;
  }
}

void Sensor::ProcessState()
{
  digitalWrite(RedLed(), LOW);
  digitalWrite(OrangeLed(), LOW);
  digitalWrite(GreenLed(), LOW);

  switch (_state)
  {
  case LOW_OUT_OF_RANGE:
    noTone(Buzzer());
    break;

  case WAY_TOO_CLOSE:
    Show(300, RedLed());
    break;

  case TOO_CLOSE:
    Show(275, OrangeLed());
    break;

  case OK:
    Show(250, GreenLed());
    break;

  case HIGH_OUT_OF_RANGE:
    noTone(Buzzer());    break;
    break;

  default:
    // Error
    break;
  }
}

void Sensor::Show(uint16_t sound, uint8_t led)
{
  tone(Buzzer(), sound);
  digitalWrite(led, HIGH);
}

void Sensor::PrintDistance()
{
  Serial.print("Sensor ");
  Serial.print(Index());
  Serial.print(": ");
  Serial.print(_distance);
  Serial.print("cm    ");

  if ((_state == LOW_OUT_OF_RANGE) || (_state == HIGH_OUT_OF_RANGE))
  {
    Serial.print(" (Out of range)");
  }

  Serial.println("");
}

Thank you for this..i am going through it to see how I can model the code to suit the one I have written


text:
How many connections can Arduino I2C method create?
I was just learning about I2C between 2 Arduinos, one as sender and another as a receiver
So I have got curiosity to know how many Arduinos can be connected to I2C connection in serial?
I mean,
Arduino1 --> Arduino2
Then can I connect Arduino3 to
Arduino 2 then again Arduino 4 to Arduino 3? Till how many Arduinos can I continue this connection?

you can't connect Arduino 3 to Arduino 2 as slave to master, because the MCUs you tagged have only one I2C interface and Arduino2 is already a slave. but you can connect many slaves to Arduino1 because I2C is a bus.

@Juraj I2C allows for multiple masters. Though it's rarely used, and requires some extra work to prevent collisions.

@Gerben that would be really very useful

@Gerben, the question describes a chain where 1 and 3 are connected only over 2. I only tor OP to realize the difference

@Gerben hello? I have a question that can a slave send data to master?

Not really. The master has to request the data. Some I2C devices have an interrupt pin, so they can "notify" the master that there is new data.

The limiting factor is the bus capacitance. This is the limit of the total capacitance of the bus from all devices connected to it plus the capacitance of the wires used.
It is also affected by the value of the pullup resistors.
The limit, according to the specifications, is 400pF.  An Arduino has an input capacitance of 10pF.  So ignoring the wires that's an absolute limit of 40 Arduinos all connected together.
Reduce that a bit for the wires, so say 30 is a reasonable estimate. Then reduce that again if you're using the internal pullups which are about 10x bigger than they should be. That gives you a guestimate of 5-10 devices.
Use proper pullups instead of the internal ones (why oh why oh why did Arduino ever encourage and even make default such a stupid option?!?!?!) of say 1kΩ and keep wires very short and you'll probably be OK up to 20-25 devices.

OP doesn't understand I2C and wants to connect Arduino 3 to Arduino 2, not to Arduino 1.

@Juraj With only one I2C interface the only way is with a bus. Whether it's 1-2,1-3,1-4 or 1-2,2-3,3-4 it's still a bus. Just the arrangement of the wires differs. I understand him to mean wiring A4/5 on 1 to A4/5 on 2, then A4/5 on 2 to A4/5 to 3, etc. That's just a single bus.

with two interfaces the MCU could be a master and slave

@Juraj Indeed. But the Uno only has one, so that observation is irrelevant.

I have to connect master arduinos scl and sda using same wires for all other slaves scl and sda ?

@SubhaJeetSikdar You can connect it how you like. You could go SDA/SCL on 1 to A4/A5 on 2, then SDA/SCL on 2 to A4/A5 on 3, etc. A4/A5 and SDA/SCL are directly connected to each other inside the Arduino's PCB. It's the same as connecting all the A4s together and all the A5s together, or connecting one A4 to another A4 to another A4 etc.

And adding pull up resistance means that 2 1k resistors will be needed per scl sda connection?

You need exactly 2 resistors, one on the SCL and one on the SDA. There is only one SCL and one SDA no matter how you arrange the wires.

And final question, can I call Arduino 3 from master Arduino when the Arduino 2 is acting as a slave?

You will have one master Arduino and a number of slave Arduinos. Every slave can be contacted by the master at any time. Only the master can talk to a slave, but it can talk to any slave it chooses. Each slave must have a unique address.

Thanks, u have cleared all my doubts :)

Hello? @Majenko can the address be a string else than an integer?

No. It has to be a number. That's how i2c works. Learn the protocol before you use it

The number is as many as you want.  There are switches that allow you to select different busses and each buss supports its full complement. From my point you are trying to use a solution before you have defined the problem fully. I have a feeling they will not be within a few inches of each other so consider an alternative designed for this type of use. CAN, RS485 and other interfaces would work much better with a lot less effort on your part.


text:
Can I control solid state relay directly from arduino digital pin?
I want to switch on/off some AC device using solid state Omron G3MB relay
I know that for magnetic relay there should be transistor and flyback diode, but what about SSR?
Can I connect it directly to arduino digital pin without any transistors and anything else?
In a closer look on special arduino module, we can see some extras. Are they necessary? I want to put solid state relay (not separated module) into my custom PCB, and I'm confused about that extras.

yes, that's the idea; it's just a resistor and an LED as far as Arduino sees.

Mate, according to the datasheet you provided it's safe to hook the arduino, but to be safe put a resistor in between, just to be sure the SS relay don't pull up to much current from the Arduino, as this may casue harm to your device.

@k.Cyborg am I misreading the datasheet? The way I read it, there are multiple (sub-) models of the G3MB. Some of which don't require a resistor, but some do.

According to the datasheet there are multiple models.
Some already have an input resistor for the led (in the opto-isolator) inside the package, but some don't. For the ones that don't have a resistor inside, you'd need to add one yourself, to limit the current to around 10mA.
Some models also have a snubber circuit inside the package. The need for this depends on what kind of load is connected (inductive vs. resistive (AFAIK)).
I thinks the green thing, in the picture, is a fuse. On the other side of the SSR you can see and indicator led, transistor, and 3 resistor (one to limit current to the SSR, one to limit the current through the indicator led, and on for the base of the transistor.). They probably use a transistor, because the current for the SSR and the indicator led combined, is to high for certain micro controllers.

the transistor is likely used as a current limiter for the ssr's led, just like commercial fotek et al.

The answer is a qualified yes.  In this case the relay is optically isolated from the load so there is no cross conduction. You need to connect the relay to the Arduino power +5 and Ground supply. I would not connect more then one to any arduino pin as the relay has a max requirement of 20mA. Not all SS relays are the same so you need to check there specs if you use another one.


text:
Is it possible my ATMega is burnt due to bad wiring?
While working on a project I tried sending data from my Arduino NANO to ATMega64 placed on AREXX Robot arm PCB via TXD/RXD. After plugging in VCC, GND, TXD and RXD to UART socket it didn't work so I figured the socket itself must be backwords or mirror image from my perspective. Then I tried plugging everything in on the other side of the socket and as I plugged VCC to one of the pins a little smoke came out (I can't specify exact place where smoke came from) and from now on there is no connection to the robot. However LEDs seem to work just like before the 'incident'. It can be seen as COM but, desktop app constantly displays 'Connection failed' when trying to access the robot. It seems that I plugged VCC to the MRESET pin and GND to the RXD1 pin of the ATMega64. Can anyone help define if my processor is burnt? And if so, what can I do to fix the robot? Are there any other ways to send data to ATMega considering it is already programmed adn I want to keep it that way? Unfotunately, replacing ATMega isn't possible for me. Thanks in advance for any help.
UART :

ATMega :

Robot PCB :

what does this mean? ... other side of the socket ....... which pin is this? ... I plugged VCC to one of the pins ... what is that pin connected to?

Yes, it's dead. You will have to learn to solder SMD components and replace the ATMega.

@jsotola just like I wrote, I plugged VCC to MRESET pin and GND to the ATMega's RXD1 pin.

@Majenko Even if LEDs like servo power LED or main power LED are on after turning on the robot?

Yes. It sounds like you burned out the RX pin of the MCU, which means no communication for you any more.

@FewArc I only read up to where you connected Vcc to an unspecified pin ... further reading is usually a waste of time ... why didn't you just say that you accidentally connected Vcc to MRESET and GND to RXD1 right at the begining of your post? ... the story about your project and about why you conected the cable backwards is irrelevant to the problem and just clutters up the post

You can touch (quickly at first) the components on your board to see what if any are unreasonably hot.  That will give you a strong indication of failure.  Lack of that doesn't tell you much though.

Smoke is a definite sign something failed. The LED (power indicator)is independent of the microprocessor, it just indicates power is applied in the appropriate direction.  Go to the basics, and load the simple blink sketch and see if it works, if so you are lucky. You then might want to write some code to check all the outputs and inputs. It is possible you destroyed both devices, you need to do some investigating to determine what is still properly operating.


text:
L293D driver DC motors need help to start rotating
I set up this circuit which uses L293D motor driver IC to control two DC motors.

+6V input is connected to unregulated power supply. It's current rating is 500 mA.
There is a connection between Arduino's ground line and power supplies ground line. There is a parallel 0.1 uF capacitor connected between motor terminal pins.
There is a wheel at the end of the motors but they don't have a gearbox. The wheels are suspended so that they can rotate freely.
The source code of the software is as follows.
#include <Arduino.h>

unsigned int firstMotorPositive = 8;
unsigned int firstMotorNegative = 7;
unsigned int enableFirstMotor = 9;
unsigned int secondMotorPositive = 5;
unsigned int secondMotorNegative = 4;
unsigned int enableSecondMotor = 3;

void setup()
{
    pinMode(firstMotorPositive, OUTPUT);
    /*  I've changed this part as shown by @timemage  */
    //pinMode(secondMotorPositive, OUTPUT); // <------
    pinMode(firstMotorNegative, OUTPUT);
    pinMode(enableFirstMotor, OUTPUT);
    pinMode(secondMotorPositive, OUTPUT);
    pinMode(secondMotorNegative, OUTPUT);
    pinMode(enableSecondMotor, OUTPUT);

    // All motors are off
    digitalWrite(firstMotorPositive, LOW);
    digitalWrite(firstMotorNegative, LOW);
    digitalWrite(secondMotorPositive, LOW);
    digitalWrite(secondMotorNegative, LOW);
}

void turnOnMotors()
{
    // Set motors to maximum speed
    // For PWM maximum possible values are 0 to 255
    analogWrite(enableFirstMotor, 255);
    analogWrite(enableSecondMotor, 255);

    // Turn on motor A & B
    digitalWrite(firstMotorPositive, HIGH);
    digitalWrite(firstMotorNegative, LOW);
    digitalWrite(secondMotorPositive, HIGH);
    digitalWrite(secondMotorNegative, LOW);
    delay(2000);

    // Turn off motors
    digitalWrite(firstMotorPositive, LOW);
    digitalWrite(firstMotorNegative, LOW);
    digitalWrite(secondMotorPositive, LOW);
    digitalWrite(secondMotorNegative, LOW);

    analogWrite(enableFirstMotor, 0);
    analogWrite(enableSecondMotor, 0);

}

void speedControl()
{
    digitalWrite(firstMotorPositive, HIGH);
    digitalWrite(firstMotorNegative, LOW);
    digitalWrite(secondMotorPositive, HIGH);
    digitalWrite(secondMotorNegative, LOW);

    analogWrite(enableFirstMotor, 63);
    analogWrite(enableSecondMotor, 63);

    delay(3000);

    analogWrite(enableFirstMotor, 127);
    analogWrite(enableSecondMotor, 127);
    delay(3000);

    analogWrite(enableFirstMotor, 191);
    analogWrite(enableSecondMotor, 191);
    delay(3000);
/*
    analogWrite(enableFirstMotor, 255);
    analogWrite(enableSecondMotor, 255);
    delay(3000);
*/

    // All motors are off
    digitalWrite(firstMotorPositive, LOW);
    digitalWrite(firstMotorNegative, LOW);
    digitalWrite(secondMotorPositive, LOW);
    digitalWrite(secondMotorNegative, LOW);
    analogWrite(enableFirstMotor, 0);
    analogWrite(enableSecondMotor, 0);
}

void loop()
{

    /*
      turnOnMotors();
      delay(1000);
    */

    speedControl();
    delay(1000);
}

The problem is they need help to start rotating. They will only start rotating if I physically twist the shaft with my fingers first.
As far as I know the motors used in this circuit are two 6 volt DC motors.
When I measure the maximum voltage between motor terminals I read about 0.5 volts. If I twist the shaft I read about 4.5 volts.

does the motor spin when connected directly to the power supply?

Yes. If I connect motors to simple 1.5 volts battery it spins.

I've already tried that but it doesn't help either.

It is also possible that there are physical problems in the wiring.  A clear picture of your actual wiring end to end may help someone spot something.

The L2978D is a terrible motor driver (I really wish people wouldn't use it!). It is "bipolar" which means that both the high and low side switches of the H-bridge are Bipolar Junction Transistors. This means that you get about 1.4V voltage drop in total between the inputs and outputs.
To counter that you must provide at least 1.4V more than your motors need for them to operate properly.

I switched to unregulated power supply to 7.5 volts. I measured unregulated voltage with a DIMM. It was about 12.8 volts. Still, motors don't start. I've also tried with 9 volts. They don't also start with 9 volts.

no pinMode(firstMotorNegative, OUTPUT)
Well, here's a start at least:
pinMode(firstMotorPositive, OUTPUT);
pinMode(secondMotorPositive, OUTPUT); // <------
pinMode(enableFirstMotor, OUTPUT);
pinMode(secondMotorPositive, OUTPUT);
pinMode(secondMotorNegative, OUTPUT);
pinMode(enableSecondMotor, OUTPUT);

You are never setting firstMotorNegative to OUTPUT and probably intended to on the second line of this excerpt.
firstMotorNegative floating or pulled high
The AVR GPIO pins are INPUT on power-up.  Writing to the PORT register, which is what digitalWrite does, takes on a different meaning when the pin's mode is INPUT.  That is, it enables or disables the pull-up internal resistors.  In other words, your     digitalWrite(firstMotorNegative, HIGH); and digitalWrite(firstMotorNegative, LOW); are effectively toggling between pinMode(firstMotorNegative, INPUT_PULLUP) and  pinMode(firstMotorNegative, INPUT) respectively.
So your L293D is seeing either this signal being weakly pulled up or floating.  During the floating condition in particular maybe a problem when you're doing:
// Turn on motor A & B
digitalWrite(firstMotorPositive, HIGH);
digitalWrite(firstMotorNegative, LOW);

... because you're disabling the pull-up here, the "negative" pin is INPUT/floating rather than reliably LOW.  So, it may be being intermittently interpreted as HIGH at the L293D, in which case there is no movement while that's happening.

Thanks I've edited the code as you suggested. But practically there is no difference.

@Erdem I will look for more problems again later and update this if I find anything I'm reasonably certain is a problem.

That is operating as expected. Take a look at the data sheet. You can lose 1.8 volt on each output pin. Since you are in bridge configuration you now lose 3.6 Volts.  Now assume your power is 6VDC with 1 volt ripple. That adds to the voltage drop through the driver so rounding it out you lose 4 volts from your supply (not counting wiring loses) before you start, that is assuming the voltage does not droop. Two simple solutions, use a power supply with more voltage or go to a MOSFET bridge device.

Thanks for the suggestions. I have an adjustable DC adapter which provides unregulated 1.5 V, 3 V, 4,5 V, 6 V, 7.5 V, 9 V and 12 V with up to 500 mA of current. I graudually switched from 6 volts to 12 volts. But motors don't spin. This confuses me since one of the motor with a small wheel attached starts spinning with only 1.5 volts battery but doesn't spins with an external DC adapter. I switched DC adapter to 6 V and measured unregulated voltage with a DIMM. It was about 17 volts. Isn't it a huge voltage for for such a small toy DC motor?

Your best bet is to use a regulated power supply with enough power to drive your load with some spair. An unregulated power supply has ripple, the amount depending on the design and components chosen. Not knowing your DMM and your adapter I can only guess but try measuring the output voltage in the AC range, it should be almost nothing. If you get a value it is a rough approximation of your AC content.

I use pen type Mastech MS8211D  multimeter. I switched unregulated DC adapter to 6 volts setting. I selected AC and used max function to measure maximum voltage. This is quite interesting because it reads maximum voltage as 5.1 volts AC. Also DC voltage was about 10.5 volts.

I think we need to go back to the beginning and have you go to this link https://www.electronics-tutorials.ws/ It is teaches the basics of electronics. While you are studying that get a regulated 10 or 12 volt power source rated at 2 amps or more. If you are in this for the long hall get a Lab Power supply, that runs about $60 on ebay, possibly a Christmas present. The only common thread is the power supply you are using. Also get an Arduino motor shield with FET outputs. This should get rid of the unknowns and get you started.


text:
Run method every hour
I have a method. I need to trigger it every hour (cron job).
I mean:
10.00 p.m -> Trigger
11.00 p.m -> Trigger
12.00 p.m ->Trigger
...
...
Card: Arduino Uno + Wifi Shield.
Draft Code
  void setup() {

  }

  void onTimeChanged() {
      runTask();
  }

  void loop() {

  }

  /*run this method when:
  13.00 p.m
  14.00 p.m
  15.00 p.m
  ........
  ........    */
  void runTask() {

  }

It is unclear what you want. Wild guess: do you want an Arduino to connect to a server when the timezone the travelling Arduino is in changes?

Do you want the Arduino to determine in what timezone it is (by IP or GPS geolocation) or do you want the Arduino to determine when local Daylight Saving Time starts or ends? There are libraries available for both.

I just want to make cron jobs. Such as; 10.00 pm,11.00 pm, 12.00pm -> Execute Method

It is not confusing anymore. I edited question.

Do you need the task to trigger at the exact hour (xx:00, full hour with zero minutes), or do you only care about the period being one hour (like at 10:23, 11:23, 12:23, 13:23...). In the former case, do you have an RTC? A GPS receiver? A WiFi module?

I need to trigger at the exact hour. I don't have any of them. If needed, i can buy them.

An Arduino Uno doesn't have a Real Time Clock, but you could contact a NTP time server on the internet using the WiFi shield you mention, and get the time from there, and then keep track of time using millis(). Every so often, you should adjust the time with a new call to the NTP time server, because the Arduino's clock isn't all that accurate.
The easiest way would be to get a RTC module (I think the most accurate and still affordable at the moment are DS3231-based). They have a slot for a backup battery so they keep time even when there is no power supply.
Connect the module using I2C to your Arduino, install the appropriate library, and ask it every second (or however accurate you want to be) in your loop() for the exact time.
These modules usually also have an interrupt pin and can generate an interrupt when an alarm time is reached; you could use that also.

FWIW, RTClib supports alarms only with the DS3231. A pull request is in progress to add support for the alarms of the PCF8563. There may be other RTC/library alternatives though.


text:
Read Comma Separated String
I have a string that looks like this "10.00,20.00,-50.00," in which these are angle values and they have 2 decimals and can be negative. I want to separate them into 3 separate floats. Here is my current code in which I use sscanf. All I get is 0.00 and have no idea why. Any help is truly appreciated.
String recvString = "10.00,20.00,-50.00,";
float r,p,y;

void setup() {
  Serial.begin(9600);
  Serial.println(r);
  int result = sscanf(recvString.c_str(), "%f,%f,%f,", &r, &p ,&y);
  Serial.println(r);
}

void loop() {}

It's not a full duplicate but it will help you understanding the problem and reason better: https://stackoverflow.com/questions/27651012/arduino-sprintf-float-not-formatting. You can use function http://www.cplusplus.com/reference/cstdlib/strtod/`

a comma is not whitespace ...https://stackoverflow.com/questions/15091284/read-comma-separated-input-with-scanf#15091406

Use the indexOf function to find index then use the subString to get values like this:
String recvString = "10.00,20.00,50.00";
float r, p, y;

void setup() {
  Serial.begin(9600);
  //Serial.println(r);
  //recvString.toCharArray(s, recvString.length() + 1);
  //int result = sscanf(recvString.c_str(), "%f,%f,%f,", &r, &p ,&y);
  int i1 = recvString.indexOf(',');
  int i2 = recvString.indexOf(',', i1+1);
  Serial.println(i1);
  Serial.println(i2);

  String firstValue = recvString.substring(0, i1);
  String secondValue = recvString.substring(i1 + 1, i2);
  String thirdValue = recvString.substring(i2 + 1);

  Serial.println(firstValue);
  Serial.println(secondValue);
  Serial.println(thirdValue);

}

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

}

definitely not this way

But it works so why not?

see the other answer

The AVR implementation of sscanf() does not support parsing floating point numbers, thus you only get zeros out of it. You can't use the %f specifier with it. You need to convert these numbers by yourself with functions like atof() or similar.
Splitting a string into parts can be done many ways. You could use sscanf() to split up the string parts and then use something like atof() to actually convert to float. Or you use strtok() for splitting (see my answer to this question). Or you use one of the many other options, that you get, when googling for something like "Arduino split string" or "Arduino split c string".
Note: Using the String class in Arduino is easy for beginners, but not a good practice (dynamic allocation, heap fragmentation). Look at Majenkos blog for more information about that. Since you already used a function for C-strings, I would suggest moving completely to C-strings (which are basically only an array of char).


text:
Why Are My High and Low Values Not Updating Correctly During Successive Loops
I am attempting to capture the high and low temperature and humidity values, then clearing the LCD and displaying them on 2 successive screen updates. All is working correctly except that the variables for high and low are updating on every loop to the current sensor pin read after the "if" statements are run. Why is this occurring?
Also note that I declare the floats for the highs and lows to the unlikely value of 10000 in order to change them all to the initial pin read on the 1st loop as I didn't find a method to determine null on the initial loop.  I would appreciate any suggestions for a better method!  TIA
    #include <dht.h>
    #include <LiquidCrystal.h>

    //Low and High Temp and Humidity Variables
    float lTemp=10000;
    float hTemp=10000;
    float lHumid=10000;
    float hHumid=10000;

    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

    dht DHT;

    #define DHT11_PIN 7

    void setup(){
      lcd.begin(16, 2);
      Serial.begin(9600);
    }

    void loop(){
       lcd.clear();

      int chk = DHT.read11(DHT11_PIN);

      float CurrTemp = DHT.temperature * 1.8 + 32;  //Converts celsius read from DHT read to farenheit

    //Sets High and Low Temperature Readings

       if (lTemp = 10000) {
         lTemp = CurrTemp;
       }
      if (CurrTemp < lTemp) {
         lTemp = CurrTemp;
      }

      if (hTemp = 10000) {
        hTemp= CurrTemp;
      }
       if (CurrTemp > hTemp) {
        hTemp = CurrTemp;
      }

    //Sets High and Low Humidity Readings

      if (lHumid = 10000) {
        lHumid = DHT.humidity;
       }
      if (DHT.humidity < lHumid) {
        lHumid = DHT.humidity;
      }

      if (hHumid = 10000) {
        hHumid = DHT.humidity;
      }
      if (DHT.humidity > hHumid) {
        hHumid = DHT.humidity;
      }

      //Prints Current Temp and Humidity to LCD and Serial Monitor
      lcd.setCursor(0,0);
      lcd.print("Temp: ");
      lcd.print(CurrTemp,1);
      lcd.print((char)223);
      lcd.print("F");

      Serial.print(CurrTemp,1);

      Serial.println(" F");

      lcd.setCursor(0,1);

      lcd.print("Humidity: ");
      lcd.print(DHT.humidity,0);
      lcd.print("%");

      Serial.print("Humidity: ");
      Serial.print(DHT.humidity,0);
      Serial.println("%");
      Serial.println("");

      delay(10000);

      //Prints Low and High Temp to LCD and Serial Monitor
      lcd.clear();

      lcd.setCursor(0,0);
      lcd.print("L Temp: ");
      lcd.print(lTemp,1);
      lcd.print((char)223);
      lcd.print("F");

      Serial.print("Low Temp: ");
      Serial.print(lTemp,1);
      //Serial.print((char,223);
      Serial.println(" F");

      lcd.setCursor(0,1);

      lcd.print("H Temp: ");
      lcd.print(hTemp,1);
      lcd.print((char)223);
      lcd.print("F");

      Serial.print("High Temp: ");
      Serial.print(hTemp,1);
      Serial.println(" F");
      Serial.println("");

      delay(3000);

     //Prints Low and High Humidity to LCD and Serial Monitor
      lcd.clear();

      lcd.setCursor(0,0);
      lcd.print("Low Humid: ");
      lcd.print(lHumid,0);
      lcd.print("%");

      Serial.print("Low Humid: ");
      Serial.print(lHumid,0);
      Serial.println("%");

      lcd.setCursor(0,1);

      lcd.print("High Humid: ");
      lcd.print(hHumid,0);
      lcd.print("%");

      Serial.print("High Humid: ");
      Serial.print(hHumid,0);
      Serial.println("%");
      Serial.println("");

      delay(3000);

    }

you have a small logic error in your code ...  unnecessary code actually ... in if (lTemp == 10000) { set lTemp, hTemp, lHumid and hHumid  ... there is no need for if (hTemp == 10000) { or if (lHumid == 10000) { or if (hHumid == 10000) {

You have this or similar a number of times:

  if (lTemp = 10000) {
     lTemp = CurrTemp;
   }

This is incorrect.  The == operator is used for comparison.
Try:

  if (lTemp == 10000) {
     lTemp = CurrTemp;
   }

The way you have it, the lTemp variable is assigned 10000 every time the statement is executed.  It's not doing the comparison as you intend.

Turning up the compiler warning level File/Preferences will show a useful message pointing to this in the code.

Thank you!  I knew that but couldn't see it.  Works great now.

@Mav If this was the answer to your question, please accept it as an answer.  Thanks.

When programming in C, the "=" assigns a value and the "==" tests a value.  So in this line of code:
if (lTemp = 10000)

... you are actually assigning variable lTemp the value of 10000.  Consider changing the line of code to this:
if (lTemp == 10000)

... this will test if the variable lTemp is equal to 10000.

Turning up the compiler warning level File/Preferences will show a useful message pointing to this in the code.

Thanks much!    I appreciate your time and knowledge.

@Mav where you found their answers useful, you can upvote them.

Although you already have two perfectly valid answers, I will share a
trick that completely sidesteps the problem. Instead of choosing a
particular number (here, 10,000) as a “magic” value that has a special
meaning, you can instead initialize the highs and lows in a way that
ensures they will be updated on the very first iteration:

make lTemp higher than any temperature you may ever read
make hTemp lower than any temperature you may ever read

For example:
float lTemp = +INFINITY;
float hTemp = -INFINITY;

and the same of course for the humidities. This way the first iteration
does not need special handling anymore, as it becomes a regular
iteration:
if (CurrTemp < lTemp) lTemp = CurrTemp;
if (CurrTemp > hTemp) hTemp = CurrTemp;

Note that the choice of ±∞ for the min and max of an empty set of
readings is not just a dirty hack. It is actually consistent with the
mathematical notion of infimum and supremum of the empty
set.


text:
NodeMCU ESP8266 Ver 0.1 not powering on with VIN
I'm trying to power on my NodeMCU ESP8266 Ver 0.1 (thats what is written in board), via VIN and Ground with my phone charger.
I'm 100% sure that the USB charger is working, providing 5V, and that the ground and VIN are connected to the right positions.
If I use the same phone charger via the NodeMCU USB, the program blinks the builtin led alright.
If I power via VIN, it flashes when I connect the charger to DC, but the program does not work.
It seems as the NodeMCU is not powering on complety.
Bizarrely, if I short 3V and G pins, the board starts working normally as powered directly via USB port.
This is the code
/*
 ESP8266 Blink by Simon Peter
 Blink the blue LED on the ESP-01 module
 This example code is in the public domain

 The blue LED on the ESP-01 module is connected to GPIO1
 (which is also the TXD pin; so we cannot use Serial.print() at the same time)

 Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
                                    // but actually the LED is on; this is because
                                    // it is acive low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}

Just as a follow up:
I've never solved the problem in this specific board, so I ended up buying a newer one which works fine.

what is the expected voltage range ar Vin?

As I know, 5 to 12 V

Can you check the voltage across AMS 1117 when you connect supply voltage to the esp-01 board

Input vs Ground is 3.4-3.6V when connected via VIN. Output vs Ground is 2.5-2.8V when connected via VIN. Input vs Ground is ~4.7V when connected via USB port;  Output vs Ground is ~3.3V when connected via USB port. Using the exactly same brick to test both

I faced the same issue. My problem was on this version of board both ground (G) pins on the side of Vin pin (I say left side of the board when usb is towards bottom direction) do not have connection with the ground of the 3.3v regulator or to the Gnd pin on right side of the board !! No continuity from ground pin to regulator is the problem I understood. The moment I connected 5v between Vin and Right side 'G' pin it started working. Check and try if not resolved yet.

I can confirm the Cherry's experience. The G pins on the left side are not connected with the regulator.

Interesting problem. The input range for Vin is 5.5 to 10 volts. This link will give you more information: https://www.make-it.ca/nodemcu-arduino/nodemcu-details-specifications/
I would not venture to guess that your board is OK, since you short pins all kinds of nasties can happen. Also you do not state your reference point for your voltage measurements so I assume it is ground but the readings do not appear correct. How are you 100% sure that the USB charger is working, providing 5V, and that the ground and VIN are connected to the right positions. Did you measure it with the load connected? Can the charger output the voltage at the current you require?

I can measure the breadboard powerrails, and they show 5V. I have two boards of the same vendor, both present the same problem (one I haven't shorted at all). I'm 100% sure because I tested load (via SK6812 leds and I can power an arduino too). This charger can output 5, 9 or 12V. 5V is max 3A, I can power a little more than 1 meter of RGBW led strips. This specific board is requiring 5V from the charger. Also, from the link you showed me, the voltage is 4.5V to 10V

Check the ground pin on the ESP and see if it is less then 0,02, if not you have an open or not connected ground connection.


text:
I get an error?
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
if(Serial.available()>0)
{s_num =Serial.read();}
if(s_num=='0'){
digitalWrite(13,HIGH);
delay(100); //the specified time for 0
digitalWrite(13,LOW);
delay(100);}
if(s_num=='1'){
digitalWrite(13,HIGH);
delay(200);
digitalWrite(13,LOW);
delay(200);}
if(s_num=='2'){
digitalWrite(13,HIGH);
delay(300);
digitalWrite(13,LOW);
delay(300);}
char s_num; if(s_num=='3'){
digitalWrite(13,HIGH);
delay(400);
digitalWrite(13,LOW);
delay(400);}
if(s_num=='4'){
digitalWrite(3,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);}
if(s_num=='5'){
digitalWrite(13,HIGH);
delay(600);
digitalWrite(13,LOW);
delay(600);}
if(s_num=='6'){
digitalWrite(13,HIGH);
delay(700);
digitalWrite(13,LOW);
delay(700);}
if(s_num=='7'){
digitalWrite(13,HIGH);
delay(800);
digitalWrite(13,LOW);
delay(800);}
if(s_num=='8'){
digitalWrite(13,HIGH);
delay(900);
digitalWrite(13,LOW);
delay(900);}
if(s_num=='9'){
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);}
digitalWrite(13,LOW);
s_num=10;
}

If you are getting a compilation error, you need to include the full error message (including the information, where the error happened) in your question.

One tip to prevent these kind of error: next time align the { and } and you see the error very fast:
void setup()
{
  Serial.begin(9600);
  pinMode(13,OUTPUT);
}

void loop()
{
  char s_num;
  if(Serial.available()>0)
  {
    s_num =Serial.read();
  }

  if(s_num=='0')
  {
    digitalWrite(13,HIGH);
    delay(100); //the specified time for 0
    digitalWrite(13,LOW);
    delay(100);
  }

  if(s_num=='1')
  {
    digitalWrite(13,HIGH);
    delay(200);
    digitalWrite(13,LOW);
    delay(200);
  }

  if(s_num=='2')
  {
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
  }

  if(s_num=='3')
  {
    digitalWrite(13,HIGH);
    delay(400);
    digitalWrite(13,LOW);
    delay(400);
  }

  if(s_num=='4')
  {
    digitalWrite(3,HIGH);
    delay(500);
    digitalWrite(13,LOW);
    delay(500);
  }

  if(s_num=='5')
  {
    digitalWrite(13,HIGH);
    delay(600);
    digitalWrite(13,LOW);
    delay(600);
  }

  if(s_num=='6')
  {
    digitalWrite(13,HIGH);
    delay(700);
    digitalWrite(13,LOW);
    delay(700);
  }
  if(s_num=='7')
  {
    digitalWrite(13,HIGH);
    delay(800);
    digitalWrite(13,LOW);
    delay(800);
  }
  if(s_num=='8')
  {
    digitalWrite(13,HIGH);
    delay(900);
    digitalWrite(13,LOW);
    delay(900);
  }
  if(s_num=='9')
  {
    digitalWrite(13,HIGH);
    delay(1000);
    digitalWrite(13,LOW);
    delay(1000);
  }
  digitalWrite(13,LOW);
  s_num=10;
}

As you can see char s_name needs to be be declared in the front of the method as you need it in the second line, so you get the following code that compiles:
void loop()
{
  if(Serial.available()>0)
  {
    s_num =Serial.read();
  }

  if(s_num=='0')
  {
    digitalWrite(13,HIGH);
    delay(100); //the specified time for 0
    digitalWrite(13,LOW);
    delay(100);
  }

  if(s_num=='1')
  {
    digitalWrite(13,HIGH);
    delay(200);
    digitalWrite(13,LOW);
    delay(200);
  }

  if(s_num=='2')
  {
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
  }
  char s_num;

  if(s_num=='3')
  {
    digitalWrite(13,HIGH);
    delay(400);
    digitalWrite(13,LOW);
    delay(400);
  }

  ...
}

Now you also can see that you process the s_num variable even if there is not a new value from the serial class, so you should put it probably inside, getting:
void loop()
{
  if(Serial.available()>0)
  {
    char s_num =Serial.read();

    if(s_num=='0')
    {
      digitalWrite(13,HIGH);
      delay(100); //the specified time for 0
      digitalWrite(13,LOW);
      delay(100);
    }
  }
}

The last statement s_num=10; does not anything.
Now, to greatly reduce your code, all digits perform more or less the same code. You can combine this by calculating the delay time (0 -> 100, 9 -> 1000), and you get the following code:
void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop()
{
  if (Serial.available() > 0)
  {
    char s_num = Serial.read();
    if ((s_num >= '0') && (s_num <= '9'))
    {
      uint16_t delayTime = (s_num - '0' + 1) * 100;
      digitalWrite(13, HIGH);
      delay(delayTime);
      digitalWrite(13, LOW);
      delay(delayTime);
    }
    else
    {
      digitalWrite(13, LOW);
    }
  }
}

By subtracting '0' from a character digit ('0' to '9'), you get its value.