hello,
I am quite new for Arduino. Currently I am doing a projet that is to use Arduino Ethernet Shield and Duemilanove 328 as webserver to control 8 relays (used 4 LEDs for testing) and 1 mini servo.
4 LEDs are attached to pin 2-8 and A0, mini servo is attached to pin 9. The sketch is made up from several projects found from internet. But, anyway, finally it works. Serial Port will print the dynamic IP. Then put the ip to browser, I can control the LEDS on/off and swivel the servo.
The problem is : the LEDs will be off and servo will turn an angle if I close the Serial Monitor Even the servo will move and 4 leds close to RJ45 socket will off for less 1s then on when I move the cursor over Tools. Does anyone know this problem? I made video in Youtube, please have a look.
I don’t think this is the sketch’s problem, but I will put here, sorry for my poor programming skills.
//ARDUINO 1.0+ ONLY
#include <Ethernet.h>
#include <SPI.h>
#include <Servo.h>
boolean reading = false;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xBD };
EthernetServer server = EthernetServer(80); //port 80
////////////////////////////////////////////////////////////////////////
String inString = String(35);
Servo radio; // creat subject to control the radio
String Vhf1;
String Vhf2;
String Vhf3;
String Vhf4;
String Uhf1;
String Uhf2;
String Uhf3;
String Uhf4;
int VHF1 = 14; // Analog input used as Digital I/O A0=14..........A5=19
int VHF2 = 2;
int VHF3 = 3;
int VHF4 = 4;
int UHF1 = 5;
int UHF2 = 6;
int UHF3 = 7;
int UHF4 = 8;
String value1="on";
String value2="on";
String value3="on";
String value4="on";
String value5="on";
String value6="on";
String value7="on";
String value8="on";
String data;
void setup(){
Serial.begin(9600);
radio.attach(9); //attach pin 9 to servo to control radio
//Pins 10,11,12 & 13 are used by the ethernet shield
pinMode(VHF1, OUTPUT);
pinMode(VHF2, OUTPUT);
pinMode(VHF3, OUTPUT);
pinMode(VHF4, OUTPUT);
pinMode(UHF1, OUTPUT);
pinMode(UHF2, OUTPUT);
pinMode(UHF3, OUTPUT);
pinMode(UHF4, OUTPUT);
Ethernet.begin(mac);
//Ethernet.begin(mac, ip, gateway, subnet); //for manual setup
server.begin();
Serial.println(Ethernet.localIP());
}
void loop()
{
EthernetClient client = server.available();
if(client){
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if(client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (inString.length() < 35) {
inString.concat(c);
}
if (c == '\n' && current_line_is_blank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html><body><form method=get>");
client.println(" <font size=\"7\">Ground Station</font>
");
client.println("
<b><font size=\"4\">Radio On/Off</font></b>
<button name=\"radio\" value=\"5\">Push</button>");
if (inString.indexOf("radio")> 0 ){
radio.write(150);
delay(1200);
Serial.println("radio on");
}else{
radio.write(80);
}
client.println("
<font size=\"6\">Polarisation Switch Controller</font>
<b><i><font color=red><font size=\"5\">Warning: Only ONE switch can be ON for each band</font></font></i></b>
<b><font size=\"4\">VHF</font></b>
");
//for(int i=1;i < (4 + 1) ;i++){
//Vhf = String("VHF") + i;
Vhf1 = String("VHF1") ;
Vhf2 = String("VHF2") ;
Vhf3 = String("VHF3") ;
Vhf4 = String("VHF4") ;
if(inString.indexOf(Vhf1+"=on")>0 ){
Serial.println(Vhf1+"on");
//digitalWrite(VHF[i], HIGH);
digitalWrite(VHF1, HIGH);
value1 = "off";
}else if(inString.indexOf(Vhf1+"=off")>0 ){
Serial.println(Vhf1+"off");
//digitalWrite(VHF[i], LOW);
//value[i] = "on";
digitalWrite(VHF1, LOW);
value1 = "on";
}
if(inString.indexOf(Vhf2+"=on")>0 ){
Serial.println(Vhf2+"on");
//digitalWrite(VHF[i], HIGH);
digitalWrite(VHF2, HIGH);
value2 = "off";
}else if(inString.indexOf(Vhf2+"=off")>0 ){
Serial.println(Vhf2+"off");
//digitalWrite(VHF[i], LOW);
//value[i] = "on";
digitalWrite(VHF2, LOW);
value2 = "on";
}
if(inString.indexOf(Vhf3+"=on")>0 ){
Serial.println(Vhf3+"on");
//digitalWrite(VHF[i], HIGH);
digitalWrite(VHF3, HIGH);
value3 = "off";
}else if(inString.indexOf(Vhf3+"=off")>0 ){
Serial.println(Vhf3+"off");
//digitalWrite(VHF[i], LOW);
//value[i] = "on";
digitalWrite(VHF3, LOW);
value3 = "on";
}
if(inString.indexOf(Vhf4+"=on")>0 ){
Serial.println(Vhf4+"on");
//digitalWrite(VHF[i], HIGH);
digitalWrite(VHF4, HIGH);
value4 = "off";
}else if(inString.indexOf(Vhf4+"=off")>0 ){
Serial.println(Vhf4+"off");
//digitalWrite(VHF[i], LOW);
//value[i] = "on";
digitalWrite(VHF4, LOW);
value4 = "on";
}
Uhf1 = String("UHF1") ;
Uhf2 = String("UHF2") ;
Uhf3 = String("UHF3") ;
Uhf4 = String("UHF4") ;
if(inString.indexOf(Uhf1+"=on")>0 ){
Serial.println(Uhf1+"on");
//digitalWrite(VHF[i], HIGH);
digitalWrite(UHF1, HIGH);
value5 = "off";
}else if(inString.indexOf(Uhf1+"=off")>0 ){
Serial.println(Uhf1+"off");
//digitalWrite(VHF[i], LOW);
//value[i] = "on";
digitalWrite(UHF1, LOW);
value5 = "on";
}
client.println("
<input type=submit name="+Vhf1+" value="+value1+">Horizontal");
client.println("
<input type=submit name="+Vhf2+" value="+value2+">Vertal");
client.println("
<input type=submit name="+Vhf3+" value="+value3+">RHCP ");
client.println("
<input type=submit name="+Vhf4+" value="+value4+">LHCP");
client.println("
<b><font size=\"4\">UHF</font></b>
");
client.println("
<input type=submit name="+Uhf1+" value="+value5+">Horizontal ");
client.println("
<input type=submit name="+Uhf2+" value="+value6+">Vertal ");
client.println("
<input type=submit name="+Uhf3+" value="+value7+">RHCP ");
client.println("
<input type=submit name="+Uhf4+" value="+value8+">LHCP");
client.println("</from></html></body>");
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
inString = "";
client.stop();
}
}