Hi to the Arduino community! I just received the Arduino Starter kit this week and electronics is new to me but not programming because I'm a programmer. After making some of the 15 projects in the starter kit, I made my first own project, an "Automatic Fish Feeder" or at least a prototype XD and I made a Sketch of it. All the components I use are from the Starter kit. Everything works well until the music start, the lcd screen display suddenly weird characters so I really don't know what's happening. There is my code, a picture of my project and a sketch I made with Fritzing. If you have questions or need anything to be able to help me, just ask Thanks!
Those pictures are way too big to be able to see what is happening. You need to resize them to no more than 1000 pixels wide.
Nothing to do with your code it is a hardware problem.
Looks like it is a power supply issue.
Try a decoupling capacitor on the LCD like you have on the servo. Also try a 100R resistor in series (in line ) with the buzzer.
Also, to try and debug this:
Comment out the servo write(s).
Some servos use too much power to power them from USB or from the Arduino.
If you aren't using the servo, does your display still get garbled ?
I tried a 220 Ohms (because I don't have 100 Ohms resistors in the starter kit) resistor in serie with the piezo as @Grumpy_Mike recommended me to try and it works like a charm now! Thanks for your help :D!
@floresta Yeah I made a mistake in my sketch, the pin 5 of my lcd screen goes to ground, not +5v. Sorry!
The piezo is highly capacitive. It is like tying an output to ground with a capacitor. Even worse is that you connected the piezo to Vcc instead of ground! When the output switches, it momentarily finds an almost short circuit as the capacitor charges, and draws the maximum current it can, causing deep transient on the power lines, internally to the chip if not externally. The resistor limits these impulses and resolves the problem
Notwithstanding the unfortunate examples in the Arduino tutorials, proper practice is to have the pushbutton going to ground whence you can use the internal pull-up function of the Arduino rather than an external resistor (which should if used, be nearer 4k7 than 220 ohms).
@Paul__B Thanks for your reply, it's really appreciated. Even if it's working I want to understand what was causing the problem!
The piezo is highly capacitive.
If I understand well, a capacitive component like the piezo will store and release energy in the circuit so the resitor helps to reduce those current variations.
Notwithstanding the unfortunate examples in the Arduino tutorials, proper practice is to have the pushbutton going to ground whence you can use the internal pull-up function of the Arduino rather than an external resistor (which should if used, be nearer 4k7 than 220 ohms).
I have to be honest, I'm not sure to understand entirely, I use a 10k resistor for the input of my pushbutton (even if in my sketch it's a 220 ohms resistor because I didn't found a 10k in fritzing) just like I learned in the Arduino projects book (in the Starter Kit). After a little reasearch about "Arduino pull-up function" and I found http://arduino.cc/en/Tutorial/DigitalPins in which I read "There are 20K pullup resistors built into the Atmega chip that can be accessed from software. These built-in pullup resistors are accessed by setting the pinMode() as INPUT_PULLUP. This effectively inverts the behavior of the INPUT mode, where HIGH means the sensor is off, and LOW means the sensor is on." but I don't understand how inverting the behavior could be useful in this circuit.
By inverting this behavior, you are making use of a (virtual, they aren't actually resistors and their value isn't exact) internal resistor in the chip.
It saves you external components and space for your design if you are going to build a project.
Because these internal resistors are only available as pull up, you have to connect the switch to GND.
When that switch is pressed it will win from the resistor and pull the level down.
So you then have to look for a LOW when the button is activated.
There is no other consequence and it will not be more difficult to the controller and the code.
You only have to get a grip of that, so it might require a little more thought for the coder (it won't hurt, i promise).
MAS3:
There is no other consequence and it will not be more difficult to the controller and the code.
There actually is another consequence beyond saving resistors.
If the pushbuttons are going to be at any distance from the main board, particularly if they are connected through cables and plugs, you really do not want to include your 5V power line in that wiring as it might accidentally be shorted to ground or one of the button wires might short to ground and short the power when that button is pressed. It might even be shorted to another power source.
If you extend the ground wires to the buttons instead, shorting anything to ground will at worst generate a spurious button press.
I noticed this problem can be easily fixed if you connect the piezo/buzzer ground directly to one of the three available Arduino ground pins, instead of using the ground row at the protoboard as the projects book says.