Pages: [1]   Go Down
Author Topic: usage of digitalRead()  (Read 494 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

I would like to jump in my function, if there is a contact on pin 7.
The client should call the following script on my web server:
Code:
http://192.168.1.10:81/index.php
The problem is that the Arduino reports also on my server if no one presses the button.
Did I made ​​a mistake in the implementation?


Greetings,
Philip


Code:
#include <SPI.h>
#include <Ethernet.h>

const int buttonPin = 7; // the number of the pushbutton pin
const int ledPin =  9; // the number of the LED pin

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x5D, 0x1C }; // mac addr. Arduino
byte ip[] = { 192, 168, 1, 31 }; // local IP Arduino
byte server[] = { 192, 168, 1, 10 }; // IP web server

EthernetClient client;

void setup()
{
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output     
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input:     
Ethernet.begin(mac, ip);
}

void loop()
{
if (digitalRead(buttonPin) == HIGH)
{
delay(1000);
digitalWrite(ledPin, HIGH); //LED on
   
if (client.connect(server, 81))
{
client.println("GET index.php");
client.println("User-Agent: Arduino");
client.println();
delay(1000);
while (client.available())
{
char c = client.read();
}
if (!client.connected())
{
client.stop();
}
}
else
{
//could not connect to IPS
}
}
else
{
digitalWrite(ledPin, LOW); //LED off

}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is your button connected?
Do you have a pulldown resistor?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

I've attached my diagram.
I don't use the LED.

Source:
http://www.katun.ch/2011/02/01/diy-turklingel-push-notification-fur-das-iphone/


* Doorbell.png (36.58 KB, 615x450 - viewed 24 times.)
« Last Edit: February 19, 2013, 06:29:26 am by pberndro » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 636
Posts: 50279
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Get rid of the resistor. Use the internal pullup resistor, instead. Connect one side of the switch to the digital pin. Connect the other side to ground.

Code:
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input:
        digitalWrite(buttonPin, HIGH); // Turn on pullup reistor

Then, HIGH will be released, and LOW will be pressed.
Logged

Pages: [1]   Go Up
Jump to: