text:
How do I convert 0-5v PWM to a 0-12v PWM
I have a Arduino which I would like to use to control a 12v PWM fan for speed control.
I know about the 0-3.3v to 0-5v logic level shifter, is there a similar option for 0-5v to 0-12v? Or is there a circuit using a IC that I need to make?
Thanks in advance for your help.

It your on about a 4 wire PC fan the control signal is ttl compatible not 12v.

This unfortunately isn't for a PC fan, this for a large blower unit for air circulation. Thanks though

@MrEditor97, what kind of current will this blower need? I've added an answer and if it is high current (10A or more), I recommend the Pololu driver in my answer, for sure.

...or if you want, you can use a Brushed ESC (Electronic Speed Controller) as well, and feed it a servo signal. It will handle the low-level PWM for you. I just added this to my answer.

@MrEditor97 For future... If you ask some question that is not in common measurements like "yours big blower", You have to mention it in your question that your project is about large machine with higher power comsuption, otherwise do not expect relevant anwser

Related: here's my answer to another question which answers your question. Replace the (relay + R2) in my answer with your motor and this is also a perfectly legitimate circuit to solve your problem. The 5V here in this circuit to the transistor base would be replaced by your 5V logic level PWM signal coming from your Arduino. I also go over calculations and how to size all components: https://arduino.stackexchange.com/questions/77600/switching-a-solenoid-using-arduinos-5v-output/77602#77602.  Try a high-current TIP120 NPN BJT 5 Amp cont. transistor.

Cheers, I will take your advice on board if I have another question! Thanks. I didn't have the serial number of the fan until today, now I have that I have checked the spec, and a low powered option is suitable as it only requires a PWM signal to control the speed the rest is done with its on-board controller - no more than a 0.5mA signal is required. So I believe a transistor method is suitable for this application

Are you just driving the PWM input on the fan or are you driving the fan directly?

@copper.hat, see his latest comment just above yours. He states he's driving the PWM input only, so low-power, low-current PWM signals to an already-existing motor driver is all he needs it turns out. He's not driving the motor directly.

@GabrielStaples Then the answers below seen needlessly complicated to me.

@copper.hat. Unfortunately, every one of the answers below were written without that information, since that info. was only just provided. Most of the answers assumed the motor was a 2-wire brushed DC motor which needed to be driven directly, so that's what they are all (or almost all) answering.

@GabrielStaples No, my MAX232 answer assumes PWM to PWM translation so it would work perfectly. Single transistor solution of sahasrar and cooper.hat also works. The only thing that doesn't work is power amplifier like H-bridge.

Did you make sure the fan doesn't have an open drain input for pwm control?

I advice you to learn about basics of how to connect external components to MCU.
Anwser to your question is simple transistor amplifier... So you can use bipolar transistor (NPN/PNP) or MOSFET... MOSFETs is better for switching like your case, switching via PWM.
If you switching inductive load with MOSFET like motors or coils, don't forget add antiparallel flyback diode. Otherwise your MOSFET will burn out.

If you need switching with higher frequency or load with more voltage or power I advice to use push-pull logic to drive mosfet gate.
Something like this:

If I was to use a MOSFET, is there a specific type you can recommend? Thanks for your helpful answer!

I use very often IRF540, but try to lookup logic-level MOSFET, It is very handy because gate voltage is 5V so it is compatible with MCUs... logic-level MOSFET are whole sieres of IRL mosfets... Take a look at this link https://circuitcrush.com/arduino/2017/06/02/logic-level-mosfets-irl-or-irf.html

For lower currents (up to several amps vs dozens of amps), NPN BJT transistors, especially Darlington transistors such as the TIP120 NPN BJT 5 Amp continuous one here, are easier to use and drive than MOSFETs.

How does this answer relate to driving a PWM input on a fan? The OP is not trying to drive the fan motor, just the PWM input.

A good design with a gate recharge/discharge circuitry. Have my upvote.

As far as I can tell the Arduino does not have open collector outputs, so you can mimic one as follows. The following inverts the Arduino output signal, so some adjustment is needed there when generating the PWM signal.
Excuse the rather gross schematic. I can't find any scaling parameters.
The particular resistors values are not terribly important, mainly to limit current.

simulate this circuit – Schematic created using CircuitLab

This would totally work, but has the downside of being inverting, and the even bigger downside of passively pulling the output up to 12V through a large R1 resistor, which results in a very weak, rounded edge and slow rise-time. This limits the possible PWM frequency a lot. So, you have active drive to LOW, but passive pull up to HIGH. To solve this problem you have to add enough transistors that in the end you create a half H-bridge, which led me to my "TLDR" answer here: https://arduino.stackexchange.com/a/78569/7727: just buy a motor driver H-bridge from my "Option 2" section and be done.

He is driving a fan not a Tesla. The stray capacitances here are negligible, you don't need microwave frequencies for fan PAM.

Use MAX232
Advantages of MAX232:

It has low rise/fall times. A good PWM needs to be sharp. Since MAX232 is designed for serial port communications, i.e., TTL to RS232 and RS232 to TTL, it has to perform reliably. Reliability ensures low rise/fall times.

It operates at low currents. The OP suggested that the fan only needs a PWM to drive, i.e., it has its internal current amplifiers.

It is cheap. Engineering solutions require to be no more expensive than it has to be, and MAX232 is half the price of L298.

Shortcomings of MAX232:

Since the computer serial port is used much less, the primary use of MAX232 is over. Therefore, it is not in all hobby kits and it might be harder to find MAX232. Mostly older engineers who used to play with PIC16F877A before ardunios become popular remembers such ICs.

Shortcomings of L298:

L298 is a current amplifier, not a voltage booster. Using it for a purpose other than its primary purpose is suboptimal.

L298 has a huge current output. It might exceed the threshold currents of the fan, and cause malfunction. It is very unwise to connect a 1A rated L298 to 0.5 mA rated signal pin.

L298 has a weird pin diagram. It has a ZIP package rather than the regular DIP to allow attachment of heatsinks, which increases the size of the circuit.

L298 has high rise/fall times. Its purpose is to generate large currents, not PWMs. Therefore, its rated rise/fall times are not only high, but also unreliable.

L298 requires four high current rated Schottky diodes. The cost of these diodes will be more than that of the L298 and they are very large, resulting in a much larger circuit area.

Do you really want to use an H-Bridge? Use L293D.

L293D is still a current amplifier but not an overkill like L298. Its current output is four times as low as L298 so chance of malfunction is reduced.

L293D has a DIP layout. Most hobby electronics application uses DIP sockets to mount the ICs later on and you can do it with L293D.

L293D has the flybacks diodes internally. So you neither need to buy nor place them on your circuit.

Do you want to design your own circuit? Use a gate/base recharge/discharge transistor.
Basically, all transistors have a gate/base capacitor which needs to be charged before the transistor switches to ON and discharged before it switches to OFF. Power amplifiers normally do not care about the rise/fall times, with a notable exception that comes to my mind is musical amplifiers.
What about a discharge resistor?
Replacing discharge transistor with a simple resistor works but it would increase your drain from the PWM source. It has a simplicity vs performance trade-off.
Commenting about relays
Relays usually have a higher switching time because their input module consists of a diode and output module consists of a transistor, i.e., you have add their reaction times together. This results in distortion in the PWM output. Furthermore, there is no need to use SSR in a low power operation, an opto-isolater would suffice.
Final comment about designing circuits
Circuits have many trade-offs. Cost, availability, complexity, size, performance are just to name a few. A good design needs to take everything into account. To rate my above suggestions:

MAX232: Cheap, simple, small, good performance, not available
L298: Expensive, complex, large, low performance, available
L293D: Cheap, simple, small, mediocre performance, available
Simple transistor: Cheap, simple, small, mediocre performance, available
Modified transistor with base recharge/discharge: Expensive, complex, large, good performance, available

So, I would rate L298 as the worst possible solution that actually works.

A few minor corrections are needed to make this answer upvotable: 1) BJT base has insignificant capacitance (but MOSFET Gate capacitance is significant). 2) PWM is still required when driving motors through an H-bridge or half-H-bridge, such as through an L293D or L298 motor driver, if you want throttling, as PWM is what throttles the motor to vary its speed, 3) amplification in motor drives refers to amplifying current, not voltage (voltage "amplification" is generally called "level shifting").

Also, to answer your question: I am not sure about this but you might not even have to use diodes of the L298 since your output voltage will always be unidirectional (or positive.) Yes: flyback diodes are always needed for any inductive load, to prevent the voltage spike which would otherwise occur any moment you turn off the load and the electromagnetic storage energy in the inductor collapses and drives a voltage spike. When throttling a motor, this occurs every PWM cycle, and when using pure ON with 100% duty cycle (therefore, no PWM), this voltage spike will still occur...

...when you turn OFF The motor.

@GabrielStaples I hope my edits answer your concerns.

You'd usually use a transistor to do that.

simulate this circuit – Schematic created using CircuitLab
SW1 is your microcontroller creating the PWM signal.

use a low side switch for a more reliable transistor turn on

This circuit won't work. To turn the 2N3906 OFF you must set the input to its base to 12V to be equal to the voltage at its Emitter, thereby causing the current to stop sinking from Emitter to Base, but, you're driving the base with only 5V, meaning you can never turn this circuit OFF. That's not good.

You must either add extra transistors and drive circuitry to make it work, or switch to an NPN instead of a PNP BJT transistor. For an NPN, connect the Emitter straight to GND, and put the load between 12V and the Collector. Then it works just fine.

Here's my answer demonstrating a proper circuit with NPN BJT transistor: https://arduino.stackexchange.com/questions/77600/switching-a-solenoid-using-arduinos-5v-output/77602#77602.

This wouldn't work even if you change PNP to NPN. You are charging the base capacitor of the BJT over a resistor. Base capacitors are usually small but base resistors are notoriously large. If you use a lower base resistor, you might exceed the output of the Ardunio. If you use a higher base resistor, your output will not be composed of straight pulses, but rather slanted pulses.

Unless the output power is to be used to drive something, it is a bad idea to use BJT. MOS is way more reliable with lower gate current and gate capacitance.

Unless the output power is to be used to drive something, it is a bad idea to use BJT. MOS is way more reliable with lower gate current and gate capacitance. This is exactly the opposite of the truth. BJT doesn't have a Gate, nor does it have Gate capacitance. It has a Base, and the Base capacitance is so insignificant it isn't even mentioned on a BJT datasheet. MOSFETs, however, have very large Gate capacitances on their datasheets. The tradeoff is power and current. BJTs drive up to ~5A max (ex: TIP120) for the same physical size MOSFET which could drive 60A (ex: IRLB8721).

@GabrielStaples You do know that BJTs are typically used in power amplifiers while MOSFETs are typically used low power logic circuits? I have designed NMOS or CMOS processor architectures but I never heard of NPN processors. Do you know why? Because MOSFETs allow faster switching (hence lower gate capacitance) and lower power.

