Ethernet shield sensitive digital input help

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Ethernet shield sensitive digital input help

Postby Daz23079 » Sat Mar 17, 2012 11:42 am

Need help i have just set up a arduino mega with ethernet shield to send twitter with four digital inputs but it keeps looping as soon as i touch a wire going in to one of the digital inputs or if i connect a digital in to an empty bread board it just seems realy sensitive is there a way around this or have i got a dodgy ethernet shield ?
Daz23079
 
Posts: 4
Joined: Sat Mar 17, 2012 11:14 am

Re: Ethernet shield sensitive digital input help

Postby adafruit_support_bill » Sat Mar 17, 2012 11:46 am

Do you have pull-up or pull-down resistors on your digital inputs? Does your code handle debouncing?

See Tutorial #5 for details on these topics. http://www.ladyada.net/learn/arduino/lesson5.html
User avatar
adafruit_support_bill
 
Posts: 15954
Joined: Sat Feb 07, 2009 9:11 am

Re: Ethernet shield sensitive digital input help

Postby Daz23079 » Sat Mar 17, 2012 11:57 am

Sorry i am new to this but the pins are set high
Daz23079
 
Posts: 4
Joined: Sat Mar 17, 2012 11:14 am

Re: Ethernet shield sensitive digital input help

Postby Daz23079 » Sat Mar 17, 2012 12:26 pm

This is the sketch i am using i wish to use basic relays to switch the inputs 2,3,4,5 can you help or modify the sketch please thanks



[Edit - moderator - use code button to submit large blocks of code]

Code: Select all
// necessary libraries
#if defined(ARDUINO) && ARDUINO > 18   // If using Arduino 0019 or later, include SPI.h
#include <SPI.h>
#endif
#include <Ethernet.h>
#include <EthernetDNS.h>
#include <Twitter.h>

// our event messages
char b1[]="one";
char b2[]="two";
char b3[]="three";
char b4[]="four";

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // create MAC address for ethernet shield
byte ip[] = { }; // choose your own IP for ethernet shield
byte gateway[] = {  }; // your network gateway
byte subnet[] = { 255, 255, 255, 0 }; // your network subnet

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("aaaaaaaa");
// replace aaaaaaa with your token
// ***********************************************************************************************

void setup()
{
  delay(5000);
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
}
 
void tweet(char msg[])
{
  Serial.println("connecting ...");
  if (twitter.post(msg)) {
    int status = twitter.wait(&Serial);
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }
}

void loop()
{
  if (digitalRead(2)==HIGH)
  {
    tweet(b1);
    delay(2000);
  }
  if (digitalRead(3)==HIGH)
  {
    tweet(b2);
    delay(2000);
  }
  if (digitalRead(4)==HIGH)
  {
    tweet(b3);
    delay(2000);   
  }
  if (digitalRead(5)==HIGH)
  {
    tweet(b4);
    delay(2000);   
  }
}
Daz23079
 
Posts: 4
Joined: Sat Mar 17, 2012 11:14 am

Re: Ethernet shield sensitive digital input help

Postby adafruit_support_bill » Sat Mar 17, 2012 3:27 pm

the pins are set high

How?
i wish to use basic relays to switch the inputs 2,3,4,5

Relays are like switches in many ways. First, you need a pullup or pulldown resistor to keep the pin from 'floating'. Second, the contacts may 'bounce' as they close. This can appear to your sketch as a series of rapid opening an closing of the contacts.

Read through Tutorial #5. All the basic concepts regarding button/switch input apply to relays as well.http://www.ladyada.net/learn/arduino/lesson5.html
User avatar
adafruit_support_bill
 
Posts: 15954
Joined: Sat Feb 07, 2009 9:11 am


Return to General Project help

Who is online

Users browsing this forum: Google [Bot], huatian and 5 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
Android[6]
 
BeagleBone[24]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]