text:
Data Fluctuation with AJ-SR04M Sensor
I'm working on water level detector using lolin nodemcu v3 and AJ-SR04M Sensor, a water proof ultrasonic sensor. It is working fine at close distance less than one meter or so. However for long distance > 1 meter, I get varying results.

Using the following code:
void setup() {

  Serial.begin (115200);
  pinMode(TRIGGER, OUTPUT);
  pinMode(ECHO, INPUT);
  pinMode(BUILTIN_LED, OUTPUT);
}

void loop() {

  long duration, distance;
  digitalWrite(TRIGGER, LOW);
  delayMicroseconds(2);

  digitalWrite(TRIGGER, HIGH);
  delayMicroseconds(10);

  digitalWrite(TRIGGER, LOW);
  duration = pulseIn(ECHO, HIGH);
  distance= duration*0.034/2;

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  delay(1000);
}

This is what I get in the monitor for the same distance 2-3 meters:
Distance: 141 cm
Distance: 135 cm
Distance: 225 cm
Distance: 195 cm
Distance: 226 cm
Distance: 226 cm
Distance: 129 cm
Distance: 135 cm
Distance: 134 cm
Distance: 146 cm
Distance: 136 cm
Distance: 129 cm
Distance: 154 cm
Distance: 123 cm
Distance: 147 cm
Distance: 226 cm
Distance: 181 cm
Distance: 137 cm
Distance: 134 cm
Distance: 136 cm
Distance: 137 cm
Distance: 145 cm
Distance: 227 cm
Distance: 179 cm
Distance: 226 cm
Distance: 226 cm
Distance: 101 cm
Distance: 134 cm
Distance: 270 cm
Distance: 294 cm
Distance: 266 cm
Distance: 281 cm
Distance: 146 cm
Distance: 279 cm
Distance: 128 cm
Distance: 579 cm
Distance: 138 cm

So, is there a way to make it right or that means my sensor is faulty.

try to put 4K7 resistance at triger pin to gnd

Outstanding! The 4k7 resistor works!

This sensor does not work on 3.3v but on 5V. Connect the red wire to Vin (=USB power = 5v)


text:
How to use d0 and d1 pins of arduino uno (Others) as a digital output when I don't want to use Serial
I have searched this topic almost everywhere also got different results that couldn't satisfy me
My new project is a 4x4 LED cube
Of which
Will contain 4 Rows and each Row will contain 16 LEDs
So, I need to use all the digital pins 0-15 as digital output.
And other pins 16-20 for grounding.
But the problem is, this project needs d0 and d1 pin to be connected as a digital output pin. (Not Serial communication)
In some places I have seen that Experts saying

If you want to use Serial communication, then you can't use them.

You can't use it while your arduino is connected to PC.

You Can't do this ,as this may harm the device

You must turn off serial connection first.

OK, reading this, I got confused, I don't need to use any serial connection (console and others) in this LED cube project so I tried to turn off serial connection by not writing the code below.
Serial.begin(9600);

So, will that free those d0 and d1 pins as digital for me ? Or USB connection is also considered as a serial connection?
So, how can I do it? And will doing it really harm my board?

If you don't use the serial port, pins 0 and 1 are regular I/O pins.
It's just as simple as that.

If you want to use Serial communication, then you can't use them.

Correct.

You can't use it while your arduino is connected to PC.

Wrong. You can keep the USB cable connected as a power supply. You will
not be able to use it for communication though.

You Can't do this, as this may harm the device

What is “this”? The device can be harmed if you drive too much current
to/from an I/O pin, irrespective of whether it's a pin that could be
used for serial communication.

You must turn off serial connection first.

Only if you did turn it on before. If you never enable Serial, you
don't have to do anything more.

An LED consumes approximately 3 volts and 30 mA (maximum rate) and the output of arduino pins are 5 volt and 40 mA, so , this shouldn't harm my board, so, Not writing the code 'Serial.begin(9600);' code will solve my problem right?

@SubhaJeetSikdar: 40 mA is the “absolute maximum rating”. Under normal working conditions, you should normally not source more than 20 mA from a single pin. Note that there are also limits on the sum of the currents sourced by a  single port. See the datasheet.

The bootloader always turns UART0 on upon the loading of the code to your Arudino Nano.
So at the end of the day pins D0 and D1 are used for their alternate functions as a UART receiver and transmitter without you doing so in your code.
Copy the following code to whatever your sketch or C program to disable the UART0 module before you initalize pins d0 and d1 as digital IO, then you can set the two pins as digital I/Os as usual and they will work perfectly.
UCSR0B &= ~(1<<3);
UCSR0B &= ~(1<<4);

the Arduino init() does this https://github.com/arduino/ArduinoCore-avr/blob/24e6edd475c287cdafee0a4db2eb98927ce3cf58/cores/arduino/wiring.c#L383

Thanks for the information. I recommend using register accessing to be more generic for the ones -like me- who are developing code on Eclipse using C and loading it to the ATmega328P on the Arduino Nano. I'm not using the Arduino IDE.

then put that disclaimer in the answer so people don't start to put those two lines in Arduino sketches

FYI I tried putting the two lines of codes in an arduino sketch and it worked. Thanks for your concern.

of course it works, but it is redundant

source: Stack Exchange

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

sort: votes


text:
Why we are using client.flush() in the program code ,when we connect Esp8266 with internet or web server?
I am using Esp8266 Wifi modular (12-E) for controlling a led through the access of wifi/webserver.
I have written code in Arduino ide taking various references from the google.In the code, I didn't understand the client.flush(), why we are using this method? In google, I have searched about many explanations, I got common to explain which I don't understand till yet.
"Waits for the transmission of outgoing serial data to complete."
I didn't get till yet. can anyone explain to me in simple terms?
/
/ Wait until the client sends some data

  Serial.println("new client");

  while(!client.available()){

    delay(1);

  }

  // Read the first line of the request

  String request = client.readStringUntil('\r');

  Serial.println(request);

  client.flush();

This is most likely related to the old usage of .flush() from pre IDE version 1.0.0.
In those old versions .flush() would erase any pending data in the reception buffer. It was the equivalent of:
while (client.available()) {
    client.read();
}

Now though it's used to ensure that all data has been sent before doing anything else. In this situation it's completely meaningless.

I mean to say suppose if I am client, request for anything from the server and my request read by in the Arduino by this line "
String request = client.readStringUntil('\r');"
Then the serial monitor will print my message.
then client. flush will flush my current request before coming to a new client request. Is it?
please give me a simple example where I can understand easily. if possible try to explain to me from the code which is posted above.

With a version of the IDE released within the past few years client.flush() will do absolutely nothing. In an ancient  version it would discard anything remaining in the buffer.

In those old versions .flush() would erase any pending data in the reception buffer. It was the equivalent of can you explain to me what is meaning of reception buffer? is it a place where incoming data will store?

Yes. It's where your "client" stores the data it receives before you .read() it.

With a version of the IDE released within the past few years client.flush() will do absolutely nothing. In an ancient version, it would discard anything remaining in the buffer. sir I need toa ask you what is buffer?

Yes. It's where your "client" stores the data it receives before you .read() it. Sir,  can you explain to me, in brief, the above code which I have posted earlier?

A client never knows when it's going to receive data. Data just arrives. When it does so an interrupt (typically) is triggered. This interrupt receives the data that has arrived and stores it away in an internal block of memory called a "buffer". Your code then uses .read() to get the data out of that "buffer". Data can arrive and be stored into that buffer at any time, not just when you're using .read() to get it into your program. If more data is sent (and thus stored in the buffer) than you read from it with .read() then there will be data left over. .flush() used to remove ...

... that data from the buffer, but now doesn't. Now if you want to empty out any remaining data you have to do it manually.

Let us continue this discussion in chat.

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


text:
Analog Read dummy file
Can we use just a analog Read without storing it
i hear it it a good practice to take two reads
for better accuracy
example:
// Read extra analog inputs
    for (int i = 0; i < 8; i++)
{
    // Read analog pin to nothing.
        analogRead(i]); // analog-read is not writing to anything
}

// Read the analog inputs
for (int i = 0; i < length; i++)
{
    // Write the state of the analog pin to the response buffer.
    slave.writeRegisterToBuffer(i, analogRead(analog_pins[address + i]));
}

You only need to do that if you are changing pins between reads in free running mode.  The way you’ve done it here wouldn’t work because you change pins after your dummy read.  You’d want to read the same pin twice in a row.  But yes, you can call the function without storing the result to answer your question.

how about this ?
// Read the analog inputs
for (int i = 0; i < length; i++)
{
    analogRead(analog_pins[address + i]); // for pre read

    // Write the state of the analog pin to the response buffer.
    slave.writeRegisterToBuffer(i, analogRead(analog_pins[address + i]));
}


text:
GPS Ublox Neo 6m issue with arduino UNO
I started working on the Arduino UNO with GPS Ublox Neo 6m. I connect GPS with arduino based on the schematic diagram as well as the script. It didn't display any data in the serial monitor even though it blinks and one more I did outside the building. I don't know what is causing it not to display any data.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup(){
  Serial.begin(9600);
  ss.begin(GPSBaud);
}

void loop(){
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0){
    gps.encode(ss.read());
    if (gps.location.isUpdated()){
      Serial.print("Latitude= ");
      Serial.print(gps.location.lat(), 6);
      Serial.print(" Longitude= ");
      Serial.println(gps.location.lng(), 6);
    }
  }
}

Did you properly connect the GPS module to VCC and GND and connected the TX of the GPS to the Arduino RX and vice versa? Also note that in my experience, many (if not most) cheap "Ublox" Neo 6M's sold are actually counterfeit and are of dubious quality, taking a very long time to get a first (or even subsequent) fix and not supporting many features of real Ublox GPS modules.


text:
How to use PWM with DRV8870?
I'm using Arduino nano and I'm struggling working with the DRV8870 IC on PWM mode.
When I use analogWrite(_pin, duty_cycle); the motor makes weird noises.
I thought it's because of the PWM frequency so I tried to change it using
TCCR1B = TCCR1B & B11111000 | B00000011; but it didn't work out.
Texas Instruments wrote this in their pdf:
"When using PWM, switching between driving and braking typically works best. For example, to drive a motor forward with 50% of the maximum RPM, IN1 = 1 and IN2 = 0 during the driving period, and IN1 = 1 and IN2 = 1 during the other period."
drv8870_pdf

Are you sure you are changing correct timer? Only pins 9 and 10 are generated by Timer1

analogWrite(_pin, duty_cycle) will work properly only on pins that support PWM. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11. The Arduino Due supports analogWrite() on pins 2 through 13, plus pins DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true analog outputs. Check the following link to find yours:
https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/


