text:
Smaller and cheaper alternative to Arduino Uno for permanent projects
I have played a bit around with a Arduino Uno that came in a kit with a breadboard and components. Soon I would like to make some more permanent things.
I would prefer a smaller and cheaper unit than the Arduino Uno but that is almost as easy to use as the Arduino Uno, and very similar to use.
Is the Arduino Pro Mini 328 - 5V/16MHz a logical next step?
At 1/6 of the size of the Arduino Uno it is plenty small.
At 10 $ a piece the price is also good.
I understand that I must solder to get it to work. That should not be a problem.
Will I also need a USB serial board to program the unit?

next smaller with 328p is Nano

ATmega32u4 chips are also a good move (same as Leonardo) for 8-bit micro.  Coding is slightly different from UNO/328p (especially with serial), but you avoid the USB/serial converter.  Eventually, you can make your own PCBs and use the SMD chips, for a really compact project.

Pro Mini, 5V 16MHz Module With Crystal Oscillator ($2.18CDN): https://www.aliexpress.com/item/Pro-Mini-atmega328-Mini-ATMEGA328P-5V-16MHz-Module-With-Crystal-Oscillator-Pins-Replace-ATMEGA128-for-Arduino/32828645889.html. PL2303HX USB to UART adaptor ($0.70CDN):  https://www.aliexpress.com/item/FREE-SHIPPING-PL2303-module-USB-to-TTL-upgrade-nine-brush-board-PL2303HX-STC-MCU-download-cable/32592463585.html.

