automation home(eee499.blogspot.com)
TRANSCRIPT
To my constant giving , precious father, who implants ambition and perseverance in me ,
To my dear mother who grants inexhaustible tenderness To my siblings who bear memories of my childhood and my youth in their eyes ,To my friends who can't be narrowed in words , so are held in my heart ,To the prisoners and detainees who sacrificed their freedom for the freedom of others ,To the martyrs of Palestine who are more noble than us ,To all the lovers of education and knowledge ,To my respected Dr-Falah Hassan,To my beloved Palestine that embraced me all these year,To my colleagues in An-Najah National University To all those who contributed in the success of this work .
ACKNOWLEDGMENTS
We would like to express our gratitude for everyone who helped us during the graduation project
starting with endless thanks for our supervisor Dr-Falah Hassan who didn’t keep any effort in
encouraging us to do a great job, providing our group with valuable information and advices to
be better each time. Thanks for the continuous support and kind communication which had a
great effect regarding to feel interesting about what we are working on
I would like to express my gratitude towards my parents for their encouragement which help me
in completion of this project..
I would like to express my special gratitude and thanks to industry persons for giving me such
attention and time.
My thanks and appreciations also go to my colleagues in developing the project and people who
have willingly helped me out with their abilities
LIST OF APPREVIATIONS
Pc personal computer
DC Direct Current
HCS Home And Community-bassed Service
PWM Pulse Width Modulation
TABLE OF CONTENTSACKNOWLEDGMENTS..............................................................................................................iii
LIST OF APPREVIATIONS.........................................................................................................iv
TABLE OF CONTENTS................................................................................................................v
INTRODUCTION...........................................................................................................................1
1.1 - Introduction..........................................................................................................................1
1.2 - Objectives............................................................................................................................2
1.3 - Project scope........................................................................................................................2
1.4 –Plan of actions......................................................................................................................3
1.5 – Home control system..........................................................................................................3
SYSTEM ANALYSIS.....................................................................................................................4
2.1 - Introduction..........................................................................................................................5
2.2 – Case study...........................................................................................................................6
2.3 – System actors......................................................................................................................6
2.4 – System use case...................................................................................................................6
2.5 – Supplementary requirment..................................................................................................7
2.6 – System element...................................................................................................................8
2.7 – System benefits...................................................................................................................8
APPLICATIONS ANA CONNECTIONS....................................................................................10
3.1 - Applications.......................................................................................................................11
3.2 – Connections.......................................................................................................................20
DESIGN AND OPERATION.......................................................................................................23
4.1 – System algorithm and microcontroller tasks.....................................................................24
4.2 – Flow chart.........................................................................................................................25
4.3 – Basic circuit.......................................................................................................................26
4.4 – Final design ......................................................................................................................27
PROJECT COMPONENTS..........................................................................................................28
5.1 Mechanical devices..............................................................................................................29
Conclusions and project future......................................................................................................47
References......................................................................................................................................48
CHAPTER ONE
INTRODUCTION1.1 – Introduction
As the amount of controllable fittings and domestic appliances in the home rises, the ability of these devices to interconnect and communicate with each other digitally becomes a useful and desirable feature. The consolidation of control or monitoring signals from appliances, fittings or basic services is an aim of Home automation.
In simple installations this may be as straightforward as turning on the lights when a person enters the room. In advanced installations, rooms can sense not only the presence of a person inside but know who that person is and perhaps set appropriate lighting, temperature, music levels or television channels, taking into account the day of the week, the time of day, and other factors.
Other automated tasks may include setting the air conditioning to an energy saving setting when the house is unoccupied, and restoring the normal setting when an occupant is about to return. More sophisticated systems can maintain an inventory of products, recording their usage through an RFID tag, and prepare a shopping list or even automatically order replacements.
Home automation can also provide a remote interface to home appliances or the automation system itself, via telephone line, wireless transmission or the internet, to provide control and monitoring via a Smart Phone or Web browser.
An example of a remote monitoring implementation of home automation could be when a smoke detector detects a fire or smoke condition, then all lights in the house will blink to alert any occupants of the house to the possible fire. If the house is equipped with a home theatre, a home automation system can shut down all audio and video components to display the alert or make an audible announcement. The system could also call the home owner on their mobile phone to alert them, or call the fire brigade or alarm monitoring company to bring it to their attention
1.2 – Objectives
the main objective of our project is to make it easy to every one to contact with his/her home and controlling there HWs; without being at home saving there time in an efficiency way.
1.3 - project scope :
Mobile devices are anywhere, these days every one is connected with the world using wireless devices and amazingly mobiles are most commonly used wireless device. Today most of the mobile devices can get connected to the internet and access the web pages. So now a days programmers and designers become to develop a mobile application which is an application that use a set of technologies and specifications developed for small devices like pagers, mobile phones, and BDAs.
Our project is a web application which will be browsed by mobile devices to control different hardware in your home to be turned off or on.
our idea came from developing an old project that was about controlling the hardware by the remote control that was made in our University , so we thought that it will be a good idea to implement it as a new idea in our graduation projects because the mobile become an important part in every one’s life and it can make it easy for every body to accomplish many things by using it.
we implement it by simulating the house hardware using special materials also we are developing a web application, that will be browsed on mobile.
1.4 - Plan of actions :
First of all after we have the idea of our project we analyzed the project by defining the actors, use cases, supplementary, functional requirements, class diagram, data flow diagram, deployment diagram……etc
then we decide what we need to start developing our idea, we started with determining the harewares that we will need then starting to build the hard ware part and testing it. The second step is programming by using visual studio2005 (ASP.Net and C#) to build our web application, after this step we design the web application using simple GUI because our application will be browsed on mobile, and the last step we did was testing our web application.
1.51- Home Control System:
HCS is a web application developed using ASP.net, its aim is to control home devices by PC and mobile, the user request our web application using his/her mobile device then he/she has to login (enter his/her user name and password) after that he can select an item of the menu to control either the home devices or the computer, also he/she can select the camera option from the menu(select camera displaying Snapshoot) to view what is happening inside his/her home.
CHAPTER TWO
System Analysis
CHAPTER TWO
System Analysis2.1 – Introduction
Home automation is the residential extension of building automation. It is
automation of the home, housework or household activity. Homeautomation may
include centralized control of lighting, HVAC (heating, ventilation and air
conditioning), appliances, security locks of gates and doors and other systems, to
provide improved convenience, comfort, energy efficiency and security. Home
automation for the elderly and disabled can provide increased quality of life for
persons who might otherwise require caregivers or institutional care.
The popularity of home automation has been increasing greatly in recent years
due to much higher affordability and simplicity through smartphone and tablet
connectivity. The concept of the "Internet of Things" has tied in closely with the
popularization of home automation.
A home automation system integrates electrical devices in a house with each
other. The techniques employed in home automation include those in building
automation as well as the control of domestic activities, such as home
entertainment systems, houseplant and yard watering, pet feeding, changing the
ambiance "scenes" for different events (such as dinners or parties), and the use
of domestic robots. Devices may be connected through a home network to allow
control by a personal computer, and may allow remote access from theinternet.
Through the integration of information technologies with the home environment,
systems and appliances are able to communicatein an integrated manner which
results in convenience, energy efficiency, and safety benefits.
Automated homes of the future have been staple exhibits for World's Fairs and
popular backgrounds in science fiction. However, problems with complexity,
competition between vendors, multiple incompatible standards, and the resulting
expense have limited the penetration of home automation to homes of the
wealthy, or ambitious hobbyists. Possibly the first "home computer" was an
experimental homeautomation
2.2 - Case Study (Legacy System) :
The idea of our system came from an old system which is controlling the house
devices using the remote control so the user can be able to control the devices
only from inside the house .Because of this, we create our system which is
controlling the house devices by using the web application which we can browse
it on the mobile that provide the ability of controlling the house devices from
inside and outside the house
2.3 – System Actors :-
1. PC User: user who browsing the web application on PC and uses it in order to
control home devices .
2. Mobile User: user who browsing web on mobile in order to control home
devices.
2.4 – System Use Cases :
U1: Browsing Web Application: System users browsing the Web application on
PC or on Mobile.
U2: Sign In: the next step after browsing the application, the user has to enter
his/her user name and password.
U3: Choose List Item: after Signing In, user can select an item from list.
U4: Sending Commands to serial: the application will send command (user
choice) to serial .
U5: Sending Commands to server: the application will send command(computer
controlling option) to server .
U6 : Receiving Command: the application will receive command from serial
when unexpected action occurred.
.
U7: Change Password: user can change his login Password.
U8: Sign Out: user can exit from his account and return to the main page.
2.5- Supplementary requirements:
1. The user should use a pc that provide an internet service.
2. The user must install the IIS server .
3. The user who is using our system must have an account in accompany that
provide SMS server.
4. Our system must be able to serve unlimited users.
5. Our web must be able to be browsed by mobile in a suitable and good layout
and interface.
2.6 - System elements
Elements of a home automation system include sensors (such as temperature,
daylight, or motion detection), controllers (such as a general-purpose personal
computer or a dedicated automation controller) and actuators, such as motorized
valves, light switches, motors, and others.
One or more human-machine interface devices are required, so that the residents
of the home can interact with the system for monitoring and control; this may be a
specialized terminal or, increasingly, may be an application running on a smart
phone or tablet computer. Devices may communicate over dedicated wiring, or
over a wired network, or wirelessly using one or more protocols.
Building automation networks developed for institutional or commercial
buildings may be adapted to control in individual residences. A centralized
controller can be used, or multiple intelligent devices can be distributed around
the home
2.7-System benefits :
Home automation refers to the use of computer and information technology to
control home appliances and features (such as windows or lighting). Systems can
range from simple remote control of lighting through to complex computer/micro-
controller based networks with varying degrees of intelligence and automation.
Home automation is adopted for reasons of ease, security and energy efficiency.
In modern construction in industrialized nations, most homes have been wired for
electrical power, telephones, TV outlets (cable or antenna), and a doorbell. Many
household tasks were automated by the development of specialized automated
appliances. For instance, automatic washing machines were developed to reduce
the manual labor of cleaning clothes, and water heaters reduced the labor
necessary for bathing.
As the number of controllable devices in the home rises, interconnection and
communication becomes a useful and desirable feature. For example, a furnace
can send an alert message when it needs cleaning, or a refrigerator when it needs
service. If no one is supposed to be home and the alarm system is set, the home
automation system could call the owner, or the neighbors, or an emergency
number if an intruder is detected.
In simple installations, automation may be as straightforward as turning on the
lights when a person enters the room. In advanced installations, rooms can sense
not only the presence of a person inside but know who that person is and perhaps
set appropriate lighting, temperature, music levels or television channels, taking
into account the day of the week, the time of day, and other factors.
Other automated tasks may include reduced setting of the heating or air
conditioning when the house is unoccupied, and restoring the normal setting when
an occupant is about to return. More sophisticated systems can maintain
an inventory of products, recording their usage through bar codes, or an RFID tag,
and prepare a shopping list or even automatically order replacements.
Home automation can also provide a remote interface to home appliances or the
automation system itself, to provide control and monitoring on
a smartphone or web browser..
CHAPTER Three
Application
&
Connection
CHAPTER THREE
Applications And Connections
3.1 Applications
3.1.1- Wi-Fi
Wi-Fi, also spelled Wifi or WiFi, is a technology that allows an electronic device to exchange data or connect to the internet wirelessly using 2.4 GHz UHF and 5 GHz SHF radio waves. The name is a trademark name, and was stated to be a play on the audiophile term Hi-Fi. The Wi-Fi Alliance defines Wi-Fi as any "wireless local area network (WLAN) products that are based on the Institute of Electrical and Electronics Engineers' (IEEE) 802.11 standards". However, since most modern WLANs are based on these standards, the term "Wi-Fi" is used in general English as a synonym for "WLAN". Only Wi-Fi products that complete Wi-Fi Alliance interoperability certification testing successfully may use the "Wi-Fi CERTIFIED" trademark.
Many devices can use Wi-Fi, e.g., personal computers, video-game consoles, smartphones, some digital cameras, tablet computers anddigital audio players. These can connect to a network resource such as the Internet via a wireless network access point. Such an access point (or hotspot) has a range of about 20 meters (66 feet) indoors and a greater range outdoors. Hotspot coverage can comprise an area as small as a single room with walls that block radio waves, or as large as many square kilometres achieved by using multiple overlapping access points
Wi-Fi can be less secure than wired connections (such as Ethernet) because an intruder does not need a physical connection. Web pages that use SSL are secure but unencrypted internet access can easily be detected by intruders. Because of this, Wi-Fi has adopted various encryption technologies. The early encryption WEP, proved easy to break. Higher quality protocols (WPA, WPA2) were added later. An optional feature added in 2007, called Wi-Fi Protected Setup (WPS), had a serious flaw that allowed an attacker to recover the router's password.[2] The Wi-Fi Alliance has since updated its test plan and certification program to ensure all newly certified devices resist attacks
Uses
To connect to a Wi-Fi LAN, a computer has to be equipped with a wireless network
interface controller. The combination of computer and interface controller is called
a station. All stations share a single radio frequency communication channel.
Transmissions on this channel are received by all stations within range. The hardware
does not signal the user that the transmission was delivered and is therefore called a best-
effort delivery mechanism. A carrier wave is used to transmit the data in packets, referred
to as "Ethernet frames". Each station is constantly tuned in on the radio frequency
communication channel to pick up available transmissions
Advantages
Wi-Fi allows cheaper deployment of local area networks (LANs). Also spaces where
cables cannot be run, such as outdoor areas and historical buildings, can host wireless
LANs.
Manufacturers are building wireless network adapters into most laptops. The price
of chipsets for Wi-Fi continues to drop, making it an economical networking option
included in even more devices.[citation needed]
Different competitive brands of access points and client network-interfaces can inter-
operate at a basic level of service. Products designated as "Wi-Fi Certified" by the Wi-Fi
Alliance are backwards compatible. Unlike mobile phones, any standard Wi-Fi device
will work anywhere in the world.
Wi-Fi Protected Access encryption (WPA2) is considered secure, provided a
strong passphrase is used. New protocols for quality-of-service (WMM) make Wi-Fi
more suitable for latency-sensitive applications (such as voice and video). Power saving
mechanisms (WMM Power Save) extend battery life
RangeWi-Fi networks have limited range. A typical wireless access point using 802.11b or
802.11g with a stock antenna might have a range of 35 m (115 ft) indoors and 100 m
(330 ft) outdoors. IEEE 802.11n, however, can more than double the range. Range also
varies with frequency band. Wi-Fi in the 2.4 GHz frequency block has slightly better
range than Wi-Fi in the 5 GHz frequency block which is used by 802.11a and optionally
by 802.11n. On wireless routers with detachable antennas, it is possible to improve range
by fitting upgraded antennas which have higher gain in particular directions. Outdoor
ranges can be improved to many kilometers through the use of high gain directional
antennas at the router and remote device(s). In general, the maximum amount of power
that a Wi-Fi device can transmit is limited by local regulations, such as FCC Part 15 in
the US.
Due to reach requirements for wireless LAN applications, Wi-Fi has fairly high power
consumption compared to some other standards. Technologies such
as Bluetooth (designed to support wireless PAN applications) provide a much
shorter propagation range between 1 and 100m and so in general have a lower power
consumption. Other low-power technologies such as ZigBee have fairly long range, but
much lower data rate. The high power consumption of Wi-Fi makes battery life in mobile
devices a concern.
Researchers have developed a number of "no new wires" technologies to provide
alternatives to Wi-Fi for applications in which Wi-Fi's indoor range is not adequate and
where installing new wires (such as CAT-6) is not possible or cost-effective. For
example, the ITU-T G.hn standard for high speed Local area networks uses existing
home wiring (coaxial cables, phone lines and power lines). Although G.hn does not
provide some of the advantages of Wi-Fi (such as mobility or outdoor use), it's designed
for applications (such asIPTV distribution) where indoor range is more important than
mobility.
Due to the complex nature of radio propagation at typical Wi-Fi frequencies, particularly
the effects of signal reflection off trees and buildings, algorithms can only approximately
predict Wi-Fi signal strength for any given area in relation to a transmitter. This effect
does not apply equally to long-range Wi-Fi, since longer links typically operate from
towers that transmit above the surrounding foliage.
The practical range of Wi-Fi essentially confines mobile use to such applications as
inventory-taking machines in warehouses or in retail spaces, barcode-reading devices at
check-out stands, or receiving/shipping stations. Mobile use of Wi-Fi over wider ranges
is limited, for instance, to uses such as in an automobile moving from one hotspot to
another. Other wireless technologies are more suitable for communicating with moving
vehicles
Figure 3.1: wi-fi connection
3.1.2- Ethernet
The Arduino Ethernet is a microcontroller board based on the ATmega328 (datasheet). It
has 14 digital input/output pins, 6 analog inputs, a 16 MHz crystal oscillator,
a RJ45 connection, a power jack, an ICSP header, and a reset button.
NB: Pins 10, 11, 12 and 13 are reserved for interfacing with the Ethernet module and
should not be used otherwise. This reduces the number of available pins to 9, with 4
available as PWM outputs.
An optional Power over Ethernet module can be added to the board as well.
The Ethernet differs from other boards in that it does not have an onboard USB-to-serial
driver chip, but has a Wiznet Ethernet interface. This is the same interface found on the
Ethernet shield.
An onboard microSD card reader, which can be used to store files for serving over the
network, is accessible through the SD Library. Pin 10 is reserved for the Wiznet
interface, SS for the SD card is on Pin 4.
The 6-pin serial programming header is compatible with the USB Serial adapter and also
with the FTDI USB cables or with Sparkfun and Adafruit FTDI-style basic USB-to-serial
breakout boards. It features support for automatic reset, allowing sketches to be uploaded
without pressing the reset button on the board. When plugged into a USB to Serial
adapter, the Arduino Ethernet is powered from the adapter.
The Revision 3 of the board introduces the standardized 1.0 pinout, that consist in:
added SDA and SCL pins that are near to the AREF pin and two other new pins placed
near to the RESET pin, this will the opportunity to shield that use i2c or TWI components
to be compatible with all the Arduino boards;
the IOREF that allow the shields to adapt to the voltage provided from the board. Shields
that use the IOREF pin will be compatible both with the board that use the AVR, which
operate with 5V and with the Arduino Due that operate with 3.3V. Next to the IOREF pin
there is a not connected pin, that is reserved for future purposes
Power
The board can also be powered via an external power supply, an optional Power over
Ethernet (PoE) module, or by using a FTDI cable/USB Serial connector.
External power can come either from an AC-to-DC adapter (wall-wart) or battery. The
adapter can be connected by plugging a 2.1mm center-positive plug into the board's
power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the
POWER connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than
7V, however, the 5V pin may supply less than five volts and the board may be unstable.
If using more than 12V, the voltage regulator may overheat and damage the board. The
recommended range is 7 to 12 volts.
The power pins are as follows:
VIN. The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.
5V. This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your board. We don't advise it.
3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.
GND. Ground pins. IOREF. This pin on the Arduino board provides the voltage reference with which the
microcontroller operates. A properly configured shield can read the IOREF pin voltage and select the appropriate power source or enable voltage translators on the outputs for working with the 5V or 3.3V.
The optional PoE module is designed to extract power from a conventional twisted pair
Category 5 Ethernet cable:
IEEE802.3af compliant Low output ripple and noise (100mVpp) Input voltage range 36V to 57V Overload and short-circuit protection 9V Output High efficiency DC/DC converter: typ 75% @ 50% load 1500V isolation (input to output)
When using the power adapter, power can come either from an AC-to-DC adapter (wall-
wart) or battery. The adapter can be connected by plugging a 2.1mm center-positive plug
into the board's power jack. Leads from a battery can be inserted in the Gnd and Vin pin
headers of the POWER connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than
7V, however, the 5V pin may supply less than five volts and the board may be unstable.
If using more than 12V, the voltage regulator may overheat and damage the board. The
recommended range is 7 to 12 volts.
Memory
The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of
SRAM and 1 KB of EEPROM (which can be read and written with the EEPROM
library).
Input and Output
Each of the 14 digital pins on the Ethernet board can be used as an input or output,
using pinMode(), digitalWrite(), anddigitalRead() functions. They operate at 5 volts.
Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor
(disconnected by default) of 20-50 kOhms. In addition, some pins have specialized
functions:
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low
value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details.
PWM: 3, 5, 6, 9, and 10. Provide 8-bit PWM output with the analogWrite() function. SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication
using the SPI library. LED: 9. There is a built-in LED connected to digital pin 9. When the pin is HIGH value,
the LED is on, when the pin is LOW, it's off. On most other arduino boards, this LED is found on pin 13. It is on pin 9 on the Ethernet board because pin 13 is used as part of the SPI connection.
The Ethernet board has 6 analog inputs, labeled A0 through A5, each of which provide
10 bits of resolution (i.e. 1024 different values). By default they measure from ground to
5 volts, though is it possible to change the upper end of their range using the AREF pin
and the analogReference() function. Additionally, some pins have specialized
functionality:
TWI: A4 (SDA) and A5 (SCL). Support TWI communication using the Wire library.
There are a couple of other pins on the board:
AREF. Reference voltage for the analog inputs. Used with analogReference(). Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset
button to shields which block the one on the board.
Communication
The Arduino Ethernet has a number of facilities for communicating with a computer,
another Arduino, or other microcontrollers.
A SoftwareSerial library allows for serial communication on any of the Uno's digital
pins.
The ATmega328 also supports TWI and SPI communication. The Arduino software
includes a Wire library to simplify use of the TWI bus; see the documentation for details.
For SPI communication, use the SPI library.
The board also can connect to a wired network via ethernet. When connecting to a
network, you will need to provide an IP address and a MAC address. The Ethernet
Library is fully supported.
The onboard microSD card reader is accessible through the SD Library. When working
with this library, SS is on Pin 4.
Programming
It is possible to program the Arduino Ethernet board in two ways: through the 6 pin serial
programming header, or with an external ISP programmer.
The 6-pin serial programming header is compatible with FTDI USB cables and the
Sparkfun and Adafruit FTDI-style basic USB-to-serial breakout boards including the
Arduino USB-Serial connector. It features support for automatic reset, allowing sketches
to be uploaded without pressing the reset button on the board. When plugged into a
FTDI-style USB adapter, the Arduino Ethernet is powered off the adapter.
You can also program the Ethernet board with an external programmer like an AVRISP
mkII or USBTinyISP. To set up your environment for burning a sketch with a
programmer, follow these instructions. This will delete the serial bootloader, however.
All the Ethernet example sketches work as they do with the Ethernet shield. Make sure to
change the network settings for your network.
Physical Characteristics
The maximum length and width of the Ethernet PCB are 2.7 and 2.1 inches respectively,
with the RJ45 connector and power jack extending beyond the former dimension. Four
screw holes allow the board to be attached to a surface or case. Note that the distance
between digital pins 7 and 8 is 160 mil (0.16"), not an even multiple of the 100 mil
spacing of the other pins.
Figure 3.2: Ethernet
3.2- Connections
3.2.1- lm35 with Arduino
Figure 3.3: lm35 with arduino
Using the lm35 is easy, simply connect the left pin to power (2.7-5.5V) and the right pin to ground. Then the middle pin will have an analog voltage that is directly proportional (linear) to the temperature. The analog voltage is independant of the power supply.
To convert the voltage to temperature, simply use the basic formula:
Temp in °C = (Vout in mV) / 10
3.2.2- camera with Arduino
Figure 3.4: camera with arduino
We connect the red line(input) with pin 2 ,and brown(output) with pin 3 ,purple
line with ground and gray line with 5v dc.
3.2.3- relay with Arduino
Figure 3.5: relay with arduino
To connect the Relay board to an Arduino is very easy and allows you to turn on
and off an wide range of devices, both AC and DC. The first to connections are the
ground and power pins, You need to connect the Arduino +5 v to the Relay board
VCC pin and the Arduino ground to the Relay board GND pin. Then it's a only a
matter of just connecting the communication pins, labeled IN1, , two 4 data pins on
the Arduino
CHAPTER FOUR
DESIGN
&
OPERATION
CHAPTER FOUR
DESIGN AND OPERATION
4.1 – System algorithm and microcontroller tasks
Figure 4.1: microcontroller tasks
Put name and password
Eather net arduino
Chose type of device that we need to control
Control the device
4.2 – Flow Chart
NO
YES
NO
YES
START
PUT NAME & PASSWORD
PASS
CORRECT
CHOSE TYPE OF DEVICE
CHOSE DEVICE
Eathernet Arduino
Control device
CONTROL
NO YES
Figure 4.2: flow chart
4.3 – basic circuit
FEEDBACK TO THE PAGE
End
Figure 4.3: basic circuit
4.4 – Final design for the project
Figure 4.4: Final design for the project
CHAPTER FIVE
PROJECT
COMPONENTS
CHAPTER FIVE
PROJECT COMPONENTS5.1 Mechanical devices :
1. Ttl camera
This camera module can be a pretty neat project addition. It was designed to be used in
security systems and does two main things - it outputs NTSC monochrome video and can
take snapshots of that video (in color) and transmit them over the TTL serial link. You
can snap pictures at 640x480, 320x240 or 160x120 and they're pre-compressed JPEG
images which makes them nice and small and easy to store on an SD card. Perfect for a
data-logging, security, or photography project.
One nice thing about this particular camera is all the 'extras' that come with it. For
example it has manually adjustable focus, auto-white-balance, auto-brightness and auto-
contrast taken care of for you as well as motion detection built in! That means you can
have it alert your project when something moved in the frame.
We also carry an enclosed weather-proof version Using the module is pretty easy and
only requires two digital pins (or a TTL serial port) - by default it transmits at 38400
baud. Of course we wouldn't just leave you with a datasheet and a 'good luck', we even
spent a lot of time researching the module and DSP to make a really nice Arduino library
with example code that shows how to change the image size and compression quality,
detect motion, control the video output stream, etc. That and more is available in our very
detailed tutorial that will help get the most use out of your camera.
Appication
General purpose embedded imaging and control. Security systems. Access Control systems. Elevator and Remote monitoring. Robot vision, object detection and recognition. Industrial control. Automotive. Medical systems. Smart Home systems. Video intercoms. Electronic Toys and Learning systems.
Figure 5.1: ttl camera
2. fan
brushless DC fan Be driven by brushless DC motor and change direction
electrically depending on holl unit: its material is PBT-UL94Vo; has long life and
low noise; and is mainly used in heat dispersion of induction cooker, computer
and home electric appliance. There are many types, YHWF-120, YHWF-12025,
YHWF-8025, and YHWF-4010.ect
The specification for this fan is as following:
Model Number: YHWF-9025
Size: 90*90*25mm
Voltage: 5 ~ 24V DC
Material : Plastic
Rated speed: 1500 ~ 6000RPM
Bearing: Sleeve or Ball Bearing
Noise: Less than 30 dB
with the Hall sensor and over current protection.
We can make this DC fan if the user requires the non-standard specification
Figure 5.2: dc van.
3. Arduino Uno
The Arduino Uno is a microcontroller board based on the ATmega328 (datasheet)
It has 14 digital input/output pins (of which 6 can be used as PWM outputs),6
analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an
ICSP header, and a reset button. It contains everything needed to support the
microcontroller; simply connect it to a computer with a USB cable or power it
with a AC-to-DC adapter or battery to get started.
The Uno differs from all preceding boards in that it does not use the FTDI USB-
to-serial driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to
version R2) programmed as a USB-to-serial converter.
Revision 2 of the Uno board has a resistor pulling the 8U2 HWB line to ground,
making it easier to put into DFU mode.
Revision 3 of the board has the following new features:
1.0 pinout: added SDA and SCL pins that are near to the AREF pin and two other
new pins placed near to the RESET pin, the IOREF that allow the shields to
adapt to the voltage provided from the board. In future, shields will be
compatible with both the board that uses the AVR, which operates with 5V
and with the Arduino Due that operates with 3.3V. The second one is a not
connected pin, that is reserved for future purposes.
Stronger RESET circuit.
Atmega 16U2 replace the 8U2.
"Uno" means one in Italian and is named to mark the upcoming release of
Arduino 1.0. The Uno and version 1.0 will be the reference versions of Arduino,
moving forward. The Uno is the latest in a series of USB Arduino boards, and the
reference model for the Arduino platform; for a comparison with previous
versions, see the index of Arduino boards.
Summary
Microcontroller ATmega328
Operating Voltage 5V
Input Voltage (recommended)
7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory32 KB (ATmega328) of which 0.5 KB used by bootloader
SRAM 2 KB (ATmega328)
EEPROM 1 KB (ATmega328)
Clock Speed 16 MHz
Power
The Arduino Uno can be powered via the USB connection or with an external power
supply. The power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or
battery. The adapter can be connected by plugging a 2.1mm center-positive plug into the
board's power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers
of the POWER connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than
7V, however, the 5V pin may supply less than five volts and the board may be unstable.
If using more than 12V, the voltage regulator may overheat and damage the board. The
recommended range is 7 to 12 volts.
The power pins are as follows:
VIN. The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.
5V.This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your board. We don't advise it.
3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.
GND. Ground pins.
IOREF. This pin on the Arduino board provides the voltage reference with which the
microcontroller operates. A properly configured shield can read the IOREF pin voltage
and select the appropriate power source or enable voltage translators on the outputs for
working with the 5V or 3.3V
Memory
The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of
SRAM and 1 KB of EEPROM (which can be read and written with the EEPROM
library).
Input and Output
Each of the 14 digital pins on the Uno can be used as an input or output,
using pinMode(), digitalWrite(), anddigitalRead() functions. They operate at 5 volts.
Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor
(disconnected by default) of 20-50 kOhms. In addition, some pins have specialized
functions:
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data.
These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL
Serial chip.
External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low
value, a rising or falling edge, or a change in value. See the attachInterrupt() function for
details.
PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.
SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication
using the SPI library.
LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH
value, the LED is on, when the pin is LOW, it's off.
The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of
resolution (i.e. 1024 different values). By default they measure from ground to 5 volts,
though is it possible to change the upper end of their range using the AREF pin and
the analogReference() function. Additionally, some pins have specialized functionality:
TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the Wire
library.
There are a couple of other pins on the board:
AREF. Reference voltage for the analog inputs. Used with analogReference().
Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset
button to shields which block the one on the board.
See also the mapping between Arduino pins and ATmega328 ports. The mapping for the
Atmega8, 168, and 328 is identical.
Communication
The Arduino Uno has a number of facilities for communicating with a computer, another
Arduino, or other microcontrollers. The ATmega328 provides UART TTL (5V) serial
communication, which is available on digital pins 0 (RX) and 1 (TX).
An ATmega16U2 on the board channels this serial communication over USB and appears
as a virtual com port to software on the computer. The '16U2 firmware uses the standard
USB COM drivers, and no external driver is needed. However, on Windows, a .inf file is
required. The Arduino software includes a serial monitor which allows simple textual
data to be sent to and from the Arduino board. The RX and TX LEDs on the board will
flash when data is being transmitted via the USB-to-serial chip and USB connection to
the computer (but not for serial communication on pins 0 and 1).
A SoftwareSerial library allows for serial communication on any of the Uno's digital
pins.
The ATmega328 also supports I2C (TWI) and SPI communication. The Arduino
software includes a Wire library to simplify use of the I2C bus; see the documentation for
details. For SPI communication, use the SPI library.
Programming
The Arduino Uno can be programmed with the Arduino software (download). Select
"Arduino Uno from the Tools > Board menu (according to the microcontroller on your
board). For details, see the reference and tutorials.
The ATmega328 on the Arduino Uno comes preburned with a bootloader that allows you
to upload new code to it without the use of an external hardware programmer. It
communicates using the original STK500 protocol (reference, C header files).
You can also bypass the bootloader and program the microcontroller through the ICSP
(In-Circuit Serial Programming) header; see these instructions for details.
The ATmega16U2 (or 8U2 in the rev1 and rev2 boards) firmware source code is
available . The ATmega16U2/8U2 is loaded with a DFU bootloader, which can be
activated by:
On Rev1 boards: connecting the solder jumper on the back of the board (near the map of
Italy) and then resetting the 8U2.
On Rev2 or later boards: there is a resistor that pulling the 8U2/16U2 HWB line to
ground, making it easier to put into DFU mode.
You can then use Atmel's FLIP software (Windows) or the DFU programmer (Mac OS X
and Linux) to load a new firmware. Or you can use the ISP header with an external
programmer (overwriting the DFU bootloader). See this user-contributed tutorial for
more information.
Automatic (Software) Reset
Rather than requiring a physical press of the reset button before an upload, the Arduino
Uno is designed in a way that allows it to be reset by software running on a connected
computer. One of the hardware flow control lines (DTR) of theATmega8U2/16U2 is
connected to the reset line of the ATmega328 via a 100 nanofarad capacitor. When this
line is asserted (taken low), the reset line drops long enough to reset the chip. The
Arduino software uses this capability to allow you to upload code by simply pressing the
upload button in the Arduino environment. This means that the bootloader can have a
shorter timeout, as the lowering of DTR can be well-coordinated with the start of the
upload.
This setup has other implications. When the Uno is connected to either a computer
running Mac OS X or Linux, it resets each time a connection is made to it from software
(via USB). For the following half-second or so, the bootloader is running on the Uno.
While it is programmed to ignore malformed data (i.e. anything besides an upload of new
code), it will intercept the first few bytes of data sent to the board after a connection is
opened. If a sketch running on the board receives one-time configuration or other data
when it first starts, make sure that the software with which it communicates waits a
second after opening the connection and before sending this data.
The Uno contains a trace that can be cut to disable the auto-reset. The pads on either side
of the trace can be soldered together to re-enable it. It's labeled "RESET-EN". You may
also be able to disable the auto-reset by connecting a 110 ohm resistor from 5V to the
reset line; see this forum thread for details.
USB Overcurrent Protection
The Arduino Uno has a resettable polyfuse that protects your computer's USB ports from
shorts and overcurrent. Although most computers provide their own internal protection, the fuse provides an extra layer of protection. If more than 500 mA is applied to the USB port, the fuse will automatically break the connection until the short or overload is removed.
Physical Characteristics
The maximum length and width of the Uno PCB are 2.7 and 2.1 inches respectively, with
the USB connector and power jack extending beyond the former dimension. Four screw
holes allow the board to be attached to a surface or case. Note that the distance between
digital pins 7 and 8 is 160 mil (0.16"), not an even multiple of the 100 mil spacing of the
other pins.
Figure 5.3: arduino uno
4. Relay
A relay is automatic device which senses an abnormal condition of electrical
circuit and closes its contacts. These contacts in turns close and complete the
circuit breaker trip coil circuit hence make the circuit breaker tripped for
disconnecting the faulty portion of the electrical circuit from rest of the healthy
circuit.
Now let’s have a discussion on some terms related to protective relay
Pickup level of actuating signal: The value of actuating quantity (voltage or
current) which is on threshold above which the relay initiates to be operated.
If the value of actuating quantity is increased, the electro magnetic effect of the
relay coil is increased and above a certain level of actuating quantity the moving
mechanism of the relay just starts to move.
Reset level: The value of current or voltage below which a relay opens its contacts
and comes in original position.
Operating Time of Relay - Just after exceeding pickup level of actuating quantity
the moving mechanism (for example rotating disc) of relay starts moving and it
ultimately close the relay contacts at the end of its journey. The time which
elapses between the instant when actuating quantity exceeds the pickup value to
the instant when the relay contacts close.
Reset time of Relay – The time which elapses between the instant when
the actuating quantity becomes less than the reset value to the instant
when the relay contacts returns to its normal position.
Reach of relay – A distance relay operates whenever the distance seen by
the relay is less than the pre-specified impedance. The actuating
impedance in the relay is the function of distance in a distance protection
relay. This impedance or corresponding distance is called reach of the
relay.
Power system protection relays can be categorized into different Types of relays.
Types of protection relays are mainly based on their characteristic, logic, on
actuating parameter and operation mechanism.
Based on operation mechanism protection relay can be categorized as Electro
Magnetic relay, Static relay and Mechanical relay. Actually relay is nothing but a
combination of one or more open or closed contacts. These all or some specific
contacts the relay change their state when actuating parameters are applied to the
relay. That means open contacts become closed and closed contacts become open.
In electromagnetic relay these closing and opening of relay contacts are done by
electromagnetic action of a solenoid
Figure 5.4: Relay.
5. WiFi Shield
OverviewThe Arduino WiFi Shield connects your Arduino to the internet wirelessly.
Connect it to your wireless network by following a few simple instructions to start
controlling your world through the internet. As always with Arduino, every
element of the platform – hardware, software and documentation – is freely
available and open-source. This means you can learn exactly how it's made and
use its design as the starting point for your own circuits.
-Requires an Arduino board (not included)
-Operating voltage 5V (supplied from the Arduino Board)
-Connection via: 802.11b/g networks
-Encryption types: WEP and WPA2 Personal
-Connection with Arduino on SPI port
-on-board micro SD slot
-ICSP headers
-FTDI connection for serial debugging of WiFi shield
-Mini-USB for updating WiFi shield firmware
Description
The Arduino WiFi Shield allows an Arduino board to connect to the internet
using the 802.11 wireless specification (WiFi).
It is based on the HDG104 Wireless LAN 802.11b/g System in-Package. An
Atmega 32UC3 provides a network (IP) stack capable of both TCP and UDP. Use
the WiFI library to write sketches which connect to the internet using the shield.
TheWiFI shield connects to an Arduino board using long wire-wrap headers
which extend through the shield. This keeps the pin layout intact and allows
another shield to be stacked on top.
The WiFi Shield can connect to wireless networks which operate according to the
802.11b and 802.11g specifications.
There is an onboard micro-SD card slot, which can be used to store files for
serving over the network. It is compatible with the Arduino Uno and Mega. The
onboard microSD card reader is accessible through the SD Library. When
working with this library, SS is on Pin 4.
Arduino communicates with both the Wifi shield's processor and SD card using
the SPI bus (through the ICSP header). This is on digital pins 11, 12, and 13 on
the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used to
select the HDG104 and pin 4 for the SD card. These pins cannot be used for
general I/O. On the Mega, the hardware SS pin, 53, is not used to select either
the HDG104 or the SD card, but it must be kept as an output or the SPI interface
won't work.
Digital pin 7 is used as a handshake pin between the WiFi shield and the Arduino,
and should not be used
Features
Technical Specifications
Requires and Arduino board (not included)
Operating voltage 5V (supplied from the Arduino Board)
Connection via: 802.11b/g networks
Encryption types: WEP and WPA2 Persoanl
Connection with Arduino on SPI port
on-board micro SD slot
ICSP headers
FTDI connection for serial debugging of WiFi shield
Micro-USB for updating WiFi shield firmware
The WiFi Shield communicates with Arduino using the SPI bus (through
the ICSP header), so is compatible with any of the boards that have this
type of bus.
This version of WiFi shield have an integrated antenna on the PCB, what
you have to do is just connect the shield to the Arduino
Figure 5.5: wifi shield.
6. LM35
is a precision IC temperature sensor with its output proportional to the
temperature (in oC). The sensor circuitry is sealed and therefore it is not subjected
to oxidation and other processes. With LM35, temperature can be measured more
accurately than with a thermistor. It also possess low self heating and does not
cause more than 0.1 oC temperature rise in still air.
The operating temperature range is from -55°C to 150°C. The output voltage
varies by 10mV in response to every oC rise/fall in ambient temperature, i.e., its
scale factor is 0.01V/ oC.
Pin Diagram:
Figure 5.6: lm35
7. lamp
A lamp is a replaceable component such as an incandescent light bulb, which is
designed to produce light from electricity. These components usually have a base
of ceramic, metal, glass or plastic, which makes an electrical connection in the
socket of a light fixture. This connection may be made with a screw-thread base,
two metal pins, two metal caps or a bayonet cap.
Types
There are several types of lamp:
Incandescent lamp, a heated filament inside a glass envelope
Halogen lamps use a fused quartz envelope, filled with halogen gas
LED lamp, a solid-state lamp that uses light-emitting diodes (LEDs) as
the source of light
Laser diode lamp
Arc lamp
Xenon arc lamp
Mercury-xenon arc lamp
Ultra-high-performance lamp, an ultra-high-pressure mercury-vapor arc
lamp for use in projectors
Metal-halide lamp
Gas-discharge lamp, a light source that generates light by sending
an electrical discharge through an ionized gas
Fluorescent lamp
Compact fluorescent lamp, a fluorescent lamp designed to replace
an incandescent lamp
Neon lamp
Mercury-vapor lamp
Sodium-vapor lamp
Sulfur lamp
Electrodeless lamp, a gas discharge lamp in which the power is
transferred from outside the bulb to inside via electromagnetic fields
Lamp circuit symbol
8. Cd-Rom
is a pre-pressed optical compact disc which contains data. The name is
an acronym which stands for "Compact Disc Read-Only Memory". Computers
can read CD-ROMs, but cannot write on the CD-ROM's which are not writable or
erasable
CD-ROMs are identical in appearance to audio CDs, and data are stored and
retrieved in a very similar manner (only differing from audio CDs in the standards
used to store the data). Discs are made from a 1.2 mm thick disc
of polycarbonate plastic, with a thin layer of aluminium to make a reflective
surface. The most common size of CD-ROM is 120 mm in diameter, though the
smaller Mini CD standard with an 80 mm diameter, as well as numerous non-
standard sizes and shapes (e.g., business card-sized media) are also available.
[citation needed]
Data is stored on the disc as a series of microscopic indentations. A laser is shone
onto the reflective surface of the disc to read the pattern of pits and lands ("pits",
with the gaps between them referred to as "lands"). Because the depth of the pits
is approximately one-quarter to one-sixth of the wavelength of the laser light used
to read the disc, the reflected beam's phase is shifted in relation to the incoming
beam, causing destructive interference and reducing the reflected beam's intensity.
This pattern of changing intensity of the reflected beam is converted into binary
data
Figure5.7: cd-rom
CONCLUSIONS AND PROJECT
FUTURE
In This project the user use our application. The user computer must be a server and the user has to have an account in a company , then he/she can browse our web application from his/her pc device.After browsing our web, the first page will appear is login page.
every thing we implement and use in this project we have not a previous idea about it so this is took from us some time to learn about every thing we want to do before do it, and we don't consider this as a problem at all instead we are thankful for having this opportunity of learning.
we developed our application under limited time in addition there is a several problems faced us as mentioned before, so it has not all features and capabilities that can be obtained, so we do a future development plan in order to develop our application.
Also, when a mobile device request our application it will detect the user agent, to know the model of this device and its capabilities, in order to provide the page with content that accepted by mobile browser
References
[1] http://en.wikipedia.org/wiki/Home_automation
[2] http://arduino.cc/en/Main/arduinoBoardUno
[3] http://forum.arduino.cc/index.php?topic=120666.0
[4] http://en.wikipedia.org/wiki/Relay
[5] http://electronics.howstuffworks.com/relay.htm
[6] https://learn.adafruit.com/ttl-serial-camera/overview
[8] http://arduino.cc/en/Reference/WiFi
[9] http://arduino.cc/en/Main/ArduinoWiFiShield
Program Code
#include <SPI.h>
#include <Ethernet.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
//#include <string.h>
//#include <stdlib.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "skyhp.com";
IPAddress ip(192, 168, 1, 177);
EthernetClient client;
SoftwareSerial cameraconnection = SoftwareSerial(2, 3);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);
float tempC;
int reading;
int tempPin = 0;
String last_door="";
String last_fan="";
String last_window="";
String last_light="";
int door_on = 8;
int door_off = 9;
int window_on = 11;
int window_off = 12;
int buzer = 7;
int fan_pin = 6;
void camera()
{
if (cam.begin())
{
Serial.println("Camera found:");
}
else
{
Serial.println("Camera not found !");
return;
}
cam.setImageSize(VC0706_640x480);
uint8_t imgsize = cam.getImageSize();
Serial.print("Image size: ");
if (imgsize == VC0706_640x480) Serial.println("640x480");
if (imgsize == VC0706_320x240) Serial.println("320x240");
if (imgsize == VC0706_160x120) Serial.println("160x120");
Serial.println("Snap in 3 secs...");
delay(555);
if (! cam.takePicture())
Serial.println("Failed to snap!");
else
Serial.println("Picture taken!");
Serial.println("connecting...");
uint16_t jpglen = cam.frameLength();
Serial.print("Storing ");
Serial.print(jpglen, DEC);
Serial.print(" byte image.");
String start_request = "";
String end_request = "";
start_request = start_request + "\n" + "--AaB03x" + "\n" + "Content-Disposition: form-data; name=\"picture\"; filename=\"CAM.JPG\"" + "\n" + "Content-Type: image/jpeg" + "\n" + "Content-Transfer-Encoding: binary" + "\n" + "\n";
end_request = end_request + "\n" + "--AaB03x--" + "\n";
uint16_t extra_length;
extra_length = start_request.length() + end_request.length();
Serial.println("Extra length:");
Serial.println(extra_length);
uint16_t len = jpglen + extra_length;
if (client.connect(server, 80))
{
Serial.println(F("Connected !"));
client.println(F("POST /hussein/camera.php HTTP/1.1"));
client.println(F("Host: 149.210.138.97:80"));
client.println(F("Content-Type: multipart/form-data; boundary=AaB03x"));
client.print(F("Content-Length: "));
client.println(len);
client.print(start_request);
byte wCount = 0;
while (jpglen > 0)
{
uint8_t *buffer;
uint8_t bytesToRead = min(32, jpglen);
buffer = cam.readPicture(bytesToRead);
client.write(buffer, bytesToRead);
jpglen -= bytesToRead;
}
client.print(end_request);
client.println();
Serial.println("Transmission over");
}
else
{
Serial.println("connection failed");
}
client.stop();
}
void insert(String door,String fan,String light ,String window)
{
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("POST /hussein/update.php?door="+door+"&fan="+fan+"&light="+light+"&window="+window+" HTTP/1.1");
client.println("Host: 149.210.138.97:80");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
while(client.connected() && !client.available()) delay(1);
while (client.available()) {
char c = client.read();
Serial.print(c);
}
}
void insert_temp(String temp)
{
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("POST /hussein/insert_temp.php?temp="+temp+" HTTP/1.1");
client.println("Host: 149.210.138.97:80");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
while(client.connected() && !client.available()) delay(1);
while (client.available()) {
char c = client.read();
Serial.print(c);
}
}
void get_data()
{
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("POST /hussein/get_control.php HTTP/1.1");
client.println("Host: 149.210.138.97:80");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
String response="";
while(client.connected() && !client.available()) delay(1);
while (client.available()) {
char c = client.read();
response= response + c;
}
int contentBodyIndex = response.lastIndexOf('\n');
if (contentBodyIndex > 0) {
Serial.println(response.substring(contentBodyIndex));
}
response =response.substring(contentBodyIndex);
client.stop();
client.flush();
response.trim();
String door = response.substring(0,1);
String window = response.substring(2,3);
String fan = response.substring(4,5);
String light = response.substring(6,7);
Serial.println("door= "+door);
Serial.println("window= "+window);
Serial.println("light= "+light);
Serial.println("fan= "+fan);
if(!door.equals(last_door))
{
last_door = door;
if(door.equals("0"))
{
digitalWrite(door_off, HIGH );
delay(2000);
digitalWrite(door_off, LOW);
}
else
{
digitalWrite(door_on, HIGH );
delay(2000);
digitalWrite(door_on, LOW);
}
}
/////////////////////////////////////
if(!window.equals(last_window))
{
last_window = window;
if(window.equals("0"))
{
digitalWrite(window_off, HIGH );
delay(2000);
digitalWrite(window_off, LOW);
}
else
{
digitalWrite(window_on, HIGH );
delay(2000);
digitalWrite(window_on, LOW);
}
}
////////////////////////////
if(!light.equals(last_light))
{
last_light = light;
if(light.equals("0"))
{
digitalWrite(buzer, LOW );
}
else
{
digitalWrite(buzer, HIGH);
}
}
////////////////////////////
if(!fan.equals(last_fan))
{
last_fan = fan;
if(fan.equals("0"))
{
digitalWrite(fan_pin, LOW );
}
else
{
digitalWrite(fan_pin, HIGH);
}
}
////////////////////////////
}
void setup()
{
Serial.begin(9600);
analogReference(INTERNAL);
if (Ethernet.begin(mac) == 0)
{
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
pinMode(door_on, OUTPUT);
pinMode(door_off, OUTPUT);
pinMode(window_on, OUTPUT);
pinMode(window_off, OUTPUT);
pinMode(buzer, OUTPUT);
pinMode(fan_pin, OUTPUT);
}
void resetEthernet() {
client.stop();
client.flush();
delay(1000);
Ethernet.begin(mac, ip);
delay(1000);
}
void loop()
{
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.println(String(tempC));
insert_temp(String(tempC));
resetEthernet();
delay(500);
camera();
resetEthernet();
delay(500);
get_data();
resetEthernet();
}