text:
Arduino Nano and 0.96 i2c oled screen not working
When I try to scan the i2c address it stays stuck on "i2c Address Scanner" which is the first line of the code.
My screen is connected with VCC-5V, GND-GND, SCL- 4.7K resistor->A5, SDA- 4.7K resistor->A4.
Nothing displays on screen, and I even tried without the resistors. I also tried with some 10K resistors and same result.

Here in the picture you can see how I connected the screen to the nano. SDA-A4, SCL-A5, VCC-5V, GND-GND.

Did you put the resistors in line?  Or as pull-ups?   Show how you wired that.  It sounds like you did it wrong.

Take A look in the picture I hope it helps, I'm a noob

A 4 kOhm resistor in series is too big. Such resistors are normally used as pullup resistors, so connection from SDA/SCL to Vcc. Resistors in series are in I2C only used to limit current, when having different voltage levels (lower values must be used). Also your solding seems not clean enough. You have tons of burned flux there and the solder points look like they might not give you good contact.

that is a really horrible soldering job ... i would not bother to do any troubleshooting until the board is cleaned up and the soldering is properly done

Yeah those resistors are wrong.  They should go from the pin to Vcc.  Not in line with the signal.

Delta_G Could you please show me in a schematic what you mean?

chrisl what type of resistor would you recommend me to use?

I think those modules already have pull-up resistors on them, so pull-ups aren't needed. Connect the SDA and SCL pins directly to the Arduino pins. Also check continuity on your solder connections, because they look a bit crumby. Try holding you iron on the solder connection a bit longer. That is. Put the iron on the connection, trying to touch both the pad and the wire. Add a bit of solder. Keep the iron in the same position for a second or two, to make the solder flow. Then remove the iron.

@peterk Most likely the resistors aren't necessary, though I always add one 4.7kOhm standard  resistor (0.25W) as pullup resistor on each line, just to be sure

From what I am reading it is not properly connected.  You are getting what I would expect. ACL of the device goes directly to A5 and a pull up resistor to +5. Same thing with SCL, connected directly, both need pull ups. You did not state what it is connected to. If there is nothing connected you will get nothing. Also the old wire library did not support timeout so you could hang indefinitely.

As I said, I have two 4.7K ohm resistors, one with sda and one with scl. Both are connected with resistors(none directly connected).

As Delta_G asked, how did you connect the resistors? They should not be in line with the SCL and SDA signals. Could you show a (simple) schematic of how you built it?

Ok I just added a picture of how I wired everything hope it helps!

As stated earlier the resistors need to be pull ups, not in series as your photo shows. Also you need to clean up the solder splatter and flux, that could also cause shorts. Isopropyl alcohol 90% works great. I would suggest you get a temperature controlled soldering iron between 40 and 50 watts max,


text:
Multiple functions at the same time with Arduino Uno
I would like to make a stepper motor run in for loop in time intervals. I also want to stepper motor run when I press the button. Two functions independently. One does not affect the other. I wrote both functions but I have no idea how to make them both work in the same time. I'm using an Arduino Uno.
This is my code:
const int stepPin = 3;
const int dirPin = 4;
const int buttonPin = 2;

void setup() {
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(buttonPin, INPUT);
}
void loop() {

 // One function
   digitalWrite(dirPin,HIGH);

  for(int x = 0; x < 100; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(3000);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(3000);
    }
  delay(30000);
    }

// Second function
  digitalWrite(dirPin,HIGH);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
  digitalWrite(stepPin,HIGH);
  delayMicroseconds(3000);
  digitalWrite(stepPin,LOW);
  delayMicroseconds(3000);
}

Can anyone help me? :)

You can’t do this with blocking code.  You’ll have to rewrite loop so that it can repeat over and over very fast and doesn’t have to stop and wait for anything to happen.  It’s called non-blocking code and it’s probably your first lesson in real coding.  Instead of thinking of a for loop that takes the action from start to finish, think of a loop function that takes one tiny step and then comes back around next time to take the next step.   Look up the blink without delay example and any of the myriad tutorials about it for some more information on how.

do not use if button pressed, then run motor and if timer, then run motor ........... instead use if button pressed, then set flag and if timer, then set flag and if flag set, then run motor

I'm also confused because your two functions both do the same thing.  What do you actually want to see happening?  If you want the stepper to just constantly step then remove the 30 second delay.


text:
How to determine what resistor value to use for LED strip
I'm trying to use an ESP8266 powered by my computer through USB cable to control a WS2812B LED strip. I've read online that you're supposed to put a resistor before the data channel to help prevent noise but I'm struggling to figure out what the resistor value should be.
I've figured out so far that the LED strip will use a MAXIMUM of 25.8W and that the Vin pin that is powering the LED strip is outputting 5V. I also plan on putting a 470uF capacitor across power and ground.

If a chicken-and-a-half lays an egg-and-a-half in a day-and-a-half, how long does it take a grasshopper with one wooden leg to kick all the seeds out of a dill pickle?

I don't know if it does, I was just trying to provide as much information as possible.

@drunkenspider you really need to ask a question ... it is not clear to everyone what the implied question actually is

It seems like people generally just use a resistor around 300 - 500 ohms so I'll just use a 500 ohm resistor. Answer found on another thread. And here as well.

From your second link: NeoPixels (WS2812B) powered by 5v require a 5V data signal. If using a 3.3V microcontroller you must use a logic level shifter such as a 74AHCT125 or 74HCT245. (If you are powering your NeoPixels with 3.7v like from a LiPoly, a 3.3v data signal is OK)

The majority of the time adding a resistor to the data line is completely pointless.  It only has an effect if the Arduino and the first WS2812B chip are connected over a long cable. By "long" I'm talking meters, not centimeters. The length of the strip of LEDs is irrelevant as each LED generates a fresh signal to send to the next LED. It's only the length of cable between the Arduino and the LED strip that matters.
If that is long you can get "ringing" and reflections of the signal through poorly matched impedances. The resistor is there to absorb some of those reflections and reduce the ringing by increasing the impedance of the Arduino's output.
What is a good value? Well, that's hard to say, since it's dependent on the length and type of cable in use. Too low a value and it will do nothing. Too high a value and it will "round off" your signal too much and you'll lose data. A typically chosen value that fits many situations is 220Ω.
But of course for short connections it's irrelevant and you shouldn't add a resistor.

Would a meter be considered too short to put a resistor before the data line?

Depends on the wire.

Strips of LEDs like WS2812Bs need a high current 5V supply, with NO current limiting resistor.
You'll need a very high current regulated 5V supply, and would probably be better off using a separate 5V supply for the Arduino and the LED strip so you don't get large voltage fluctuations in the power to the Arduino as the LEDs turn on and off. If you do you a single power supply for both, you should use a power supply with extra capacity. I'd suggest at least a 30W supply. And yeah, you should probably have a filter capacitor on the 5V rail right at the Arduino.
Edit:
Were you asking about a resistor on the power line, or one on the data pin?

the OP is talking about the data pin, not the power supply pin

How do you know that? The OPs question asks "...what resistor value to use for LED strip" and then all the details provided are about power. Re-reading the question, I still think they are asking about a current limiting resistor. ("Bare" LEDs do need current limiting resistors, so somebody might think that a digital LED strip needs one too.) I'm not familiar with WS2812B LED strips and had to google them. Do they use I2C or some other serial interface? I take it the serial line needs a pull-up resistor?

I've read online that you're supposed to put a resistor before the data channel to help prevent noise but I'm struggling to figure out what the resistor value should be.

Sorry. To clarify, yes I was asking about the resistor for the data channel and not a current limiting resistor.


text:
How to capture the compilaton output to a text file in Windows?
I am trying to capture the verbose output of the compilation to get it into a text file. I am using the IDE 1.8.12 running on Windows 10. I have tried looking for a right mouse button context menu, CTRL-C doesn't work, and finally in desperation, the CMD.exe trick of hitting the Enter key after selecting text.
I also went to the build folder in appdata/local/temp/arduino_build_nnnnn but there's nothing like that there.
There is a topic already about this but it refers to the Linux IDE which can be launched from the command line. It turns out that it's somewhat the same on Windows.

in console window Ctrl+A to select all and Ctrl+C to copy should work. selecting with mouse works too

Yes, of course. In the DOS box, but not the IDE. Thanks.

in the IDE, in the console pane

Whaaat? It works now. Why not before? Anyway, I'm letting the post stand because it's can still be useful to separate the stdout and stderr.

The post Capturing avrdude command in IDE gave me the clue. Under Windows the file
C:\Program Files (x86)\Arduino\arduino_debug.exe
can have its output redirected to files same as a shell command.
In the CMD.exe DOS box, I executed:
C:\Program Files (x86)\Arduino>arduino_debug.exe >\temp\logfile.txt 2>\temp\errfile.txt
and the regular log stuff went to logfile and the errors and warnings went to errfile.
There's enough material in those two files to hurt yourself.


text:
How much current can arduino ground absorb?
I am currently working on an LED 4x4 cube, so here is my pre planned circuit diagram.
https://easyeda.com/editor-mobile/#id=ffca9f3303f242a185b950b0bee4fa29|

I am to connect 220ohm to each positive terminals.(16)

I am to use 4 transistors(2n2222) for 4 negative layers of which, collector terminal will be connected to the negative terminal layers , base will be connected to 4 analog pins through 1k ohm, and emitter to be connected to the GND pin of arduino. Using transistor as a switch.

Can my studio ground get damaged if connected directly without a resistor.
If no?
Is there any way to make it?
Explanation with circuit diagram will highly be preferred...
Thanks for your precious time...

Ordinary LEDs take 20 mA at most, and they are already bright enough (to my taste at least) at 10 mA or even less. If you get 1 A for 16 LEDs there is probably something wrong with your current-limiting resistors.

But if I connect resistor with higher ohm, the cube won't be able to run a single LED when needed as resistance will be too high for a single one, or if I connect low resistors that might either burn my LEDs or produce amps, btw, let's head to the main discussion point, can arduino ground tolerate 5 amps at max? If u have an idea please do share with me via sending a diagram. Thanks.

Since you are going to multiplex your LEDs, first you will design the DC current to a brightness of your linking. Second, you will multiply this current with the number of multiplexing steps. This results in a peak current for each LED, with breaks in between. Practically all LEDs withstand such a driving. Finally, you will multiply this current with the number of LEDs switched on at the same time. This is the expected maximum current that your circuit shall handle.

The best approach in my experience is to let that high current not on the Arduino. Design your driver's circuit separated, and just connect the grounds.

That's right @busybee but, I am to make driver for sure , but before it, I wd like to test it connecting it bare (maybe resistors)on arduino pins.

Those measurements don't make any sense. You can't get 1A of current with 16 x 220Ohm resistors, even if the forward voltage of the LEDs is 0V. I'd expect at most 200mA. So something is wrong. Either you have a short, or you multimeter is of. If your UNO is connected via USB, you can (theoretically) only get 500mA before the polyfuse cuts out the power.

Since you will be multiplexing you don't have to worry about the other layers, as only a single layer will be on at the same time. So you don't also multiply the current, of the one layer, by four.

@Gerben yeah I recently spotted my mistake thanks for the advice, but if I make a voltage amplifier using transistor and then, I guess I will be able to run all the LEDs together right?

there is no reason why the LED current should run through any part of the arduino

Not sure what you mean with "voltage amplifier". But running 16 leds with 220Ohm resistors will only give you 200mA, so I don't see any problem here. The only problem I see is with the columns. The Arduino pins can source the ±14mA, but the ATMega has some limitations on the total amount of current, total current for certain groups of pins. The maximum total current the ATMega328P can supply to all pins combined is 200mA. Ports C0 - C5, D0- D4, ADC7, should not exceed 150mA. Ports B0 - B5, D5 - D7, ADC6, XTAL1, XTAL2 should not exceed 150mA.

PS could you share what the mistake was?

@Gerben , my mistake was R=1/R + 1/R , as resistance of a standard LED is almost 48 ohm and they were in parallel connection,  (tried to pick a paralled connection of the LEDs row from layer 1)  R = 1/48*4 (because there are 4 LEDs in a row of a layer) , so answer is 0.0833, let's inverse it , 1 / 0.0833 = 12ohm for each row in a layer. Now, as I = V/R , 3 / 12 = 0.25 ,  =25, something like this....

What should be the delay() time of blinking those LEDs? delay(10) will be enough I guess

You want an update rate of at least 50-100Hz, so your eyes don't perceived flicker. So let's go with 100Hz here. Since you have 4 layers, you need to change layers at a rate of 4*100 = 400Hz. Which is every 2.5ms. In my project I'd setup one of the timers to call my ISR every 2.5ms. Then have to ISR update the leds and layer transistors based on a global (volatile) array of all led states. This way the display is updated at a fixed rate, even if some code takes a bit longer. Then the main loop only have to change the led state array to show some nice animation.

You can even add some grayscale to the leds, instead of only ON and OFF. You'd have the multiply the update rate, with the number of grayscale levels.

@Gerben, I am not only including ON OFF but also dimming and other animations too and for that, as per my calculations, '''delaymicroseconds(2);''' should work fine so that human eye can't recognize it and also I can do as much animations as I like in a single layer at a time.

2µs is only 32 clock cycles. You can't do a whole lot in 32 clock cycles. My last project updated it's leds every 52µs, and just the code updating the display used around 30µs of that. The other 20µs where to run the animations. I a bit doubtful if you can run all your code in under 2µs. Also, don't use delay, as you code will take various amounts of time, depending on branching (if-statements etc.). Store the micros() value, do your calculations, then wait till there is a 2µs difference between the current value of micros() and the stored value.

@Gerben OK got it!

No your gnd won't get damaged if you source current through it. If u need explanation let me know

You are asking the wrong question. It does not matter how much current the arduino ground can adsorb, it was designed for what it needs not what other devices may need. What you want to do is connect all the grounds at the power supply (please tell me you are not using the arduino 5v for this). You might look as MOSFETs as you will have a lower voltage drop and much easier to drive.

I am connecting all 16 positive pins to arduino pins 0 - 16 through 220ohm resistor and then I am gonna connect the negative layers to the ground using transistor and transistor's base will be connected to the rest of the 4 pins

None of the power output pins were used


text:
Sim800L does not send SMS messages in a row
I created a project with sim800l that comes and stores 5 phone numbers in eeprom memory and then when a sensor is triggered, it sms all the numbers and then calls the first one.
But the module does not send an SMS to everyone and only sends an SMS to the first number and then nothing else and then calls. The problem is not that the numbers are not read correctly, because when sending the text message, I said, show the number in the monitor series and it will show correctly. It is not a problem not to send a text message request because I also connected a usb to ttl module to the tx rx module and saw that it comes for all numbers and at sends the at command correctly.

#include <EEPROM.h>
#include <SoftwareSerial.h>

#define SIM800RX 7 //D7 - SIM800L RX PIN
#define SIM800TX 8 //D8 - SIM800L TX PIN

#define SENSOR1SMSTEXT "Fire error" //Sensor 1 SMS Text
#define SENSOR2SMSTEXT "Theft error" //Sensor 2 SMS Text

SoftwareSerial SIM800(SIM800RX, SIM800TX);

String readSerial(String txt) {
  SIM800.flush();
  if (SIM800.readString() != "") {
    while (SIM800.readString() != "") {}
  }
  String text = "";
  if (txt != "") {
    SIM800.println(txt);
    int timeout = 0;
    while  (!SIM800.available() && timeout < 12000) {
      delay(1);
      timeout++;
    }
    if (SIM800.available()) {
      text = SIM800.readString();
    }
  }
  return text;
}

void readSerialOK(String txt) {
  while (readSerial(txt).indexOf("OK") == -1) {
    delay(700);
  }
}

void configSim800L() {
  readSerialOK("AT");
  delay(200);
  readSerialOK("AT+CMGF=1");
  delay(200);
  readSerialOK("AT+CNMI=1,2,0,0,0");
  delay(200);
  readSerialOK("AT+CMGDA=\"DEL ALL\"");
  delay(200);
  readSerialOK("AT+CSMP=17,167,0,0");
  delay(200);
}

void SendTextSMS(String num, String sms) {
  SIM800.print("AT+CMGS=\"");
  SIM800.print(num);
  SIM800.println("\"");
  delay(150);
  SIM800.print(sms);
  SIM800.write(26);
  delay(700);
  Serial.println("");
  Serial.print("Send SMS to:");
  Serial.print(num);
  Serial.print(":");
  Serial.println(sms);
}

bool checkPhone(String phone) {
  if (phone.substring(0, 2) == "09" && phone.length() == 11) {
    return true;
  } else {
    return false;
  }
}

void WriteEEPROM(byte part, String val) {
  int start_addw = part * 16;
  int w_len = val.length();
  EEPROM.write(start_addw, w_len + 1);
  int end_w = start_addw + w_len;
  byte len = 0;
  for (int i = start_addw + 1; i < end_w + 1; i++) {
    EEPROM.write(i, int(val[len]));
    len++;
  }
  len = 0;
  EEPROM.commit();
}

String ReadEEPROM(byte part) {
  int start_addr = part * 16;
  String str;
  int ch;
  int r_len = EEPROM.read(start_addr);
  int end_r = start_addr + r_len;
  for (int i = start_addr + 1; i < end_r; i++) {
    ch = EEPROM.read(i);
    str += char(ch);
  }
  if (checkPhone(str) == false) {
    str = "";
  }
  return str;
}

void ClearEEPROM(byte part) {
  int start_addw = part * 16;
  int w_len = 11;
  EEPROM.write(start_addw, 0);
  int end_w = start_addw + w_len;
  byte len = 0;
  for (int i = start_addw + 1; i < end_w + 1; i++) {
    EEPROM.write(i, 0);
    len++;
  }
  len = 0;
  EEPROM.commit();
}

void SendSMS(String sms) {
  String num1 = ReadEEPROM(1);
  String num2 = ReadEEPROM(2);
  String num3 = ReadEEPROM(3);
  String num4 = ReadEEPROM(4);
  String num5 = ReadEEPROM(5);
  if (num1 != "") {
    SendTextSMS(num1, sms);
  }
  if (num2 != "") {
    SendTextSMS(num2, sms);
  }
  if (num3 != "") {
    SendTextSMS(num3, sms);
  }
  if (num4 != "") {
    SendTextSMS(num4, sms);
  }
  if (num5 != "") {
    SendTextSMS(num5, sms);
  }
}

void Call() {
  String call = "";
  String num1 = ReadEEPROM(1);
  String num2 = ReadEEPROM(2);
  String num3 = ReadEEPROM(3);
  String num4 = ReadEEPROM(4);
  String num5 = ReadEEPROM(5);
  if (num1 != "") {
    call = num1;
  } else if (num2 != "") {
    call = num2;
  } else if (num3 != "") {
    call = num3;
  } else if (num4 != "") {
    call = num4;
  } else if (num5 != "") {
    call = num5;
  }
  Serial.println("");
  Serial.print("Call to:");
  Serial.print(call);
  if (call != "") {
    readSerialOK("ATD"+call+";");
    delay(300);
  }
}

void trigSensor1() {
  SendSMS(SENSOR1SMSTEXT);
  Call();
}

void trigSensor2() {
  SendSMS(SENSOR2SMSTEXT);
  Call();
}

void setup() {
  SIM800.begin(9600);
  Serial.begin(9600);
  EEPROM.begin(512);
  pinMode(IN1, INPUT_PULLUP);
  pinMode(IN2, INPUT);
  pinMode(SSS, OUTPUT);
  digitalWrite(SSS, LOW);
  while (readSerial("AT+COPS?").indexOf("+COPS: 0,0,\"") == -1) {
    delay(700);
  }
  configSim800L();
  digitalWrite(SSS, HIGH);
}

void loop() {
  if (digitalRead(IN1) == LOW) {
      trigSensor1();
  }
  if (digitalRead(IN2) == HIGH) {
      trigSensor2();
  }
}

Thanks if friends have experience in this area tell me.
Thanks in advance.

this exact problem and solution is repeated many times on the internet

I find error:
void SendTextSMS(String num, String sms) {
  SIM800.print("AT+CMGS=\"");
  SIM800.print(num);
  SIM800.println("\"");
  delay(150);
  SIM800.print(sms);
  SIM800.write(26);
  delay(3000);
  Serial.println("");
  Serial.print("Send SMS to:");
  Serial.print(num);
  Serial.print(":");
  Serial.println(sms);
}

i replaced delay with 3000ms the error solved.


text:
MAX30100 not working
I am unable to get the MAX30100 sensor to work
It keeps throwing the following error:
16:06:32.936 -> Initializing...
16:06:32.936 -> MAX30105 was not found. Please check wiring/power.

