Multiple Buttons on analog; problematic when using VIN

Hello there!

I'm having some trouble with my project and hope you can help me. The project is basically a light and sound hub for dollhouse furniture. Connect some lights and they light up, press a button on a device (e.g. washing machine) and hear the correspondend sound.
For this project I'm using an Arduino nano and dfplayer mini & speaker for the sound.
There will be 21 connectors, which can be used to either plug in a light or a device which will make sound. The lights are directly connected to +5v and ground. The sound devices are connected to +5v and A1. This is being achieved by using headphone sockets and plugs which have 3 individual pins (in my case, +5v, ground and the one connected to the analog input) There are different resistors in each device and if you press the button on it, the respective analog value is being read and the right sound being played.
So far, so good. It works fine until I change the power source. Since I want to use the full 2000mA of the USB power supply, I cant run it through the Arduino. So therefore a USB socket is used to power everything, including the Arduino via VIN.
This is where it becomes problematic. If I run the power directly through the Arduino the reading of the analog values works fine, but if I change it to the USB socket I always receive the same reading of 1023.
So before I had values between 20-1000 depending on the resistor but now as mentioned before every resistor results in 1023. The analog input is connected to ground via a 100k resistor.
I hope you can help me what I could change to get proper analog readings.

Thank you!

Post real wiring diagrams.Those poetry type descriptions are not useful.

I'm no expert in drawing these up, I hope it is still clear enough

Rather well done! What is that thing, a right arrow in a circle? Some kind of power source. What voltage, what current capacity?
That source goes to Nano Vin and Vcc on the DFP.
I don't know the Nano that well. Does it run on the 3.3 volt level? Then connecting a 5 volt device like the DFP is not good.
The 4 buttons are wired to Vin. That looks bad to me. Too high voltage will be passed to A1.
The magnitude of the resistors is a bit too high. Cut down the values to one half or one tenth.

The Arduino ADC is ratiometric, i.e. voltage dividers should use the ADC reference voltage (5V), not any other voltage (Vin...).

@Railroader
Ok, so the circle with the arrow is the power source, +5v from a usb powerbank (max 2A). According to the specs the Arduino can be powered via the VIN port with +5v. The resistors on the lower left are just arbitrary, they represent the different buttons with a resistor connected to each button. Once a button is being pushed, the 5v runs through the resistor into the A1 Analog port. They are not connected to the VIN port

@DrDiettrich
I dont really understand what you mean.

You can’t use Vin and connect the same supply to the analog inputs .

Vin feeds a regulator , dropping a couple of Volts to the Arduino itself , and providing a reference for the analog inputs.
So if you use a 5v power supply the Arduino will be trying to operate at about 3.3v , and the analog reference voltage will be 3.3v , so your input voltage will read high (1023) as they are above the maximum span of the analog inputs ( and you may damage the processor ). IF you have a stable 5v supply , power the Arduino with the 5v pin.

( the usb powers the Arduino at 5v, and sets the analog reference to 5v too ).

I would rather use digital
Inputs for this job using a port expander, or shift register .

5 volt from USB is not passing Vin, can be tapped at the +5 volt pin. Don't connect to Vin as Your wiring diagram tells.
Does the Nano supoort "INPUT_PULLUP"? In that case connect the buttons between a digital input and GND, and drop the resistors.

@hammy

Thanks! that clears things up. So if I understand you right, I can use the +5v Pin on the Nano as a power input and not only as a power supply? Did not know that!
I guess the 5v from a USB power source are stable...

Can you explain how you would use digital?

Digital input..... button = digitalRead(D-pin);
When the buttons is pressed a LOW level is read. Not pressed, a HIGH level is read.

@Railroader

The reason why I want to use the analog Input for the buttons is because I want to use only 1 input for e.g. 10 buttons. This is because there are in total 21 sockets and the user should be able to plug a device in any of the 21 sockets and the button will cause it to play the right sound. So all 21 sockets are connected to the 1 analog input. Obviously, only one push of a button can be detected at once, but thats no problem.
If I use digital inputs this wont work I think. It needs to diffentiate between the different buttons which are all connected to the same input. This can only work with different resistors I think.

Okey, You use different values for the button resistors. I missed that! My fault.

Ok so I changed to power supply pin from VIN to +5V but still the analog value read is 1023...

Reduce the 100 kOhm to 47 kOhm, or 27 kOhm.

I think I got it to work now, the resistor I used for the first test after switching to +5v as power input was 10ohm, which was probably just too low to show any impact on the reading. I used a 3.3 k ohm resistor next and the reading is lower than 1023... so i think its working! Still, if you have any recommendations on how to achieve my project goals in a better/ smoother way I am very interested in that :slight_smile:

Use Ohms law to calculate what voltage each button will bring to A1!
Maybe You can update Your wiring with actual resistor values and post it again?

Port expander stuff :