binary to bcd converting output error need help asap

I am trying to take 8 bit binary input from dip switch 8 and output as bdc. But its not properly working for some reason. Some pins (which should give 0 volt) giving 1-3 volts not 0 or 5 volt. Dont know why this is happening. It should be either 0 or 5 volts. I have tried on 2 different arduino uno both same result. So i am not getting the exact result :frowning: Can anyone tell me what i am doing wrong?

converter_final.ino (5.41 KB)

 pinMode(A0, INPUT);
 pinMode(A1, INPUT);
 pinMode(A2, INPUT);
 pinMode(A3, INPUT);
 pinMode(A4, INPUT);
 pinMode(A5, INPUT);
 pinMode(2, INPUT);
 pinMode(3, INPUT);

Change those to INPUT_PULLUP so they are pulled high when your switches are not connecting them to Gnd,

well using INPUT_PULLUP giving me fixed 0010 0110 0110 fixed output. Dosen't matter what the input is :(

I haven't looked at your code, but I find it truly remarkable that you have managed to get a twelve bit reading out of eight bits of input. disregarding that as an indication of your coding ability, then you must have a bad dip switch, or bad wiring. gives you three places to look...

Why not simplify? Looks to me that you do just do this:

digitalWrite (opin[0], digitalRead(ipin[0]);
digitalWrite (opin[1], digitalRead(ipin[1]);
digitalWrite (opin[2], digitalRead(ipin[2]);
digitalWrite (opin[3], digitalRead(ipin[3]);

digitalWrite (opin[0], digitalRead(ipin[4]);
digitalWrite (opin[1], digitalRead(ipin[5]);
digitalWrite (opin[2], digitalRead(ipin[6]);
digitalWrite (opin[3], digitalRead(ipin[7]);

digitalWrite (opin[6], digitalRead(ipin[8]); // add 2, 3, to ipin[]
digitalWrite (opin[7], digitalRead(ipin[8]);

@CrossRoads Thanks mate. Your solution INPUT_PULLUP worked. I had to change the circuit a bit and put ground insted of vcc one the other side or the dip switches. :D

and the code is to convert binary to bcd. like if you input 11111111 it will output 0010 0101 0101. So i didnt do that as it wouldnt work. But i still dont understand y it output 1-2 volts even when the digital output set to LOW. :(

Show us a good schematic of your circuit. Show us a good image of your wiring.


You are getting good levels now tho? Maybe you had Vcc/Gnd shorts with the inputs connected direct to +5. INPUT_PULLUP and connecting to Gnd are always recommend to avoid that issue.

I see what you are doing now, converting 2 hex characters to 3 decimal representations. Clever. Little hard to see that from just the code.

ya now the output is perfect (0v for LOW and 5V for HIGH). All i did was use INPUT_PULLUP instead of INPUT and connect GND instead of VCC on the other side of Dip switches. No i didnt have any short circuits. Even there was no input connected, the output should be 0000 0000 0000 but some pins were giving like .5v to 3v random. I cant figure it out why it behaved like that? But after the change it was giving perfect result.

Hi, When you declare a pin as an input, it has to be connected to 0V or 5V, if its left open, it will do what is called float, that is assume any arbitrary value depending on any electric charge that is around it.

Your initial circuit would have switched an input to 5V when ON, but left the input OPEN when OFF, the input may have stayed at the ON voltage potential.

The Arduino has a facility where you can turn ON some resistors in the IC that connects the input to 5V. So you place your switches from the input to 0V, now when the switch is closed the input is at 0V, when the switch is OPEN the input is pulled to 5V by the resistor.

This way you can only have 0V = LOW = logic 0 and 5V = HIGH = logic 1

Tom... :)