@C.Koca, this is getting really painful. MOSFETs are typically used low power logic circuits? True, in part I'm sure because they don't bleed current. They are voltage-controlled, not current-controlled, so they don't require continual current flow to stay on, unlike BJTs. Because MOSFETs allow faster switching. I'm not sure this is true. hence lower gate capacitance very false. and lower power very true, because they (MOSFETs) are voltage-controlled, not current-controlled (BJTs are current-controlled, and hence continually bleed power just to stay on).

@GabrielStaples I agree that this is getting painful so this is my very last comment. We use mosfets in computers because they allow faster switching. You can't have a 3 GHz NPN. It can't switch that fast and it can't dissipate heat. The only difference between a MOS and BJT is the current gain. BJTs typically have around 100 while MOSFETs have typically have much much higher because the gate current is much lower than base current. MOSFETs also have much larger GS resistance so C_G is charged much faster. MOSFETs saturate easier so MOSFETs are not good amplifiers. They are good switches.

You are denying physics what it is due.I implore you: please seek truth.This book (ISBN-13: 978-0199339136),"Appendix G: COMPARISON OF THE MOSFET AND
THE BJT" (here) bipolar transistor amplifiers have superior high-frequency performance compared to their MOS counterparts. (Ex G.3: NPN BJT is higher freq: f_T: 15.3GHz vs NMOS: f_T: 9.7GHz).But MOSFETs have extremely high input resistances and an almost zero input bias current

This applies too, and is true: No, BJT has less extent than MOSFET because BJT is used where we need more speed. But MOSFET is used where we want less power dissipation, low operating voltage, less noise, simple manufacturing process, low chip area and easily scalable.

@GabrielStaples There are many trade-offs there where simple cut-off frequency explanations don't cut. Specific to this question, you need switching not amplifying hence the MOS. BJT is suboptimal in whatever way you use. Don't mistake your google search with my electrical engineering degree. Thanks.

@C.Koca ... so many wrong things in what you continuously post. Your arguments are too accademic, the suggested circuit in the npn/nmos version is just fine, at least in this application!

@C.Koca oh, and MOSFETs are not suitable for high power? Lol, I bet you blew up a lot of BJTs in your life

Note: my entire answer below assumes you need to drive a 2-wire brushed DC motor (or similar load, such as an audio speaker) directly, with real power and real current. That is what my entire answer is based on. However, after I wrote my answer, the OP posted this in a comment under his question (emphasis added):

I didn't have the serial number of the fan until today, now I have that I have checked the spec, and a low powered option is suitable as it only requires a PWM signal to control the speed the rest is done with its on-board controller - no more than a 0.5mA signal is required.

So, although my answers below will still work to provide an output PWM at, lets say, 12V, from an input PWM at 5V, they are intended to drive a 2-wire brushed DC motor directly with real power and real current. The fact that they can also provide an output PWM signal at 12V is incidental, but just as applicable.
Also, it is important to note that all my answers below are expected to be usable up to a few dozen kHz max PWM frequency, unless otherwise stated on the product datasheets--Ex: many high-end Pololu brand motor drivers (H-bridges) I recommend below can be driven with up to 100kHz PWM frequency since they use such high-quality and fast MOSFET Gate driver circuits with both high-power active Gate drive HIGH and active, high-power Gate drive LOW in their H-bridges.

TLDR;
Jump straight down to the section titled "Here's some H-bridges you can buy", in the "Option 2" section below. Buy one of those and be done.
Reminder: on any H-bridge, when you drive a PWM to the input at 5V with a certain duty cycle and frequency, an equivalent or almost-equivalent PWM output at voltage level Vsupply will occur on the H-bridge output. This is the exact purpose of the half-H-bridge. And, this, in addition to allowing bi-directionality of power, current, and voltage, is the exact purpose of the full H-bridge. PWM output freq from the H-bridge will be exactly identical to the input PWM, and PWM duty cycle will be almost identical, with output PWM waveform distortion increasing as PWM frequency is increased.
Option 1 of 3: [custom circuitry] The Electrical Engineer / "very curious hobbyist with lots of time" answer:
I've upvoted @Sahasrar's answer. If you haven't taken a look at it, you should. It fits squarely into this "Option 1" category.
However, in his first image, when controlling pin D7, the MOSFET gate is actively driven both HIGH and LOW with a max (initial) current of I = V/R = 5V / 100 Ohms = 0.05A = 50mA, which is good, but kind of weak (a good MOSFET gate driver is more like 500~1000mA drive current). This is also exceeding the 40mA max current rating of the Arduino pin, so I recommend you choose a slightly bigger resistor. The resistor here is to limit current to not damage your Arduino pin when charging and discharging the Gate capacitance of the MOSFET, which capacitance is significant enough for MOSFETS (but NOT BJT transistors), that it is even listed as a parameter in a MOSFET transistor datasheet (but not in a BJT transistor datasheet). WithOUT this Gate resistor, each time you drive the Gate HIGH or LOW, you'd otherwise have the equivalent of a momentary instantaneous short through the Arduino pin, which could damage the pin.
Also, you have to be sure to use a Logic-Level N-Channel MOSFET which can be driven with a gate voltage as low as 3.3V~5V instead of requiring more like 10V~12V.
So, with @Sahasrar's first circuit, the max PWM frequency you can use is probably a few dozen kHz.
If you need to drive higher PWM frequencies, the solution is to use the push-pull logic circuit which @Sahasrar shows next instead. But, you have to fill in the blanks: choosing parts, doing calculations, having advanced knowledge.
In both cases, you must also be sure to use a flyback diode to snub inductance-induced voltage spikes!
Option 2 of 3: [just buy an H-bridge DC motor driver] The normal hobbyist / time-constrained-individual answer:
So, the quick solution is to just buy a motor driver instead and be done!
You can use any H-bridge for a 1-channel (1 device) bi-directional drive, or for a 2-channel (2 separate devices) uni-directional drive.
Or, you can use a half H-bridge for a 1-channel uni-directional drive.
H-bridges are frequently called "brushed motor drivers". They handle all the fancy Electrical Engineering circuitry for you.
H-bridges are excellent for driving things like:

brushed, NOT brushless, DC motors
high-power LEDs, assuming you have a means of current-control too, such as a large passive power resistor, or current feedback control loop and control code
speakers (for tone's, beeps, or digital PWM-based [NOT analog-amplifier-based] music, voice, or rich audio). Ex:

tone library

[ok] tone() library
[best] toneAC() library

Example siren project I did with toneAC library, a large speaker, and a custom driver or H bridge:

https://www.electricrcaircraftguy.com/2016/01/arduino-playing-siren-sound.html
https://www.youtube.com/watch?v=anuan0oEOQw&feature=emb_logo
https://www.youtube.com/watch?v=y31gM3m3VJI - final project video demo: siren

music/rich audio PWM-based library

[excellent] TMRpcm library

Here's some H-bridges you can buy:
When searching for these things, recommended search terms include "DC motor driver" or "h bridge". Even if you plan to drive an LED or speaker with it, these are still the correct search terms and parts. Just make sure what you buy accepts PWM input as the control signal is all, and that this PWM input means true PWM, NOT a servo "PWM" signal, which is very different.
Just buy one of these and be done:

Cheap $1 L9110S H-bridge:

Ebay search for "arduino h bridge"
L9110 datasheet

2.5V to 12V supply
800mA max continuous current per channel

Cheap $3 L298N H-bridge (much more powerful):

Ebay search for "arduino h bridge L298"
Example specs sheet: http://www.handsontec.com/dataspecs/L298N%20Motor%20Driver.pdf

3.2 to 40V supply
2A peak current
20W max power

High-end, reliable, very-well-engineered DC motor drivers/H-bridges by Pololu robotics company:

See the full list of motor drivers here! https://www.pololu.com/category/11/brushed-dc-motor-drivers
Ex: $40 Pololu G2 High-Power Motor Driver 18v25

6.5V to 30V supply
1.8V, 3.3V, or 5V logic signals
25A max continuous current
up to 100kHz PWM operation, because they have excellent MOSFET gate drivers to minimize MOSFET time in the ohmic region, and therefore MOSFET heating!
If you're in a hurry and want high-quality, Pololu is an excellent choice!
Tiny! 1.3" x 0.8", and no heat sink required, again, because of their excellent MOSFETS and MOSFET gate driver circuits.

Option 3 of 3: [Radio Control brushed ESC (Electronic Speed Controller)] (easiest of them all!)--preferred by people with RC vehicle experience and/or who need really high power
Important: since this option does NOT give you the low-level control over the PWM output directly, these controllers can NOT drive speakers for audio, whereas Option 1 and Option 2 drivers above can!
I'd be remissed if I didn't include this answer as well, since this is one of my specialties. This is the easiest by far! Its only downside is it gives you less fine-tuned control than controlling the low-level PWM output to the motors directly, as you can do with the motor drivers above, versus the motor controllers below. Another advantage of the hobbyist RC brushed ESCs below over the Pololu-type robotics motor drivers above is power and current: the above motor drivers from Pololu peak out at 25A continuous, for instance, whereas some RC brushed motor controllers, some less-powerful examples of which are shown below, can drive as much as 100~200A continuous, which is HUGE.
Just buy a Radio Control (RC) brushed ESC and feed it a servo PWM signal via the Arduino servo library, NOT a true PWM signal with analogWrite()!
You give it a servo signal, and it generates the low-level PWM to the motor automatically using its internal microcontroller and MOSFET driver circuitry, usually on the order of 8kHz~16kHz PWM output frequency. Many of these types of ESCs use the ATmega168 mcu internally.
For a single-direction ESC, such as for RC airplanes, a microsecond servo value between 700~1300us is 0% throttle, and a microsecond servo value between 1700~2100us is 100% throttle.
For a dual-direction ESC, such as for RC cars, with both forward and reverse, a microsecond value of ~1500us is 0% throttle, with ~2000us or so being 100% forward throttle and ~1000us or so being 100% reverse throttle.
Sample code:
#include <Servo.h>

Servo brushed_motor;

void setup()
{
  brushed_motor.attach(9); // pin 9

  // ~0% throttle (0% output PWM duty cycle), depending on ESC
  // calibration, and assuming a forward-only ESC for RC airplanes
  brushed_motor.writeMicroseconds(1000);

  delay(2000);

  // ~100% throttle (100% output PWM duty cycle), depending on ESC
  // calibration, and assuming a forward-only ESC for RC airplanes
  brushed_motor.writeMicroseconds(2000);
}

void loop()
{
    // whatever you need here
}

To calibrate one of these ESCs to whatever throttle values you want, just set it to 2000us (full throttle) BEFORE you turn it on (careful--just in case it decides to go full throttle instead), then power it up, and it will register that as "full throttle". Next, withOUT powering it off, set it to 1000us (0% throttle), and it will register that as 0% throttle. Now, it is calibrated to have 1000us be 0% throttle and 2000us to be 100% throttle. If using an RC car brushed ESC instead of an RC airplane brushed ESC, you may have to play with it, do some research, and read its manual to get what you want, since 1500us might be considered 0% throttle, with 2000us being 100% forward throttle and 1000us being 100% reverse throttle. So, do the research.
In either case, here's some brushed RC ESCs which can drive motors and blowers or whatever just fine too.

HobbyKing:

Brushed RC CAR ESCs on HobbyKing

$12 45A ESC, 2S LiPo (6V to 8.4V) max here
$40 80A continuous, 400A split-second peak (yes, these numbers seem legit to me), 2-3S LiPo (6V to 12.6V) here

These are just a couple examples. RC ESCs like these are designed to be really high power for high-end RC vehicles which can go up to 25~100mph sometimes, and be quite large. Do some research. Brushed RC ESCs are sold in many places. HobbyKing has the best prices in the industry for these types of things, with generally good to very-good quality parts.
Related:

[my answer]  Switching a Solenoid Using Arduino's 5V Output?

Here's my answer to another question which answers your question. In the diagram below, from this other answer, the relay + R2 is the load. Replace this load (relay + R2) with your motor as the load instead, and this is also a perfectly legitimate circuit to solve your problem. The 5V here in this circuit to the transistor base would be replaced by your 5V logic level PWM signal coming from your Arduino. I also go over calculations and how to size all components. Try a high-current TIP120 NPN BJT 5 Amp continuous transistor in place of the 2N3904 in my circuit, and be sure to redo the calculations to size your base resistor, R1.
Note that this circuit allows your Arduino pin to actively drive the output both HIGH and LOW, but since its through this (relatively small) base resistor, it's probably only good for PWM frequencies up to a few dozen kHz or so. An oscilloscope used to look at the output would make this clear. Increase input PWM frequency until output PWM waveform distortion becomes significant.

H bridge wouldn't work for this specific question. The question asks for 5V PWM to 12V PWM, so I assume that the fan has a current amplifier. You will never get a pulsed output from H bridge. If the fan doesn't have a current amplifier, then L298 is a good answer, assuming the OP asked the wrong question.

@C.Koca, your comment isn't correct. L298 is an H bridge. And, if you supply an L298, or any other H bridge, with 12V, and then PWM the logic input side with 5V, then you get the 12V output side with an identical output PWM, except at 12V. Remember, an H bridge is just 4 transistors set up in two complementary pairs designed to drive a single reversible channel in forward and reverse, or two non reversible channels to drive two separate motors in one direction only.

I can update my answer with exact wiring details if you'd like me to. I've done this on many projects in the past, used H bridges often, and even designed them from scratch. One H bridge can dual drive one speaker, one dual direction DC brushed motor, or two unidirectional DC brushed motors. Also, he mentions under his Question it's a large blower unit. My answer assumes it's a 2 wire DC brushed motor he's driving. Unless he tells me it's a 3 or 4 wire motor, my answer is correct.

H bridge is a fancy word for couple of BJTs. You have an RC circuit at the base with a mediocre performing base discharge.
Just check Fig 3. https://www.st.com/resource/en/datasheet/l298.pdf and check the rise fall times. It is about 4 times the ones of MAX232. For low frequency, it wouldn't make much difference but for high frequency PWM switching it would. For 10 kHz, your design will be off by 3%. For 100 kHz, it would be off by 30%. Besides, the comment suggests the fan itself has its current amplifier so L298 output would properly exceed the input current.

H bridge is a fancy word for couple of BJTs. No, "H-bridge" is a very specific word to mean 4 transistors arranged in two complementary high-side + low-side pairs, allowing dual-driving 1 bidirectional 2-wire motor or speaker, or 2 separate unidirectional 2-wire motors or two single-driven speakers. An H-bridge can be designed with either MOSFETs or BJTs, so it implies nothing about being made with BJTs. Motors are driven usually with 8kHz to 16Khz PWM frequencies, rarely ever above 100kHz due to H-bridge limitations and motor inefficiencies/losses which increase with PWM frequency.

H-bridge is a just four transistors arranged in two Darlingtons. When you have amplifier transistors but not base discharge transistors, you will face distortions in the voltage waveform. That 3% doesn't even include the results of heating. Do you know how MAX232 achieves such a result? Because it has discharge capacitors and lower base capacitance. I know what L298 does, it is in my answer as well. But it will not give a PWM output.

@C.Koca, please quit commenting. Nearly every single comment you leave is at least partially incorrect, and you're sowing misinformation wherever you go. You say some truth, some misinformation, some truth, some misinformation, and are seriously confusing anyone reading your comments. Here's a Darlington: https://en.wikipedia.org/wiki/Darlington_transistor. It is a BJT which feeds the base of a BJT. Here's an H bridge: https://www.build-electronic-circuits.com/h-bridge/. It has zero BJT Darlington pairs in it. And, an H-bridge can be made of MOSFETs OR BJTs. A Darlington refers to BJTs.

MAX232 drives low-power signals. L298 or other H-bridges drive real power & current. Signal drivers always have better, more square output than real power drivers, because real power drivers have bigger components to deal with. I have an oscilloscope. I've looked at the PWM output from H-bridges. Please quit sowing misinformation.

You got me at Darlington but do you want to go personal? Alright, you don't even know about base discharge, slew rate and PWM and still trying to push L298 for a low power operation. Have you checked the comment by OP: and a low powered option is suitable as it only requires a PWM signal to control the speed the rest is done with its on-board controller - no more than a 0.5mA signal is required. H bridge do not have discharge transistor. Do you know what a discharge transistor? It is a PNP for an NPN or vice versa that only becomes ON when the power transistor is OFF.

Jeez, hobby electronics is not the same as being an electronics engineer.

Also, my circuit at the bottom of my answer is neither an H-bridge NOR a half-H-bridge. It is a circuit for a different answer, which happens to have some overlap with this answer, and it has pretty good rise time and fall time, since it is actively driven both HIGH and LOW, albeit through a (not large) base resistor, meaning its PWM output would be good only up to a few dozen kHz or so.

I am not commenting on that part but using a relay in a fast switching circuit? You really try to reduce the rise time, don't you?

Let us continue this discussion in chat.

There is nothing to discuss.

I hadn't even read the TLDR part. Connect a 1A rated L298 to a 0.5 mA rated signal circuitry? (Sorry cat wrote the rest)


text:
serially parse integer after serially read
I want to write below code but I don't know where I doing wrong, so please help me solve this issue.
Serially read some text like number then I want to serially parse integer value into some variable and then my next task is if I wrote as text then serially read string and should save in some other variable...
char c;
String s;
long num1=0;
long num2=0;
void setup()
{
  Serial.begin(9600);
  Serial.println("Let's start: ");
}
void loop()
{
  if(Serial.available()>0)
  {
    delay(5);
    c = Serial.read();
    s += c;
  }
  if(s.length()>0)
  {
    if(s=="n")
    {
        if(num1==0)
        {
        Serial.println("write number: "); //serially print
        num1=Serial.parseInt(); // not serially print
        if(num1>0)
        Serial.print(num1);
        }
        if(num1>0)
        {
        Serial.println("write second number: ");
        num2=Serial.parseInt();
        if(num2>0)
        Serial.print(num2);
        }
    }
    s="";
  }
}

And what's your problem? The sketch works fine : You send n12 33 and the sketch detects two numbers 12 and 33.

Once num1 != 0 it never goes back to 0 so you'll see "write number" only once after reset

There is serially print as "Let's Start".. done.
After gives input "n", Print as "write number".
But after not read any integer value(parseInt).

There's no dialog. After entering only an "n"  your logic is broken: The "n" is removed from s and your code works as programmed.

source: Stack Exchange

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

sort: votes


text:
Wiring up an ESP 01 to Nano
I've been at this for over a week now and still cant get things working. Im attempting to wire up an ESP-01 chip to a Nano to send AT commands over Serial. I've followed many different tutorials, but the best (and my current) setup seems to be this one:
https://www.youtube.com/watch?v=YKn2ZXYb_EI (Wiring)
https://www.electronicslovers.com/2017/11/learn-how-to-setup-wifi-module-esp8266.html (Wiring & Code)
My breadboard has that exact wiring as shown in the video and the website. I understand that the 3.3v pin doesnt provide enough power, so I've used a DC Voltage regulator to step the 5v pin down to 3.3v, and I'm using that as my main power line.
When I plug the Arduino in, I get a quick couple of flashes from the blue light on the ESP, as well as a solid bright red light. The light is brighter than when it is directly from the 3.3v, so I'm pretty sure it's powered enough.
I then open Serial monitor and get no response when I type AT:

I have tried at both 9600 and 115200 baud, and tried many different wiring setups, all to no avail.
If someone could help with this I'd be forever appreciative

After taking some readings with my multimeter - I see the output of my regulated 3.3 rail drops to 2.55 with the ESP plugged in... Do I want to bring this up even more so it's 3.3 WITH the ESP plugged in?

I don't think the above edits suggestion will work since I've also wired the chip to a 3.3 breadboard power supply powered by a barrel jack - still no avail

I understand I can write firmware directly to the ESP-01, this is not my goal here. I require it as an add-on to the Nano, since I need its analog pins, amongst other things'

Wowwww i finally figured it out after a week of messing around, and 20 mins after posting my question.
To anyone else who stumbles across this: Please understand if you're following this tutorial here or here. There is a bug in the code:
SoftwareSerial softSerial(3, 2); // RX, TX

should be
SoftwareSerial softSerial(2, 3); // RX, TX

Also the suggested baud rate of 9600 doesnt seem to work, adjust to 115200 and go from there. Once you get a receiving signal, run the following to adjust the 01's baud to 9600:
AT+UART_DEF=9600,8,1,0,0

After this, reflash your nano with serial bauds set to 9600 and you should be able to send AT commands over your Nano to the ESP-01 via 9600 baud
In addition to this. You will read online that you might be able to get away with stepping the Nano's 5v pin down to 3.3 to power the module. This didnt work for me, and i suggest you get a breadboard power supply
Good luck to all!

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


text:
Leds become dimmer after they reach a certain brightness, why?
Even if I don't use buttons and I do an automated thing that makes the led brighter(Even the non-rgb one)after sometime it resets itself to a dimmer light, why?*
int Gled = 5;
int Bled = 6;
int Rv;
int Gv;
int Bv;

int b1 = 7;
int b2 = 8;
void setup()
{

  pinMode(b1, INPUT_PULLUP);
  pinMode(b2, INPUT_PULLUP);
  Rv = 0;
  Gv = 0;
  Bv = 0;
  analogWrite(Rled, Rv);
  analogWrite(Gled, Gv);
  analogWrite(Bled, Bv);

}

void loop()
{

  if(digitalRead(b1) == LOW)
  {
    Rv += 10;
    analogWrite(Rled, Rv);
  }
  if(digitalRead(b2) == LOW)
  {
    Gv += 10;
    analogWrite(Gled, Gv);
  }

}

The loop is quite fast, can you imagine how many times it goes into if section, when you press the button? Also you are providing int value into analogWrite, but usual values are 0-255...

The described behavior stems from 2 important facts:

The loop() function will run very fast (microsecond range), while the button presses of a normal human will be rather slow (in the tens or even hundreds of milliseconds). That means, that with only one button press you will enter the corresponding if statement many times, everytime adding 10 to the value. You don't have control how many times exactly the if statement will be entered, so the value, that comes out after your button press is somewhat randomly growing.

While the analogWrite() function takes an int as the value parameter (16 bits on AVR), internally it assigns that value to the corresponding Timer register, which is only 8 bits big. So it can only hold values between 0 and 255 anyway. If you provide a bigger number as a parameter, the higher part will just be cut off. For example: Providing 257 will result in a value of 1 (= 257 % 256 = 257 % 2^8 --> 257 modulo 256). The higher values get wrapped around back into the range of 0 to 255.

So together you have a value, that is growing very fast and somewhat randomly, while the analogWrite() function will only take the lower 8 bit of that value. The outcome is a rather erratic, somewhat random LED brightness, which is difficult to control.
What to do now? That depends on what behavior you want to have exactly:

One button click (press + release) should increase the value of the corresponding LED by 10:

Currently you are checking, if the button is being pressed. Instead you have to look for the transition between not-pressed and pressed, so a HIGH to LOW transition. You can do that by saving the last read value in a variable at the end of the button reading part and comparing this previous value to the newly read value at the start of it. Though that still leaves you with the bounce problem. There are many measurements, that you can do, to debounce the button (you can google that easily), though here I just will suggest using the Bounce2 library. You can find it here on github or in the library manager (I think). It makes it much easier to read buttons reliably. It has good examples to learn how to use it.

The value should rise, while the button is pressed, and stopping to rise, when it is released again:

Here you should limit the rate in which the if statement is entered. You can do this by limiting the execution rate of the loop() function with a simple call to delay(), though that isn't a good coding practice and can limit you, when adding more functions to your code (because it's blocking the execution of other code). Instead you can use the non-blocking coding style involving the millis() function, that you can see in the BlinkWithoutDelay example. You use a timestamp variable to save the last time, when the if statement was executed. The if statement should then check (additionally to the button state), if enough time has passed, meaning if the difference between millis() and the timestamp is high enough. You can change the interval for this comparison to change the rate, in which the value is increased.


