Differences
This shows you the differences between two versions of the page.
| humidifier:start [2011/05/31 00:42] – created epsg1wiki | humidifier:start [2011/05/31 00:59] (current) – epsg1wiki | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | #include <SPI.h> | + | {{: |
| - | #include < | + | |
| - | byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x44, 0x7A };// mac addres of arduino | ||
| - | byte ip[] = { 10,0,18,110 }; // ip address of arduino | ||
| - | byte server[] = { 193, | ||
| - | Client client(server, | ||
| - | |||
| - | int analogPin=0; | ||
| - | float LHS; //Local humidity sensor | ||
| - | int sensor_number=8; | ||
| - | int min_value = 100; | ||
| - | int water=0; | ||
| - | int pump=1; | ||
| - | int fan=1; | ||
| - | int stand_by=0; | ||
| - | |||
| - | |||
| - | void setup() | ||
| - | { | ||
| - | pinMode(2, OUTPUT); //FAN | ||
| - | pinMode(4, OUTPUT); //PUMP | ||
| - | pinMode(7, INPUT); //WLS 1 | ||
| - | pinMode(8, INPUT); //WLS 2 | ||
| - | | ||
| - | | ||
| - | // start the Ethernet connection: | ||
| - | Ethernet.begin(mac, | ||
| - | // start the serial library: | ||
| - | Serial.begin(9600); | ||
| - | // give the Ethernet shield a second to initialize: | ||
| - | delay(1000); | ||
| - | } | ||
| - | |||
| - | float getValue(String reply) | ||
| - | { | ||
| - | String startString = " | ||
| - | int start = startString.length() ; | ||
| - | int finish = reply.indexOf(" | ||
| - | String roi = reply.substring(start, | ||
| - | start = roi.indexOf(" | ||
| - | String result = roi.substring(start); | ||
| - | char arrayOfChars[result.length()]; | ||
| - | result.toCharArray(arrayOfChars, | ||
| - | float res = atof(arrayOfChars); | ||
| - | return res; | ||
| - | } | ||
| - | |||
| - | //Water Level Control: | ||
| - | String control_water() | ||
| - | { | ||
| - | String alarm; | ||
| - | boolean WLS1=0; | ||
| - | boolean WLS2=0; | ||
| - | WLS1=digitalRead(7); | ||
| - | WLS2=digitalRead(8); | ||
| - | | ||
| - | if (WLS1==0) | ||
| - | { | ||
| - | | ||
| - | | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | if (WLS2==0) | ||
| - | { | ||
| - | | ||
| - | | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | | ||
| - | | ||
| - | } | ||
| - | } | ||
| - | |||
| - | WLS1=digitalRead(2); | ||
| - | WLS2=digitalRead(7); | ||
| - | |||
| - | return (alarm); | ||
| - | |||
| - | } | ||
| - | | ||
| - | void loop() | ||
| - | { | ||
| - | float LHS=0; | ||
| - | float value=0; | ||
| - | String alarm; | ||
| - | String reply; | ||
| - | String s1= "GET / | ||
| - | String s2= "& | ||
| - | while (1) | ||
| - | { | ||
| - | stand_by=(pump& | ||
| - | LHS = analogRead(analogPin)/ | ||
| - | min_value = LHS; | ||
| - | |||
| - | if (client.connect()) | ||
| - | { | ||
| - | Serial.println(" | ||
| - | // Make a HTTP request: | ||
| - | if (client.available()) | ||
| - | { | ||
| - | for (int i=1; i< | ||
| - | { | ||
| - | | ||
| - | reply = client.read(); | ||
| - | if (reply==!(" | ||
| - | { | ||
| - | value = getValue(reply); | ||
| - | if (min_value > value) min_value = value; | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | // if no connection with the server | ||
| - | Serial.println(" | ||
| - | value=min_value; | ||
| - | } | ||
| - | // | ||
| - | if( value>70 ) | ||
| - | { | ||
| - | client.println(" | ||
| - | if(stand_by==0) | ||
| - | { | ||
| - | digitalWrite(2, | ||
| - | int fan=0; | ||
| - | digitalWrite(4, | ||
| - | int pump=0; | ||
| - | } | ||
| - | } | ||
| - | if( value>55 ) | ||
| - | { | ||
| - | client.println(" | ||
| - | if(stand_by==0) | ||
| - | { | ||
| - | digitalWrite(2, | ||
| - | fan=1; | ||
| - | digitalWrite(4, | ||
| - | pump=1; | ||
| - | client.println(" | ||
| - | } | ||
| - | if( value<40 ) | ||
| - | { | ||
| - | client.println(" | ||
| - | if(stand_by==1) | ||
| - | { | ||
| - | digitalWrite(2, | ||
| - | int fan=0; | ||
| - | digitalWrite(4, | ||
| - | int pump=0; | ||
| - | } | ||
| - | if( value<45 ) | ||
| - | { | ||
| - | client.println(" | ||
| - | if(stand_by==1) | ||
| - | { | ||
| - | digitalWrite(2, | ||
| - | int fan=0; | ||
| - | digitalWrite(4, | ||
| - | int pump=0; | ||
| - | } | ||
| - | } | ||
| - | |||
| - | // Water level message | ||
| - | alarm = control_water(); | ||
| - | | ||
| - | |||
| - | }// if available | ||
| - | } // if do connect | ||
| - | |||
| - | // if the server' | ||
| - | if (!client.connected()) | ||
| - | { | ||
| - | Serial.println(); | ||
| - | Serial.println(" | ||
| - | // | ||
| - | } | ||
| - | } | ||
| - | delay(1000); | ||
| - | } | ||
| - | } | ||