Go Down

Topic: Project 15 Hacking BUTTON (Read 1 time) previous topic - next topic

uaefame

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 ?

polymorph

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?
Steve Greenfield AE7HD
Nick Gammon on multitasking Arduinos:
http://gammon.com.au/blink
http://gammon.com.au/serial
http://gammon.com.au/interrupts

polymorph

Do you have a pullup resistor on pin 7?
Steve Greenfield AE7HD
Nick Gammon on multitasking Arduinos:
http://gammon.com.au/blink
http://gammon.com.au/serial
http://gammon.com.au/interrupts

uaefame

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

polymorph

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.
Steve Greenfield AE7HD
Nick Gammon on multitasking Arduinos:
http://gammon.com.au/blink
http://gammon.com.au/serial
http://gammon.com.au/interrupts

uaefame

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

Go Up