text:
storing 600 unsigned int values in an array and find minimum and maximum values
I am reading an ASCII serial data values from a sensor and storing it in an unsigned integer variable. The values are ~45000 to 50000 range. I need to store 600 values and then find the minimum and maximum. after 600 values reached the oldest value is being replaced with the new value. The array size required is 600 which is approx.1200Bytes of the size of storage. I'm using Atmega 2560. I would like to know is it possible to store all 600 values in SRAM or do I need to use EEPROM memory?

The ATmega2560 has 8kB of SRAM. So yes. possible. Do you have a question, that cannot be answered by simply one word?

If you only need the minimum and maximum, you could calculate them on the fly, and not even have to store any of the values. Add a counter, so you know when you've received 600 values. Just a thought.

@gerban  @ chrisl  After reaching 600 values, the first stored value is deleted and all 599 values are shifted left, a new value is added(LIFO). This is a continuous process, from every 600 values, need to find out max.and min values. This is my requirement.

@Gerben Say the dropped value is the minimum value and the new value isn't lower than that value--the current minimum needs to be re-calculated. Could keep the two lowest/highest values, though.

The Atmega 2560 has 8K of static ram, more than enough for your 1200-byte array.
Reading-, and especially, writing EEPROM are very slow, and EEPROM has a rather limited lifetime-number-of-write-cycles, so it is not a good candidate for active use but rather for storing data that change infrequently and need to survive a power-down. These would typically per-system preferences, or data that needs to be stored to let the system resume at the next power-up, where it had left off when the power went down. This latter function requires that the system store enough power (capacitor or tiny battery) to keep it running long enough to sense the main power failing and still have run-time enough to write to EEPROM.


text:
How can I increase the torque or speed of the stepper motor with Arduino
I run 28BYJ-48 12 Volt Motor with ULN 2003 Driver using Arduino UNO.
I am also using external 12 volt power outside.
I aim for the syringe pump to move back and forth with the rotation of the motor.
I'm using the code below.
The code is running but the motor cannot move the syringe back and forth.
How do I change to be able to move the syringe pump
const int motorPin1 = 8;
const int motorPin2 = 9;
const int motorPin3 = 10;
const int motorPin4 = 11;

int bekleme =2
;
// bekleme süresini değiştirerek step motorun hızlı veya yavaş ilerlemesini sağlayabilirsiniz.
//1sn=1000

void adim1() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(bekleme);
}

void adim2() {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(bekleme);
}

void adim3() {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(bekleme);
}

void adim4() {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(bekleme);
}

void setup() {

pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);

}

void loop() {

for (int i = 0; i < 2048 ; i++)
{
adim1();
adim2();
adim3();
adim4();
}
{

exit(0);
}
}

İleri
// Meraklı Mühendis Sayfasının hazırlığı kodlar kullanılmıştır.
//Dilerseniz farklı fonksiyonlar kullanabilirsiniz.

const int motorPin1 = 8;
const int motorPin2 = 9;
const int motorPin3 = 10;
const int motorPin4 = 11;

int bekleme =2;
// bekleme süresini değiştirerek step motorun hızlı veya yavaş ilerlemesini sağlayabilirsiniz.
//1sn=1000

void adim1() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(bekleme);
}

void adim2() {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(bekleme);
}

void adim3() {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(bekleme);
}

void adim4() {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(bekleme);
}

void setup() {

pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);

}

void loop() {

for (int i = 0; i <2048; i++)   // buradaki 512 değerleri step motorun tam bir tur dönmesini sağlıyor. dilerseniz bu sayıyı değiştirebilirsiniz
{
adim4();
adim3();
adim2();
adim1();

}
{

exit(0);
}
}

You haven't given much detail, that we can work with. Though I'm seeing, that you are only activating 1 phase at a time. For full steps you need to activate 2 at a time. Maybe my answer to this question is helpful here.

@chrisl I think OP is using an unipolar stepper motor. Though you could add a step in between where two coils are active, creating a crude form of micro-stepping.

@Gerben This is purely experience with the exact same motor and driver combination. I also had problems driving the motor with the phase combinations 1000,0100,0010 and 0001. Instead I tried 1100, 0110, 0011 and 1001. That worked for me. Or for half steps 1000,1100,0100,0110,0010,0011,0001,1001. Don't really know, why, but I wanted to share the experience

To increase torque of 28BYJ-48 you have to perform a simple mod (cup one path on the PCB) to change it from unipolar to bipolar and then use it with an H-bridge like the A4988 or the DRV8825 driver.

Sources:

https://ardufocus.com/howto/28byj-48-bipolar-hw-mod/
https://coeleveld.com/wp-content/uploads/2016/10/Modifying-a-28BYJ-48-step-motor-from-unipolar-to-bipolar.pdf
https://everythingsmarthome.co.uk/howto/converting-the-28byj-48-stepper-motor-for-more-torque/
http://www.jangeox.be/2013/10/change-unipolar-28byj-48-to-bipolar.html
https://www.youtube.com/watch?v=hkxnQIKybiI
https://www.youtube.com/watch?v=jHLyJbNgcDo

Assuming you are driving your motor correctly (And it sounds from Chris like you are not) and that you are using a power supply with enough current and a motor driver with a low internal resistance, you could put a reduction gear on the motor to reduce the rotation speed and increase the torque. It would take more rotations to push the syringe the same distance, but it will have more force.
If you use a 4:1 reduction gear, for example, you'd need 4 times more rotations, and you'd get 4 times as much force.


text:
Arduino communication
I want to message and call arduino board. I want some type of automation. But where should I get started I don't know I've tried sim900a module which was disappointing experience for me. Then I found out that this module was designed for asian regions and needed some type of firmware update. I wonder if there are another methods to make calls and send messages to arduino board. Any answers will be appreciated.

Choose a modem that is suitable for your region. You should be looking for an LTE modem not a GSM/GPRS modem these days. GSM/GPRS is gradually being phased out.

SIM900A is not just for Asia, it is supports dual band GSM/GPRS 900/1800MHz which works in Asia, Europe except North America. You should get SIM900B which is a quad-band supporting GSM/GPRS 850/900/1800/1900MHz.


text:
arduino usb host shield hard drive
Greeting to all,
i have a mega2560( NOT AN ADK ), and usb host shield 2.0, and the following
a) 1 pendrive( 8GB) formatted as fat32
b) 1 300GB usb hard drive formatted as fat32
c) 1 1TB usb hard drive also formatted as fat32
i know, there is a limit on fat32 that the maximum
drive/partition size must be 32GB, and i have found
a disk utility that can format such big drive as fat32(
if you want to know what it is, please ask)
after formatting all these drives( a)+b)+c) ), i have
created folders+files on them, no access problem when
using them in linux, mac, win?;
so i have wrote a sketch in arduino and was successful
in create+write to the pendrive, but when i use the
identical sketch to write to the other two drives, the
sketch died at usb init;
all these were using the same+identical arduino+usb
host shield 2.0, and the operation of the hard drive(
one at a time ) was power with external adapter,
after b) and c) failed, again i used the same pendrive,
and wrote successfully;
then i reformatted those two large drives as fat32(this
time both with size 30GB)...again failed at usb  init;
any advice/suggestion would be greatly appreciated ,
thanks for reading and STAY HEALTHY !!!

I have no direct experience with that, but using a drive as big as 300GB or 1TB seems rather off limits with an Arduino. For what do you ever need that much space with a small and slow AVR Arduino?

thanks for your comment, what you have said about the size is TRUE+CORRECT, the 300GB and the 1TB was just laying around, and i wanted  to test out the limits, since i have 5 sensors in a robot, and by each write size is 100bytes and over 720 minutes...you get the picture...

Ok, that sparks the question how often you read per minute. To fill up 300GB in 720 minutes you would need to write the sensor data for all 5 sensors every 72us. I think the writing itself will take way way longer than that. With the 30GB from the stick you are still at a rate of every 720us. I mean, I don't want to invalidate your question, since it is a good question. Just wondering about the closeness to reality here.

the 300gb was just laying around, i used it to test out 00) this fat32 will work on drive/partition larger than 32gb, 01) the test i did with 5 sensors, for 3 hours each sensor took 1GB...so for 5 sensors over 12  hours that would be 20gb+(???) and if i run those sensors in a 24 hours that will go over the fat32 limit of 32gb

You are dealing with an MCU without an OS, if you want to have a hard disk, get a Raspberry Pi which run Linux with proper hardware driver. 2) Do you really need to read the sensor that frequent? I don't know your application, normally if you need that kind of data, you would process the data immediately rather than storing it in storage for later to process, I would suggest to understand the concept of edge computing if you need to process such intensive data acquisition.