I am using the Sparkfun library Example sketch "Example5_HeartRate"
As far as I understand the breakout board for the MAX30100 is a bit buggy -
By which I mean the internal pullup resistors are connected to 1.8V for some reason instead of 5V
I have used MAX30100 before and had faced the same issue. However, after scouring the internet for hours  I found this helpful article: https://reedpaper.wordpress.com/2018/08/22/pulse-oximeter-max30100-max30102-how-to-fix-wrong-board/
I want to use another MAX30100 sensor and have followed the above article again and have done the said changes to my sensor which resulted in the board being detected at address 0x57 when I run the i2c scanner. However, unlike the previous time, the Example sketch did not run as expected.
I even tried this solution:
https://github.com/oxullo/Arduino-MAX30100/issues/51#issuecomment-391193292
But kept receiving the same error message.
The pin connections are:
ARDUINO -> MAX30100/MAX300102
3V3     ->    VIN
SDA (A4)->    SDA\
SCL (A5)->    SCL
GND     ->    GND
I need help asap.
Thank you in advance!
I hope the links mentioned are helpful for someone else.

This video might help you, in this video, an Indian guy explained the issue in detail with the help of the max30100 sensor schematic diagram, and solved it in two ways.
https://youtu.be/ZqdmA4NAqb0

It would be good for you to summarize the important point from the video in case the video disappears in the future.

Check out this link. I guess it will work I had the same MAX30100 module what i did was removed those 4.7k resistors mounted through hole resistors on breadboard and pull-uped them using 5V and it was working fine for me

I had similar trouble with a cheap board (RCWL-0531). Used the same “How to fix wrong board” fix you mentioned (pictured). Which worked ... sort of ... Achieved terrible sensing stability (both HR and O2). I read the comments in the sample code about Uno boards (which I had started out on) having insufficient capacity to handle the full sample data, so migrated to ESP32. Still not great.  Gave up and bought a Sparkfun MAX30105, still connected to an ESP32 and OLED display. Immediately a different experience, much higher quality but I don't know why. I have some "still to-do" ideas to investigate the MAX30102_by_RF library and also to use a more capable processor (e.g., Due) to see if the signal processing capability can be cranked up. Hope this helps - you're not alone.


text:
How to calculating requirements of power supply for a project
I am starting with electronics and been working with Arduino for some time now. I did some basic LED and servo motor project and was hoping to jump into making an obstacle-avoidance car. I used 4 AA batteries to make it, but the voltage was too low, as the motors were not moving. Then I knew about the volt requirements and all that. I also tried with a 9v alkaline battery, but it didn't help much.
Here are the electrical parts I used:

Arduino
Ultrasonic sensor
4 toy motor
1 hobby servo motor
Motor driver shield L293D
Battery

These are the operating voltages that I know of:

Arduino = 7 to 12 v
Hobby servo motor =  3.0V~ 7.2V
Toy motor = 3v ~ 12v dc; has a No load current 40 - 80 mA

Because AA batteries are of 1.5v and are in series, it has 6v, and I am assuming that was the reason it was not working as expected. What I am confused about is, how do I choose a battery or power supply to be specific.
Please forgive me for asking such a noob question. Since 1 Arduino + 4 toy motor  + 1 hobby servo motor = 7v + 4 x 12v + 7v = 62 v, but I checked and I couldn't find battery that is above 15v. I surely don't understand how to pick a power supply. Could you please help me out on how to calculate and choose the right battery/power supply? Also, what to look for if for example, I want to run it for a minimum of 10 minutes?

The loads of a supply are typically connected in parallel, not in series. Read Series and Parallel Circuits.

9V batteries can hardly handle any current, so that's probably why that didn't work for you. I'd add more AA batteries in series. Using 6 would give you 6-9V (6V when empty, 9V when full). 8 would give you 8-12V. In that case you'd have to run the servo from the regulated 5V on the Arduino, as to not exceed its rated voltage.

A power supply a 9V battery is not. Since you are using batteries the L293D is a very poor choice for a driver, it uses silicon transistors which I believe are in a darlington configuration which will cause a voltage drop of from 1.4 to 2.8 volt on the motor.  The 4 (or more) AA batteries will work but use a MOSFET bridge. You can always use a small SEPIC (Buck/Boost) converter to power it, that will keep the voltage constant until the batteries are exhausted. Set it to about 9V and power the arduino via the VIN input for more filtering. You will need a way of measuring voltage. You will lose less power with the converter then you are losing in your current driver.


text:
No programmers available for this board - Programming ESP32 Cam with Ardunio IDE
This is my first time working with ESP32 Cam boards.
I have followed the instructions as given in this site https://technoreview85.com/how-to-program-esp-32-cam-using-arduino-uno-board/
However my IDE doesn't display any programmers for this board.

Couldn't find any details about this in google. I just want to know how I could fix this problem(i.e. get the programmers listed).
Thanks in advance.

Thank you the older version of Arduino IDE. 1.8.12 also worked for me.

There are no programmers for ESP32. It only accepts Serial upload over bootloader.
Versions of IDE before 1.8.13 displayed programmers for all board support packages, that is why a programmer could be selected. Now only programmers for package of the selected board are available. But programmers are used only with the "Burn bootloader" or "Upload with programmer" commands, not with standard Serial upload over bootloader.

The older version of Arduino IDE. 1.8.12 worked.


text:
Arduino timer interrupts for PID
I'm working on a robotics project where an arduino nano is acting as the motion controller. I'm trying to use a trapezoidal motion profile generator and PID loop to follow that profile, but I found out the motion was quite jerky and I assumed it's because both the motion profile and the PID run at the same speed (10ms loop using timer interrupt library)
#include <TimerOne.h>
void setup() {
  Timer1.initialize(10000);
  Timer1.attachInterrupt(Compute);
}

