Project Description
Description:
This guide is just the tip of the ice berg to build a complete home automation project using Arduino. We will build a Ethernet controlled home automation to control 3 LED’s or switches in your room.
Hardware Required:
• Arduino Uno R3
• Ethernet shield w5100
• Led’s
• Relay
• Temperature Sensor LM-35
• Light Dependent Resistor (LDR)
Pins:
- LED’s : Digital Pin’s 4,5,6
- LM35 : Analog Pin 2
- Light Dependent Resistor : Analog Pin 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
#include // FOR HTHE THERNET LIBRARY #include include // FOR SENDING IR COMMANDS IRsend irsend; // SEDNDING IR CODES // IR VALUES unsigned int AC_ON1[60]={8450,4100,600,1450,650,400,600,450,600,450,600,1500,600,400,650,400,600,450,600,450,600,450,600,450,600,400,650,400,600,450,600,450,600,450,600,400,650,400,650,1450,600,1500,600,400,650,1450,600,450,600,450,600,450,550,1500,600,1500,600,1500,600}; unsigned int AC_OFF1[60]={8450,4050,600,1500,600,450,600,450,600,400,650,1450,600,450,600,450,600,400,650,1450,600,1500,600,450,600,400,650,400,600,450,600,450,600,450,600,450,600,400,650,400,600,450,600,450,600,1500,600,400,650,1450,600,450,600,450,600,400,650,1450,600}; unsigned int chUp1[36]={500,200,200,250,200,550,250,350,250,500,250,200,250,200,250,200,200,250,150,600,200,550,250,350,250,700,200,250,200,550,250,200,200,250,200}; unsigned int chDw1[36]={500,200,200,200,250,550,250,350,250,500,250,250,150,250,200,250,200,200,250,200,200,550,250,350,250,700,250,200,250,500,250,200,250,350,250}; unsigned int Source1[67]={4550,4500,600,1650,650,1600,650,1600,650,500,600,500,650,500,600,550,600,500,600,1650,650,1600,650,1600,650,500,600,500,650,500,600,550,600,500,650,1600,650,500,600,500,650,500,600,500,650,500,600,500,600,550,600,550,600,1650,600,1650,600,1650,600,1650,650,1600,600,1650,650,1600,650}; // LED STUFF boolean a=0;// LED 1 STATUS boolean b=0;// LED 2 STATUS boolean c=0;// SWITCH CASE boolean d=0;// LED 3 STATUS float temp_val = 0; // TEMPERATUERE VALUE int ldr_val = 0; // LIGHT INTENSITY VALUE boolean reading = false; //ETHERNET // ETHERNET SETTINGS byte ip[] = { 192, 168, 1, 221 }; byte gateway[] = { 192, 168, 1, 1 }; byte subnet[] = { 255, 255, 255, 0 }; byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; EthernetServer server = EthernetServer(80); //port 80 // IR REMOTE STUFF void AC_ON() { irsend.sendRaw(AC_ON1,60,38); delay(20); } void AC_OFF() { irsend.sendRaw(AC_OFF1,60,38); delay(20); } void chUp() { for(int i = 0; i < 5; i++) { irsend.sendRaw(chUp1,36,38); delay(20); } } void chDw() { for(int i = 0; i < 10; i++) { irsend.sendRaw(chDw1,36,38); delay(20); } } void Source() { irsend.sendRaw(Source1,67,38); delay(20); Serial.print("Source changed "); } void Temp() { } void Ldr() { } void setup(){ Serial.begin(9600); pinMode(4,OUTPUT); //LED 1 pinMode(5,OUTPUT); //LED 2 pinMode(6,OUTPUT); //LED 3 analogReference(INTERNAL); // Setup the Reference Voltage as Internal Ethernet.begin(mac); Ethernet.begin(mac, ip, gateway, subnet); //for manual setup server.begin(); Serial.println(Ethernet.localIP()); } void loop(){ // listen for incoming clients, and process qequest. checkForClient(); } void checkForClient(){ EthernetClient client = server.available(); if (client) { // an http request ends with a blank line boolean currentLineIsBlank = true; boolean sentHeader = false; while (client.connected()) { if (client.available()) { if(!sentHeader){ // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); sentHeader = true; } char c = client.read(); if(reading && c == ' ') reading = false; if(c == '?') reading = true; //found the ?, begin reading the info if(reading){ Serial.print(c); switch (c) { // CONTROLLING THE AC case 'O': // -O Turn On AC AC_ON(); break; case 'F': // - F Turn Off AC AC_OFF(); break; case 'U': // - U Channel Up chUp(); break; case 'D': // - D Channel Down chDw(); break; // CONTROLLING THE LEDs case '1': // LED 1 ON if(a==0){ digitalWrite(4,HIGH); client.print("Light1 Turned On "); a=1;} break; case '2': // LED 1 OFF if(a==1){ digitalWrite(4,LOW); client.print("Light1 Turned Off "); a=0;} break; case '3': // LED 2 ON if(b==0){ digitalWrite(5,HIGH); client.print("Light2 Turned On "); b=1;} break; case '4': // LED 2 OFF if(b==1){ digitalWrite(5,LOW); client.print("Light2 Turned Off "); b=0;} break; case '5': // LED 3 ON if(d==0){ digitalWrite(6,HIGH); client.print("Light2 Turned On "); d=1;} break; case '6': // LED 3 OFF if(d==1){ digitalWrite(6,LOW); client.print("Light2 Turned Off "); d=0;} break; // STORE THE STATUS OF THE PINS case '7': // POST VALUE OF LED 1 client.print(a); break; case '8': // POST VALUE OF LED 2 client.print(b); break; case '9': // POST VALUE OF LED 3 client.print(d); break; case 'T': // -T Print the temperature { int sensor_val = analogRead(2); // Read the raw sensor value and store it in the variable temp_val = sensor_val * 0.11; // The calculated value client.println(temp_val); // print the temperature value to serial monitor } break; case 'L': // -L Light Intensity { ldr_val = analogRead(3);// Reads a 10-bit value corresponding to the voltage applied on analog input pin 3. client.println(ldr_val);// } break; } } if (c == '\n' && currentLineIsBlank) break; if (c == '\n') { currentLineIsBlank = true; }else if (c != '\r') { currentLineIsBlank = false; } } } delay(1); // give the web browser time to receive the data client.stop(); // close the connection: } } |
Leave A Comment