A.6. How to troubleshoot

This one of the most important things and most common things you'll do: troubleshoot!

Here is a guide that will help you at the those "what is happening? It doesn't make any sense" times.

So, read it carefully.

This is a post that is pinned in our Facebook group page, where you should post your doubts.

[READ ME BEFORE POSTING YOUR DOUBT - HOW TO TROUBLESHOOT]

This post will be a "Read Before Posting" but also a collection of frequently asked questions and answers. I count on your collaboration in the comments!

In order to help you, we need the most accurate and clear description of the problem. The more of these items you present to us, the more likely we are to spot the problem! This includes code: including more information such as where you adapted this code from, or whether it was from scratch; photos of your circuit, with good light and well focused; a video reproducing the problem; the schematic you are using, etc.

To post the codes use Pastebin: http://pastebin.com

For schematics, use Fritzing: http://fritzing.org

And, of course, look up your keyword to see if your question has not been answered yet.

What can you do before you ask a question?

~~ Troubleshooting / Finding the Problem ... ~~

~ Your code is not compiling ~

In the IDE, try to read in the dialogue box, the black box below the IDE, what the problem is. Sometimes it seems Greek, sometimes it gives you a good idea of what it can be.

Did you choose the right board? Did you choose the right USB port? Have you downloaded and installed all libraries correctly?

Did everything right go so far? You've read in your code and can't find any error? Be humble, it is not because you have read 10 times that it means you read it right. Do not underestimate your tiredness! Take the time to read the code again. Often it is a different letter that we wrote, or missed a ";". Search, search, search, rest, search.

~ Your code compiles, so you do not know where the problem is ~

First, be humble, do not blame the Arduino, do not blame the board, do not blame the computer, the problem is (98% chance) you. In this case, the ideal is first debugging the circuit. For this, you MUST have a multimeter. Use the multimeter to check the continuity of your circuit. First, check the continuity of all the GNDs, 5Vs, and, after, each component, or go straight to the "faulty" component if it is only one or more problematic components. If you find that there is a lack of continuity somewhere, redo the soldering, or rearrange the jumpers. If the problem continues, you may have a faulty component. If it's just one, or another component that does not work, it's very likely that the problem is in the circuit and not in the code.

~ You checked your circuit and you're sure it's all right ~

Debugging the code is more complicated, there is no exact recipe. It is reading, line by line, that you'll might find the possible problem. Often your algorithm is wrong. That means you are not giving the correct instructions to the Arduino, something is in the wrong order, or, who knows?

In this case, use the serial monitor a lot! Try printing what's coming out of various parts of your code, one at a time. Sometimes you think it should be coming out "10-100", but it's coming out "-2". Why? Then, you'll have to do a mental gymnastics to find out. It can be difficult, but for me it's one of the nicest parts of the process.

A good practice is to put on paper every task your Arduino is doing and try to simulate what numbers are coming out of there, do the calculations, do the "IFs" and see what actually is coming out.

~ It still does not work, I'm in doubt ~

Take a step back. If you used a multiplexer and it is not working without your code, try using the library example, it's still not working, it's because your system is having problems. Using the native Arduino and library examples is a better way to test the problem in your circuit or without code. If it works there, the problem is your code, does not work, the problem is no circuit!

~ The Potentiometer, or any other analog sensor, is sending a signal when it should not ~

Every pot has an unstable nature. We try to solve this in the code, setting a minimum value that must be changed for an event to happen. In general this minimum is stored in the variable "varThreshold". Increase the value of it and see if it improves.

~~ Frequently Asked Questions ~~

~ Which Arduino should I buy? What do you think of such an Arduino? Etc, etc. ~

I did a post explained all this. You can read here:

https://www.musiconerd.com/single-post/qual-o-ardu... (just in Portuguese yet, but Google translate it)

~ Where can I buy such a thing? ~

I live in the USA, so here I buy everything from Ali Express (which is cheap and does not take so long). Or if I need something faster, and/or more specific, I buy on mouser.com or digikey.com.

~ Where can I have my PCB made? ~

To do in China is a lot cheaper than any other place, for an absurd difference. You can do on JLCPCB.com, PCBway.com, among others.

~ Which multiplexer should I use to ... ~

To multiplex analog components, use the cd4067 (16-channel), or cd4051 (8-channel). For leds, use the 74HC595 bit shifter.