now I want to use two seperate loops, one running at the same 10ms interval for the profile generation and one running at 1ms for the PID (I'm not sure if the motors can actually act that quickly, but I can adjust the timings a bit), this way the PID has about 10 loops to get to the desired position accurately, reducing the jerky motion.
I'm not sure how I can set up two different interrupts using that library or by setting the flags like TCCR0A to generate the desired interrupt timers.
Here's the actual "Compute" function in case it's relevant (there are some bugs regarding the direction and it's using two different methods for generating the profile, also I'm changing it so don't think it matters, but just in case it does, I posted it)
void Compute(){
  int dir;
  if (setPoint > target){
    dir = 1;
  } else if (setPoint < target){
    dir = -1;
  }
  if (mode == 1) {
    target += v*dir;
    if (abs(setPoint - target) <= turningPoint){
      v -= acceleration;
    } else {
      if (v < maxV){
        v += acceleration;
      }
    }
    if (abs(target) >= abs(setPoint)){
      target = setPoint;
      mode = 0;
      v = 0;
      Serial.println("Finished!");
    }
    #ifdef DEBUG
      printDebug();
    #endif
  } else if (mode ==2){
    target += v*dir;
    if (phase == 1 and v < reachableV){
      v += acceleration;
      if (v >= reachableV){
        phase = 3;
        v = reachableV;
      }
    } else if (phase == 3){
      v -= acceleration;
      if (v <= 0){
        target = setPoint;
        mode = 0;
        v = 0;
        phase = 0;
        Serial.println("Finished!");
      }
    }
    #ifdef DEBUG
      printDebug();
    #endif
  }
  error = target- pos;
/////////////////////////////////////////////////
  PID_P = kp * error;
  if (PID_P > outMax) PID_P = outMax;
  if (PID_P < outMin) PID_P = outMin;
/////////////////////////////////////////////////
  if (abs(error) < 50){
    PID_I += ki * error * sampleTime;
  } else {
    PID_I *= 0.8;
  }
/////////////////////////////////////////////////
  PID_D = kd * (pos - lastPos) / sampleTime;
  if (PID_D > outMax) PID_D = outMax;
  if (PID_D < outMin) PID_D = outMin;
/////////////////////////////////////////////////
  output = PID_P - PID_D + PID_I;
  if (output > outMax) output = outMax;
  if (output < outMin) output = outMin;
/////////////////////////////////////////////////
  lastPos = pos;
  if (output < 0){
    digitalWrite(DIR,1);
  } else {
    digitalWrite(DIR,0);
  }
  analogWrite(PWM,abs(output));
/////////////////////////////////////////////////
}

p.s: I'm most likly going to use the PID library instead of trying to write my own like I currently have the code.

When you speak about different loops, does that mean, that you previously didn't use interrupts for this?

no I mean two loops with different periods, one running at 10ms and one at 1ms. I'm using a single 10ms interrupt timer right now.

the ISR should be as brief as possible and should not contain any serial I/O code ... if you wish to print a message, then use a flag ... set the flag in the ISR ... print message and clear the flag in loop()

Just use a single 1ms timer interrupt and count them. Every 10 interrupts do both things.
void interruptHandler() {
   counter++;

   // do things that happen every 1ms

   if(counter == 10) {
      // do things that happen every 10ms
      counter = 0;
   }
}

that'd be a nice solution but I'm assuming there are better ways to do this? the counters have 3 options for interrupt: A, B and overflow. I'm assuming this was done to set a PWM signal with duty cycle and frequency control, but I'm not sure how to set the proper flags to use them.

Why would you assume that?  What is wrong with this solution?  Newbies always want something "elegant" and by that they mean hard to understand or deep into the hardware.  But that's not very often the case.  If you do this with separate interrupts then the 1ms and the 10ms will both have to fire at the same time.  Thus one interrupt will be late and you'll have the extra overhead time interrupting your other code.  Sometimes the simple answer is really the best answer.  What would there be to gain by having one interrupt exit and another enter late?  You want to waste time?

In order to set two interrupts on that timer and have one be at 10ms, then you have to let the timer run all the way to 10ms.  So for every 1ms interrupt you have to update the OCRA register to a new time so it fires at 1ms then 2ms then 3ms then 4ms.  If you want the interrupts to be regular then you'll have to calculate how much to add each time.  What's better about that?

You could use a second timer, but then you lose PWM on two more pins.  And I assume you're wanting to use Timer1 for the 16 bit resolution.  You only get one of those.  So you'd have to give up resolution on the second interrupt.  How does that help?


text:
RGB LED using potentiometer and push button
I'm currently working on an assignment which has to turn on an RGB LED using a potentiometer and button.
The problem I currently have is that the button is supposed to change the color I want the LED to display (press one time: red (pin9), press again: green (pin10), press again: blue (pin11)).
As I'm changing through the ports with the potentiometer, the potentiometer will read it with as analogWrite. For example, when I move the potentiometer all the way to the left and press the button the LED will display red, and when I move it back all the way to 0 and press the button twice the LED will stay red (do nothing). If I press it one more time it will turn off.
Another example, I turn on red again, then use green and turn off blue using the potentiometer and button giving me orange. How do I make it so to accomplish all of this while using both and combining colors?
This is a HW question. I am not asking for a whole solution but rather where to start because I already got stuck and I want to restart.

So - if I'm understanding that right - you want your button to be the set button, which is used 3 times sequentially to mix the colors red, green and blue with the value, that the poti has at the respective stages. So building the RGB color in 3 stages out of its components. Is that, what you want? And what exactly is your problem here? Reading the poti? Outputting 3 PWM signals for the RGB LED? calculating the values? Managing the program flow?

Oh, sorry for not making it clear. I'm kind of new to this (as shown). I believe my main problem is reading the reading the button and poti as to mix the colors as aforementioned.

Edit: The current problem I'm experiencing is the next: I'm running the simulation with if and counter for the button and my first color should be green. The next part in my code is to turn on blue but that's on two presses. On the first press it seems to skip green and go straight to blue.

So that means, that it actually is more of a software question. You need to show us your code (you can edit your question to include it there), so that we can help you with that

one thing that you need to realize is that the button and the potentiometer do not control the LEDs ... they are completely separate from the leds ... the Arduino program controls the LEDs ... the Arduino program reads the button state and reads the voltage level on the potentiometer slider .... keep the button reading and the potentiometer reading functions separate from the LED lighting function ... the button should only set a flag ... the same flag could also be set by a timer, or by a remote control ... the LED lighting function checks only the status of the flag, nothing else

The most common problem beginners have with buttons is coding it to be "If HIGH do this" and then wonder why it keeps happening rather than just happening once when the button is pressed. You have to learn to watch for a change in the state of the button - as in "If changed from LOW to HIGH do this".

If you solved your own question, please post the answer or how you fixed it.  That way someone who finds your question will know how you fixed it this question will show as
"Answered"

If the answer below worked for you then please tick it.

You method sound a bit more complicated that it needs to. What I would do is have the button switch between three colors, and have the potentiometer change the brightness of the currently selected color.
For example, when first starting up, the red led is selected. Turning the potentiometer changes the brightness of the red led (in real time). Let's say you turn it 50%, so the red led is at 50% brightness. When you're happy with that, you press the button, and now green is selected. (Since the potentiometer is still at 50% from the red, the green led will immediately turn on at 50% brightness.) You can then turn the pot to change the brightness of the green led. Let's say you turn it all the way of to 0%. Then press the button to select the blue led. Turn it to 100% and the combined color would be a dark purple. Press the button again to select red again.
Here is some proof of concept code:

byte selectedColor = 0; // 0:red, 1:green, 2:blue
byte oldButtonState = HIGH;

void loop() {
  byte buttonState = digitalRead(buttonPin); // read the button
  if( buttonState==LOW && oldButtonState==HIGH ) // see if the button is pressed, but wasn't pressed the last time
  {
    selectedColor++; // to to next color
    if( selectedColor==3 )
      selectedColor = 0;// after blue, go back to red
  }
  oldButtonState = buttonState; // remember the buttons state for the next loop

  int brightness = map(analogRead(potPin), 0, 1023, 0, 255);

  if( selectedColor==0 )
    analogWrite(redPin, brightness);
  else if( selectedColor==0 )
    analogWrite(greenPin, brightness);
  else
    analogWrite(bluePin, brightness);
}

PS I left out the pinMode stuff in the setup.
PPS make sure the led leads are connected to PWM pin on the Arduino (they have a ~ next to them on the PCB).


text:
ATMega328 functions, but will not output to any pins
Problem:
ATMega328 Refuses to digitalWrite() to any pins, I can upload and run sketches using the board UNO from the ide on the 328 and can confirm it is working using the serial monitor (see code).
I am using this FTDI module.
Board Manager -- UNO works, but ATMega328 Doesn't

By using the UNO board under board manager, I am capable of writing sketches and communicating with the 328 just fine.
But when I use the ATMega328 at 5.5V,16Mhz I receive the following error.
         Using Port                    : COM3

         Using Programmer              : arduino

         Overriding Baud Rate          : 57600

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xe0

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xe0

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xe0

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe0

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xe0

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

avrdude done.  Thank you.

Code & Serial Monitor "Proving" it works
I have tried every usable PWM and other pins to attempt to output using LED's, buzzers and even other Arduino's to read inputs but none of the pins will output high when requested.
I believe that Arduino IDE is attempting to compile my code for the UNO and those pins do not work on the ATMega328 but this could be completely incorrect and someone please correct me if this is a wrong assumption.
Lastly, I have been able to use the SCL and SCA pins to communicate with an I2C LED shield.
Does anyone know why I cannot write sketch to the ATMega328 using the FTDI and my configuration.
Posted Below are images and very rough Fritzing schematics of how I am setup.
void setup() {
  Serial.begin(9600);
  pinMode(5,OUTPUT);
}

void loop() {
  Serial.println("TICK");
  digitalWrite(5,HIGH);
  delay(1000);
  digitalWrite(5,LOW);
  }

My Breadboard

Fritzing Schematic

the top bus of your breadboard is not powered ... why do you say that you can upload a sketch and then present an error listing that shows an upload failure?

pin 5 is low only a few milliseconds

The top part of my breadboard IS powered, I have two cables to the right, as shown in the second fritzing but just out of frame on the camera. If you read the text in the question I explain "By using the UNO board under board manager, I am capable of writing sketches and communicating with the 328 just fine. But when I use the ATMega328 at 5.5V,16Mhz I receive the following error."

What do you mean by when I use the ATMega328 at 5.5V,16Mhz. Do you mean that you're using the Board Manager with that setting (as opposed to the selecting the Uno)? What Board Manager did you install for that (MiniCore?). Did you (re)flash the bootloader with the ATMega328 selected in Board Manager?

The error message you get means it can find the Arduino to be programmed. So your sketch isn't being uploaded, and thus you pins won't change. Not sure why you'd still get the serial output. My guess would be that that's an old sketch.

@StarCat https://imgur.com/8GR4GOs this is a link to what settings I am talking about, Arduino IDE gives you the option to select what chip, frequency and voltage your board is operating at. Using these settings I have been unable to write sketches to my board. The bootloader is a PU, I have not attempted to reflash the bootloader on my chip.

You've selected the Arduino Pro in Board Manager and the "AVRISP MkII" programmer. You can't simply choose a different board manager and programmer and expect to keep using the same bootloader you've used for an Arduino Uno (although they have the same processor). You need to program the Arduino Pro bootloader into your ATMega328 or just keep using the Arduino Uno from Board Manager and the ArduinoISP programmer. Please add the image you linked to, to your question.

In combination with Nick Gammon's answer above, I was not aware that the physical pin numbers are different from the digital pin numbers used in the sketch. I resolved my issue by referring to this digital pin map.

This may not be your only problem, but you need a second delay.
void loop() {
  Serial.println("TICK");
  digitalWrite(5,HIGH);
  delay(1000);
  digitalWrite(5,LOW);
  delay(1000);    // LOW for a second as well
  }

Otherwise you will not be able to see the LOW part, because it will be really quick.

I believe that Arduino IDE is attempting to compile my code for the UNO and those pins do not work on the ATMega328

The Uno has an Atmega328 on it, and I usually compile for the Uno when uploading to a custom board, so this is not the issue.

How old is your chip, or the bootloader on it? Most chips sold (with bootloaders preloaded) - and bootloaders available to upload - for the last several years at least, have uploaded at 115200 baud.


text:
Using ESP32 Cam internal RAM
I am new to the ESP32 series of boards.I powered up my ESP32 Cam board using the Vcc pin supplying about 7.4V using two 18650 batteries only to find out later that was a completely incorrect way to power up the board.
Now I cannot get my board to flash. I am guessing that the SPI SRAM on my board is burnt because when I measure the Vcc at the SPI SRAM chip it doesn't read 3.3V as its supposed to.
Also there is continuity between the ground and Vcc of the SPI SRAM chip. And it heats up excessively when powered up using 5V.
However I read in the documents that the ESP32 has a few bytes of internal RAM in it.
I was planning to use the ESP32 Cam as an IP Camera for one of my projects.
I want to know if its possible to desolder the SPI SRAM chip (IPS1704) and somehow use the internal ram to get my job done or else if I have to buy a new board.
Thanks in advance

It's dead. You killed it. Well done.  The ESP32 has lots of internal RAM. However it has no internal flash, and requires external flash to operate. External PSRAM is optional. If you toasted the flash chip you will have to replace it (it's inside the metal can). If you toasted the PSRAM chip you can remove it. If you toasted the ESP32 itself then you will have to replace that too. If you toasted all three then all three will have to be replaced. By the time you've done all that you will be asking yourself "was it worth it?" - just get a new one.

If there is continuity between 3.3V and GND your board is dead. Most likely (from my experience) the ESD protection diode on the ESP module is fried which leaves you no chance to repair it. Even if you could remove the shielding to change the diode, you have no chance to find out which components are damaged. Considering the cost of the whole device, repairing it doesn't seem to be worth the effort.
For your understanding:

reading less than 3.3V on the external RAM means you would also read the same voltage at the ESP's Vcc. It's not an indicator for the RAM being dead
the ESP32 has plenty of internal ram (some hundreds of kB remain for use of your sketch after subtracting what the RTOS uses)
the ESP32 (chip) has no internal flash, so there is always an external flash on the ESP module
the ESPcam has an additional SPI RAM assembled externaly to the module. The internal RAM is by far too small to do any useful image processing at any desired resolution, so using only the internal RAM does not work

It appears you have some paper weights. I would suggest before you make more read the instructions and be sure you understand them. It is much less costly that way. There may be some light at the end of the tunnel, if the ESP32 and it is mounted on another board, and it possibly has a voltage regulator, you might be OK, but I have two neighbors chances, Slim and None. Read the data or as they say RTFM.


text:
Bluetooth module vs wireless module Arduino
My main question is, what is the main difference between HC-05 Bluetooth module and NRF24L0 wireless module?
Which should I buy?
Which makes these 2 modules different than each other?
Which one should I use in remote control arduino projects?
Which one is made for what purpose?

do you want to communicate between two arduinos or with a device which has bluetooth?

I m talking of Both of the cases @Juraj

what is the main difference between HC-05 Bluetooth module and NRF24L0 wireless module?

The main difference is the protocol they use. While some attempts have been made with varying success to get the nRF24L01+ to emulate Bluetooth it is not designed for that. You can only really get rudimentary beacon mode working and that only partially.
nRF24L01+ modules can only communicate with other nRF24L01+ modules. They use their own proprietary protocol that is incompatible with any other system. That's not to say they're bad - they're great modules, and the same RF core and protocol is used in many many other devices by Nordic that are used all over the place - the most notable of which is wireless keyboards and mice.
The HC-05 though is a Bluetooth module which is designed to talk to anything else that also talks Bluetooth - such as your phone or computer. It presents an "SSP" profile and gives "master" mode operation to emulate a serial port connection between your Arduino and any other device that knows about Bluetooth and SSP.
The biggest difference in how they work though is when it comes to connecting devices together. Bluetooth devices have to be "paired" before they will communicate. nRF24L01+ devices don't. This means that getting Bluetooth devices to talk to each other takes a certain amount of time and effort, but nRF24L01+ devices are ready to go the moment they are powered on. It's then just down to your software to set up addresses and such to target the communication.
For Arduino-to-Arduino communication the nRF24L01+ is far less trouble as you set everything simply in your code. There are "LNA+PA" variant boards available that include an amplifier and antenna for longer range communication (I have had 300m+ out of those quite happily).
If you want to communicate with anything else, like your phone or computer, then you will want Bluetooth. Otherwise you will have to add an nRF24L01+ to your computer or phone through USB and (probably) another Arduino, which just gets messy.

Very well explained, I choose HC05 then

NRF24L01+ module is a RF module and HC-05 is an Bluetooth module
It depends on the application you want to perform and what suits best for your application
nrf24l01+ is a great module but it can have issues if you want long distance communication also if you want to increase the distance then there is a module which comes with an antenna
On the other hand It seems that Hc-05 offers 10m range theoretically but according to one the arduino forum link its 15m when in line of sight but if there is some obstacle than it falls drastically
What is the distance you want to cover from the remote control it will specify which best suits you

Well u didn't mention what the max range is of the nrf24l01


text:
digitalwrite() HIGH for arduino
How too know whether digitalwrite(HIGH, pin_number) sets the voltage to 5 volts or 3.3 volts. I am yet to purchase arduino uno. I want digital pin voltage to be 5 volts. I am aware that thereis a pin already have 5 volts but I want to know only about the voltage output at digital pins.
Sorry if question is too silly. I am not very knowledgable in Electronics.

Different boards operate internally at different voltages. This is dictated by the main chip on the board.  That main internal operating voltage is also the voltage at which the IO pins operate.
Most "old" Arduino boards operate at 5V.  This includes, but is not limited to:

Arduino UNO
Arduino Mini
Arduino Leonardo

Newer more powerful boards, many made by other companies, operate at 3.3V. Again, this includes such boards as:

Arduino DUE
Arduino MKR1000
Teensy boards (v3.0+)
chipKIT boards
ESP8266 & ESP32 boards

Some boards come in variants that give either voltage - the most notable being the Pro Mini boards from Sparkfun.  These come in both 5V and 3.3V variants and it is important to pick the right board for your needs.
In general, though:

If it's 8-bit and runs on an ATMega chip it's likely 5V unless otherwise stated
All 32-bit boards will be 3.3V unless otherwise stated.

When you use digitalWrite(pin_Number,HIGH); this sets the output pin to 5 V but still if you want to check the voltage you can you a digital multi meter set its knob to DC voltage and connect its positive to the pin and the ground pin to ground and the voltage will be displayed on the multi meter

Thanks, but this link says HIGH depends on 5volt board or 3.3 volt board https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/ . How to know Arduino Uno is 5 volt board or 33 volt board ?

@HiteshSomani: It's 5 V, written very prominently on the product page.

The Uno is a 5V Arduino. For other types the answer is more complicated, as explained in Majenko's excellent answer.


text:
Angle sensor to measure the stepper motor shaft rate of rotation
what Kind of Sensor that i can use to know how much angle stepper Motor shaft has rotated ?
Actually,I am thinking to rotate my stepper Motor at 1 rpm and my stepper Motor shaft Diameter is 8mm and length would be around 20 mm. I am using this stepper Motor in very sensitive Case that is the reason why iam  going to use microstepping Driver also.
Can anyone help me out form this query?
And ,Thanks in Advance.

What did your web recherche reveal? I would expect at least a few manufacturers providing such sensors. Over 20 years ago I was working on such a sensor that produces absolute angles, but had to abandon it before it was finished. It had a resolution of 1/1000 of a degree, giving 360'000 parts per revolution.

If skipping steps isn't a concern, you can just count the step pulses you sent to your driver.
If it is, you'd usually use an optical encoder.

You can get absolute position rotary encoders that are made for this task. Google them.

The datasheet on the stepper motor contains the number of steps per rotation. So divide 360⁰ by the number of steps to get the angle per step. Then it just a case of counting steps. The only issue is finding the 0⁰ position, so you'd need to add some mechanism to home the motor. Either manually, of with something like a limit switch.

Thank you for your Wonderful Response @Majenko ,I am going to run  at 1 rpm and I wanted to see the exact Speed while ist rotating and i wanted to know the exact angle is it possible with this ,and sorry for asking again:)