I think the first best choice is to remove the ATMega328p-pu chip from your Arduino UNO and incorporate it into your final circuit.
The chips are only about $1.50.
That way, you can just use your UNO as a programmer instead of the final device that you deploy.
I'm not sure why there isn't more documentation about the proper way to remove the ATMega328p-pu chip and using it on your breadboard, after completing your programming.
I explain exactly how to do this on my blog: http://raddev.us/arduino/post/2018/07/03/arduino-uno-using-your-atmega328p-u-as-stand-alone
But, here are the basics.
First you remove the chip.  It will look like the following after you do so.  (Note: I'm using the Elegoo clone of an UNO).

Next, you apply power to pin 7 and connect pin 8 to GND.
Need A 16MHz Crystal
But, the chip won't seem to run your sketch at this point.
That's because you actually need a crystal to run at 16MHz.
The UNO board has that chip installed and that is why it works.
You can see it here:

Finally you add the 16MHz crystal and a couple of 22pF caps and your chip will run standalone (no UNO).
You add the crystal to pins 9 & 10.  You can see all the details by reading my blog entry or reading the atmega328 datasheet.

Finally, Just Wire Everything Else Up
After that, just wire the rest of your circuit up to the proper pins and you can run your ATMega328p-pu standalone.
It's actually a nice learning experience too.
Just buy replacement atmega328p-pu chips for your UNO and you can create all the projects you want to for very cheap.

You'd be well served to add some circuit protection in there, since the 328p doesn't have any of it's own. Otherwise, this is a great way to go.

@SnakeDoc Thanks. And, I agree, any circuit protection is always advantageous. An interesting note: I had a circuit built on a cheap breadboard like the one shown, powered off an old phone charger and sitting on a shelf in my garage and running for over two years with no problems.  We even had a lightning strike that took out another item in the garage but my atmega328p-pu based circuit (bluetooth garage door opener) kept on running. Of course, I'm not advising people to build circuits like that but it is really cool that as a hobbyist we can do things like this.

@duskwuff, I believe that is only when you're doing DAC.  This is just a simple example to get someone started in the direction of using the chip as standalone.  I assure you the code to blink the LED in the sample does run.  Also, when I was starting out I created the circuit I mentioned in a comment above and I never connected AVCC and GND and the circuit ran for two years.  Of course, i'm not saying that will always be true.  Just mentioning the way the chip actually works. As always, check the datasheet for exact specs and especially if you experience something different.  Thanks.

@duskwuff I was reading over the datasheet and reminding myself too. I will keep that in mind and alter the doc soon.  Thanks  Edit - Wait where does datasheet say that leaving AVCC unpowered may cause damage?

@duskwuff also section 1.1.7 says, "AVCC is the supply voltage pin for the A/D Converter, PC 3:0, and ADC7:6. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter." Notice the use of should instead of must. Interesting.

@duskwuff Thanks for the enlightening discussion. I agree with what you are saying and will change my docs and circuits soon to insure that is always connected.  FYI - I started working with ATMega328p-pu via the fantastic book AVR Programming : Learning to Write Software For Hardware (https://amzn.to/2PS9OOA) and in those first circuits the author, Elliott Williams, does not hook up those pins either. I think I was influenced by that.  The book really is great though and the author is knowledgeable. Thanks again, great discussion.

Why is there no bypass capacitor on the power pins in the breadboard picture? That is an absolute must. As close to Vcc and Gnd as possible.  Hey, but it is the Internet. Anyone can publish what they want.

@Kavka That's great information.  Thanks for adding.

Check the STM32F103C8T6 development board, cost about $ 1.5, and is faster/has more memory than the Arduino Uno, and is much smaller.
It can work with the Arduino IDE, but not all libraries are supported, so check before you want to use it if your used libraries are supported, or if there are different libraries you can use instead.
Update
Differences:
                       Arduino Uno       STM32F103C8T6 Mini Dev Board

MicroController            Atmega328P           Cortex M3
MIPS/MHz                        1                   1.25
Operating Voltage [V]           5                   3.3, most pins 5V tolerant
Input Voltage   [V]            7-12               USB only
Input Voltage (limit) [V]      6-20                (USB)
Digital I/O Pins               16                   37
From them:PWM Digital I/O Pins  6                   12
Analog Input Pins               6                   10
DC Current per I/O Pin [mA]    20                    ?
DC Current for 3.3V Pin [mA]   50                    ?
Flash [KB}                     32                   64
SRAM [KB]                       2                   20
EEPROM [KB]                     1                    -
Clock Speed [MHz]              16                   72

I2C                             1                    2
SPI                             1                    2 (18 MBit/s)
UART                            1                    3
CAN                             0                    1
USB                             0          USB 2.0 FS 12 MBit
DMA                             0          7 channels (ATsP, SPI, I2C, USART)
RTC                             0                    1
CRC                             0                    1
Unique ID                       0                    1

Programmed by                  USB                 SWD Debug (around $5)

IDE                         Arduino IDE         Arduino IDE, CubeMX, ...
Libraries                      Many               Limited

Dimensions  [mm]            68.6 x 53.4           53 x 22
Weight       [g]               25                    ?
Price (cheapest)  [$]         2.50                 1.50

Note: as written earlier, despite the mostly better specs, not all libraries are supported. Also a programmer need to be bought (only once, cost about $5).

You can also avoid getting the programmer if you get the Maple Mini clones (same uC, almost same HW, but with a bootloader already flashed)

The STM32F103C8T6 is a great part. But it still is only 3.3v. It isn't a drop in replacement for the Uno. Try to connect it to a 5v character LCD and you will have problems, if it works at all. (the LCD)

For my product, I went from an Arduino Uno:

to the Arduino Pro Mini:

Yes you will need a  FTDI cable for programming and serial coms to the PC, but providing you don't need coms all the time, you will only need the one cable to upload the program to each device. They can be found pretty cheap too.
However I notice that the Arduino Pro Mini is retired now, so it may be a bit harder to source (it is still available on AliExpress). So for this reason, I suggest that you instead try the Arduino Nano:

which has the added advantage of onboard USB, meaning you no longer need the FTDI cable for programming or coms.
The ATMega328P that is the processor of these 3 boards does not have native USB, which means that the board also needs to include the FTDI FT232RL IC that is used in the FTDI cable. Having this IC can add additional costs to your bottom line.
For a few dollars cheaper per device, you can use a microcontroller (such as the ATMega32U4) that has native USB coms (and hence you save on the FTDI IC). One such product is the Arduino Micro:

All of these boards mentioned are native within the Arduino Ecosystem and (apart from the retired Pro Mini) should be easy to source online or at your local electronics shop. Your Arduino Uno program will work for all of these alternatives - you just have to change the board in the Arduino IDE:

There is one more board that I would like to mention - the DigiSpark:

It is only suitable for smaller programs, is limited in some of its features and is not an oficial Arduino board. Having said that, there is plenty of Arduino support - and its cheap!

If you want to stick with using Arduino and it's toolchain, you can order just a bare ATmega 328p (the microcontroller at the heart of the Arduino Uno) and use it by itself!
They're fairly low cost ($1.50-$3.00 range) and are breadboard friendly. For a more permanent solution, you can solder them into a proto-board (perfboard), or even a custom designed circuit board once your design gets to that level.
Here's an excellent guide from the Arduino folks about setting up an Arduino on a breadboard, using only raw components such as the ATmega 328p. This design uses an external 16MHz clock crystal, just like an Arduino Uno.
If you're OK with using the internal 8MHz clock onboard the 328p, you can do away with most of the extra components and just run the raw chip like in this guide (using the Arduino Lilypad Bootloader instead of the default Arduino bootloader). This will save even more money!
Either way, you'll need an AVR Programmer unit, since there is no USB port built into the 328p. This will be the most expensive part of this setup, but good news is you only need one, and it can program any 328p's you need. They can also be used to program non-standard chips that are capable of being programmed over Serial Tx/Rx pins, such as the ESP chips (you just hand-wire them). Very useful to have one of these if you're serious about these types of microcontrollers.
ATmega 328p Microcontroller Chip
ATMega Pin Stickers
Perfboard
AVR Programmer

If you order your ATMEGA328P-PU with the boot loader already installed: https://www.ebay.ca/itm/ATMEGA328P-PU-DIP-28-Microcontrolle-r-With-ARDUINO-UNO-R3-Bootloader-or-Not/401232444724?hash=item5d6b513d34:m:mDLpPK1-t0vsiOhYFC4DDpg:rk:4:pf:0, then a PL2303HX USB to UART adaptor ($0.70CDN) will work to upload "code": https://www.aliexpress.com/item/FREE-SHIPPING-PL2303-module-USB-to-TTL-upgrade-nine-brush-board-PL2303HX-STC-MCU-download-cable/32592463585.html

I always found it odd that Arduino uses a special bootloader for programming instead of using the built-in programming interface.

@immibis not sure what you mean exactly, but the arduino bootloaders do a lot of things that make working with the arduino's (and Atmel chips) a lot easier, including resetting of pins, switching to external clock, handing-off to your code, etc. Without it, you'd essentially need to write your own... which would be a waste of time since for majority of cases, the stock Arduino bootloader does everything you want anyway.

@immibis I think it is much easier to have a serial port interface rather than a programmer interface from the PC. Moreover, especially at the beginning, I think (personal opinion) that they wanted a complete system on a board, and integrating a programmer on the PCB was much harder than writing a serial bootloader. Consider that the first arduino boards had a serial port (Arduino RS232), so only one programmer was needed to program a lot of them (they were used at school)

@frarugi87 that's probably true, but for real beginners, plugging in a USB cable and using the Arduino IDE to upload "sketches" is about as easy as it can be. I think they made the right move to make it super accessible, especially for those who have zero microcontroller experience.

There isn't a good reason to use the dip parts. The Pro Mini doesn't take up any more space and it is a lot less hassle. Maybe ten years ago it made sense to use a dip part when there wasn't cheap alternatives. But now with the inexpensive (dirt cheap) modules available it just doesn't make sense.

@Rudy If you want to do your own thing, make your own packaging, or layout, save power (prolong battery life) or just make it look more professional, using the raw chips is certainly a great way to go. Plus you'll learn a lot more in the process, which makes the end result even more of a benefit. You can also help ensure people don't mess with it by plugging into the USB port, or do your own voltage regulation stuff, such as a buck-boost or whatever. Don't dismiss using the raw chips just because you can buy a Pro Mini...

@SnakeDoc The compiler could easily add that code for you, like it already adds code for you.

@frarugi87 Makes sense for the RS232 version, for sure, but now they have a custom-programmed USB interface on-board!

"I would prefer a smaller and cheaper unit than the Arduino Uno but that is almost as easy to use as the Arduino Uno, and very similar to use." A dip CPU is NOT as easy to use as the Arduino Uno. You are putting your values into your answer and not listening to the person who posted the question.

@Rudy Have you tried it? (I haven't tried with this chip, but I've tried with different similar DIP uCs)

@immibis Tried what? I have been designing commercial electronic products for almost 35 years. I'm a hardware designer. I have recently started using the Arduino platform because I wanted to do my own projects at home and the Arduino IDE and all the libraries was the easiest to start with. At work I design the electronics and then pass it on to the firmware, then software, programmers. I have designed with many different chips. I have even made a product (my code) with a PIC part with 512 bytes of code space. Efficient.

@Rudy it's pretty darn easy if you keep using the Arduino environment. It's exactly why at least two of us here have made that recommendation, including the accepted answer! The Arduino toolchain is very mature - and as the OP advances, they can branch out into more flexible solutions such as PlatformIO etc, all while still using the Arduino libraries! Pretty neat.

@SnakeDoc As I have said above. I design electronics for a living. I can't put out a marginal design. Something that is going to only work most of the time. Industrial controls not consumer items. I think it is great that someone wants to learn. But the question asked was for a smaller cheaper unit that was easy to use. And I believe my answer fits that. The breadboard example in the picked answer shows the lack of knowledge of the constructor. And it disappoints me when I see someone learning from someone who is not ready to be teaching.

@Rudy To summarize everything you've said - You use premade boards because you're too tired after work to make one yourself, and you've already learned all there is about uC's so everyone else should just skip learning and use premade uC boards cuz reasons and cheap Chinese clones are definitely more reliable than a home-made uC board cuz more reasons. Sorry, but you sound pretty salty right now. OP accepted his answer. OP clearly is interested in assembling their own ATMega328p custom implementation, and will still use the Arduino tooling. It's wonderful, and no skin off your back.

Unless you happen to be making and selling Arduino Pro Mini's for a living.... hmm....

@SnakeDoc  Your summary you attribute to me is pure fiction. I think you need to read the Code of Conduct because you are not acting the way expected on this site. -  As I have already explained, the answer I provided was based on the original question asked and the requirements expressed. And if the person considers a new criteria then that is his prerogative.  My reason for using stable modules is most newbies do not have the equipment required to troubleshoot the issues that often will come up due to a lack of understanding about stable design. They have more than enough to deal with.

@SnakeDoc I thought you might be interested in this. https://www.esp8266.com/viewtopic.php?f=13&t=17514

@SnakeDoc  A problem for you.  I hope you can help. https://arduino.stackexchange.com/questions/57938/problem-with-arduuino-to-breadboard-mega8

I like the Nano and the Pro Mini. I like to work with it on a breadboard with other modules. If there is more circuitry involved I found it much more convenient than using an Uno. There are faster processors but for a lot of projects the 16Mhz 328 is more than sufficient. And like the Uno, these two are 5 volt powered parts. Sometimes what you need to connect to doesn't work well with 3.3 volt processors.
The Pro Mini and the Nano with easily be soldered into 0.1" spaced "Veroboard" (or equivalent) If you don't mind buying cloned parts, the cost of a Nano and Pro Mini is only a couple of dollars. Buying parts off Aliexpress, or even Ebay, can save you a lot, as long as you are patient when it comes to delivery.
The module that I am now use most often is the ESP8266. It is a powerful WiFi platform that only costs a few dollars and has quite a mature Arduino framework. Often I use this as the only processor in the design. I have even used it as the basis for a data logger and completely ignored the WiFi capability. 20x4 character LCD, current/voltage measurement chip (INA219), and a SD memory card, powered by a 18650 lithium battery.
There are lots of good inexpensive options.

you might want to point out that ESP12 modules do NOT have .1" pin spacing, which is a bit of a nuisance. There are inexpensive breakout boards, but these are quite wide and hard to use with solderless breadboards. Other than that, they're pretty handy. For about $1 more than a bare ESP12 module you can get a Wemos D1 mini (clone) that is about as easy to use as an Arduino Pro Mini or Nano.

Where did I say to use the ESP-12? I didn't go into a lot of detail on the ESP8266 because that really wasn't the focus of the question. I thought it was worth mentioning since a lot of people are not familiar with it. I totally support people using the Wemos D1 mini platform. It is a ready to go solution unlike ESP01, ESP12, etc. USB to serial and an onboard regulator makes a big difference. But I still feel the Nano or the Pro Mini is the most appropriate answer for the person who asked the question.

It's hard to consider any atmega based system in 2019 in comparison to the ESP systems, so you might mention for $2 with an ESP8266 you get a 40MHZ processor, a full development board ( not a chip ), wifi, and USB-based programming and monitoring without any extra cables. And also mention the ESP32 systems, which are more expensive at $7 to $10, but contain two CPUs, a full RTOS, multiple MB of flash, adds BT to WIFI, and native USB support. Compatibility with Arduino is included, and even running the provided RTOS they include Arduino libraries.

The ESP8266 has a 160MHz processor. It is a great option but it does have limitations. It only has one A/D converter and a bad one at that. The digital IO pins also have quirks. Pull up resistors are on by default at power up on most. Three IO pins set the operating mode and special care must be taken. The ESP8266 also needs a decent power supply. With the ESP8266 there is a lot of code running in the background and your code must co-exist with it. I really like the ESP9266 but it is not a great general purpose microcontroller. The ESP32 is better but also with issues.

Arduino Pro Micro clones are super cheap and all you need to program them is a normal micro USB cable. You will probably have to solder the headers to do anything useful. They are available in a 3.3V/8MHz and a 5V/16Mhz version.

ProMicro has a 3.3v processor. That can be a problem with some designs. It isn't a drop in replacement for an Uno. But it is an interesting part.

No, just as with the Pro Mini there is a 5V/16MHz and a 3.3V/8MHz version.

Sorry then, my mistake.


text:
Cannot load anything from library
So I installed libraries through the Arduino interface (Sketch > Include Library > Manage Library). Then I check: C:\Users\username\OneDrive\Documents\Arduino\Libraries, and I confirm the new libraries are there.
However, when I compile I always get the error that Arduino cannot find the library, no matter which one I try to import.
I'm on Arduino 1.8.5, Windows. What am I missing?

Does this answer help? https://arduino.stackexchange.com/questions/51813/this-error-is-shown-continuosly-after-first-time-it-compiles-successfully/51825#51825

@VE7JRO OH MY GOD!! It was OneDrive!?? What the what!? Thanks, this solved it.

This was a problem with using your OneDrive folder.
duskwuff wrote:

This is a known incompatibility between the Arduino IDE and Microsoft OneDrive. A fix should be available soon; in the meantime, move your Arduino sketches out of the OneDrive folder.

The issue with OneDrive folders has been resolved as of version 1.8.6.
https://www.arduino.cc/en/Main/ReleaseNotes

ARDUINO 1.8.6 2018.08.23
[ide]

Updated arduino-builder to 1.4.0:

parallel build (improve compile speed)
better reuse of already compiled files
Windows: fixed build for sketch stored under OneDrive cloud folders

Simply update to a newer version of the Arduino IDE and you will be able to compile and upload your sketch.

source: Stack Exchange

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

sort: votes


text:
Regarding PGA bypass in ADS1262
I want to bypass the PGA to change the input signal range from +/-2.5 to 0/5 V range.
I have taken the reference of example given in this library.
I have interfaced protocentral-ads1262-32-bit-precision-adc-breakout-board with Arduino Ethernet Board.
In the example, I have put #define VREF 5 but it shows the double the input voltage in serial window and when I put VREF 2.5, it shows regular input voltage.
For input voltage range 0 to 5V (single signal), I need to bypass the PGA but I dont know how to do it.
When the input signal is more than 2.5V then it always give the 2.5V only. If the input signal is, say 4.86V then it should give 4.86V but its gives 2.5V.

You don't want to bypass the PGA.
By default the chip uses the 2.5v internal reference. You need to switch that to using AVDD/AVSS as the voltage reference. If the library doesn't allow that you will have to do it manually referring to the datasheet.

I want to bypass the PGA to change the input signal range from +/-2.5 to 0/5 V range.

Look at the register map. it should allow you to by pass the pga.

In the example, I have put #define VREF 5 but it shows the double the input voltage in serial window and when I put VREF 2.5, it shows regular input voltage.

Simple solution: divide the library's output by 2.
Right solution: the library likely doesn't support bipolar output. So re-write  your own.

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


text:
Strange behaviour on splitting char array and converting the chunks to int
I have this function:
void changeColor(char control[16])
{
  char _red[3], _green[3], _blue[3], _brightness[3], _white[3];
  int red, green, blue, brightness, white, offset;

  offset = 1;
  for (int i = 0; i < 3; i++) {
    _red[i] = control[i + offset];
  }
  offset = 4;
  for (int i = 0; i < sizeof(green); i++) {
    _green[i] = control[i + offset];
  }
  // strncpy(_green,control+offset,3); // same result
  offset = 7;
  for (int i = 0; i < sizeof(_blue); i++) {
    _blue[i] = control[i + offset];
  }
  offset = 10;
  for (int i = 0; i < sizeof(_white); i++) {
    _white[i] = control[i + offset];
  }
  offset = 13;
  for (int i = 0; i < sizeof(_brightness); i++) {
    _brightness[i] = control[i + offset];
  }

  red = atoi(_red);
  green = atoi(_green);
  //sscanf(_green, "%d", &green); //same result
  blue = atoi(_blue);
  white = atoi(_white);
  brightness = atoi(_brightness);

  Serial.print(" control ");
  Serial.println(control);
  Serial.print(" _red ");
  Serial.println(_red);
  Serial.print(" _green ");
  Serial.println(_green);
  Serial.print(" _blue ");
  Serial.println(_blue);
  Serial.print(" _white ");
  Serial.println(_white);
  Serial.print(" _brightness ");
  Serial.println(_brightness);
  Serial.print(" red ");
  Serial.println(red);
  Serial.print(" green ");
  Serial.println(green);
  Serial.print(" blue ");
  Serial.println(blue);
  Serial.print(" white ");
  Serial.println(white);
  Serial.print(" brightness ");
  Serial.println(brightness);
  //... do something with ints
}

And by calling from the setup:
 char _control[16]={'6','2','5','5','0','0','0','0','0','0','0','0','0','0','5','0'};
 //6255000000000050

 void setup() {
   Serial.begin(9600);
   // ... do something
   while (!Serial) {
     ; // wait for serial port to connect. Needed for native USB
   }
  changeColor(_control);
}

I get from console this output:
   control 6255000000000050
   _red 255ÿ
   _green 000255ÿ
   _blue 000000255ÿ
   _white 000050000000255ÿ
   _brightness 050000000255ÿ
   red 255
   green 255
   blue 255
   white 29951
   brightness 29951

Basically, the char array are filled with more elements than the actual dimension (3), but I don't get error or warnings from the compiler
I also tried with strncpy, strcpy, strncat, and by using the pointer in the for loops
for(int i=0;i<sizeof(_green);i++){
  _green[i]=control+i*sizeof(char)+offset*sizeof(char);
} // also without the sizeof()

And I got the same result in the console (with nl&cr), any hints?
EDIT:
Added NULL char
  ...
  char _red[4], _green[4], _blue[4], _brightness[4], _white[4];
  int red, green, blue, brightness, white, offset;
  _red[4]='\0';
  _green[4]='\0';
  _blue[4]='\0';
  _white[4]='\0';
  _brightness[4]='\0';
  offset=1;
  for(int i=0;i<3;i++){
    _red[i]=control[i+ offset];
  }
  // same as above

Output:
control 6255000000000050
_red 255
_green 100255
_blue 000100255
_white 0000050
_brightness 050
red 255
green 100
blue 0
white 50
brightness 50

Where's the NULL termination of your strings?

@Majenko, I added the null char(edited the question), but I get messed up output

In C you start counting from 0, not 1. _red[4] is actually _green[0].

@Majenko Understood, adding the null character with good index (been coding for too long today!) fixed the issue. Thank you sir.

In this piece of code you have a strange mix of upper bounds:
  for(int i=0;i<3;i++){
    _red[i]=control[i+offset];
  }
  offset=4;
  for(int i=0;i<sizeof(green);i++){
    _green[i]=control[i+offset];
  }
 // strncpy(_green,control+offset,3); // same result
 offset=7;
 for(int i=0;i<sizeof(_blue);i++){
   _blue[i]=control[i+offset];
 }
 offset=10;
 for(int i=0;i<sizeof(_white);i++){
   _white[i]=control[i+offset];
 }
 offset=13;
 for(int i=0;i<sizeof(_brightness);i++){
   _brightness[i]=control[i+offset];
 }

The first looks correct at 3.  The second loop has an upper bound of sizeof(int) which is 2.  The third loop seems to be sizeof(char) which is 1.
Unfortunately non of those values match up with the results you are getting.  What I would try is refactoring whats inside you function to this.
int Convert (char* buffer, char const* control, const int& offset, char const* name)
{
    int value = 0;
    for (index = offset; index < offset; ++index)
    {
        buffer[index-offset] = control[index];
    }
    buffer[4] = '\0';
    atoi(buffer);
    Serial.print(name);
    Serial.print(" = ");
    Serial.print(buffer);
    Serial.print("  Value = ");
    Serial.println(value);
    return value;
}

And then call it to populate your values:
void changeColor(char control[16])
{
    char buffer[4]; // You can reuse this buffer, unless you wanted to have separate ones.
    const int red    = Convert (buffer, control, 1, "red");
    const int green  = Convert (buffer, control, 4, "green");
    const int blue   = Convert (buffer, control, 7, "blue");
    const int white  = Convert (buffer, control, 4, "white");
    const int bright = Convert (buffer, control, 4, "bright");
}

sizeof(green) is a typo. This is a much more good looking and working code. Thanks

re: sizeof(green) I thought so, but just in case it wasn't I thought I'd say.

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


text:
How to read from and write to rs232 device from/to Arduino
I would like to read data from a rs232 device (SL-5868P Sound Level Meter).
protocol and more : https://sigrok.org/wiki/Colead_SL-5868P.
I already have a Python script to read the data with a TTL to USB converter (without Arduino). Now I also want to be able to read the meter via the Arduino.
I've bought a RS232 to TTL Converter (MAX3232). I get either very weird characters (baud rate set correctly), or not logical numbers. With the MAX chip I get no data at all.

To see if there is data ready, 0x10 must be sent by the meter.
To get the data, send 0x20.

Would someone be willing to help me out a bit? That would be really nice. Maybe there is someone who has experience with reading (and writing to) RS232. The only thing that matters is how I can retrieve the data. I know the rest what needs to be done with software (conversion, etc.). I'm not that familiar with Arduino's .
The code below is an example from SoftwareSerial (a little bit modified). I'm using the Arduino Uno.
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(2400);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(2400);
}

void loop() { // run over and over
  if (mySerial.read() == 0x10) {
    //mySerial.write(0x20);
    Serial.println("Data available");
    Serial.println(mySerial.read());
  }

  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
  //delay(300);
}

And the current schematic (sorry for my drawing skills)

you only read one byte after the 0x10. is it ok? If you send numbers from Serial Monitor they are sent as text. I doubt the meter accepts "10\r\n" (0x30, 0x31, 0x0D and 0x0A)

Joost, I have a very similar problem. Were you able to make it work?
I don't have enough reputation to comment on your post ;) therefore, I am posting my query as an answer here.

You didn't show how you connected the MAX3232, so I cannot say anything about that. But I can write something about your code and how the data gets received on the PC.

On the PC: Here it is important how you are reading the serial data on the PC. The Serial Monitor for example expects ASCII encoded text. It cannot correctly display binary data. That is the reason, that you get weird characters with the correct baudrate. The data is correctly received, but it doesn't represent ASCII characters. It is just binary data and interpreting it as ASCII characters will not make any sense.
Also it just sends ASCII encoded text, no binary data. So when you are sending "10" it will send the bytes 0x31 and 0x30, plus any line ending, that you have selected (\n aka 0x0A if you selected newline as line ending). As your device speaks in binary data you might wanna speak binary to it. So you either need to decode the ASCII data on the Arduino, before sending it to the device, or you need to use a different serial program, which can handle binary data.

Your code: First look at this line
  Serial.println(mySerial.read());

Here you are reading exactly one byte from the SoftwareSerial interface and then you are printing it. Serial.read() or SoftwareSerial.read() only read one single byte from the buffer, but the data from your device spans over multiple bytes, as described on the wiki page, that you linked. Look at the table titled "Data structure". The returned data consists of 10 bytes in total (numbered from 0 to 9), where bytes 3 to 7 contain the actual data. The rest gives configuration and status data, a header as packet start and a checksum to check for transmission errors. So reading only one byte isn't enough you need to read all of them.
Then you are Serial.print()ing the data. The print() function and its siblings are formatting the data human readable. That might help you here, but you need to make sure, that the resulting output is really readable for you, especially when you are reading multiple bytes (as you need to do, as explained above). Here you need to make a decision: Either

you could decode and format the binary data from the device on the Arduino and send the human readable format over Serial
or you could send the binary data straight to the PC and decode it there with a fitting program (either a Serial program, which can handle binary data, or your own program, for example with python or processing)

If you go the first way, you should first read the different parts of the message and then print these parts with additional text, that explains, what data means what. Otherwise you would have just a long line of numbers, which are also rather difficult to read. Also you might wanna decide on a number base. I think only decimal or hexadecimal are really relevant here. For that you could use Serial.print(value, DEC) or Serial.print(value, HEX), which tells the Serial library to use the specified number base.
Now about the actual data format: The data format is described with

BCD-encoded value, one byte per digit 0x00-0x09. 0x0a means ignored digit. The last digit represents the decimal.

on the linked wiki site. So while this is still binary data (not ASCII encoded), each byte represents a decimal digit of the actual value. You could decode it accordingly. So I guess a byte sequence of 0x01 0x00 0x02 0x09 0x07 would mean 1029.7. As you wrote, that you already know how to convert the data, I will not go deeper about this here.
And lastly you need to rethink your program structure. The workflow with your device is the following:
  Arduino waits for device to send data ready byte (0x10)
  device sends 0x10
  Arduino sends 0x20 (command to send data)
  Arduino waits for device to send at least 10 bytes of data
  device sends a complete data packet with 10 bytes
  Arduino interprets the data in the received packet and acts accordingly
  repeat

You need to follow this workflow and also anticipate, that the data transmission takes some time (especially at the really slow 2400 baud). For this a Finite State Machine (FSM) is a good fit (there are many extended descriptions about FSMs on this site, for example my answer to this question or this question, though there are many more, which you just need to search for). We just track at which part of the workflow we are currently and execute the according code. Something like this:
  enum ReceiveState {IDLE, RECEIVING};
  ReceiveState rec_state = IDLE;

  void loop(){
      if(mySerial.available()){
          switch(rec_state){
              case IDLE:
                  if(mySerial.read() == 0x10){
                      // data is ready, command to send data
                      mySerial.write(0x20);
                      // change state to receiving
                      rec_state = RECEIVING;
                  }
                  break;
              case RECEIVING:
                  if(mySerial.available() >= 10){// only read data, if a full packet was received, at least 10 bytes
                      // Here you need to decode the binary data and handle it accordingly (for example printing in the wanted format)
                      // Reset rec_state afterwards to be ready for the next time, that data is ready to read
                      rec_state = IDLE;
                  }
                  break;
              }
          }
      }
  }

That might seem like a bit of overkill, but the concept is very important in the Arduino world and it is very powerful. Also it makes it easier to accommodate workflow structures.

Thanks for the detailed explanation. This is going to help me. But I still have one problem. When I add debug printlines, it won't be printed. So, no data is coming in. I think it has to do with the MAX3232 chip. I've added a simple schematic in the main post. Maybe it isn't correct connected, or the wrong chip? Connect RS232 directly to Arduino is not a option if I understand correctly.

Hi and welcome to the wonderful world of Arduino. It appears that you have picked-up Arduino with ease. Your program is almost there. Your wiring connection diagram looks to be correct.
When I am doing a project like this, I won't write my full application first. Instead I write a series of test programs to make sure each chunk is performing exactly as I want it to.
I would start by writing a program that just passes the serial information recieved from the Sound Level Meter and displays it on the serial monitor. Something similar to this:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
  // Open USB serial communications
  Serial.begin( 2400 );
  Serial.println("USB Serial is up and running");

  // set the data rate for the SoftwareSerial port
  mySerial.begin( 2400 );
}

void loop()
{
  if ( mySerial.available() )
  {
    // Write the serial from the S.L.M. to the USB (debug) serial port
    Serial.write( mySerial.read() );
  }

  if ( Serial.available() )
  {
    // Write the serial from the USB (debug) serial port to the S.L.M.
    mySerial.write( Serial.read() );
  }
}

This program should be enough to communicate with the Sound Level Meter. But this leads me to my first concern - choice of serial monitor.
While the Arduino built in serial monitor is adequate it is only really good for sending/recieving text. (Plus it sends a CR/LF every time you hit enter.) I can see straight away that you require to send/recieve hex numbers. Hex numbers won't display well on the serial monitor.
Instead I prefer to use a terminal program by "der-hammer" called hterm. (Screenshot here). It lets you view the input in ASCII, hex, bin and decimal. Likewise it lets you send ASCII, hex, bin and decimal or a mixture of each. When sending information, you can configure it so that it finishes the data with either a line feed, a carriage return, both or none.
By the sound of it, you don't want a CR or LF at the end of the data you send. So in the "Input Options" set the "Send on enter" to "None".
For the recieved data, you need to view that in hex so make sure the "hex" box is checked just above the recieved data. (Uncheck "ASCII".)
You could create a loop-back test by removing the Sound Level Meter and instead link the RS232 Rx to the RS232 Tx. This will allow you to see on hterm exactly what the Sound Level Meter sees when you send data.

Issues with your program
  if (mySerial.read() == 0x10) {
    //mySerial.write(0x20);
    Serial.println("Data available");
    Serial.println(mySerial.read());
  }

The section of code will only read one byte of data after it has detected 0x10 (See the Serial.Read() reference page). Anything more than that will get consumed by the next time the if statement checks the serial line for 0x10.
I notice in the line Serial.println(mySerial.read()); that you are reading the data in (which is in hex format) but then trying to write it out in ASCII by using the println() function. This will not give you the output you desire.
Also, after detecting 0x10 it reads the software serial line for one more byte - meaning if there is nothing following the 0x10 then the mySerial.Read() command will hang for 1s until it timeouts.
if (Serial.available()) {
  mySerial.write(Serial.read());
}

As others have pointed out, using the serial monitor will send this as ASCII characters (and include a CR/LF character(s)) instead of the hex value that you want. Kudos is given to you, that you chose mySerial.write() instead of mySerial.println().

My Take on Your Program
The follwoing code is untested.
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(2400);
  // The wait for serial port to connect is not needed for Arduino Uno
  Serial.println("USB Serial is up and running");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(2400);
}

void loop()
{
  if ( mySerial.available() )
  {
    int recievedByte = mySerial.read();
    Serial.write(recievedByte);    // Send to USB serial - assuming using hterm in hex
    if ( recievedByte == 0x10 )
    {
      mySerial.write(0x20);
    }
  }

  // You could remove the following code - data must be in hex.
  if ( Serial.available() )
  {
    mySerial.write(Serial.read());
  }
}

Thank you so much for your effort to explain this all. But as said earlier in the other post, there is totally no data coming in. Maybe there is something wrong with the MAX3232. With debugging (add println's in if-statements), there is also no result. Only when I disconnected and connect the GND again I get data from the mySerial.available() if statement.

Which GND are you referring to?

It's working for now. I've disconnected the MAX3232 chip and connected the RS232 device directly to the Arduino. I know, it's not a best practice, but it is low voltage.

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


text:
Fading LED Lights
How do you make a fading led with 8 different colors I already made a blinking led every 1 second. Can you give me an idea how am I going to fade it every time it switch?
const int red = 5;
const int green = 6;
const int blue = 9;

void setup() {
    // put your setup code here, to run once:
    pinMode(red, OUTPUT);
    pinMode(green, OUTPUT);
    pinMode(blue, OUTPUT);
}

void loop() {
    lightMe(red);
    lightMe2(red, green);  // yellow
    lightMe(green);
    lightMe2(green, blue);  // cyan
    lightMe(blue);
    lightMe2(blue, red);  // magenta
    lightMe3(red, green, blue); // white
}

void lightMe(int pin){
    digitalWrite(pin, HIGH);
    delay(1000);
    digitalWrite(pin, LOW);
    delay(500);
}

void lightMe2(int pin1, int pin2) {
    digitalWrite(pin1, HIGH);
    digitalWrite(pin2, HIGH);
    delay(1000);
    digitalWrite(pin1, LOW);
    digitalWrite(pin2, LOW);
    delay(500);
}

void lightMe3(int pin1, int pin2, int pin3) {
    digitalWrite(pin1, HIGH);
    digitalWrite(pin2, HIGH);
    digitalWrite(pin3, HIGH);
    delay(1000);
    digitalWrite(pin1, LOW);
    digitalWrite(pin2, LOW);
    digitalWrite(pin3, LOW);
    delay(500);
}

I explain a good method here: https://hackingmajenkoblog.wordpress.com/2016/10/02/flexible-led-fading/

You could look at this example, which fades an LED using PWM.
https://www.arduino.cc/en/Tutorial/Fading
Basically you use analogWrite to control the output of the pins with finer resolution, 0-255 rather than 0-1.  Only certain pins support PWM, they should be marked on your board.  You just need to extend the example to support your LED.  (Put the resistor on the common pin)

int color_set = 0;    //set to red first
int wait_fade = 1000 // delay time in ms.  1000ms is equal to 1sec

// set the color for all the LEDs based on the color code
void setcolor(int colorcode) {

  for (int i = 0; i < LED_COUNT; i++) {
    // instead of setting the color all at once we're going to step through each LED to show how to set them individually
    switch(colorcode) {
      // We're going to pass a CRGB here,
  case 0: leds[i] = CRGB(255, 0 , 0); break; // red

  case 1: leds[i] = CRGB(255, 127, 0); break; // orange

  case 2: leds[i] = CRGB(255, 255, 0); break; // yellow

  case 3: leds[i] = CRGB(0, 255, 0); break; // green

  case 4: leds[i] = CRGB(0, 255, 255); break; // cyan

  case 5: leds[i] = CRGB(0, 0, 255); break; // blue

  case 6: leds[i] = CRGB(75, 0, 130); break; // indigo

  case 7: leds[i] = CRGB(148, 0, 211); break; // violet
}
  }
     LEDS.show();
    }
// we'll make the color fade in and out by setting the brightness
void pulse(int wait_fade) {
  // let's fade up by scaling the brightness - in general, brightness shouldn't go above 93, so the strip won't draw too much power.
  // Oh, and 93 is plenty bright!
  for(int scale = 0; scale < 93; scale++) {
    LEDS.setBrightness(scale);
    LEDS.show();
    delay(wait_fade);
  }
  // now let's fade down by scaling the brightness
  for(int scale = 93; scale > 0; scale--) {
    LEDS.setBrightness(scale);
    LEDS.show();
    delay(wait_fade);
  }
}

// this is the main loop where we call the other functions.
void loop() {
  int waiting_time = 10; //time in ms for color scaling
  setcolor(color_set);  //we call our color-set routine
  pulse(waiting_time); //now we make it fade in and out
  color_set++;        //next color
  color_set = color_set % 8; // number of color modulus, remember it's 0 based.
}

because there are so many different microcontrollers, i left it basic, and you only need to define color_set as a integer and then the setcolor() loop, as you can see in the main loop we pass the parameter color_set from our integral 8 colors. here is my complete arduino setup:
#include <FastLED.h>

#define LED_COUNT 96 // number of LEDs!
struct CRGB leds[LED_COUNT]; // this struct contains 60 CRGB values.

#define PIN_BUTTON 10
#define PIN_IO_A   7
#define PIN_IO_B   11
#define PIN_SIGNAL 13
#define PIN_INPUT  10

int color_set = 0;   // set to red
int wait_fade = 1000 // delay time in ms.  1000ms is equal to 1sec
// first, let's get ready to blink using some FastLED routines
// take a look at the FastLED example called Fast2Dev for more usage info
void setup()
{
  LEDS.addLeds<WS2812B, PIN_SIGNAL, GRB>(leds, LED_COUNT); // this configures the Board - leave as is.
  LEDS.showColor(CRGB(0, 0, 0)); // set the color for the strip all at once.
  LEDS.setBrightness(0); // start out with LEDs off
  LEDS.show(); // you'll always need to call this function to make your changes happen.
}

// set the color for all the LEDs based on the color code
void setcolor(int colorcode) {

  for (int i = 0; i < LED_COUNT; i++) {
    // instead of setting the color all at once we're going to step through each LED to show how to set them individually
    switch(colorcode) {
      // We're going to pass a CRGB here,
  case 0: leds[i] = CRGB(255, 0 , 0); break; // red

  case 1: leds[i] = CRGB(255, 127, 0); break; // orange

  case 2: leds[i] = CRGB(255, 255, 0); break; // yellow

  case 3: leds[i] = CRGB(0, 255, 0); break; // green

  case 4: leds[i] = CRGB(0, 255, 255); break; // cyan

  case 5: leds[i] = CRGB(0, 0, 255); break; // blue

  case 6: leds[i] = CRGB(75, 0, 130); break; // indigo

  case 7: leds[i] = CRGB(148, 0, 211); break; // violet
}
  }
     LEDS.show();
    }
// we'll make the color fade in and out by setting the brightness
void pulse(int wait_fade) {
  // let's fade up by scaling the brightness - in general, brightness shouldn't go above 93, so the strip won't draw too much power.
  // Oh, and 93 is plenty bright!
  for(int scale = 0; scale < 93; scale++) {
    LEDS.setBrightness(scale);
    LEDS.show();
    delay(wait_fade);
  }
  // now let's fade down by scaling the brightness
  for(int scale = 93; scale > 0; scale--) {
    LEDS.setBrightness(scale);
    LEDS.show();
    delay(wait_fade);
  }
}

// this is the main loop where we call the other functions.
void loop() {
  int waiting_time = 10; //time in ms for color scaling
  setcolor(color_set);  //we call our color-set routine
  pulse(waiting_time); //now we make it fade in and out
  color_set++;        //next color
  color_set = color_set % 8; // number of color modulus, remember it's 0 based.
}

A lot of the code is commented.  I use FastLED too.  If you have any questions please let me know.

i defined 'wait_fade', which is the delay time.  everything runs just fine in any arduino IDE


text:
Unable to compare two integer values in Arduino Mega
I wrote Arduino code (code is given at the end) to compare two integer values. The steps I took was:

Give input to DC motor to rotate it using serial port. Input was: G254
Then I store it in XX string and using XX.remove(0,1); I removed G from G254. XX now become 254
Then I used Serial1.println("P"); to get position of motor after rotation. I stored this value in ZZ string using String  ZZ = Serial1.readString();. ZZ will be P254.
And using XX.remove(0,1); I removed P from P254. ZZ now become 254.
Now, I convert both XX and ZZ into integer from string using  XX.toInt(); ZZ.toInt(); .
After that, I compare both values using:

if (XX == ZZ)
{
    Serial.println("BOTH ARE EQUAL");
}
else
{
    Serial.println("BOTH ARE NOT EQUAL");
}

But it shows BOTH ARE NOT EQUAL which is not true. I want to know where I'm making a mistake?
Code I used:
void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    Serial1.begin(9600);

    pinMode(13, OUTPUT);
}

void loop() {
    // put your main code here, to run repeatedly:
    if (Serial.available() > 0)
    {
        Serial1.println(Serial.readString());

        String  XX = Serial1.readString();
        XX.remove(0,1);

        Serial1.println("P");

        String  ZZ = Serial1.readString();
        ZZ.remove(0,1);

        XX.toInt();
        ZZ.toInt();
        Serial.println(ZZ);
        Serial.println(XX);
        Serial.println(typeof(XX));

        if (XX == ZZ)
        {
            Serial.println("BOTH ARE EQUAL");
        }
        else
        {
             Serial.println("BOTH ARE NOT EQUAL");
        }
    }
}

Thanks.

A question will get downvotes if question shows no effort. Fine. But I tried hard and do above coding by myself. I need to add int x (Thanks @Michel) in my code which I don't know and that's why I put my question here. I think this question should not be downvoted  on the basis of efforts because I try to find out a solution from other sources but cann't and at last, I put my query here. I loose my points unnecessarily.

You should use
 int x = XX.toInt()

Without the int x = part, the string is converted and the result (the integer) is not used.
Also comparing strings should be done with the strcmp function. The problem is that if you compare two strings, you compare the pointers to those strings and two strings can have equal texts but (probably) not equal addresses.

Might need to add that XX.toInt() returns the value of the string after converting to a number. It does not convert the string (internally) to a number. The string is still a string. Also it is possible to compare the strings directly to be equal.

@LookAlterno True but equal is equal even for strings - isn't it :) https://www.arduino.cc/en/Tutorial/StringComparisonOperators

Thanks for all comments, I updated the answer accordingly.


text:
How to "break" a function we made?
This is code about a keypad lock. The user can unlock the device by entering the secret code. To lock it again they press "#" or "*".
I want to let the green LED turn on for about 0.5 seconds then return to the first line of the loop: char key = keypad.getKey();.
The problem is that this code makes the green LED turn on forever after we enter the correct secret code or until we enter "#" or "*".
void loop() {
  char key = keypad.getKey();
  if (key=='*'||key=='#') {
    position = 0;
    setLocked(true);
  }
  if (key==secretCode[position]) {
    position ++;
  }
  if (position ==3) {
    setLocked(false);
  }
  delay(100);
}

void setLocked(int locked) {
  if (locked) {
    digitalWrite(redpin, HIGH);
    digitalWrite(greenpin, LOW);
  } else {
    digitalWrite(redpin, LOW);
    digitalWrite(greenpin, HIGH);
    delay(500);
  }
}

Use bool locked instead of int locked in setLocked it's a waste of space.

@Avamander, doesn't gcc/gpp promote booleans to integers anyway?

@sa_leinad But by declaring it "bool" you let others know that it's either true or false. But if your point is right, it does indeed take away the "waste of space" argument. But by that logic you could better use a unsigned char, since it's an 8-bit platform.

Indeed, I forgot that a Leonardo is 8-bit, so indeed no space will be saved by using bool instead of int this time but it's not a bad habit to have, to try and not waste space. @sa_leinad Yeah, both false and true have integer values and are treated in most cases as such.

I may be missing something, but couldn't you just modify your setLocked function?
void setLocked(int locked) {
  if (locked) {
    digitalWrite(redpin, HIGH);
    digitalWrite(greenpin, LOW);
  } else {
    digitalWrite(redpin, LOW);
    digitalWrite(greenpin, HIGH);
    delay(500);
    digitalWrite(redpin, HIGH);
    digitalWrite(greenpin, LOW);
  }
  return;
}

I tried , but it returns to setLocked function, not ordinary loop.

@AntonyPossible I amended my answer. I'd put the return statement inside the else clause!

The problem is that when the device is unlocked with the correct code, you turn the green LED on wait for 0.5 seconds and then you don't turn it off again. So the simple answer would be sempaiscuba's answer.
Personally, I like the fact that the red LED indicates that the device is locked and the green LED indicates that it is unlocked.
The problem that I see with your code is that if the user enters an incorrect number, it doesn't reset, allowing any amount of wrong numbers until it sees the right number. This means that I could come along and press the keypay randomly and after a while I would have pressed every digit in the secret code and it would unlock.
Think of the problem as a state machine. You start with 0 digits correct (ie position==0). If at any time the user presses an incorrect digit (or the * or #), the state machine will reset back to 0 digits correct state. If the user enters the first digit correctly then it progresses to the 1 digit correct state (ie position==1). And so on until all of the digits are correct and the device is unlocked. Due to the simplicity of this state diagram it can be accomplished using a few if statements.
int position = 0;
char secretCode[] = "7890";
char inputCode[] = "????";      // This can be any character and just acts as a placeholder
boolean newKey = false;

void setup()
{
    setLocked(true);
}

void loop()
{
    char key = keypad.getKey();

    // Only process when a new key has been pressed
    if ((key != NO_KEY) && newKey)
    {
      newKey = false;  // Don't enter this if statement again if the key is being held down (used for debounce)

      if ((key == secretCode[position]) && (position < 3))
      {
          // The correct key has been pressed
          position ++;
          if (position == 3)
          {
            // Correct code has been entered (all 4 digits)
            setLocked(false);
          }
      }
      else
      {
        // It must be a wrong key (including * & #)
        // Or the device is unlocked and the user is locking it again.
        setLocked(true);
      }
    }
    else
    {
        // Key has been released (used for debounce)
        newKey = true;
    }
}

void setLocked(boolean locked)
{
    if (locked)
    {
        position = 0;
        digitalWrite(redpin, HIGH);
        digitalWrite(greenpin, LOW);
    }
    else
    {
        digitalWrite(redpin, LOW);
        digitalWrite(greenpin, HIGH);
    }
}

Once unlocked, all you have to do is press any key to lock it again.
Resources:
http://playground.arduino.cc/Code/Keypad

This is wide-open to powerline/timing attacks. Don't  "grade" the pin until all 4 digits have been received. as is, I can quickly tell if the left-most digit is correct, then work my way over to the right in under 36 guesses.

Agreed, however the OP is a beginner and I wanted to keep it simple and as close to his original code as possible.


text:
Arduino Due custom platform for school and library installation
I have made a custom-development hardware for our school, where you can plug in an Arduino Due. It is mainly for driving all kind of motors and reading sensor signals. Therefore I added a custom SAM board into board.h based on a copy of the Arduino Due. Furthermore I need a global PWM frequency on all PWM Channels of 20 kHz. So I also changed the variants.h file.
(I have not found a solution that is setting all the underling Timer/Counters for PWM on the Due Pins 2, 3, 4, 5, 6, 7, 8, 13 to 20 kHz by user code, I think this is only possible with the variants.h file - because some timers can not be reset after they where set within the Arduino IDE once)
The Question now:
Today all students have to find and modify their variants.h file, which can be located almost anywhere! (Sometimes it is located in the support packages of Matlab...).
Is there an easy solution to give the students one .zip containing the Arduino IDE already with the custom Board included?
There is the Arduino IDE working without installation for download on the Arduino website. But how can I add my custom SAM board to it?

"I have made a custom arduino board". Please edit your question to explain exactly what you mean by that. Did you just add a new board definition to the Arduino SAM Boards boards.txt file or did you create a complete hardware package? "give them one Zip with everything included". Please edit your question to explain what you mean by "everything". Does that mean the Arduino IDE and the custom Due hardware definition or the custom hardware definition only?

The part about what you mean by the .zip file is clear but you forgot to answer my first question.

I think I did it :)

It's still not very clear. I'm going to assume that you mean you added a new entry to the Arduino SAM Boards boards.txt file rather than creating a complete hardware package and my answer reflects this assumption. If this is not the case then I will need to modify my answer somewhat.

Exit the Arduino IDE.
Create a folder in the Arduino IDE installation folder named portable. This will cause the Arduino IDE to run in portable mode.
Start the Arduino IDE.
Tools > Board > Boards Manager
Wait for the download to finish.
Click on "Arduino SAM Boards".
Click "Install".
Wait for installation to finish.
Make your modifications to the Arduino SAM Boards hardware package installed at {Arduino IDE installation folder}/portable/packages/arduino/hardware/sam.
If necessary, configure File > Preferences to your liking.
Exit the Arduino IDE.
Zip the Arduino IDE installation folder.

When you run the Arduino IDE in portable mode it causes hardware packages installed via Boards Manager to be installed to the portable folder, rather than a folder outside the Arduino IDE installation folder. It also stores preferences.txt in the portable folder. This means you can supply a .zip file that contains a copy of the Arduino IDE with the customized Arduino SAM Boards package already installed.
By default it will also set the sketchbook folder to be there but that can be changed via File > Preferences > Sketchbook location if you like.

this is exactly what I was looking for! Thanks a lot!


text:
After burning bootloader, Windows 10 doesn't recognize the USB device
I just built my own version of an Arduino Micro, using the ATMEGA32u4 chip. I burned the bootloader to it via another Arduino (Arduino Nano from banggood.com).
The Arduino Nano uses an ATMEGA328 chip, so it should work as an ISP programmer. None the less, I hooked up the Nano to my custom board, according to Sparkfun's Guide, and proceeded to burn the bootloader. The Arduino IDE says that I have successfully burned the bootloader.
However, when I plug in the newly burned custom board, Windows 10 throws the error, saying, USB Device Not Recognized followed by The last USB device you connected to this computer malfunctioned and Windows does not recognize it.
I have searched for a solution, but none seem to come up. My question is, what do I need to do in order to get this custom board working as an Arduino? Thanks!

Which bootloader did you burn?

You need a number of things to be true before the (new) bootloader will work:

