Go Down

Topic: usage of digitalRead() (Read 552 times) previous topic - next topic

pberndro

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: [Select]
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: [Select]
#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

}

AWOL

How is your button connected?
Do you have a pulldown resistor?
"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.

pberndro

#2
Feb 19, 2013, 12:27 pm Last Edit: Feb 19, 2013, 12:29 pm by pberndro Reason: 1
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/

PaulS

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: [Select]
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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy