Some pins always output 5V no matter what, what's going on here?

Hi,

I'm having a hard time making my first project work and i've encountered a few remarkable and confusing things which i cannot figure out.
The soldering and the programming are done, and i'm currently in the testing phase.
The project is an arduino fan controller with an LCD display which is built-in in my PC's DVD Bay.
It monitors the current(and thus power in watts) from the wall outlet to the PSU, the 12 and 5V voltages, the (3)fan speeds, and 2 temps, and prints these values to the LCD and the Serial monitor along with other info.
Based on the temps, it regulates the fans. There's also a possibility for manual fan control and a switch which toggles the lighting which is built-in in the case.
There's a piëzo buzzer attached which gives a warning when voltages or temps exceed their limits. There's two buttons for additional user input, and a separately manually controlled sidefan.
To manually control the case fans and the sidefan, i've used a construction of two switches for both of them, shown in the picture attached below.
This way these two constructions return 00, 01, 10, or 11 to the arduino.

I've first tested my code with the arduino hooked on usb with only the lcd attached.
Because nothing was attached the values were floating and made no sense, but it worked fine.
So i built it in and powered it on but i got the following problems right away:
-Fans were blazing at full speed
-Lighting went on while the switch was off
-Arduino doesn't react to any attached switch or button input.

So i started to troubleshoot the thing, and i measured 5V on each digital pin (also on input configured pins) and on one analog pin.
Except for pins 6 and 7 these are 0V, pin 10 is 1.2V, pin 1 fluctuates between 5 and 3V.
I used the AVS712 for current measuring but i found out it doesnt work well with AC current without some extra circuitry.
This is the only thing i can think of that could have damaged the arduino.
While these voltages on the pins could be signs that the arduino is damaged, it still works quite well;
I do have correct temperature and voltage readings on the lcd as well as on the serial, and i can still upload stuff to the arduino.

I have used pull ups and downs always where necessary i believe, i've tied all grounds together, and i have checked all the mosfet's, resistors, and diods before placing them.
What could possibly be going wrong here? And how can i solve this problem?

A very big thanks and kudos to anyone who can help me with this.

The schematic and the code (370 lines) are attached below.
Couldn't post the code within this post due to charachter limit.

controller_simpleForum.ino (13.8 KB)

370 lines of code is a bit for us/me to wade through this time of day.
Can you cut that down to less than 50 lines, that still has a problem?

If you have pullup resistors, then you may expect to get 5volts on those resistors.

You have external pulldowns and enable internal pullups in the sketch. Why?

Pins 0 and 1 are used by Serial (unless you have a Leonardo).

You seem to have SCL and SDA going through resistors. I think those are supposed to be pull-up resistors.

SCL and SDA on the Arduino UNO are the same as A4 and A5 which you appear to be using for analog inputs. You can't have it both ways.

If you don't mind the reversed logic (HIGH means switch open, LOW means switch closed) you can get rid of a lot of external pull-down resistors by using the internal pull-up resistors and have the switch connect the pin to Ground.

To all, thanks for your time and your reaction,

Yeah sorry i know, but i cannot think of any bug in the code that could cause this kind of problem.. :s
I think i should rather look for the problem in the pull ups/my wiring like you said.

But it shouldn't be possible for a pin to output 5V when it's configured as an input right?
Or for analog pins?
Even with internal pullups are enabled, because then it'd alway read a high.
And that's the case, because my fans start blazing at full speed right after i plug in my arduino.

But the strange thing is also I measure these voltages when i have detached my arduino from everything.
So that'd mean it doesn't have anything to do with the wiring, this leaves the code as the cause for the problem. But like i said i don't understand how input configured pins can output 5V.

Could it be that the device is, like, half broken ore something?

oqibidipo:
You have external pulldowns and enable internal pullups in the sketch. Why?

Pins 0 and 1 are used by Serial (unless you have a Leonardo).

To be sure i don't draw too much current i also use external pull ups. Could this be a cause for my problem in any way? And as i said in my reaction to @jack wp i also measure these voltages when i have my arduino detached from everything. I haven't actually used and connected pins 0 and 1 yet, and i'll keep it that way if you say these pins are reserved for serial communication.

johnwasser:
You seem to have SCL and SDA going through resistors. I think those are supposed to be pull-up resistors.

SCL and SDA on the Arduino UNO are the same as A4 and A5 which you appear to be using for analog inputs. You can't have it both ways.

If you don't mind the reversed logic (HIGH means switch open, LOW means switch closed) you can get rid of a lot of external pull-down resistors by using the internal pull-up resistors and have the switch connect the pin to Ground.

