Irina's Atelier

Happy New Year :)

Home automation with EthernetShield

  • arduino_story_01

    This post is about boiler remote control.It is connected to temperature/ humidity sensor and arduino.

    Operation method

    • It has to set the status of pin or status of servo(0 or 90) and you push the Update button.
      you see current light value/ temperature/ humidity.
    • It connected to len cable, it allows access from the outside on the router using port forwarding setting.
    • It receive and transmit the URL GET method in HTTP.

    The original post can’t see except member of site
    arduino_story_02

    Hardware Components

    • Arduino Uno
    • Ethernet Shield
    • DHT22
    • Temperature sensor
    • Servo

    Software Components


    #include
    #include
    #include
    #include

    byte mac[] = {0x90,0xa2,0xda,0x0e,0xf7,0xfc};
    byte ip[] = {192,168,0,30};
    EthernetServer server(80);
    Servo myservo;
    dht DHT;

    //pin state
    int numPins = 5;
    int pins[] = {3,4,5,6,7};
    int pinState[] = {0,0,0,0,0};
    char line1[100];
    //servo
    int servoState = 0;
    //light sensor
    const int LSensorPin = 1;

    void setup()
    {
    for(int i = 0; i<numPins; i++){
    pinMode(pins[i], OUTPUT);
    }
    Serial.begin(9600);
    Ethernet.begin(mac, ip);
    //
    server.begin();
    myservo.attach(9);
    myservo.write(0);
    int chk = DHT.read22(8);
    }

    void loop()
    {

    EthernetClient client = server.available();
    if(client){
    while(client.connected()){
    readHeader(client);
    if( ! pageNameIs("/")){
    client.stop();
    return;
    }
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html");
    client.println();
    client.println("");
    client.println("Output Pin");
    client.println("");
    //pin control
    setValuesFromParams();
    setPinStates();
    for(int i = 0; i< numPins; i++){
    writeHTMLforPin(client, i);
    }
    //servo control
    SVsetValuesFromParams();
    SVsetPinStates();
    SVwriteHTMLforPin(client);
    client.println("");
    client.println("");
    //Light sensor
    int lightValue = map(analogRead(LSensorPin), 0, 1023, 0,100);
    client.println("Light : ");
    client.print(lightValue);
    client.println(" %,");
    //Temp sensor
    client.print(DHT.temperature,1);
    client.println(" C, ");
    client.print("Humid :");
    client.print(DHT.humidity, 1);
    client.println("%");
    //
    client.println("");
    client.stop();

    }
    

    }

    }

    void writeHTMLforPin(EthernetClient client, int i){
    client.print("

    Pin ");
    client.print(pins[i]);
    client.print("");
    client.print("Off");
    client.print("On");
    client.println("

    ");
    }
    void SVwriteHTMLforPin(EthernetClient client){
    client.print("

    Servo ");
    client.print("");
    client.print("0 degree");
    client.print("90 degree

    ");

    }

    void setPinStates(){
    for(int i=0; i<numPins; i++){
    digitalWrite(pins[i], pinState[i]);
    }
    }
    void SVsetPinStates(){
    myservo.write(servoState*359);
    delay(200);
    }

    void setValuesFromParams(){
    for(int i =0; i<numPins; i++){
    pinState[i] = valueOfParam(i + '0');
    }
    }
    void SVsetValuesFromParams(){

    servoState = SVvalueOfParam();
    

    }

    void readHeader(EthernetClient client){
    //read the first line of header
    char ch;
    int i = 0;
    while(ch != '\n'){
    if(client.available()){
    ch = client.read();
    line1[i] = ch;
    i ++;
    }
    }
    line1[i] = '';
    Serial.println(line1);
    }

    boolean pageNameIs(char* name){
    int i = 4;
    char ch = line1[i];
    while(ch != ' ' && ch != '\n' && ch != '?'){
    if(name[i-4] != line1[i]){
    return false;
    }
    i++;
    ch = line1[i];
    }
    return true;
    }

    int valueOfParam(char param){
    for(int i=0; i<strlen(line1); i++){
    if(line1[i] == param && line1[i+1] == '=')
    {
    return (line1[i+2] - '0');
    }
    }
    return pinState[param-'0'];
    }

    int SVvalueOfParam(void){
    for(int i=0; i<strlen(line1); i++){
    if(line1[i] == '9' && line1[i+1] == '=')
    {
    return (line1[i+2] - '0');
    }
    }
    return 0;
    }

  • Advertisements

    답글 남기기

    아래 항목을 채우거나 오른쪽 아이콘 중 하나를 클릭하여 로그 인 하세요:

    WordPress.com 로고

    WordPress.com의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

    Twitter 사진

    Twitter의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

    Facebook 사진

    Facebook의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

    Google+ photo

    Google+의 계정을 사용하여 댓글을 남깁니다. 로그아웃 / 변경 )

    %s에 연결하는 중

    정보

    이 엔트리는 30/03/2015에 님이 IoT Project에 게시하였으며 , , , , , 태그가 지정되었습니다.

    내비게이션

    %d 블로거가 이것을 좋아합니다: