Arduino Forum

Products => The Arduino Starter Kit and Basic Kit => Topic started by: uaefame on Jun 24, 2014, 05:18 am

Title: Project 15 Hacking BUTTON
Post by: uaefame on Jun 24, 2014, 05:18 am
Hello,

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.

Code: [Select]
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);
Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(optoPin, HIGH);
pushButtonValue=digitalRead(pushButtonPin);
Serial.println(pushButtonValue);
delay(10);
digitalWrite(optoPin, LOW);
pushButtonValue=digitalRead(pushButtonPin);
Serial.println(pushButtonValue);
delay(1000);
}


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 ?
Title: Re: Project 15 Hacking BUTTON
Post by: polymorph on Jun 24, 2014, 06:03 am
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?
Title: Re: Project 15 Hacking BUTTON
Post by: polymorph on Jun 24, 2014, 06:09 am
Do you have a pullup resistor on pin 7?
Title: Re: Project 15 Hacking BUTTON
Post by: uaefame on Jun 25, 2014, 05:21 am
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
Title: Re: Project 15 Hacking BUTTON
Post by: polymorph on Jun 25, 2014, 05:56 am
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.
Title: Re: Project 15 Hacking BUTTON
Post by: uaefame on Jun 25, 2014, 03:45 pm
Thanks,

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