thanks to all, yes i do understand my case is a mcu without an os, and yes, i have considered among raspberry pi( 3+4), and udoo, udoo is the only one that has a leonardo mounted...but with very limited  digital+pwm capable pins, so without exception, ALL operates on 3v, and all my sensors operate( meaning giving feedback to arduino ) at 5v...as to why am i collecting this amount of data, that is an assumption on your part, in worse case scenario, as i have stated can be over 40GB, since it worked with a 8GB pendrive, next i will try with a 64gb pendrive,

if that works,  then pcb inside these usb hard drives are over  8 years old...thus speed ,any comment would be appreciated, thanks again

ok, folks, i am sure i have this solved, after i used 2 64GB pendrives, 1 is with usb 3.0, 1 with 2,0... the 1 with a 2.0 worked and the one with 3.0 did not...and i found out that  i was attaching those hard drives to the usb host shield 2.0 with a usb 3.0 adapter...so consider this closed


text:
U-Blox Neo M8N GNSS-GPS interface with ESP32-TTGO-T-CALL
I have tried contacting the manufacturers as well as many Google searches.
I have tried many different libraries to get this GNSS-GPS working.
Libraries I've Tried:

Arduino_GPS

Arduino_Parser_Ublox_Neo_M8N

esp32-ublox

MicroNMEA

NEO-M8N

NeoGPS

UBLOX-NEO-M8N

The library I am trying now:

Parser_Ublox_Neo_M8N
with:
ESPSoftwareSerial

(I have a non-AVR board so NeoSWSerial and SoftwareSerial didn't work for me.)
Link to files on GitHub:
https://github.com/toskyRocker/Arduino_Parser_Ublox_Neo_M8N
My questions for someone who has done this before with a U-Blox M8N:

Must I use U-Center software to configure the gps before it will output data?
Does my code look to be functional? I can compile but then when attaching GPS I get the output (as my psuedo error message) that lets me know the serial connection between my TTGO T-Call V1.3 and U-Blox-M8N is not valid.
Here is a link to the board I have and the GNSS-GPS:

Board:
https://www.ebay.com/i/284030711638?chn=ps&norover=1&mkevt=1&mkrid=711-213727-13078-0&mkcid=2&itemid=284030711638&targetid=4580840328168117&device=c&mktype=&googleloc=&poi=&campaignid=403206339&mkgroupid=1235851284533722&rlsatarget=pla-4580840328168117&abcId=9300372&merchantid=51291&msclkid=52c16af1ba571d52ddfe35755ba68854
GPS:
https://www.bidorbuy.co.za/item/319275677/GYGPSV5_NEO_M8N_NEO_M8N_001_GPS_Chip_Module_for_APM2_6_Flight_Control.html
(The "<#include SoftwareSerial.h>" in the code below is what was added when I used the Arduino IDE's drop down libraries menu when I selected espsoftwareserial to include.)
Here is the (.ino) code:
#include <SoftwareSerial.h>

#include "Ublox.h"
#define SERIAL_BAUD 115200
#define GPS_BAUD 9600
#define N_INTS 4
//gpsSerial(3,1);
Ublox M8_Gps;
// Altitude - Latitude - Longitude - N Satellites
int gpsArray[N_INTS] = {0, 0, 0, 0};
SoftwareSerial gpsSerial;

/////////////////////////////////////////////////////////////

void setup() {
Serial.begin(SERIAL_BAUD);
gpsSerial.begin(GPS_BAUD,SWSERIAL_8N1,3,1);
//gpsSerial.begin(GPS_BAUD);
pinMode(0,OUTPUT);
}
///////////////////////////////////////////////////////////
void loop() {
digitalWrite(0,LOW);
if(!gpsSerial.available()){
    Serial.print("Problem with GPS ");
}
while(gpsSerial.available()){
    char c = gpsSerial.read();
     if (M8_Gps.encode(c)) {
      gpsArray[0] = M8_Gps.altitude;
      gpsArray[1] = M8_Gps.latitude;
      gpsArray[2] = M8_Gps.longitude;
      gpsArray[3] = M8_Gps.sats_in_use;
    }
 }
 for(byte i = 0; i < N_INTS; i++) {
 Serial.print(gpsArray[i], 10);Serial.print(" ");
 }
 Serial.println("");
 }

By default the GPS module has a baud rate of 115200; 2) ESP32 has more than 1 hardware serial, use Serial2 allows you to operate at 115200 and connect to GPS module.

Thank you very much for your help.  Is serial2 the pins labeld Rx Tx or would that be a different UART pin combo?

ESP32 Serail2 is at Pin16 (Rx) and Pin 17 (Tx), see HardwareSerial source code for ESP32.

Must I use U-Center software to configure the gps before it will
output data?

No, but it is HIGHLY recommended.  It's the only (easy) way to change the baudrate, and the only (easy) way to change what messages are output over serial.

Does my code look to be functional?

I can't answer 100%, as I have not used that library before, but the problem I did run into with the NEO-M8N and multiple libraries I tried (MicroNMEA, TinyGPS, TinyGPS++, ...) was that as a multi-constellation GNSS receiver that can receive more satellite constellations than just GPS, it by default outputs $GNGGA.  These libraries I had tried using only decoded the old standard $GPGGA, and ignored the more universal ones.
Here is how you can use U-Center to verify this is the problem, and if so how to configure your module to output GPGGA messages that these libraries will parse:

Connect to your NEO-M8N using U-center.  (Usb is pprefered, but serial will work fine too)
Confirm that this is the problem by clicking View -> Messages View.
You should see either GPGGA or GNGGA messages being received.

If you are currently getting GNGGA, here is how to switch them to GPGGA:

View -> configuration View
Click on "NMEA (NMEA Protocol) config entry
Click "Poll" at the bottom to pull the current settings from your device.
Change the "Main Talker ID" to "1 - GP (GPS)"
Change the "GSV Talker ID" to "1 - Use main talker ID"
Click "Send" at the bottom to upload your changes.
Click on the "CFG (Configuration)" config entry
Choose "Save current configuration" and then "Send" at the bottom.

Now just use the method above to verify what NMEA packets you are receiving!
Now that you're in U-Center, I'd recommend also checking out the GNSS config, to enable the use of more satellites (GPS, Glonass, Galileo) and set the SBAS config depending on your location.  (In the US, setting to WAAS may help it lock on quicker as it won't bother searching for other SBAS sources)  You can also change the baud rates for different ports under "PORTS", increase or decrease the frequency of sending location updates under "RATE" and enable or disable individual NMEA messages for each port under "MSG"


text:
Downloading code from Arduino mega
A while ago I made a code for a drag timing system and uploaded it to my Arduino mega after that I broke my computer and got a new one and I don't have that code anymore. Does anyone know how to recover it from my Arduino?

this has been asked before

You can easily recover the binary (look up avrdude and the command your IDE uses to upload to the board), but you won't get your source code back from that.


text:
Arduino Uno cant be powered by VIN pin
Im trying to power an Arduino Uno from a pack of 8 AA batteries (so 12V) and it just doesn't turn on. When I connect the barrel jack, it works! Any idea why the VIN doesn't work? Thank you in advance.

VIN pin should be connected directly to barrel jack. Could you test if they are connected in your Uno?

@AleksejVasinov Actually there's a diode in the + of the barrel jack connection, so it's not directly connected. A simple continuity test may fail if not done right.

I have known some inferior Chinese clones to use sub-par headers with bad connections in them. Try connecting to the pin underneath the board where the VIN is soldered.


text:
Reading Serial String Gives Null Lines with JSSC
I need to send serial data to my Arduino UNO from within a java application. I am using JSSC for this.
I wanted to verify that my data actually arrives correctly to the arduino before going to the next step of my application. For this I tried to just return the string I am sending, however when I send "test", this is what is returned:
t
null
est

I am wondering if this is a problem on the Java side with sending/reading the string, or that it's a problem with sending/reading on the arduino, and how I could possibly fix this.
This is my java code to read the data:
try {
    port.addEventListener(event -> {
        try {
            System.out.println(port.readString());
        } catch (SerialPortException e) {
            e.printStackTrace();
        }
    });
} catch (Exception e) {
    e.printStackTrace();
}

This is my java code to send the data:
try {
    port.writeString("test");
} catch (SerialPortException e) {
    e.printStackTrace();
}

And this is the code on my arduino:
void loop() {
  while (Serial.available() > 0) {
    Serial.print(Serial.readString());
  }
}

I hope someone can help :)

you have to say "over" when using walkie-talkies. or serial. Otherwise, a response of "Yeah, that's a bad idea" could be interpreted as just "yeah" if it cuts out.

This is a common misconception about how serial communication works.
You're "sending" the "string" test. Except you're not.
What you're actually doing is you're placing the string test into the send buffer. Another routine then takes each byte from that send buffer in turn and sends it out through serial.
The Arduino then receives that byte and places it into its internal receive buffer.
You then get around to reading from the serial and you just get whatever is in the receive buffer at that moment in time - however many bytes that happens to be.
Then you "send" those bytes back - except again, you don't. You place those bytes into the internal transmit buffer in the Arduino and another routine takes each byte in turn from that transmit buffer and sends it out through the serial.
Again the Java program gets around to reading from the serial, and all it gets is what happens to be in its receive buffer at the time, however many bytes that may be at the time.
There is no such thing as "a string" or "a line" in serial. All there is is bytes - one after another.
It is up to you to receive those bytes and reconstitute them back into the form you want as each byte happens to arrive.
As it stands you have no way of knowing what that form should be, since you just send four bytes with no meaning attached to them.
It's common to add a "terminator" to a string when sending so that the receiver knows when all the bytes have arrived.  For us humans the simplest to use is a "line feed" or \n character.
Your receiving routine would then receive each character in turn appending it to the target String up until it receives the terminating character, at which point it knows that it has finished receiving this chunk of data and can act on it.
I have a popular blog post all about reading serial on the Arduino here, and the same principle can be applied to any other language.


text:
RFMesh (NRF24) for STM32F1
I wanted to know the RFMesh library available for Arduino Uno can be used for STM32F1? Will it work? Or they have seperate set of library for STM32

Have you tried it?

what problem are you having?

I have not yet tried. But wanted to work on that. But I am not sure will it work with STM32 or not. But when I compiled the sketch in Arduino IDE by selecting STM32F1 from board manager it compiled without any error. So I wanted to put this in front of community.


text:
Piezo sensor requires parallel or pull-down resistor?
Apologies but I didn't happen to find ultimate answer to this.
I'm trying to make a simple piezo sensor (https://www.sparkfun.com/products/10293) which triggers something (e.g. a sound or lights up a LED) when it's pressed. This is similar to Arduino "Knock Lock" project.
However, I see there are 2 different basic ways to connect the piezo as vibration sensor:
Way 1) [as in Arduino project]

Piezo + to 5V
Piezo - to A0
1MΩ Resistor between A0 and GND

Way 2) [as in many other references on the internet]

Piezo + to A0
Piezo - to GND
1MΩ Resistor between A0 and GND

I tried both and have very different behaviours.
Way 1 seems working correctly: analogRead(A0) returns a value related to how strong the vibration is, and then decays to almost 0 (I expected 0 but it stays to 50-60ish).
Way 2 provide more of an impulse-type response, and stays at 400ish after triggered.
Are these behaviors correct and what's the proper way for piezo sensor?
Using Arduino UNO powered via USB.

what piezo sonsor are yout talking about?

@jsotola this one https://www.sparkfun.com/products/10293


text:
Can Arduino Sketch be used for production
There are lot of device support with the help of Boards Manager today and is on going in Arduino IDE.
So I am curious to know about can one use those for production purpose. Or it is recommended for quick prototyping purposes only...

Are you asking about using an Arduino board in production or its board description? If the board, what is your concern about production vs. prototyping (I'm assuming you've already done a cost comparison of Arduino boards vs. custom board for your anticipated production quantity)?

Are you thinking about copyright of the IDE or the Arduino libraries? Please read the statements on that issue.

That greatly depends on the requirements, that you have for the production environment

My plan is not to use Arduino Board into production. I will explain by an e.g suppose I did a prototype on Arduino UNO it uses ATmega328p and it worked as per expectations. So I want to push them into production. But instead of using whole Arduino UNO what I do is I will flash ATmega328p with Arduino Bootloader and by using AVRDude I will flash the .hex file. And I will place into my design. Will it work. Are there any copyright issues?

Are you using libraries? If yes, then search for an issue on Github or create one if you're allowed to use them.

Related: Using Arduino for Industrial process

Also related: LGPL and Arduino in Commercial Products

Industrial applications tend to steer more towards ladder logic vs C programming. The Do More PLC is an open source PLC that has some characteristics of an Arduino. Look at automation direct to see line up. However, you need to ask who is going to maintenance your project when you are gone? That is the big reason why companies love Allen Bradley and Seimens controllers.

There's a lot of controversy on this issue, but if it works for your needs, absolutely do it!
Basically, there are 2 questions you have to answer:

Should I use actual Arduino boards in production?
The answer is generally "no", simply because you need to customize the boards to add components to support your project, and to make them more robust, and cheaper, if possible. So, use an Arduino schematic as a guideline, then modify it to suit your needs.
One big exception to this, however, could be if you create a "mother board" onto which you will plug in a "daughter board" such as an Arduino Nano, Pro Mini, Pro Micro, or similar. You could make the Nano removable by soldering male headers onto it, and female headers onto the main "mother board", then you just plug in the Nano into the headers on the main board. Or, you could make it permanent by soldering male headers onto the Nano and then also solder that straight onto the "mother board" directly into the holes where female headers would otherwise be soldered. Both of these are great options, and this vastly simplifies your design and assembly process as you learn to get started manufacturing. Legal Arduino Nano clones are ~$1~$4 each, with shipping, on Ebay, and Pro Minis (not as good--here I recommend the Nano) are about the same, so buying a pre-made Nano is generally cheaper than buying just the raw chips on the Nano anyway, oddly enough. And again, this vastly simplifies your design and makes designing and assembling boards and products much much easier for the beginner/entry-level manufacturer (you) or micro business. It also allows you to make hand-made boards using perf-boards or proto (prototyping) boards, as I show in my other answer here.
For designing your own board, I recommend KiCad, which is Free and Open Source, and no cost ("free" == "free to modify"; "free" != "no cost"!), and actively developed by a volunteer team of about 6 people on a daily basis (I'm on their mailing lists and see this daily). It is a great product and is highly-capable. It is used by hobbyists and professionals alike, and has been used on many professional products world-wide. CERN, Arduino, and DigiKey have all contributed to KiCad in one way or another. See the lists of sponsors under the "Sponsors" tab at the top of the KiCad website, here:

Corporate Sponsorship
In Kind Sponsors
Historical Sponsors

The CERN Open Hardware Repository states here:

We think that KiCad can do to PCB design what the gcc compiler did to
software: ensure there are no artificial barriers to sharing so that design and
development knowledge can flow more freely.

That's an incredibly exciting mission!
There is also Autodesk Eagle, which is also popular among hobbyists and small businesses. It is a paid product, but has a no cost version for hobbyist, non-commercial use. It is also actively developed, by a tiny team of paid software developers on a pier in San Francisco. I've been to their office, and they are very excited about their work on it. They are doing a great job at making it a more-professional product. They've made some great improvements to Eagle over the last few years, hence why its price has gone up. It is also a great product.
Both products work on Windows, Mac, and Linux.
The Arduino board schematics are open-source hardware, so follow the licenses and provide attribution to where your design stemmed from. Ex: here's the Uno schematic. It shows the CC BY SA license logo at the bottom. I don't see a license version, but if it's 1.0, here's that license in plain terms. So, if you copy parts of the original schematics, release your design under the same license, and give credit to the original design.
You can NOT, however, use the Arduino logo or name. Those are trademarked and copyrighted, respectively. Arduino clones which do NOT use the Arduino name or logo are legal, and any clones which DO use the Arduino name or logo are illegal. There's no excuse for making an illegal Arduino clone. The schematics are intentionally open-source.
See also: Since Arduino uses Creative Commons licenses, do I also need to do that on my product?

Deriving the design of a commercial product from the Eagle files for an Arduino board requires you to release the modified files under the same Creative Commons Attribution Share-Alike license. You may manufacture and sell the resulting product.

And: Can I design my own Arduino board and sell it?

Since the hardware designs of Arduino are open source it is allowed to copy and further develop them. However this is not the same thing as making an Arduino board, only the company Arduino can design and produce Arduino products.
Your finished product is a product compatible with Arduino which should have its own name and brand. In case a copy uses the Arduino name and/or logo on it, this board is no longer a copy but a counterfeit which is illegal to manufacture and produce.

Should I use the Arduino software (build system and core libraries, and my program / "sketch") in production?
The answer is generally, "yes". This may be using the IDE for building or using the Arduino CLI command-line build interface.
The Arduino core and build system works great and has tons of internal and 3rd-party library support. The Arduino IDE itself is released under the GPL license (see below), and the core libraries are LGPL-licensed, which means if you modify them for your project, and put your project result into someone else's hands, you MUST release your modifications you made to the core code and libraries to those who have your project in their hands. See the main license file here:

this file includes licensing information for parts of arduino.
first, the gnu general public license, which covers the main body
of the processing/arduino code (in general, all the stuff inside the 'app'
and 'core' subfolders).
next, the gnu lesser general public license that covers the arduino core
and libraries.

But, you can keep your programs/"sketches" and main bits of project closed-source if you wish. Your programs are your own. They are copyrighted solely by you and you can license, use, and/or sell them however you wish. This includes the right to sell your Arduino/C and C++ programs as software or as firmware within a commercial product.
As a matter of fact, the GPL and LGPL licenses on the Arduino IDE and source code even allow you to sell the Arduino IDE and source code itself if you wish! This is really important, and is a fundamental right that "free and open source" software grants you. The Free Software Foundation, which is the owner of the copyrights on the license text itself, and the author of the GNU GPL and LGPL and other free and open source licenses, has this official guidance about selling and even reselling free software (they strongly encourage it!) (italics added):

Selling Free Software
Some views on the ideas of selling exceptions to free software licenses, such as the GNU GPL are also available.
Many people believe that the spirit of the GNU Project is that you should not charge money for distributing copies of software, or that you should charge as little as possible—just enough to cover the cost. This is a misunderstanding.
Actually, we encourage people who redistribute free software to charge as much as they wish or can. If a license does not permit users to make copies and sell them, it is a nonfree license. If this seems surprising to you, please read on.
The word “free” has two legitimate general meanings; it can refer either to freedom or to price. When we speak of “free software”, we're talking about freedom, not price. (Think of “free speech”, not “free beer”.) Specifically, it means that a user is free to run the program, study and change the program, and redistribute the program with or without changes.
Free programs are sometimes distributed gratis, and sometimes for a substantial price. Often the same program is available in both ways from different places. The program is free regardless of the price, because users have freedom in using it.
Nonfree programs are usually sold for a high price, but sometimes a store will give you a copy at no charge. That doesn't make it free software, though. Price or no price, the program is nonfree because its users are denied freedom.
Since free software is not a matter of price, a low price doesn't make the software free, or even closer to free. So if you are redistributing copies of free software, you might as well charge a substantial fee and make some money. Redistributing free software is a good and legitimate activity; if you do it, you might as well make a profit from it.
Free software is a community project, and everyone who depends on it ought to look for ways to contribute to building the community. For a distributor, the way to do this is to give a part of the profit to free software development projects or to the Free Software Foundation. This way you can advance the world of free software.
Distributing free software is an opportunity to raise funds for development. Don't waste it!
In order to contribute funds, you need to have some extra. If you charge too low a fee, you won't have anything to spare to support development.

This is only the first portion of their stance on the topic. Read the rest of the Free Software Foundation's encouragement to sell free software here.

That's the gist of it.
I am not a lawyer, and even if I was, none of my words herein are official legal advice.
When words come from the Free Software Foundation, who authors the GPL and LGPL licenses, however, those words are automatically extra legitimate.
Related:

Using Arduino for Industrial process
LGPL and Arduino in Commercial Products

When using LGPL libraries (which is unavoidable with Arduino) you must share at least the object code of your entire application to let users relink your application code to a different version of the LGPL libraries. This is regardless of whether you made any modifications to those libraries or not. See LGPL section 4, especially 4(d)(0).

There is two cases. First you use arduino boards. I would avoid this because it will be more expensive and harder to assemble the product. There is one exception, the new arduino nano family. These boards are made to be easily use in production (they can be soldered as a SMD components) but it's always expensive.
The second case is to use arduino software on custom microcontroller setup. It cheaper and easier tu put in production. The limitations are the choice of microcontroller (mostly Atmel) and speed and memory usage of microcontroller. As you use an extra layer of software (the Arduino bootloader) there is a risk of bug.
To conclude : it's possible but as most of the people that put projects in production know how to use microcontrollers without Arduino hardware or software and there is limitations to Arduino software there is not a lot of case of uses and it's not reccomended.

Note that if you use a bare microcontroller, you probably won't use the bootloader, as you can burn the firmware through ISP instead.

The "Arduino software" is fine. Some of it is written to help beginners. But you can write production quality code in it as well. Much the same as a pencil and paper. You can write rubbish, or something really good.


text:
Switched from 3ft to 10ft connection wires. My setup doesnt run correctly now. Timing issues?
Running a DC motor(6.5A max input), motor driver (MD10C 7Amp peak output), and Arduino Mega. I am stabilizing an object with an accelerometer as my sensor. I switched to longer wires so I can have my board next to me and the stabilized object far away. Now I believe there are timing issues because of this. How would I fix this? How would i test to see how long it takes to travel through my wires?
I can add my code if that helps.

The extra 2 m of wires will delay the signals by about 10 ns. 2. A schematic of your setup might help.

@EdgarBonet I have edited my original post with wiring setup

I2C over long wires is bad. Very bad. You mustn't do it. Not without an I2C repeater / extender.

@EdgarBonet is the repeater/extender a physical thing or something in the code

@ThunderDornhofer I'm Majenko not EdgarBonet :P and it's a physical thing. I think Maxim do some.

@Majenko oh my bad oops. okay I will have to look into that. thank you

The pins of logic chips and processors are not line drivers and will not operate properly when used as such. Sometimes you may get lucky but that generally would be intermittent in operation. They make drivers to drive wires off board from the controller and other chips that are receivers on the other end. This needs to be done with each digital line. There are some specialty drivers such as I2C repeater chips, RS485 etc. Remember the wires are antennas and the system is operating at a high enough frequency to be a great radio transmitter. The main thing is to isolate the controller wires from the world.

Okay thank you!

A better solution would be to get a Pololu Wixel and companion shield for your Mega, and then put the Mega near the object.  You can then program the Mega wirelessly and completely avoid problems with long signal lines.  See this post for how I used it on one of my wall-following robots.  You'll need two Wixels and one Wixel shield.  They aren't particularly cheap, but you won't regret getting them.
There are other options for wireless control and programming, using Bluetooth rather than a proprietary protocol, but they aren't as easy to implement as the Wixel method.

I ended up putting everything close and then using a relay attached to my switch which is on a smaller signal wire. Runs great now. I think what I am doing is basically the wired version of what you were saying above. I like your idea better than what I am doing though, I am going to look into that and try to implement it, thank you!

Would one wixel be on my computer and the other on the wixel shield which is on my mega? and is communicates through the two wixels?

yes, exactly.  The two wixels form a 'wireless serial bridge' so the two ends (your PC and the Mega) don't know they aren't wired together with the normal USB cable.  Of course, this requires that the Mega have a separate power supply, as it will no longer have +5 & GND available via the USB cable


text:
Measure Vcc on ATtiny13a?
I am trying to figure out if I can measure the Vcc of attiny13a, but the code I use for arduino's and attiny85 does not work. This is where I got the code from. I know that it works by using the 1.1v reference and the ADC, and in the attiny13a datasheet it says that it has these, but I can't get it to work.

The code you linked to measures the 1.1 V internal reference using
Vcc as a reference. The ATtiny13A cannot do that. It does have a 1.1 V
internal reference, but it can only use it as a reference for the ADC,
not as a measured channel.
What you can do, if you don't mind adding extra hardware, is divide Vcc
with some resistors in order to get a voltage proportional to Vcc but
lower than 1.1 V. Then use the 1.1 V reference to measure that
voltage. In other words, measure a scaled-down Vcc against the
1.1 V reference instead of measuring the 1.1 V reference
against Vcc. The datasheet should help you with the details.

I tried this and it worked! I don't understand to much about the bit settings on the datasheet but with the help of a tutorial I got it to work Thankyou


text:
Measuring li-ion that arduino is running from
I am using a 5v Arduino pro mini (with regulator and power led removed).
I have been reading how to accurately measure Li-ion batteries when powering from the same battery you are trying to measure from. Using the 1.1V internal analog reference to measure a draining VCC source by using a voltage divider on it, and math to show that converted reading.
Reading the Arduino forums I came across this answer.
  long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV
  return result;
}

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