text:
External RAM (23LC1024) and external Flash (W25Q64JVSSIQ) with Sparkfun SAMD21
i'm trying to extend the capabilities of the Sparkfun SAMD21. My question is, which pins do I have to share? I mean, I understand that MISO, MOSI and SCK are shared, but CS connects each to a different pin, am I correct?
My schematics:

I connect my CS_RAM to the D10(PA18 on SAMD21).
and i connect my CS_FLASH to the D6(PA20 on SAMD21)

Yes, you are correct.

Atmel SAMD21 is manufactured by Microchip. you have some Sparkfun board with SAMD21 MCU?

Im doing my design with this board as reference: https://www.sparkfun.com/products/13664 | Schematics: https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/sparkfun-samd21-mini-breakout-v10.pdf

You are correct, MISO, MOSI and SCK are common to all the SPI devices. Be sure they are all set up for clock polarity etc. The CS\ line is the select line. If the device is not selected it does not matter what goes on with MISO, MOSI and SCK. There are chips such as the 74HC138 that will give you chip selects with just a few additional pins. 1 pin gives you 2 selects 2=4 and 3 gives you 8 selects.

Ok, but i can connect my CS to digital pins, right?

With polarity u mean put a litle power in the lines? like u can see on the image that i add, i have 10k resistors from +3.3V to CS and in one case MISO and MOSI. SCK no needs nothing, right?

Yes they are digital, and that is probably 3V3 in your system. It should work fine, the Arduino pins should be high during reset which will disable the CS\ (active low) chip select.

so, with a Mosfet connected to the RESET pin of my SAMD21, i connect my CS_RAM and CS_FLASH to 3.3v? or what do u mean? check that i have 10K resistors between CS and 3.3V.

Simple digital thoughts. Inputs can go to inputs or outputs or VCC or Ground but never floating. Outputs can go to inputs only (resistor in series with LED ok). Normally outputs can NOT go to outputs they have a maximum current beyond which they will fry In your case CS in an input. There are exceptions of course but this is not the time to enumerate them.

I dont get you, i have my CS connected with a 10k resistor to 3.3v and to the digital pin. What go to fry?

It sounds like it is connected correctly. Your software has to select and communicate with it. You need to select the device to communicate with it. SPI is simply a fancy shift register, you have to send something to it in order to receive. It clocks data out as you clock data in.


text:
Bluetooth no COM port connection? ESP32
I am experiencing issues sending serial data via bluetooth with my ESP32. When the device is plugged in, I am able to call bluetooth, and connect to PC and even obtain the serial data via the registered bluetooth COM port after connecting. Though, once I remove the USB power, and power the ESP32 with a battery, I am still able to connect to the PC, but the COM port disappears therefore leaving me unable to choose the port to send data over.
I've tried adding this device to COM port but when I try to add my ESP connected device, I am returned with "parameter is incorrect".

.
.
Usually the COM port is listed here

I know others have posted about this to other forums but none of seemed to solve the problem cut and dry. I also experienced this issue with HC-05 on Arduino Nano
Would appreciate any help I can get with this. I'm sure there is a simple solution that I just haven't come cross yet, as I'm relatively new to all this
Thx in advance

What battery are you using to power it?

Perhaps the COM-port you're trying to access is the one provided by the USB chip that might not be powered when you use a battery? If you can, get power from a USB power bank or a USB phone charger, and see if the COM port appears again.


text:
How to burn the bootloader and upload sketches on ATmega328P U (specifically this model)?
Recently I started to learn embedded electronics and C/C++ and for a couple of days I tried and I am still trying to burn a new ATMega328P U bought from Aliexpress. From what I know new ATMega328P's come with bootloader included, but after I wired everything up and connected the FTDI FT232RL to load the sketch (wiring is completely right after many many hours of checking on the internet for a dozen of pictures), I get errors like "programmer is not responding" in case of sketch upload and "error while burning the bootloader" or "Yikes, signature bla bla". I don't think the FTDI is the problem since the Arduino IDE recognizes it as COM7 on my PC. Now here's my question: is my atmega328p u broken or have I missed something during the process of both (trying to) burn(ing) the bootloader and upload(ing) the blink sketch? (I have also tried uploading the board programmer from Nick Gammon on my arduino Uno and the burning the bootloader AND followed the instructions from arduino.cc "from arduino to microcontroller on a breadboard"). If you need pictures of some sort, I'll provide them

ATMega328 don't come with the (Arduino) bootloader preprogrammed, unless you specifically orders ones that do (where the seller has done that for you). You can't burn the bootloader with the FTDI. You can indeed use a separate Arduino board to act as an ISP programmer, so you can burn the bootloader.

I know I can't do the burn with the FTDI, that's why I tried to use my Arduino UNO to load the ArduinoISP on it and burn the bootloader on ATmega like this... But no luck whatsoever. And I can't find any tutorialnor solution that can fix my problem

Since you don't provide any specifics, we can't do any better than link to those two methods. Did you get any error message when burning the bootloader? Can you verify that the bootloader is installed (led on pin 13)? A picture would help, in case there's something mis-wired.

I don't have anything wired right now, but tomorrow I'll send some pictures here, errors, wiring and whatever can help

There is no such thing as an ATMega328P-U. There's the ATMega328P-PU or the ATMega328-PU - the former is what is used on the Uno, but it sounds like you have the latter.

https://imgur.com/gallery/rAEq9kg

I am not sure if the tutorials vary from model to model. All I want to know is if there is someone who knows a method that is guaranteed to work for my model in the picture above. Or at least show me what is the problem in what I did. I really want this to work and reach higher and higher in knowledge of circuits and programming

Fwiw I’ve come across the ATMega328P U (like the one in your photo) and I suspect it’s not an official Atmel chip (i.e. it might be counterfeit), although I’m not sure, That said, the ones I have seem to be behaving completely normally and can be programmed with a bootloader in exactly the same way.

328P is the model. Package type is the next letter (P for SPDIP) and temperature range the last letter (U = -40C to +85C). There has to be a hyphen between the model and the package type. Anything else is fake. Possibly a 328-PU clone with dodgy labeling.

