Project 15 Hacking BUTTON


I wanted to start project 15 in arduino starter kit. THe problem is I don't have anything to hack.
So, I though about hacking a push button.

const int optoPin  =   2;
const int pushButtonPin = 7;

int pushButtonValue;
void setup() {
  // put your setup code here, to run once:
pinMode(optoPin, OUTPUT);
pinMode(pushButtonPin, INPUT);


void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(optoPin, HIGH);
digitalWrite(optoPin, LOW);

I tried to test the output of this code. I get 0 0 0 0 0 0 0 0 .
I was expecting 1 0 1 0 1 0 .

I guess the hacking of the push button attempt was failed.

Any idea why is that ? or my code is wrong or the setup i have is wrong ?

Any idea what is going on ?

Derp! Ignore my first "answer"....

I'm saddened to see that something as far in as Project 15, the last project if the Starter Kit page is right, is still using delay().

In any case ... are you pressing the button? Can you post a schematic of what you've connected?

Do you have a pullup resistor on pin 7?

I have pull down resistor connected to the ground.

I took a snap shot of the setup i have.

So when i press the button i get a reading of 1 as expected.

The aim of the project 15 was to use an external source to get the button pushed. --< that what i understood.

Thanks again for reading and trying to help

OK, I think I get it. The aim of the project is to show that an optoisolator can turn a button on and off.

Which Optoisolator are you using? Both the input and output sides are polarity sensitive, unless the output is a triac, in which case it probably won't work with that low a voltage.

I presume this is an optoisolator included in the kit. Check your wiring again for proper polarity.


The wiring was the issue....

Problem solved you are right it is polarity sensitive. I need to connect PIN 5 to ground. ALWAYS.
I also has pin one not connect to anything.

I fixed the wiring and it work fine now.
thanks again guys