You mean i can't use both sda & scl and A4 & A5 both at the same time? That's a pity :frowning:
but thanks for mentioning it. The lcd on sda and scl, and pin A4 do work however, only pin A5 doesn't work.
The arduino freezes when i plug in the sensor. Can I switch between them softwarematically somehow?

I get the reversed logic, but i dont understand how this can solve the problem. If it's only to reduce the number of resistors used i'll keep it this way, and it saves time for rewiring things. However, if it can solve the problem i'm eager to hear how you think i could solve the problem, i suppose that would take more than only "reverse" those switches?

You mean i can't use both sda & scl and A4 & A5 both at the same time? That's a pity :(
but thanks for mentioning it. The lcd on sda and scl, and pin A4 do work however, only pin A5 doesn't work.
The arduino freezes when i plug in the sensor. Can I switch between them softwarematically somehow?

SDA/A4 and SCL/A5 are the same. You cannot use them for different functionality at the same time. See the schematics of Arduino. The reason for duplicity was to have I2c at the same specific place for different Arduinos to be usable by the same shields.

Budvar10:
SDA/A4 and SCL/A5 are the same.

Thanks, that's clear to me now. But it won't solve the problem having 5V output on almost every digital pin unfortunately.. :frowning: I suppose the best way to have more analog inputs is to use a extender/multiplexer or whatever?..

An input with the internal pull-up enabled will read as 5V. You are reading the pull-up.

It looks like you have run out of pins. You may want to migrate to the Arduino MEGA 2560.

I have perceived now that there is incorrect I2C connection in the schematics. The resistors 4k7 on SCL,SDA should be connected as pull-up not between devices. Arduino and LCD have to be connected directly. It is a bus so more devices can be connected on it.

johnwasser:
An input with the internal pull-up enabled will read as 5V. You are reading the pull-up.

It looks like you have run out of pins. You may want to migrate to the Arduino MEGA 2560.

Oh okay. Then i should disable those internal pull ups and it will solve the problem i guess. I guess i didn't correctly understand the exact working of a pull up, and I think i'm beginning to figure out what the problem is.. XD
And yeah i'm desperatly in need for more pins, but i was thinking of an i2c ADC and a bit shift register to hook onto the arduino. It'd be a lot cheaper. Can you recommend me on how i should approach this? You've also pointed me in the right direction to solve my problem, so thanks for that! :thumbs up:
Oh and sorry for my poor english..

Budvar10:
I have perceived now that there is incorrect I2C connection in the schematics.

I see that now.. I didn't correctly understand the working of a pull up i see, and i bet my problem is solved once i correct that.
Thanks for noticing and pointing me to the solution!

TR_7:
It'd be a lot cheaper.

Hmm? Mega clones are like $8-10 with CH340G serial, $12ish with 16U2 like the official one. (I prefer the CH340G) - they hardly break the bank; no need to make things hard on yourself.

Consider to use digital temperature sensors instead of analog. DS18B20 1-wire bus sensors are frequently used. It will require just 1 digital pin for all sensors. You can also connect the swithes for fan speed etc. via i2C device, same as for LCD (e.g. based on PCF8574 chip).

DrAzzy:
Hmm? Mega clones are like $8-10 with CH340G serial, $12ish with 16U2 like the official one.

Although not by much it's still more expensive. And those clones are ~$20 if get them shipped to my country. But you're right it's way easier and it'd be silly if i'd make things hard for myself, but it'd still do it for the purpose of learning :stuck_out_tongue:
So that's why i've bought a mega clone and also e few i/o expanders and other IC's alike.

Budvar10:
Consider to use digital temperature sensors instead of analog.

That's a great advice, i'm still discovering what is possible with the arduino and sensors because i started with arduino just a few weeks ago. I've added those digital temp sensors to my order list already :slight_smile:

As for the buttons, it's not really possible for me because is use bulky buttons from an old jaguar, for their nostalgic look and they're built in my pc case. but i certainly appreciate the idea and i'll keep it in mind for future plans/projects. Thanks for the help

I am recommending to you go throughout your project step by step, not all things at once. It should be not a problem to find an appropriate solution for each part of your project here on this website and test it.
About the switches. If they are simple switches and it looks that they are, it should not be a problem to connect them behind the I2C device. Similar like for LCD another I2C device should serve the switches but digitally. One switch per I/O and to read the status 0 or 1.
I have another idea about the transistors. There is not exact type in schematic but consider to replace the transistors with the single IC ULN2803 e.g.