So it results in the posibility of not being able to correctly burn the bootloader and work with it? (sorry if my questions are too dumb or "captain obvious" - ish, but I'm learning on my own)

Do you have some bare minimum circuit around the MCU? Mainly Xtal (usually 16MHz but the bootloader can be also for 8MHz or the internal 8MHz). Also you have to have "auto reset" circuit too (DTR -> capacitor -> reset pin and pull-up) - otherwise you have to reset the MCU into bootloader mode in short period time before the arduino starts the actual upload...

https://imgur.com/gallery/ZX9el3x, this is the picture with the minimal circuit I think you are talking about. 2 22pF capacitors, 16MHz oscillator, wires for gnd and 5v where necessary and the first 3 pins for FTDI usage. I did saw a schematic with a switch button added for reset functionality, but I didn't give it much attention. Could that be the solution for everything?

@VladGeorge If you have FTDI with accessible DTR, it should be possible to add capacitor between DTR and RESET pin to enable auto reset - info in section auto reset. Otherwise reset button and good luck with pressing reset in the right time. Btw, you should also look into section Decoupling capacitors.

I did try to do that, that's why on the 1st pin I put a 100nF capacitor. And when I try to burn the bootloader I get an error regarding the signature... And the circuit is working because at first I programmed the ATmega that was on the Arduino UNO and managed to get blink and fade sketches working on it. But when switched to the individual ICs... Neither the burn or the sketches worked. I'll try to do it manually, with a button on the first pin, and keep you updated

IT WORKED, FINALLY. I followed this tutorial: https://www.electronics-lab.com/project/installing-the-arduino-bootloader-on-the-atmega328p-microcontroller/, followed exactly as it is explained, made the connections (nothing more, nothing less; I even removed the LED on pin 19 and its resistor) and to my surprise... the bootloader was actually loaded and the sketches were uploading just by using the FTDI. Thank you a lot for your help and information and I hope someday I'll pass this knowledge to someone who will be in the spot I was until now. Have a great time and love ya all


text:
Why does controlling power with a transistor interfere with MHZ19B's serial communication?
I've been trying to turn off an MHZ19B (datasheet and teardown photos: revspace.nl/MH-Z19B). I've used an Arduino, NPN, PNP transistors and mosfets as well as the diagram below for connecting the sensor to an ESP32. In all cases, PWM communication works great! I can power off the sensor, turn it back on, and values derived from PWM communication are as expected. However when I connect the Rx and Tx lines (to software serial Tx and Rx pins respectively on Uno pins A0 A1 or ESP32 pins 32 33) they spit out gibberish and the PWM signal also suffers hiccups.
Otherwise, without any kind of logic power control, the MHZ19B works great and can communicate with anything via UART, even my PC usb port via FTDI.
I added resistors to the Rx and Tx lines so the voltage on them doesn't exceed Vcc. I tried 1n4007 diodes (they're the only ones I have; no Schottky diodes either). I tried an NPN equivalent optocoupler. I also tried powering the sensor from my breadboard. I don't own an oscilloscope :(
My High School teacher said to just use PWM, but as I searched for a solution to this error, I noticed hundreds of others have this exact same problem with all sorts of different sensors and loads with ICs; no one has come up with a general solution.
I've been obsessing with this for weeks and if anyone can help or can recommend a book about sensor schematics I would really appreciate it. Thanks!

You need to disconnect the serial, before turn of the power of the module. What I think happens is that the TX pin on MCU (RX on the MHZ19b) is HIGH when it isn't sending it anything. So you get 3.3-5V going into the MHZ19b that's powered down (which is bad). A lot of chips have clamping diodes on there input pins. So you are essentially powering the chip via the TX pin. The TX pin can supply enough power to the chip, with cause weird things to happen. For example gibberish UART data.

PS R2 looks weird to me. I think you need to move it the the horizontal section. Otherwise you only get 2.5V at the base of Q1, when Q2 is turned on.

It seems software serial doesn't have a function to "disconnect". A workaround is to set the TX pin to an INPUT, and to LOW (pinmode(txPin, INPUT); digitalWrite(txPin, LOW);). Then make sure you don't call any mySerial.print commands while power is off. Then when powering on the chip, do the reverse (pinmode(txPin, OUTPUT); digitalWrite(txPin, HIGH);

@Gerben R2 is okay. The base of Q1 will not go more than one diode drop below 5V regardless of R2 value.

Just guessing but I suggest you use a level translator. Also when you power off the sensor the serial output should go to ground disabling that channel.  Check your voltages and put a bypass cap on the transistor for the sensor. You can use a simple P channel Logic Level fet,only a 50 ohm resistor in the gate to prevent oscillation.  Your output will now be active low instead of active high. If you stay with transistors make R2 & R3 510 ohm so you have enough drive for the transistor and be sure it is NOT a darlington device, if it is you will not have enough voltage for the sensor.

I think the sensor has a built in level translator since the datasheet says it can use 3.3V or 5V logic. I tried to add a 100uF capacitor between +5V and VIN, but I don't know if it did anything. The sensor itself has 12 internal capacitors (or maybe 16 cause there is a silkscreen labeled C16) connected to ground. Is there an alternative to using transistors? How do some sensors just go to sleep and use virtually no power?

That capacitor will only decrease your noise immunity and make it more susceptible to line noise. That is not enough information, those are operating voltages, not input voltages. 3.3V and 5V logic are not compatible with each other even though both can operate on both voltages. If you look at the input structure you will see the threshold changes with the supply voltage. Thresholds are roughly 40% and 60% of VCC. That is only really valid if the sun comes up on the east side of the moon on February 33d. As far as something to read I would suggest you start with something in basic electronics.

When troubleshooting a problem like this, try 'cutting the world in half' before doing anything else.  In this case, replace the entire circuit with a manual switch (or a wire) and manually power and de-power the sensor.  If you still have the problem, then the circuit is irrelevant to the solution.  If the problem goes away, then the circuit IS the problem.
Once this experiment has been performed, then 'cut the world in half' again, working on the 'half' that is the problem. Repeat until only one component is left.

Thanks! Yeah I did that from the start. I didn't even use a microcontroller to power on and off the sensor. I just had the Rx and Tx ports connected to my computer to monitor values, and powered the sensor from a breadboard power supply connected to a wall outlet. I managed to get 4.6V @50 milliamps, using NPN or PNP based circuits, which is within spec. But the sensor never wanted to work. I suspect the internal capacitors are doing something. I would try to add a capacitor inline with the circuit but I don't know how. I think the sensor needs to draw 150 mA at the start to turn on its logic.

Glad you tried the simple route first, but it sounds like your setup still had problems.  You can get 5V power supplies from MeanWell power supplies that are cheap and reliable.

The sensor works. I ran it 24/7 for 3 months with a read every 60 seconds. If it didn't work I never would have made a post about transistors. Also why would I need a 100W power supply for a project designed to use an ordinary 5V 1A cell phone charger?

No no - not 100W or even close. For instance,https://www.meanwell.com/webapp/product/search.aspx?prod=GS05U-USB is a 5W (1.0A at 5V) wall plug with a USB connector - perfect for supplying reliable power to a range of projects.  Cut off the end of a USB cable, and wire the +/- wires to a barrel plug that fits the Arduino, and 'Bob's your Uncle' (saying from "The world's fastest Indian" movie).


text:
problems with Blue Pill (stm32f103c8t6) direct register manipulation
I'm trying to access registers but I keep getting the "was not declared in this scope" error message.
I'm currently using the STM32F1xx boards from http://dan.drown.org/stm32duino/package_STM32duino_index.json
The board package does not seam to recognize any of the registers from the reference manual, mostly trying to access the ADC registers such as 'ADC_CR2'. Does anyone know where I can find the register names which works in the Arduino IDE?

You probably have to include some special header. No idea what, as it's not anything related to Arduino.

@Majenko I'm using the "stm32duino" boards, I thought it was connected to Arduino? :S

stm32duino is a third party package made by Roger Clark. Nothing to do with Ardiuno. Roger's the guy you need to speak to about that core - maybe through github issues if it's hosted there, or find its own forum if there is one.

https://www.stm32duino.com/

you need to use something like this:
ADC1->CR2 = ... ;

note 2 things:

you need to use ADC1, ADC2 ... to access the registers. not just ADC.
you need to use arrow (->) operator to access the registers

and you may need to include the header file, something like this :
#include <stm32f030x6.h>

find the proper header file for your MCU. (it's not the same as stm32f1xx, but if proper definitions are made somewhere, it may also work)

For anyone else having this problem, the registers were called, surprise surprise, ”regs”, so ADC1->regs->CR2.       I still would want to know if theres any easy way to see what a struct contains though, for future problems :)


text:
Beginners code, loop doesn't detect unplugged pin
I'm learning on an Arduno UNO board, and im trying to turn a LED on three times when I connect pin 10 to ground and then turn it off. Then when I unplug the pin number 10 it should NOT blink again... yet it does and I can't find the issue.
this is the entire code:
bool ledBlinked = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(7, OUTPUT);
  pinMode(10, INPUT_PULLUP);
}

//Turns on and off a digital pin, a number of times, with a certain delay
void blinkLed(int pin, int times, int del){
  // activates a pin a number of times
  for (int i=0; i<=times; i++){
    digitalWrite(pin, HIGH);
    delay(del);
    digitalWrite(pin, LOW);
    delay(del);
  }
}