The hardware needs to be wired correctly
You have used an appropriate crystal as the clock
You have installed the correct bootloader (ie. one for the Atmega32U4)
The fuses are set to boot into the bootloader
The fuses are set for the correct bootloader size
The fuses are set correctly for the clock type and the clock speed (for example, don't have the "divide clock by 8" bit set)

I have a sketch that analyses your chip signature and fuses which will also report on what bootloader it detected (assuming it is one from a recognized list). You could run that and amend your question to post the resulting display from the serial monitor.
I also have a sketch that programs a bootloader for various chips including the Atmega32U4. This sketch also sets the appropriate fuses.

I figured out my own problem. After further testing, I found that my ATMEGA32u4 from DIGIKEY was damaged. Most likely I damaged it by accident, but I can't be sure. Oh man, wouldn't it be nice if life had a CTRL+Z on it?


text:
Problem communicating between arduino UNO R3 and Mega 2560 via MAX485
I want to send data between Arduino Uno and Mega via MAX485.
When I set the data Enable pin to HIGH on Mega (to transmit data) and set the same pin on UNO to LOW (to receive data) I can read data from Mega into Uno properly. However, when I want to do it vice versa (send data from uno to mega) can't get any data from Uno into Mega. Tried different pins on both boards but still no answer.
This problem happens when I want to change data Enable pins to low or high inside loop(), I mean when I use for example Uno as permanent master and mega as permanent slave, it works properly but when I try to change them from slave to master on runtime, data cannot be sent from uno to mega!
PS: Im newbie on RS485 and MAX485. Here is my code in MEGA side:
#include <SoftwareSerial.h>'
SoftwareSerial mySerial(2, 3);
String inputS = "";
boolean stringComplete = false;
int i = 0;
bool b= false;

void setup() {
  mySerial.begin(9600);//Using SoftwareSerial Port
  Serial.begin(9600);
  pinMode(8, OUTPUT);//DE/RE Controling pin of RS-485
  digitalWrite(8, HIGH);//DE/RE=HIGH Transmit Enabled M1
}

void loop() {
  mySerial.println("MEGA:Hi");
  Serial.println("Hi Sent");
  digitalWrite(8, LOW);
  CheckAndReceive();
  if(stringComplete)
  {
  stringComplete = false;
  inputS.trim();
  Serial.print(inputS);
  Serial.println(": " + String(i++));
  inputS = "";
  }
  digitalWrite(8, HIGH);
    delay(1000);
}

void CheckAndReceive()
{
  while (mySerial.available()) {
    // get the new byte:
    char inChar = (char)mySerial.read();
    // add it to the inputString:
    inputS += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

This code is supposed to send a string to UNO and listen to it.
UPDATE:
UNO cannot send data to MEGA at all. I think there is a problem with my UNO

Are you waiting for the data to actually send before switching...?

I set the dataenable pin on uno to high and on mega to low and then try to send data. Doesnt that mean switching ?

And what do you do next after sending? Please show your code.

Im far away from my pc, but will show that as soon as i sit behind my pc. After i send data from uno i check serial1.available() on mega. But it never runs

You have forgotten to add mySerial.flush().
mySerial.flush() waits for the transmission of outgoing serial data to complete.
Add it right after you have sent the data and want to change the DE pin status.

Care to elaborate on that? What is the purpose of flush()? What is the effect that it is working around and why does that effect exist?  Teach a man to fish...

When i added this line to my code, it worked properly! Strange!


text:
Force Sensitive Resistor OverLoad
I've got just a simple question. What happens when I overload Force Sensitive Resistor (FSR). Example Here.

Let's say that it's got force sensitive range between 100g and 10 000g. What would happen if I'd create pressure about 100kg? I see that resistance is decreasing with bigger pressure. Will there be almost 0 ohm resistance? If so, can this FSR survive this overload? Has somebody test that?
Thank you for any answer.

It depends a lot on how it is mechanically set under pressure. The backside has to be against a very flat surface and the pressure has to be applied evenly spread over the whole sensor. That is hard to achieve, so the mechanical stress damages it. I did not test it, but I suppose it can handle a lot more than the 10kg, but it will get damaged. I think that it is impossible to get to almost zero ohms. There are other materials, for example conductive rubber, that can handle someone standing on it.

Also asked at http://forum.arduino.cc/index.php?topic=499102

I see that resistance is decreasing with bigger pressure. Will there be almost 0 ohm resistance?

The harder the force, the lower the resistance. Sparkfun has a datasheet attached that shows the following graph:

Notice how both axis of the graph are logrithmic. This means that the resistance will never reach 0 ohms. However it will get close. At 10 Kg (22 lb) the resistance is about 250 ohms.

What would happen if I'd create pressure about 100kg?

The datasheet has the following to say for weight above the 10 Kg mark:

At the high force end of the dynamic range, the response deviates from the power-law behavior, and eventually saturates to a point where increases in force yield little or no decrease in resistance. Under these conditions of Figure 2 [ie. the graph above], this saturation force is beyond 10 kg. The saturation point is more a function of pressure than force. The saturation pressure of a typical FSR is on the order of 100 to 200 psi. For the data shown in Figures 2, 3 and 4, the actual measured pressure range is 0 to 175 psi (0 to 22 lbs applied over 0.125 in^2). Forces higher than the saturation force can be measured by spreading the force over a greater area; the overall pressure is then kept below the saturation point, and dynamic response is maintained. However, the converse of this effect is also true, smaller actuators will saturate FSRs earlier in the dynamic range, since the saturation point is reached at a lower force.

In summary, the weight applied can go over 10 Kg providing that weight is spread over the sensing area. The larger FSRs (such as this one) are better suited for this purpose as they have a larger area for which to spread the pressure.
Note: It is quite possible that with 100 Kg you could irreversibly damage the FSR, particularly if the weight isn't spread over the sensor area.
Measuring an analog voltage from the sensor is possible so that it can be fed into one of the analog pins of the Arduino. This Adafruit page has a nice table at the bottom showing the analog voltage that you get when you put the sensor in a voltage divider network (ie. in series) with a 10K ohm resistor.


text:
how to set the delay on for 7 hours?
For my application I need to simulate the sunlight including the rising and setting of the sun.
I have a program that will light up some LEDs slowly over a period of time but I need to know what to type in the (delay on) to keep the lights on for 7 hours?
Will it work if I just replace delay(1000) with delay(25200000UL) ?
I don't want to run anything else at the same time and don't want to use or understand millis().
Thanks for any help.

Hi, I already have it lighting up slowly over time just need to stay on for 7 hours then slowly turn off.

It does upload but with an error but still compiles, tried again and no error...seems to be working.

Very new to this, it seems to be working now. Thankyou very much for your responce.

Please add the answer to this page by clicking on the answer your own question button at the end of the page. This will then help others that have the same problem.

Yes, absolutely, it should work. But your code will be easier to read if
you use some constants, like:
const unsigned long SECOND = 1000;
const unsigned long HOUR = 3600*SECOND;

delay(7*HOUR);

Yes you can write delay(25200000UL) and it will delay for 7 hours.
How it works
delay(x) will delay for x number of milliseconds.
1 second = 1000 milliseconds
1 minute = 60 seconds
1 hour = 60 minutes
7 hours = 1000 * 60 * 60 * 7 =  25,200,000
This number is quite large but is well within the scope of an unsigned long: 32 bits = (2^32)-1 = 4,294,967,295. Doing the sums, this will last for 49 days and 17 hours.
Delaying for >49 days
If for some reason you needed to go longer than 49 days, you can do so by placing the delay inside a for loop.
const unsigned long ONE_DAY = 24UL*3600*1000;
const unsigned int numOfDays = 51;
int i;
int j;

for( i=0; i<numOfDays; i++ )
{
    delay(ONE_DAY);
}

You wrote: 1000*3600*24UL. This will overflow. You mean 1000UL*3600*24: multiplication is left-to-right associative in C++. You also wrote i<7 while you probably meant i<numOfDays.

It's an old one but I give an answer.
I think someone needs help like you.
I trying to make a fish meal machine with the Arduino Uno.
In the first.
I counted seconds over a minute.
It works well.
But when I try over an hour it does not work.
After all.
I got to know another way to count a long time
In the second.
I used the SimpleTimer.h.
The link is here.
Arduino SimpleTimer
It's an easy way to makes a circular moving but it has the same problem.
SimpleTime can't make a count over time.
I think it's 30 seconds.
Now I referenced StackExchange Arduino.
Here is my code.
#include <SimpleTimer.h>
#include <Servo.h>

#define FIVE_SEC 5000UL
#define ONE_MIN 60000UL
#define FIVE_MIN 300000UL
#define TEN_MIN 3000000UL
#define ONE_HR 3600000UL
#define EIGHT_HRS 28800000UL
#define TWELVE_HRS 43200000UL

SimpleTimer timer;
Servo servo;
int servoPin  = 9;
int servoReadyAngle = 180;
int servoMoveAngle = 170;
int servoMoveCnt = 0;
int servoJobCycle = 35000;

unsigned long startTime;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  servo.attach(servoPin);

  startTime = millis();
}

void loop() {

  if(millis()- startTime > TEN_MIN) {
    startTime = millis();
    giveAFishMeal();
  } else {
    Serial.print("ping ");
    Serial.println(millis());
  }

}

void giveAFishMeal() {

  int servoAngle;
  if(servoReadyAngle > servoMoveAngle) {
    servoAngle = servoReadyAngle - servoMoveAngle;
  } else {
    servoAngle = servoReadyAngle + servoMoveAngle;
  }

    Serial.println("I give a meal to your fish");

    delay(500);
    servo.write(servoReadyAngle);
    delay(500);
    servo.write(servoAngle);
    delay(500);

}

delay(1000) is a delay in ms.
So for a 7 hour delay you need 7 hours * 60 minutes * 60 seconds * 1000 = 52,200,000
Adding UL is good, to show it's long and unsigned.
Also it fits in an unsigned long which has a max value of 2^32-1 = 4,294,967,295.
If you really want to test it you can wait 7 hours, or use a smaller number (like dividing by 60 * 60, thus 7,000 which should be 7 seconds, or make it 70.000 and check it is 70 seconds.
If you would want to make it explicitly how 52,200,000 is calculated or want to make your program more flexible you can always create some defines (or constants):
static const uint32_t DELAY_1_S      = 1000UL;
static const uint32_t DELAY_1_MINUTE = DELAY_1S * 60UL;
static const uint32_t DELAY_1_HOUR   = DELAY_1MINUTE * 60UL;

than you can use
delay(7UL * DELAY_1_HOUR); // Delay 7 hours

For my application I need to simulate the sunlight including the rising and setting of the sun.

if you have to simulate that long of a delay, you are doing something seriously wrong.
but if you do want to go down that path, something like this may work
#define delay_1hr()  delay(1000ul * 60 * 60)  //delay a hour

//delay a day
void delay_hr(uint8_t hr) {
  while (hr--) delay_1hr();
}


text:
ESP8266 like WiFi modules
I am trying to make a circuit using Nodemcu ESP8266 to control the speed and direction of 3 DC servo motors, however I am short of analog pins.
So are there any ways to increase the number of analog pins?
Or are there other WiFi modules like the ESP8266, but with more number of analog pins?

Short of Analog input pins or output pins? ESP8266 can do PWM on all it's output pins.

I need to control both speed and direction of multiple motors via WiFi, can PWM signals do that?

Your question noted that you don't have enough Analog pins -- what do you need them for? HOW are you controlling motors? There are many different ways, modules, and methods. Please add detail to your question.

ESP32 has much more pins

How many PWMs do you need?
Here you can find a useful description about PWMs on ESP8266 NodeMCU.
According to image, ESP8266 NodeMcu has 9 PWMs pin.


text:
1-10 volt analog signal
I have an Arduino project where I am using an ESP8266 (Wemos D1 mini) powered via USB. I want/need to output an analog voltage from 0 to 10V.
Goal:
A solution that is pre-made (eg a shield or sparkfun type module) or easy to build circuit that does not require a new power supply (besides the ones I have which is 3.3V and 5V, thanks to Wemos USB power).
Many devices allow you to control them using a 1-10V signal. I have two LED drivers at home that I would like to interface with: specs1, specs2.
What would be the easiest solution to generate a 1-10 Volt signal? Is there a module I can use?
I read about Op-amps but I don't yet have the knowledge to build one myself.
Another method is a DAC, but that seems to require a separate 10 Volt power supply.

Why the downvote? Please let me know so I can improve the question

Seriously! My question might have issues, but downvoting without leaving an explanation is to say the least not constructive. This gives me a sour taste as a new user. My only option now is to leave as I am clearly not welcome here for reasons unknown to me,

Welcome to Arduino:SE. I'm not one of those who downvoted, but the question does look to be off-topic here.  There is a good guide on How to ask a good question for Arduino Stack Exchange on our meta site.

I didn't downvote, but I did vote to close, unfortunately. This would be better asked on SE.Electronics as it isn't really Arduino specific (unless I am missing something)

@Greenonline, the question is here, so we can answer, how to do it with Arduino. my answer is on-topic, I think

But @Juraj, whilst your answer seems to be a good answer, it doesn't really mention Arduino (apart from your link), and it seems to be an electronics interfacing question & answer, rather than Arduino specific. I'll cast a reopen vote though

This question in my opinion exists in the grey area between Arduino and Electronics Stack Exchange.  I think if your question included more mentions of "Arduino" and/or "Arduino project" I think it may have been OK. On the other hand, there is no other way to generate a voltage of 1-10V without using external electronics. The question would then be what circuit is best suited for your situation. With all that said, the majority of Arduino projects need some electronics - just look at the examples and most of them give a circuit to use. I think this would be useful for other Arduino users.

You do not need a DAC. In this 'regulation cases' PWM on digitalPin is used. See analogWrite Arduino function.
I use Grove MOSFET module to have PWM of desired voltage. The MCU generates a 3.3 V PWM. MOSFET module gets in my case 5 V as input voltage. You would use 10 V as Vin. MOSFET switches the 10 V line on and off at 'PWM speed' resulting in 10 V PWM.
As 10 V source you could use a 'boost' converter, to convert 5 V to 10 V.
This is the schema of the Grove MOSFET module:

i would add a cap to the output to filter the PWM into a steady voltage.

The ADM660, link below,

is a charge-pump voltage converter that can be used to either invert the input supply voltage giving VOUT = -VIN or double it (ADM660 only) giving VOUT = 2 x VIN.

It accepts an input range between 1.5V-7V so if you use the 5V from the Wemos USB power you'll be able to reach the desired 10V for your application, and it's cheap :)
http://www.analog.com/media/en/technical-documentation/data-sheets/ADM660_8660.pdf


text:
Can I make a 455Khz Sine Wave with the Arduino UNO?
Can any one help me, I need to make a sine-wave of 455Khz for use in aligning a Super 7 - AM Radio.
I looked into buying a function generator but I have an Arduino UNO. Can this do the tasks?

No, but realize you don't need a sine wave - a square wave will work too, as it's unlikely that the IF can be mis-tuned to the third harmonic (though you might be confused by that coming in through the front end).  Also, you might be able to use an integer fraction of 455 KHz.  If you wanted to be really, really, clever you could probably use an Arduino to make a sort of PLL synthesizer by dividing the internal oscillator to 455 KHz and having software adjust its calibration so a further division matches some other slow speed reference source.  But there are inexpensive chips you can buy...

The Arduino does not has a DAC (digital analog converter), so you cannot make an output varying in voltage (except for 0V / 5V) by default.
The PWM outputs use 0V/5V with duty cycle but this is not a sine wave.
So you need additional hardware anyway.
Also, regarding speed if you have a DAC. Assume 16 MHz for the Arduino, having a 455 Khz sinewave, you have about 35 clock cycli per complete sine wave. The sine values you can store in a table, but you need probably at least 3 or 4 clock cycli per sine wave value (to fetch the value from the table and to send it to the DAC), this results in about 8 values which will give a very rough sine wave.
So I would go for a separate sine wave generator.

For example, AD9850

Or ICL8038 if you want to go cheaper

If you don't want to buy a chip, and you do have a few other parts laying around, it would not be hard to do a simple oscillator with Op Amps and get a nearly true sine wave.  Alternatively an inverter (74ls04, or any inverting gate chip cmos or ttl) with an R-C can be made into a square wave generator, and another RC or two could get it to approximate a sine wave.


text:
Arduino IDE Permision Denied For Upload, Ubuntu
I am having issues uploading to my Arduino from the IDE on Ubuntu 18.04. The error message I have received is:

Arduino: 1.6.10 (Linux), Board: "Arduino/Genuino Uno"
  avrdude: ser_open(): can't open device "/dev/ttyUSB0": Permission denied

I have checked other questions similiar to this one and have tried adding myself to the dialout group running:
sudo usermod -a -G dialout username

and added permission to write:
sudo chmod a+rw /dev/ttyUSB0

After, when I run:
ls -l /dev/ttyUSB0

I get:
crw-rw-rw- 1 username dialout 188, 0 jūl  2 16:09 /dev/ttyUSB0

However,I still get the same error message from the IDE.
Any help would be greatly appreciated!

Also have set the port in Tools to ttyUSB0

log-out and log-in https://www.arduino.cc/en/Guide/Linux#toc6

Are you sure it's /dev/ttyUSB0? A real Arduino will be /dev/ttyACM0. Maybe yours is a cheap chinese clone?

Yeah just discovered it is a CH340G chip. Any hope of still getting it to work? Have heard of people having success on Windows but haven't found any good troubleshooting for Linux.

Were you able to make it work?

No I ended up giving up and using another board I have. I have another project I am going to start in a month or so for which I am going to try to use that board so will post an update then if I figure it out.

Arduino has added a script to the install to fix this problem.  I found it after much annoyance trying to get it to work with all these suggestions.
In the arduino-1.8.8-linuxarm.tar.xz file that you download is a script called arduino-linux-setup.sh
run that from commandline with your user name ./arduino-linux-setup.sh <username>
It'll ask for the root password, and then ask you to reboot.  After that you won't have any more port trouble.

As mentioned on the official guide for Linux, you need to run
sudo usermod -a -G dialout <username>
with the <username> replaced with the username of your system.
After running this, log out and log in (or in some cases reboot the computer) and you should be good to go.

When you run

ls -l /dev/ttyUSB0

you have
crw-rw-rw- 1 username dialout 188, 0 jūl  2 16:09 /dev/ttyUSB0

The Problem is you have the dev as <username>, try to change to as root
sudo chown root:dialout -R /dev/

Note:
One thing after your plug your USB, check your port with follow
ll /dev/tty*

if you can see my port as ttyUSB0 or with difference name (i.g ttyUSBx / ttyACMx ).
and then try to compile your sketch with following,
cd /path/your/arduino/installation/
$ARDUINO-DIR(pwd)
cd /path/your/sketch/
$ARDUINO-INO/arduino --verify sketch.ino --board arduino:avr:uno --port /dev/ttyUSB0 --verbose //compile your sketch.ino with arduino uno board.

Hope this helps.

You definitely SHOULD NOT change the ownership of every file under /dev as chown -R will.


text:
Extremely unstable analogRead() on Arduino Nano when powered from an external source
I'm doing a really simple project with an Arduino Nano and found a problem.
The circuit is a simple temperature sensor and a tension read from an analog pin everything showed on a Nokia 5110 LCD.
When the Nano is connected to the USB everything works and the reads are perfect.
When I install the circuit on my car taking the 12V to the Vin and the GND from the centraline everything goes bad: I certainly know that the 12V is obviously not stable and oscillates a lot (between 12V and 14V).
What can be the solution? Should I add some ref or should I regulate the input tension to maintain it stable to a certain quantity?

Car power is incredibly noisy. You need lots of filtering to get it to work right. Either that or get a proper automotive grade power supply. The simplest is a "cigarette lighter" USB charger...

Thanks. Unfortunately I'm taking the readings from the cables that go to the lpg commuter. If the problem is the stability of the input does exist some (cheap) circuit that I can use to stabilize it to 12V?

Why is that "unfortunate"? What does where you're taking readings from have to do with how you're powering the board?

To keep everything compact I take power and readings from the same part. To use the cigarette lighter usb charger I should keep it plugged in and pass a cable along all the front part of the car

You're thinking too literal. A "cigarette lighter" style power supply doesn't have to be plugged into a cigarette lighter socket. Take a screwdriver to it. Pull it apart. Solder wires to it. Think outside the plastic shell it comes in.

Thanks, I will give it a try. Can I ask you if this cheap product
https://a.aliexpress.com/_BPIybF (A DC-DC regulator)  can do the work? Thanks

Since the Arduino uses the power input as the reference for the ADC, taking power and readings from the same source is a recipe for disaster.   If you want really stable readings divide your signal down to 1v1 and use the internal reference on the Arduino.

Can the DC-DC help with that? I don't need perfect readings but actually the temperature readings jump from 20°C to 40°C in a matter of seconds. (I take the average of some readings)

No. Like I said, you need automotive grade. That means it can cope with spikes in excess of 65V or so.

Really? An old car centraline can reach 65V? I didn't know that thanks

Like I said: noisy.

Yes but I tough less noisy. Using the usb charger I will get 5V. Since the VIN pin wants at least 7V can I connect the 5V from the charger to the 5V pin even if the LCD and the temperature sensor are already connected there?

Yes. Of course you can.

Thank you for your help, I thin that the question is resolved. I've a last doubt: can I trust the car charger or should I put something between the 5V pin and the output of it? Thanks

You can use a branded 5 V charger made for cars. You can directly connect this to 5 V pin of the Arduino.
By doing this:

you are protecting the Arduino from the noise as well as high voltage spikes coming from the car 12 V supply
protecting yourself and others coming in contact with the Arduino or the sensors connected to the Arduino.

You can also

consider filtering the analog data read
protection circuits such as surge protection diodes or a 5.7 V Zener across 5 V and Ground of Arduino


text:
How to read .txt file from the internet wirelessly
I am a complete beginner to Arduino, so I'm asking this moreso to see if a project will be feasible.
My ultimate goal is to have this arduino (whenever powered) check this website "https://services.swpc.noaa.gov/text/aurora-nowcast-map.txt" (every 15 minutes or something). If a specific value in the sort of array of space delimited numbers is above a threshold, it'll turn on an LED.
I want to use some WiFi shield (price is not an issue, I just don't want complicated powering) to have the Arduino read a .txt file from the internet. What will the simplest, most reliable hardware be, and how will I read this data in? An example may be very helpful!!!
I think I can handle the string-to-light part of the code, but am very unfamiliar with the wireless portion. Once I upload the script with the wireless "credentials" onto the Arduino, I would like it to just run whenever there's power/ the credentials change!
Sorry for the long mess, I know the question is a little buried and that there are similar questions, but I'm hoping by providing all the info, somebody might point me to a similar project, or have some advice with the whole project in context.
-Alex

a quick google search results in this .... https://www.arduino.cc/en/Reference/WiFi101

most reliable is Ethernet by cable, not WiFi


text:
Remotely uploading code to an Arduino board over the internet
I recently used Particle Photon that allows me to upload firmware (.bin file) remotely over the internet.
I would like to use something like this for my Arduino but I cannot find anything like that. Does anyone know any possible way to upload firmware to my Arduino board remotely connected to internet via Ethernet shield of any WiFi module?

you want to use Ethernet shield/module?

@Juraj yes I have ethernet shield.

You can upload to your Arduino board over Ethernet if you flash it with a special bootloader named Ariadne.
You will need an Ethernet module or shield that uses the W5100, W5200, or W5500 Ethernet controller chip. You can not use the ENC28J60 Ethernet controller with Ariadne.
You will need an ISP programmer to burn the Ariadne bootloader to your Arduino board. If you don't own an ISP programmer, you can use a spare Arduino board as an "Arduino as ISP" programmer. If you're going to purchase an ISP programmer, I recommend the 6 pin USBasp. The USBasp works well with the Arduino IDE and is very reasonably priced. You can buy them on eBay.
A description of how the Ariadne upload over Ethernet process works:

Compile the sketch you want to upload.
Use avr-objcopy to convert the .hex file of the sketch generated from the Arduino IDE compilation into a binary (.bin) file.
Reset the Arduino board to activate the bootloader code. You could do this by pressing the reset button on the board but the need to have physical access to the board negates much of the advantages of uploading over Ethernet. For this reason, the upload will typically be accomplished by sending a command to your Arduino board which triggers the application to reset the microcontroller by activating the watchdog timer and then allowing it to time out. There is a library named EthernetReset bundled with the Ariadne hardware package for this purpose, but you can easily implement your own solution if you have other needs.
Start a TFTP upload of the .bin file to the IP address of your Arduino board within the 10 seconds that the bootloader is activated after the reset. The upload doesn't need to finish within the 10 second window, it only needs to start.

You can get the Ariadne bootloader, as well as detailed instructions, here:
https://github.com/loathingKernel/ariadne-bootloader

some of the links on https://github.com/codebndr/Ariadne-Bootloader are not working ! but is it possible to link me up with some of ISP programmer

I want to know how can a bootloader can flash new firmware from the internet ?

"some of the links on github.com/codebndr/Ariadne-Bootloader are not working" The project has been moved to https://github.com/loathingKernel/ariadne-bootloader. If you find any broken links in that repository, please let me know and I'll get them fixed.

"is it possible to link me up with some of ISP programmer" What do you mean by that? Are you asking for a link to buy an ISP programmer? If so, here you go: www.ebay.com/itm/232327462892

"I want to know how can a bootloader can flash new firmware from the internet ?" I've added a summary description of the upload process to my answer. After reading that, if you have any specific questions let me know and I'll try to improve my answer. I don't want to reproduce the full Ariadne documentation here. The idea behind the answer was only to explain that this is an option for uploading firmware over the Internet, with a short description in order to make it more than just a link.

can you explain the point 3, after I press the reset button on my uno then what command to run to upload the ariadne bootloader

http://loathingkernel.github.io/ariadne-bootloader/#using-a-tftp-client-to-upload-the-sketch

This will do it. ESP8266 as wireless AVR (arduino) ISP programmer.
https://github.com/rene-win/esp_avr_programmer
or
https://github.com/jeelabs/esp-link
The ESP8266 can be programmed with the Arduino IDE. So it can be used for a lot of Arduino projects. And it can be OTA (Over The Air) programmed as well.
https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html

sounds  great I also came across ArduRF1 by tindie that has onboard capability to upload firmware remotely over internet with lipo battery support onboard.


text:
4-digit 7-segment display not showing value properly
I'm trying to add a 4-digit 7-segment display to an existing project (a temperature & relative humidity sensor) to show the temperature on the display.
I bought the display a long time ago and I it doesn't have any ID and I don't have any reference to a schematic, so I followed this article to find out both if it's a common cathode or anode and the pinout.
It turns out it's a common cathode display and the pinout goes like this (numbered from upper left):
1 -> D1
2 -> A
3 -> F
4 -> D2
5 -> D3
6 -> B
7 -> E
8 -> D
9 -> DP
10 -> C
11 -> G
12 -> D4
Where D{1,2,3,4} are the digit control pins and the rest are the segments.
So I added the SevSeg library to my project. And the sketch compiles, but when I upload it to my Arduino Uno all the LEDs in the digits 1 and 4 light up and digits two and three remain off.
I checked the pinout twice, with the same results and the display doesn't seem to be damaged. Do you see any issue on my code?
Thanks in advance!

isolate the area of failure ... switch the digit pin wires ... see if the problem is with the display, or with program

Be sure, that you don't connect anything to the pins used by the ethernet shield

https://www.instructables.com/Using-a-4-digit-7-segment-display-with-arduino/ This maybe helpful... I used this and this worked.

What caused the problem of the digit that driven by pin 12 is quite obvious to me. You use pin 11, 12, 13, 14 for driving the 7-segment digits. While SPI library by default uses pin 10, 11, 12, 13 as SS, MOSI, MISO and SCK, and set pin  12 (MISO) as INPUT which is in conflict with your pin 12 (as an OUTPUT) for driving the digit.
Pin 13 is also used by the interval blinking LED (i.e. BUILTIN_LED) when defined as a digital i/o.
Your code uses quite a few libraries, and those libraries could uses some of the I/O pins, I would suggest you reduce your code to only the code related to SevSeg, set the display to all '8888', and add each library one by one back to find out what caused the problem.

Your issue could be in code or in your hardware.
To work out which one, try running one of the example sketches like the testWholeDisplay.ino that comes with the library you are using. This way you have known working code and you are testing that your hardware is wired up correctly. If this step doesn't work, then you need to look into your wiring and/or setup.
If using the example sketch works, then you can start looking into your sketch. Divide it into chunks and test each chunk independently. If any chunk doesn't work then work out what is different from the example sketches compared to your code.

You're right, I used the example and the display works fine. The problem may be what @hcheung says, so I'll try to free the pins 11, 12, 13, 14 and use the analog pins as digital pins instead. Another option would be to use a LED driver.

Reverse engineering your code, which is generated by https://examples.blynk.cc, I have found that you are using:

an Arduino Uno
W5100 Ethernet shield (or Arduino Ethernet Rev3)
DHT11
4-digit 7 segment display

Your Blynk example code looked something like this.
For the 7 segment display you are using pins 3, 5, 6, 7, 8, 9, 11, 12, 13, A0, A1, A2.
byte digitPins[] = { 11, 12, 13, A2};
byte segmentPins[] = {3, A0, 5, 6, 7, 8, 9, A1};

However, the W5100 Ethernet controller uses pins 10, 11, 12 and 13 as seen on the Arduino Ethernet webpage:

NB: Pins 10, 11, 12 and 13 are reserved for interfacing with the Ethernet module and should not be used otherwise. This reduces the number of available pins to 9, with 4 available as PWM outputs.

Pins 2 & 4 are used for the DHT11 and SD card chip select respectively.
All you have to do is change the wiring of the seven segment display to not use pins 11, 12 and 13, and then adjust your sketch accordingly. For example, you could use A3, A4 & A5.