Hello every1 i try to make a project for my univercity and i have a few questions.My project is that i controll a plug outlet by a web page.I use arduino-0022 and i have put this code on the arduino UNO:
#include <SPI.h>
#include <WString.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 240 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(80); //server port
int speakerPin = 2; // speaker connected to digital pin 9
int ledPin = 8; // LED pin
int inputPin3 = 3; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
boolean LEDON = false; //LED status flag
String readString = String(30); //string for fetching data from address
void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(ledPin, OUTPUT);
pinMode(inputPin3, INPUT); // declare pushbutton as input
Serial.begin(9600);
pinMode(speakerPin, OUTPUT); // sets the speakerPin to be an output
}
void loop(){
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 30)
{
readString.concat(c); //store characters to string
}
if (c == '\n') { //if HTTP request has ended
ledstatus(); //LED Status Sub
htmlcontent(); //LED Html Content Sub
readString=""; //clearing string for next read
client.stop(); //stopping client
delay(100);
}
}
}
}
}
void htmlcontent(){
Client client = server.available();
client.println("HTTP/1.1 200 OK"); // now output HTML data starting with standart header
client.println("Content-Type: text/html");
client.println();
client.print("");
client.println("Activate Outlet
");
client.print("Outlet status: ");
if (LEDON)
client.println("ON");
else
client.println("OFF");
client.println("
");
client.println("");
}
void ledstatus(){
if(readString.equalsIgnoreCase("L=1")) //lets check if LED should be lighted
{
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = true;
}else{
digitalWrite(ledPin, LOW); // set the LED OFF
LEDON = false;
}
}
and my problem is that i try to controll a ssr relay drom arduino to enable outlet,but i think that i need a tranzistor...but i dont know what type of tranzistor i need and how to conect in the way from arduino to relay.