//Checks if passed pin number is connected to ground
bool pinIsGround(int pin){
  return (digitalRead(10) == LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(pinIsGround(10) && !ledBlinked){ //if pin is connected to ground and the LED hasn't blinked
    blinkLed(7,3, 100); //blink pin 7, 3 times, with a delay of 100ms
    ledBlinked = true; //LED has blinked already
  }
  if (!pinIsGround(10) && ledBlinked){ //if pin is not connected to ground and the LED hasn blinked
    digitalWrite(7, LOW); //turn LED off (unnecesary?)
    ledBlinked = false; //LED hasn't blinked yet
  }

}

if pinIsGround() returns false, and ledBlinked is false,   then (false && false) is true

Not sure what the use of the ledBlinked bool is,   but i think you should just use an else branch

google switch bounce

@ChadG : DO not confuse new student with bad logic. you are mixing it up with double negation.
If first operation of && returns false then the second is newer checked, but hole statement is false

SInce I can coment I have to write this as answer.
there are two ways of understanding your question:
If you dont want it to ever blink again then simply remove
ledBlinked = false;
If you are trying to prevent the blinking until the button is depressed and pressed again then first think I see is the error in blinkLed function as
for (int i=0; i<=times; i++) would run times+one time. because it runs first with value of i being 0 (Eg times=4 would run for i equal 0,1,2,3,4 -> Five times ) So correction to for (int i=0; i<times; i++) would run correct number of times (Eg times=4 would run for i equal 0,1,2,3 -> four times )
Although as you are not checking status during the running of blinkLed function for the status of the button, if you release it while blink is running the script would not notice unless its still unpressed when script gets back to Loop.

Although since hardware operation take more work then logical operation I would recommend if...else statement rather then multiple hardware operations. Although they make code simpler to read
if(digitalRead(10) == LOW){
         if(ledBlinked != true)...
   } else { ...}

I have intentionally avoided writing full code as that would kill the point of you learning


text:
Arduino Vin pin does not work, but Arduino 5v pin power works
I have a very weird problem, at least it seems to me that way. I have connected L298N motor driver, Arduino and a hobby servo with a 6v power supply (tested with both 4xAA and 9v alkaline batteries). And wrote a simple program to rotate the servo every 10ms. There are no other motors connected as of yet.

Power supply is connected to the L298N 12v and GND.
Arduino is connected to the 5v and GND of L298N driver with the Vin and GND of Arduino respectively.
Servo's power (red wire) is connected to L298N 5v, GND is connected to the L298N's GND, and, servo's control (orange wire) is connected to pin 9 of Arduino.

The problem is that the servo hardly moves when Arduino gets power supply gets from the Vin input. However, if I connect it to the 5v of the Arduino power it works as expected. But I was under the impression that 5v pin of Arduino was to for the output and not for the input power supply. Could you guys please tell me what am I doing wrong here?

Could you draw a simple drawing for your circuit ?

@R1S8K I have updated with a simple circuit. Please have a look.

OK, let articulate my answer in answers section, and let me know if there's something need to be modified in my answer.

The Vin pin on the Arduino Uno board is connected to the input of the 5V onboard voltage regulator of the Arduino board.
This voltage regulator needs an input voltage that’s about 1.5V above its (regulated) 5V output that will feed the Arduino.
Arduino - note the recommended values of the Input Voltage (7-12V)
If you feed 5V into Vin, the voltage drop on the internal regulator will cause the Arduino board to be supplied with only about 3.5V, which is probably enough to make it function, but not enough to control the servos.
The solution, as you already found out, is to feed the 5V from the L298N board directly into the 5V pin of the Arduino. Please take care to measure the actual voltage from the L298N before you do this (it should be 5 Volts). Alternatively you could connect 12V to the Vin pin of the Arduino, but again, make sure you know what you’re doing.

Yes, on researching about the issue, I saw Vin drops 1.5V, that is why I tried with a 9v battery hoping it would at least provide 7.5V. Now I'm thinking that 9V batteries awful. Am I correct?

@Kakar 9 V batteries are very good in smoke detectors where they only need to supply a few milliamps ... they are made of six AAAA cells in series

You are using Arduino to drive one servo motor and that's simple with only using arduino board with this setting:

5V supply pin
GND pin
any pwm pin

Now using the LM298N here isn't optimal. If you googled LM298N, you would get the main application of this driver which is to drive DC and stepper motors.
For driving multiple servo motors, you can use this module board to drive upto 16 servo motors.

Here is a link for it on Banggood.
PCA9685 16-Channel 12-bit PWM Servo Motor Driver I2C


text:
board stops working when writing serial
i just started using Arduino IDE for my XMC1100XMC2Go. Information about the microcontroller can be found here: https://github.com/Infineon/XMC-for-Arduino/wiki/XMC-2Go
I now started with my first codes and want to print things on the serial monitor with this code:
*/
/* For on board LEDs */
#include <LED.h>

/* Create an LED object */
LED Led;

//#define SERIAL_DEBUG 1

int p_LED = 5;
int p_Button = 4;
int i_stateButton = 0;

void setup()
{
  Led.Add(LED1);            // Configure the LEDs
  Led.Add(LED2);
  pinMode(p_LED, OUTPUT);
  pinMode(p_Button, INPUT);

  // Set default state of LEDs
  Led.On(LED2);
  Led.Off(LED1);

  digitalWrite(p_LED, LOW);
  Serial.print("Hello World!");

  Serial.begin(9600);
}

void loop()
{
  Serial.write("Hello World!");
  Serial.println(i_stateButton);
  delay(200);
  Led.Toggle (LED2);
  Led.Toggle(LED1);

  i_stateButton = digitalRead(p_Button);
  //digitalToggle(p_LED);
  digitalWrite(p_LED, i_stateButton);
}

I checked under tools that SerialOutput is set to PC (https://github.com/Infineon/XMC-for-Arduino/blob/master/variants/XMC1100/config/XMC1100_XMC2GO/pins_arduino.h#L54)
There are two Ports, COM1 and COM3. I can send new sketches to the microcontroller using COM3. I checked my Serial Monitor and it is set to COM3, too.
Baudrate is for both the same (code and monitor)
Now that i send the above sketch to the microcontroller it stops working. one LED is on and the other is off. But they do no longer change the state. Nothing appears on the monitor.
When i remove the both lines Serial.write("Hello World!");  Serial.println(i_stateButton); and send the sketch, the LEDs start flashing again.
I'm pretty sure it's a kind of configuration problem, but i cannot find out what it is. Does anyone have an idea?

Maybe you should avoid printing to Serial before calling Serial.begin().

serial.begin() is in the setup part. Or does this belong to the loop?

What do you have right before Serial.begin()?

Ouch. Thank you

There was a Serial.print("Hello World!"); before Serial.begin(9600); Thanks @Edgar Bonet

on a normal Arduino it doesn't stop the sketch

@EdgarBonet This sounds like an answer. Perhaps turn your comment into an answer. Stack Exchange will think that this Arduino section has very few answers if you guys keep answering in comments.

In the setup(), you have:
Serial.print("Hello World!");
Serial.begin(9600);

One should avoid printing to the serial port before enabling it with
Serial.begin().


text:
Bluetooth connection problem
I am using Arduino Uno and Blue tooth HC-06, I am trying to use this in order to switch a LED through mt phone but I cannot create communication  between the Bluetooth and the Arduino, I am using software version 1.8.13 and I manage to pair to the Bluetooth through my phone, this is my code:
    char data = 0;                //Variable for storing received data
    void setup()
    {
    Serial.begin(9600);         //Sets the data rate in bits per second (baud) for serial data transmission
    pinMode(13, OUTPUT);        //Sets digital pin 13 as output pin
    }
    void loop()
    {
    if(Serial.available() > 0)  // Send data only when you receive data:
    {
    data = Serial.read();      //Read the incoming data and store it into variable data
    Serial.print(data);        //Print Value inside data in Serial monitor
    Serial.print("\n");        //New line
    if(data == '1')            //Checks whether value of data is equal to 1
    digitalWrite(8, HIGH);  //If value is 1 then LED turns ON
    else if(data == '0')       //Checks whether value of data is equal to 0
    digitalWrite(8, LOW);   //If value is 0 then LED turns OFF
    }

}

and this is the image of the wiring:

I don't have any problem with the computer the software or the Arduino different codes I can run very easily the only problem is with the Bluetooth device
Thanks a lot

With what app your you trying to send the serial data? Are you using Andriod? The HC-06 will only be connected, if the app starts and holds the connection. So you cannot just connect the HC-06 just in the Andriod bluetooth settings. That is only for pairing. The actual connection is initiated by the app. Thats what I already stumbed across myself.


text:
AFMotor.h Throws Multiple Errors
I'm trying to get AFMotor.h working on an Arduino Uno Wifi Rev2 with a L293D Motor Shield.
However, when I install the library (regardless of whether I do it using the in-built library manager or by downloading a zip and moving it to the relevant folder), the following errors get thrown on compilation.
In file included from c:\users\charya\documents\arduinodata\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\io.h:99:0,
                 from c:\users\charya\documents\arduinodata\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\pgmspace.h:90,
                 from C:\Users\Charya\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/String.h:31,
                 from C:\Users\Charya\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/Print.h:24,
                 from C:\Users\Charya\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/Stream.h:25,
                 from C:\Users\Charya\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/Client.h:22,
                 from C:\Users\Charya\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/api/ArduinoAPI.h:29,
                 from C:\Users\Charya\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.6\cores\arduino/Arduino.h:23,
                 from sketch\code.ino.cpp:1: C:\Users\Charya\Documents\Arduino\libraries\afmotor/AFMotor.h:49:30: error: 'CS01' was not declared in this scope
     #define MOTOR34_8KHZ _BV(CS01)              // divide by 8
                              ^ C:\Users\Charya\Documents\Arduino\libraries\afmotor/AFMotor.h:52:33: note: in expansion of macro 'MOTOR34_8KHZ'
     #define DC_MOTOR_PWM_RATE   MOTOR34_8KHZ    // PWM rate for DC motors
                                 ^~~~~~~~~~~~ C:\Users\Charya\Documents\Arduino\libraries\afmotor/AFMotor.h:156:47: note: in expansion of macro 'DC_MOTOR_PWM_RATE'    AF_DCMotor(uint8_t motornum, uint8_t freq = DC_MOTOR_PWM_RATE);
                                               ^~~~~~~~~~~~~~~~~ C:\Users\Charya\Documents\Arduino\libraries\afmotor/AFMotor.h:49:30: note: suggested alternative: 'B101'
     #define MOTOR34_8KHZ _BV(CS01)              // divide by 8
                              ^ C:\Users\Charya\Documents\Arduino\libraries\afmotor/AFMotor.h:52:33: note: in expansion of macro 'MOTOR34_8KHZ'
     #define DC_MOTOR_PWM_RATE   MOTOR34_8KHZ    // PWM rate for DC motors
                                 ^~~~~~~~~~~~ C:\Users\Charya\Documents\Arduino\libraries\afmotor/AFMotor.h:156:47: note: in expansion of macro 'DC_MOTOR_PWM_RATE'    AF_DCMotor(uint8_t motornum, uint8_t freq = DC_MOTOR_PWM_RATE);
                                               ^~~~~~~~~~~~~~~~~ exit status 1 Error compiling for board Arduino Uno WiFi Rev2.

I've also attached an image of the error if that's easier to read. I have no code written, and I am only importing the library and compiling it.
What am I doing wrong? I'm unsure what's even happening.

Looks like the library doesn't support the newer MegaAVR chips, and the "compatibility layer" either isn't working or you have it turned off.

have you examined any example code that may be included with the library?

I have the same problem.
When I am using an Arduino Uno board the sketch is compiled without errors.
When I am using an Arduino Wifi Rev 2 board I get the same error messages.
My feeling is, that the AFMotor library is not compatible for Arduini Wifi 2 boards.