void loop() {
  Serial.println( readVcc(), DEC );
  delay(1000);
}

However, I cant see a analogRead anywhere in this sketch. (Is this a strictly internal reference?)
At the bottom of the thread someone is saying that you can do this without a voltage divider on the analog pin.
Can someone confirm or explain this? I don't want to fry my Arduino...

Using the 1.1V internal analog reference to measure a draining VCC
source by using a voltage divider on it

You could indeed use a voltage divider, and measure a scaled-down Vcc
against the internal 1.1 V reference. This is, however, not what
the code you posted is doing. It is instead measuring the internal
reference against Vcc, as stated in the comment within the code. The
REFS0 bit selects Vcc as the reference for the ADC. The bits MUX1...MUX3
select the internal reference as the input channel.

result = ADCL;
result |= ADCH<<8;

This idiom dates back from a time when the compiler did not know how to
read 16-bit I/O registers: you had to explicitly read one byte at a time
and then put these together into a 16-bit word. This time is long gone,
and you can now just access the 16-bit register as ADC directly. I
would even get rid of the result variable and just:
return 1126400L / ADC;  // Vcc in mV

Edit: As suggested by the busybee, here is the explanation of the
factor 1126400: The ADC meaures the ratio of its input voltage to its
reference voltage, and returns this ratio scaled by a factor 1024. In
this case,
ADC = 1024 × (Vbg ÷ Vcc)
where Vbg is the voltage of the 1.1 V bandgap reference. Thus,
Vcc = 1024 × Vbg ÷ ADC
If we want Vcc in millivolts, we plus the Vbg voltage in millivolts in
the above equation and get
Vcc (in mV) = 1024 × 1100 ÷ ADC = 1126400 ÷ ADC

You might add that 1126400 is 1024 * 1100, which is scaling the result, and why.

@thebusybee: Thanks for the suggestion. Added.

Outstanding answer, as usual. (voted)

Thank you for the very detailed explanation!

wouldn't it be 1.1v x 1023 x 1000? the 1023 being the 10bit total value for the ADC?

@LindsayCox: No, it's 1024, although 1023 is a very widespread error, presumably because it's the highest reading you can get. According to the datasheet, “the maximum value represents the voltage on the AREF pin minus 1 LSB.” (emphasis mine) and “ADC = Vin ⋅ 1024 ÷ Vref”. The datasheet is the only authoritative source. Note that, given the uncertainty in Vbg, it doesn't really matter.

If anyone else is confused by this:
Will it hurt your Arduino?

No, this is a internal voltage reference between VCC & the 1.1v internal analog reference.

Is a voltage divider necessary?

Not unless you have something external of the Arduino to measure!

Is the internal reference actually 1.1v?

No, it seems like each pro mini I have the the 1.1v reference is slightly different. My pro minis do not have a break out for the AREF pin, so you need to figure out what the value is for each individual Arduino.

I used this,
1.15 x 1023 x 1000 = [value in quotation from second to last line in the Function]

return "1125300L" / ADC;

I just incremented the 1.1v reference by 0.01 a couple of times until the output matched the voltage reading on my digital multi-meter. I would think with a known voltage you could do this math backwards to find what AREF actually is. I am sure that would be easier.
A big thanks to JRobert & @ EdgarBonnet for your answers!

Instead of calling analogRead(), this sketch performs the equivalent actions by directly manipulating the hardware registers to begin a conversion, wait until the conversion is complete, and collect the converted value.
Just reading the final value is accomplished by the statements:
result = ADCL;
result |= ADCH<<8;

All of the statements following delay(2) up to and including the above 2, taken together, do what analogRead() does.

Re “All of the statements following delay(2)”: Note that analogRead() does set ADMUX.

Yup - I missed that. Thanks, @EdgarBonet.


text:
NodeMcu 1.0 resets automatically after sometime
I want to show some digits in a 3x3 p10 red led pannel where the number will come from the cloud and the number keeps updating. For this I have used esp8266 based Nodemcu. I have used WiFi Manager library and DMD2 library for this and I am requesting the server every 5 seconds to get the number in response. Everything is working fine but it keeps restarting after some time and there is no fixed timing for this but it keeps restarting. It provides a message that "reset cause 4 boot mode(3,6)" wdt reset... I have tried different hardware and esp board version but nothing is working. I am currently using arduino 1.8.9 and esp8266 board version 2.5.2
please look into my code and suggest me what is wrong....
#include <Arduino.h>

#include <WiFiManager.h>
#include <math.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <EEPROM.h>
#include <ESP8266WiFi.h>
WiFiManager wifiManager;
int countT;
HTTPClient http;
String svrHost = "";
unsigned int svrPort = 80;
String svrURL = "";
//DMD
#include <SPI.h>
#include <DMD2.h>
#include <fonts/Arial_Black_16.h>
#include <fonts/Droid_Sans_36.h>
#include <fonts/Droid_Sans_12.h>
#include <fonts/Arial_New_56.h>
//#include <fonts/Dmd13x20ClockX.h>
//DMD PIN
#define pin_A 16
#define pin_B 12
#define pin_sclk 0
#define pin_clk 14
#define pin_r 13
#define pin_noe 15
int respin = D2;
int btnstt = 0;
int wlcmgs = 1;
String ssid;
String dmdText = "0";
SPIDMD dmd(3, 3, pin_noe, pin_A, pin_B, pin_sclk);
// Number of P10 panels used X, Y
//DMD_TextBox box(dmd,0,0,32,5);
// Set Box (dmd, x, y, Height, Width)
//const char *MESSAGE = "iTrack LIVE InWard";
void setup(){
Serial.begin(115200);
EEPROM.begin(512);
pinMode(respin, INPUT);
//Reset Val
String doResetWifi = "0";
doResetWifi = readESP(257,1);

if(doResetWifi == "1"){
    writeESP(257,1,"0");
    wifiManager.resetSettings();
}

Serial.println("\nReset Val "+doResetWifi);
//wifiManager.resetSettings();
countT = 0;
wifiManager.autoConnect("LED-1");
Serial.println("connected...yeey :)");

//Read/Write EPROM
if(wifiManager.svrURL != ""){
    svrHost = wifiManager.svrHost;
    svrPort = wifiManager.svrPort;
    svrURL = wifiManager.svrURL;
    //HOST
writeESP(0,50,svrHost);

    //PORT
writeESP(51,5,String(svrPort));

    //URL
    writeESP(56,200,svrURL);

}else{
    //HOST
    svrHost = readESP(0,50);

    //PORT
    svrPort = readESP(51,25).toInt();

    //URL
    svrURL = readESP(56,200);
}

//DMD Setup
    dmd.setBrightness(255); // Set brightness 0 - 255
    //dmd.selectFont(Droid_Sans_36); // Font used
    dmd.begin();     // Start DMD

}
void loop(){
btnstt = digitalRead(respin);

if (btnstt == 1){
flashESP();
ESP.reset();
}
doRequest();
  //box.print(dmdText);

if(wlcmgs==1){
dmd.selectFont(Droid_Sans_12);
dmd.drawString(0,0,"Connected");
delay(5000);
dmd.clearScreen();
//scrlssid();
delay(5000);
wlcmgs=0;
}
dmd.clearScreen();
dmd.selectFont(Arial_New_56);
int padingTop = 2;
dmd.drawString(round((96 - (dmdText.length() * 24)) / 2), padingTop, dmdText);
delay(1000 * 5);
//dmd.selectFont(Arial_Black_16);
//scrtxt();
}
void doRequest(){
Serial.print("[HTTP] begin: "+svrHost+" "+svrPort+" "+svrURL+"\n");
String response;
if (httpRequest(svrHost, svrPort, String("GET /") + svrURL, "", response)) {
if (response.length() != 0) {
        response.trim();
        dmdText = response;
        Serial.println(response);
        Serial.println(countT);
        countT++;
    }
}

}
bool httpRequest(const String svrHOST,
unsigned int svrPORT,
const String& method,
const String& request,
String&       response)
{
WiFiClient client;
if (client.connect(svrHOST, svrPORT)) {
    Serial.println("HTTP Connected");
} else {
    Serial.println("failed");
    return false;
}

client.print(method);
client.println(F(" HTTP/1.1"));
client.print(F("Host: "));
client.println(svrHOST);
client.println(F("Connection: close"));
if (request.length()) {
    client.println(F("Content-Type: application/json"));
    client.print(F("Content-Length: "));
    client.println(request.length());
    client.println();
    client.print(request);
} else {
    client.println();
}

//Serial.println("Waiting response");
int timeout = millis() + 5000;
while (client.available() == 0) {
    if (timeout - millis() < 0) {
        Serial.println(">>> Client Timeout !");
        client.stop();
        return false;
    }
}

//Serial.println("Reading response");
int contentLength = -1;
while (client.available()) {
    String line = client.readStringUntil('\n');
    line.trim();
    line.toLowerCase();
    if (line.startsWith("content-length:")) {
        contentLength = line.substring(line.lastIndexOf(':') + 1).toInt();
    } else if (line.length() == 0) {
        break;
    }
}

//Serial.println("Reading response body");
response = "";
response.reserve(contentLength + 1);
while (response.length() < contentLength && client.connected()) {
    while (client.available()) {
        char c = client.read();
        response += c;
    }
}
client.stop();
return true;

}
void writeESP(int start, int len, String text){
EEPROM.begin(512);
int ind;
for(ind = 0; ind < len; ind++){
EEPROM.write(ind+start,text[ind]);
}
EEPROM.write(ind+start+text.length(),'\0');
EEPROM.commit();

EEPROM.end();
}
String readESP(int start, int len){
EEPROM.begin(512);
char dataS[len];
int ind;
for(ind = 0; ind < len; ind++){
if(EEPROM.read(ind+start) != '\0'){
dataS[ind] = EEPROM.read(ind+start);
}else{
break;
}
}
dataS[ind]='\0';
EEPROM.end();
return String(dataS);
}
void flashESP(){
Serial.print("\nResetting ESP\n");
writeESP(257,1,"1");
ESP.reset();
delay(2000);
}
/*
void scrtxt(){
const char *next = MESSAGE;
while(*next) {
Serial.print(*next);
box.print(*next);
delay(200);
next++;
}
}
/
/
void scrlssid(){
dmd.drawString(5,0,"Connected With");
DMD_TextBox box(dmd,0,20,96,16);
ssid = WiFi.SSID();
const char *ssidNext= ssid.c_str();
int len = 0;
while(ssidNext && len < ssid.length()){
Serial.print(*ssidNext);
box.print(*ssidNext);
delay(200);
ssidNext++;
len++;
}
}
*/

Welcome Angkon. Align your code (select and ctrl-k), and remove any code that doesn't cause the reset (try removing parts until it doesn't reset anymore, so you also can find out yourself what is the problem).

You have a watchdog timeout. That is caused by your code blocking and not "kicking the dog" enough. You should check for parts of your code that do nothing for long periods of time and regularly yield() so that the IP stack can do its work.

From your description it sounds like a Watchdog Timer reset.
The ESP8266 needs to regularly run internal householding tasks outside of your own code, such as Wifi/network related tasks. It will normally take some processing time for those tasks with every loop() iteration and with every delay() command.
If your code is doing things that take longer than about 3.2 seconds, the internal "watchdog timer" will time out and reset the ESP, which is what you observed.
To ensure this does not happen, you should put a yield(); command inside pieces of your code that can potentially take longer than 3 seconds, like waiting loops (for example the "Waiting response" while() loop and similar pieces of your code). Try this and see if this solves your problem.


text:
Error compiling to ESP32 using Arduino: Operand 2 of 'l32r' has out of range value
I was trying to follow this tutorial and ran into a problem compiling on the Arduino IDE with an ESP32 board. https://eloquentarduino.github.io/2019/12/how-to-do-gesture-identification-on-arduino/
I end up getting multiple lines of error from Arduino saying:
Error: operand 2 of 'l32r' has out of range value '4294704916'

The code that its struggling to compile is the converted SVM model generated from SciPy. The file is very long, but here is a snippet of what it looks like:
#include "model.h"
#include <cstdarg>

int SVM::predict(float *x) {
    float kernels[92] = { 0 };
    float decisions[21] = { 0 };
    int votes[7] = { 0 };
    kernels[0] = compute_kernel(x,   1.2  , -1.79  , -1.1  , 1.22  , -1.36  , 0.26  , 1.0  , -1.57  , -0.81  , 1.08  , -1.45  , -0.18  , 1.18  , -1.77  , -0.31  , 1.59  , -1.69  , 0.55  , 6.74  , 0.71  , -13.06  , 6.31  , 12.0  , -4.34  , 1.55  , -0.16  , 0.0  , 1.38  , 1.91  , 1.02  , 0.96  , -2.28  , -0.45  , 1.3  , -2.12  , -0.49  , 0.83  , -0.18  , -0.79  , 0.92  , -0.73  , 1.34  , 2.59  , -4.15  , -3.4  , 2.22  , -0.2  , 1.41  , 0.61  , -3.91  , -1.39  , 9.29  , 1.85  , -16.0  , 2.4  , -1.02  , -0.75  , 1.87  , 0.18  , 0.47  , 1.38  , -2.06  , 0.06  , 1.32  , -2.16  , 0.1  , 1.63  , -2.2  , -0.16  , 1.47  , -1.49  , -0.08  , 0.98  , -1.51  , -0.55  , 1.3  , -1.53  , -0.12  , 1.32  , -1.61  , -0.47  , 1.18  , -1.26  , -0.2  , 1.43  , -1.06  , 0.06  , 1.3  , -1.18  , -0.59  , 0.94  , -0.1  , 1.04  , 1.28  , -1.41  , -0.55  , 1.26  , -1.3  , -0.18  , 1.28  , -1.65  , -0.39  , 1.26  , -1.36  , 0.63  , 1.45  , -1.45  , -0.57  , 1.65  , -1.32  , -0.63  , 1.3  , -1.28  , -0.35  , 1.22  , -1.3  , -0.31  , 1.22  , -1.02  , 0.16  , 1.12  , -1.43  , -0.39  , 1.1  , -0.96  , 0.43  , 0.92  , -1.12  , -0.37  , 1.24  , -0.86  , 0.0  , 1.1  , -1.12  , -0.24  , 1.12  , -1.34  , -0.2  , 1.16  , -1.14  , -0.1  , 1.14  , -1.12  , -0.24  , 1.24  , -1.1  , -0.26  , 1.16  , -1.39  , -0.24 );
    kernels[1] = compute_kernel(x,   1.1  , 0.24  , 9.49  , -11.73  , -9.12  , 9.63  , -2.5  , -5.48  , 1.87  , 1.53  , -1.14  , 0.96  , 0.79  , -1.96  , -0.75  , 0.55  , -1.61  , -1.39  , 1.41  , -1.91  , -0.57  , 0.88  , -2.1  , 0.2  , 0.29  , -2.22  , 0.73  , 1.69  , 0.45  , -0.14  , 2.08  , -1.89  , 1.0  , 1.16  , 0.84  , 1.59  , 1.45  , -2.36  , -0.83  , 2.36  , -0.71  , 0.61  , -9.51  , -16.0  , 6.13  , 2.61  , 1.18  , 0.77  , 0.69  , 0.63  , -0.96  , 1.0  , -0.67  , -0.02  , 1.57  , -1.08  , 0.2  , 1.14  , -1.47  , -0.08  , 1.57  , -1.93  , -0.22  , 1.18  , -1.36  , -0.57  , 1.57  , -1.39  , 0.71  , 1.16  , -1.55  , -0.65  , 1.04  , -1.12  , -0.77  , 1.55  , -2.12  , 0.67  , 1.57  , -0.86  , -0.75  , 1.41  , -1.2  , 0.53  , 1.55  , -1.39  , -0.83  , 1.32  , -0.75  , 0.59  , 1.67  , -1.49  , -0.55  , 1.65  , -1.51  , -0.49  , 1.36  , -1.16  , -0.02  , 1.63  , -1.22  , -0.35  , 1.49  , -1.2  , -0.26  , 1.38  , -1.32  , -0.02  , 1.39  , -1.22  , -0.12  , 1.41  , -1.0  , -0.1  , 1.43  , -1.18  , -0.14  , 1.41  , -1.22  , -0.02  , 1.55  , -1.3  , -0.33  , 1.45  , -1.2  , -0.24  , 1.38  , -1.3  , -0.26  , 1.38  , -1.28  , -0.12  , 1.3  , -1.06  , -0.12  , 1.39  , -1.32  , -0.2  , 1.39  , -1.22  , -0.18  , 1.43  , -1.1  , -0.24  , 1.43  , -1.32  , -0.33  , 1.45  , -1.08  , -0.37 );
    kernels[2] = compute_kernel(x,   1.55  , -1.67  , -2.16  , 1.59  , -0.04  , 1.16  , 1.38  , -2.71  , -1.06  , 2.04  , 1.41  , 1.49  , 1.16  , -0.67  , 6.66  , 0.79  , -7.94  , 8.51  , 2.4  , -0.41  , 2.32  , 1.45  , -0.37  , 0.0  , 1.61  , -1.67  , -0.28  , 2.04  , -0.96  , -0.57  , 1.04  , -0.83  , 0.61  , 1.38  , -1.08  , -0.33  , 1.65  , -0.24  , -1.96  , 2.06  , -2.99  , -0.92  , 8.31  , 4.83  , 2.3  , 4.79  , -3.89  , -5.38  , 0.67  , -2.67  , 1.2  , 3.03  , 1.41  , -0.86  , 2.36  , -1.85  , -1.32  , 2.32  , -1.32  , 0.75  , 1.69  , -1.2  , -0.35  , 1.28  , -1.04  , 0.22  , 1.28  , -1.12  , -0.37  , 1.87  , -1.14  , 0.33  , 1.83  , -1.24  , -0.26  , 1.77  , -0.94  , -0.51  , 1.63  , -0.79  , 0.22  , 1.47
//and so on
decisions[0] = 1.245222806707
    + kernels[1] * 0.00090445776
    + kernels[2] * 0.000488112628
    + kernels[8] * 0.000123322494
//and so on

I have the following flags enabled on the compiler:
compiler.c.extra_flags=-mlongcalls -mtext-section-literals

It just won't compile for some reason and gives me the same l32r message. Can someone please help? Much is appreciated.

May be related: https://github.com/espressif/esp-idf/issues/3258

do you have the flags on cpp and S too?

@Juraj yes the flags are enabled on both