Pages: [1]   Go Down
Author Topic: Project 15 Hacking BUTTON  (Read 1403 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 ?
Logged

Lacey, Washington, USA
Offline Offline
Edison Member
*
Karma: 162
Posts: 2439
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Steve Greenfield AE7HD
CET Consumer Electronics and Computer
Please don't read your attitudes into my messages

Lacey, Washington, USA
Offline Offline
Edison Member
*
Karma: 162
Posts: 2439
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have a pullup resistor on pin 7?
Logged

Steve Greenfield AE7HD
CET Consumer Electronics and Computer
Please don't read your attitudes into my messages

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* photo.JPG (141.01 KB, 640x480 - viewed 45 times.)
Logged

Lacey, Washington, USA
Offline Offline
Edison Member
*
Karma: 162
Posts: 2439
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Steve Greenfield AE7HD
CET Consumer Electronics and Computer
Please don't read your attitudes into my messages

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: