Hi,
I am a pretty inexperienced arduino/electronics guy.
I am currently trying to set up a turnstile monitoring system. Fairly easy setup. as the turnstile already had a relay that I can connect to. Everything seemed fine during development and dry testing ( on my desk ). But when I installed it on the turnstile, I encountered a problem that the arduino even though configured with a static IP address would boot up without IP address. Was wondering if someone could help me with this and explain what I have done wrong.
So I am using a Uno with an ethernet shield.
Wiring is simple. I put a cable from the 5v pin to the relay and then from the relay back to pin 13. Then I added a 10k resistor from pin 13 to GND. Note: I have tried other pins and have the same problem.
I narrowed the problem down, that the relay is an always open relay. so as soon as I wire up the arduino, the 5v is connected to pin 13. If I disconnect the 5v from the relay, boot up the arduino and then connect the 5v again to the relay it works perfectly fine.
The reason why I say that the arduino doesn't have an IP is because I output the IP on the serial console.
Here is the code that I am using.
#include <SPI.h>
#include <Ethernet.h>
const int TURNSTILE = 5;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 };
IPAddress dnServer(8, 8, 8, 8);
//TEST NETWORK
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress ip(192,168,1,105);
//LIVE NETWORK
//IPAddress gateway(10, 0, 0, 1);
//IPAddress subnet(255, 255, 255, 255);
//IPAddress ip(10,0,0,108);
const int buttonPin = 13;
String PATH_NAME = "/somescript.php?t=";
int HTTP_PORT = 80;
String HTTP_METHOD = "GET"; // or POST
char HOST_NAME[] = "some.domain.com";
EthernetClient client;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = millis();
unsigned long debounceDelay = 40;
unsigned long lastTime = millis();
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
// initialize the Ethernet shield using DHCP:
Ethernet.begin(mac,ip,dnServer,gateway,subnet);
delay(100);
Serial.println(Ethernet.localIP());
Serial.println("connected");
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
recordEntry(TURNSTILE);
}
}
}
lastButtonState = reading;
}
void recordEntry( int turn) {
if(client.connect(HOST_NAME, HTTP_PORT)) {
Serial.println(HTTP_METHOD + " " + PATH_NAME + turn + " HTTP/1.1)");
client.println(HTTP_METHOD + " " + PATH_NAME + turn + " HTTP/1.1");
client.println("Host: " + String(HOST_NAME));
client.println("Connection: close");
client.println();
}
}
Can anyone point out what I am doing wrong? Why does the arduino not boot up if there is 5V to the pin I am using?
Thanks