ALL.pdf

Embed Size (px)

Citation preview

  • COMPUTER CONTROLLED SWITCHING SYSTEM FOR RESIDENTIAL

    LIGHTING CIRCUITS

    BY

    LAWANI OLUWASHEUN .A

    MATRIC NUMBER: 2010/1582

    A DISSERTATION SUBMITTED TO THE DEPARTMENT OF

    ELECTRICAL/ELECTRONICS AND COMPUTER ENGINEERING,

    BELLS UNIVERSITY OF TECHNOLOLGY, OTA, NIGERIA

    IN PARTIAL FULFILMENT OF THE REQUIREMENT FOR THE

    AWARD OF THE BACHELOR OF TECHNOLOGY (B.Tech) DEGREE IN

    ELECTRICAL AND ELECTRONICS ENGINEERING

    JUNE, 2015

  • ii

    CERTIFICATION

    This is to certify that Lawani Oluwasheun Abdulrasaq, matriculation number 2010/1582 of the

    Department of Electrical and Electronics Engineering, College of Engineering, Bells University

    of Technology carried out the project on the Design and Construction of a Computer Controlled

    Switching System for Residential Lighting Circuits in partial fulfillment for the award of degree

    of Bachelor of Technology in Electrical Electronics Engineering.

    _______________________ ___________

    External Examiner Date

    Date

    Date Dr. Megbonwon I.O.

    Project supervisor

    Head of department

  • iii

    ACKNOWLEDGEMENT

    First and foremost I give thanks to Almighty God.

    I thank my parents for their support and guidance.

    I thank Bells Engineering Department and its lecturers for guidance and impacting knowledge.

    I thank my supervisor for his guidance on my final year thesis.

    I thank my friends and all other member of the Bells University Community that have been

    helpful to me.

  • iv

    ABSTRACT

    This paper is presents the design and construction of a computer controlled lighting system using

    PIC18F2550 and VB.NET. The paper focuses on using USB interfacing with the PIC18F2550

    microcontroller using mikroC which uses C programming language, as development

    environment for the PIC18F2550 and Visual Basic .Net in developing the window based

    application (User Interface). The computer generates control signals to switch on or off the bulbs

    and also monitor if they are on or off. Proteus was used for circuit simulation and design.

  • v

    TABLE OF CONTENT

    Title Page..i

    Certification.ii

    Acknowledgement .....iii

    Abstract...iv

    Table of content...v

    List of figures ....vi

    List of tables .vii

    Chapter One: Introduction...1

    1.1.Background....1

    1.2.Aim and Objective.....1

    1.3.Methodology......2

    1.4.Scope of project.....3

    1.5.Significance of project.......4

    Chapter Two: Literature review...5

    2.1. Electrical Lightning and Lamps....5

    2.2. Bipolar Junction Transistor......10

    2.3. Relay........10

    2.4. Microcontroller....11

    2.5. Programming Microcontroller.....14

    2.6. PIC Microcontroller.....17

    2.7. Visual Basic and the .NET Framework....22

    2.8. Related works...24

    Chapter Three: Design Methodology......28

    3.1. Hardware Part...28

    3.2. Interface Part....37

    3.3. Software Part....43

    3.4. Working Principle............................................................................................46

    Chapter Four: Results and Discussions...49

    4.1. Simulation.....49

    4.2. Testing Microcontroller ...52

    4.3. Challenges and limitations....54

    Chapter Five: Conclusion and Recommendation....56

    5.1. Conclusion....56

    5.2 Recommendation...56

    References...57

    Appendix A- Apparatus .58

    Appendix B- Cost Estimate ....60

    Appendix C- Web Links .61

  • vi

    List of Figures

    Fig 3.1. Basic Linear Regulated Power Supply

    Fig 3.2. Relay Datasheet

    Fig 3.3. Picture of a compact Fluorescent Lamp

    Fig 3.4. Incandescent Lamp

    Fig 3.5. G-Type Plug

    Fig 3.6. G-Type Socket

    Fig 3.7. Four assorted LED indicators with very specification

    Fig 3.8. PIC 18F2550 Diagram

    Fig 3.9. Code Snippet from mickroC

    Fig 3.10. Programmer used to program microcontroller

    Fig 3.11. Type A USB connector

    Fig 3.12. SAMPLE CODE for the VB

    Fig 3.13. Circuit Diagram of Main Circuit Board

    Fig 3.14. Visual Basic Interface

    Fig 4.1. Power Pack (Closed)

    Fig 4.2. Power Pack (Open)

    Fig 4.3. Microcontroller Circuit (Closed)

    Fig 4.4. Microcontroller Circuit (Open)

    Fig 4.5. Relay Circuit (Closed)

    Fig 4.6. Relay Circuit (Open)

    Fig 4.7. Complete design

    Fig 4.8. USB Analyser

  • vii

    List of Table

    Table 3.1. Table of USB Pin showing name and color

    Table 4.1. PIC pin with voltage levels

  • 1

    CHAPTER ONE: INTRODUCTION

    1.1. BACKGROUND OF PROJECT

    Light is essential for human life. Modern societies have created homes, schools, and workplaces

    that rely on electric light sources.

    Use of an artificial source of light for illumination is lighting. It is a key element of architecture

    and interior design. Residential lighting uses mainly either incandescent lamps or fluorescent

    lamps and often depends heavily on movable fixtures plugged into outlets; built-in lighting is

    typically found in kitchens, bathrooms, and corridors and in the form of hanging pendants in

    dining rooms and sometimes recessed fixtures in living rooms.

    The computer control switching system for residential lighting circuit is a system that is

    incorporated into the circuitry of a house and whose purpose is to control the lighting of the

    house from a computer system.

    This has been made possible by the growth in telecommunication and computer technology. This

    allows control of lighting of a household by the use of a computer and even a mobile phone.

    1.2. AIMS AND OBJECTIVES

    The objectives are:

    -To allow for the control of the lighting in a residential building from a remote location using a

    computer system.

    -To allow the monitor of various lightings in a residential building.

  • 2

    1.3. METHODOLOGY

    The system is divided into three main part: Hardware part, Interface part and the software part-

    located on the portable computer system.

    The Hardware part is the part of the system actual physical switching takes place. The hardware

    part consists of Power pack, Transistor switching system, Relay switching system, and the lamp

    holders- where the bulb, tube or any form of lighting is connected.

    The Interface stage is the process of connecting Hardware to Software. The simplest methods to

    use for this purpose are:

    -PIC Microcontroller

    It is a microcontroller used in variety of embedded systems. It is a small computer on a single

    integrated circuit containing a processor core, memory, and programmable input/output

    peripherals.

    -USB

    The USB powers up the PIC microcontroller and also transmit data from and to the computer

    through the USB port. It is through the USB the computer and microcontroller communicate

    with each other.

    -MAX232 Converter

    The MAX232 is an IC that converts signals from an RS-232 serial port to signals suitable for

    use in TTL (Transistor-transistor logic) compatible digital logic circuits.

    The software part controls the switching process by using various layers of programming

    languages.

  • 3

    The language implementations are used are:

    - .NET Visual BASIC for user interface using kernel mode driver or port Libraries

    available.

    The programming languages in Visual Studio run in the .NET Framework. The

    Framework provides for easier development of Web-based and Windows-based

    applications, allows objects from different languages to operate together, and

    standardizes how the languages refer to data and objects.

    The .NET language all compile to (are translate to) a common machine language, called

    Microsoft Intermediate Language (MSIL). The MSIL code, called managed code, runs in

    the Common Language Runtime (CLR), which is part of the .NET Framework.

    - MickroC

    1.4. SCOPE OF THE PROJECT

    Focus is placed on designing a system that will control and monitor various lighting types

    (Ballast, Fluorescent light, Halogen, Neon, Light Emitting Diode (LED), Compact Fluorescent

    Lamps (CFLs) from a remote location. The system to be designed can be implemented into

    Building Management Systems, Smart Houses, and Energy saving initiatives and even for

    Industrial applications.

    Various techniques and methods of application will be expanded upon in subsequent chapters

    and working principle, as to give a broad outlook of the project.

  • 4

    1.5. SIGNIFICANCE OF PROJECT

    Achieving the objectives of the project solve a lot of problems upon implementation they

    include:

    - Saves time needed to switch all individual lightning switch; especially in large buildings.

    - Can be improved to automatically switch off light at a particular time in order to save

    energy e.g.: Upon sunrise (7:00 am) lights are automatically switched off and back on at

    (6:00pm) in the evening.

    - Can also be improved upon to allow for global control across the web.

    - It can also be used on household appliances and device switching.

    - Assistance for disabled individuals in turn on household light

    The development of this project also creates an avenue into the study of this kind of control

    and switching systems.

  • 5

    CHAPTER TWO: LITERATURE REVIEW

    2.1. ELECTRICAL LIGHTING AND LAMPS

    Electrical lighting has significantly improved the standard of living globally. The availability of

    bright and reliable illumination has made it possible for people to read, write and do intricate

    task much more effectively during the nighttime hours, without fear of fire hazard posed by

    using open flame be it lamp fueled by gas , oil or kerosene. It has also made homes more secure

    and streets safer to travel after dark.

    Incandescent lamps have long been the dominant light sources, but that dominance is being

    challenged by halogen and fluorescent lamps. The halogen lamps offer more intense and natural

    appearing light, while the newer fluorescent lamps consume less power for equivalent

    illumination, have far longer lives, and also provide cooler, more natural light.

    Various types of lamps/light bulbs are:

    1. Incandescent Lamp

    2. Tungsten-Halogen Lamp

    3. Compact Fluorescent

    4. Fluorescent Lamp

    5. High-Intensity Discharge (HID) Lamps

    6. LED Lamps

    1. Incandescent Lamps

    Incandescent lamps are available in many different bulb shapes with a various ranges of

    light output, energy consumption, and life ratings. Energy consumption can range from a

    fraction of a watt for a flashlight lamp to more than 10,000 W.

  • 6

    The number and types of available incandescent lamps are astonishing. Typical

    manufacturers catalogs list hundreds of different bulb styles with a wide range of

    wattage and voltage ratings, estimated useful lives, output in lumens - The unit of

    luminous flux - and other special qualities. However, average hardware stores, home

    improvement centers, and supermarkets narrow the number and type of lamps they carry

    down to the relatively few of those that are most familiar and most likely to be purchased

    by consumers.

    The smallest incandescent lamps are made for flashlights, holiday lighting strings, and

    instruments, while the largest bulbs, with diameters exceeding 20 inches, are spotlights

    and street lights. Mid-sized incandescent lamps, typically rated from 40 to 200 W, are

    those most widely used in home and office lighting.

    All incandescent lamps are made in essentially the same way, and today these

    processes are automated.

    2. Tungsten-Halogen Lamp

    A halogen or tungsten-halogen lamp is a high-pressure incandescent lamp containing a

    halogen gas such as iodine or bromine which allows the filament to be operated at a

    higher temperature than an incandescent lamp, increasing its efficacy. Halogen lamps

    emit brighter, more intense white light than incandescent lamps, but they are smaller than

    incandescent lamps with comparable wattage rating. However, the characteristics of the

    two lamp sizes are similar. Because of the higher color temperatures of halogen lamps

    (3000 K versus 2800 K), they use quartz rather than glass bulbs. The high-temperature

    chemical reaction involving tungsten and the halogen gas recycles evaporated

  • 7

    particles of tungsten back onto the filament surface. These lamps are used in high-

    intensity desk and reading lamps, vehicle headlights, spotlights, and flashlights.

    3. Fluorescent Lamp

    Fluorescent lamps are high-efficiency lamps that produce visible light as a result of an

    interaction of the ultraviolet (UV) energy they produce with the phosphor coating on the

    insides of their glass enclosure. The lamp envelope contains traces of an inert gas and a

    drop of mercury. When the lamp is turned on, the mercury is vaporized, and this vapor

    and the inert gas are ionized by electron flow between electrodes at each end of the lamp

    to produce UV emission.

    The UV energy excites the phosphor power electron that have been applied as thin layers

    on the inside of a glass envelop, tube or bulb. The UV emission that fall on the phosphors

    layer is transformed into visible light whose properties depend on the composition of the

    phosphor layer.

    The phosphor coatings inside the tube are mixed to tailor the properties of the emitted

    light for specific coloration and lighting effects. Among the possibilities are cool white,

    deluxe cool white, warm white, deluxe warm white, white, and daylight. Energy-

    saving lamps have an argonkrypton gas mixture, and others have combinations of argon

    and neon or argon, neon, and xenon.

    Fluorescent lamps can produce 50 to 100 lumen per Watt, making them 4 to 6 times more

    efficient than incandescent lamps. In general, a quality fluorescent lamp can produce 3 to

    4 times the light output of an incandescent lamp with an equivalent wattage rating.

  • 8

    4. Compact Fluorescent Lamp

    Compact fluorescent lamps (CFLs) are intended to replace standard incandescent lamps

    where longer life, lower power consumption, and lower heat dissipation justify their

    higher cost. They are available in many different shapes, but are generally about the same

    size as conventional incandescent lamps.

    The number of turns on a spiral CFL bulb relates directly to its lumen output, and the

    number of U-shaped elements (two to four) on a bi-ax lamp relates directly to its lumen

    output. There are also circular, cylindrical, globe, three-way, chandelier, and candelabra

    CFLs.

    5. High-Intensity Discharge (HID) Lamps

    A general class of lamps called high-intensity discharge (HID) includes mercury-vapor,

    metal halide, and high-pressure sodium lamps. All electric discharge lamps include

    cylindrical transparent or translucent arc tubes that enclose the mercury, various gases,

    and metal salts and confine the electric discharge. The arc tubes are enclosed in a glass

    bulb which performs three functions:

    Excludes air to prevent oxidation of metal

    Stabilizes operating temperature of the lamp

    Reduces ultraviolet radiation emitted by the excitation of the vapor

    These lamps operate at high pressures and very high temperatures. They can be ruptured

    by mishandling, misapplication, or ballast failure. An arc-tube rupture can burst and

    shatter the outer glass bulb, resulting in an explosion that scatters glass fragments at

    temperatures as high as 1832F (1000C). To reduce the risk of personal injury, property

    damage, or fire, the lamp must be enclosed in a rigid housing with a combination lens and

  • 9

    diffuser that can contain these hot fragments. HID lamps give full light output over a

    wide range of ambient temperatures. This makes them suitable for street, stadium, and

    parking lot lighting as well as building floodlighting and interior high-bay illumination.

    6. LED Lamp

    An LED lamp is a light-emitting diode (LED) product that is assembled into a lamp for

    use in lighting fixtures. LED lamps lifespan and electrical efficiency are several time

    better than incandescent lamps and significantly better than most fluorescent lamps.

    Like incandescent lamps and unlike most fluorescent lamps LEDs come to full brightness

    without need for a warm-up time. The initial cost of LED is usually higher.

    Some LED lamps are made to be a directly compatible drop-in replacement for

    incandescent or fluorescent lamps. LEDs do not emit light in all directions, and their

    directional characteristics affect the design of lamps. The light output of single LEDs is

    less than that of incandescent and compact fluorescent lamps; in most applications

    multiple LEDs are used to form a lamp, although high-power versions are becoming

    available.

    LED chips need controlled direct current (DC) electrical power; an appropriate circuit is

    required to convert alternating current from the supply to the regulated low voltage direct

    current used by the LEDs. LEDs are adversely affected by high temperature, so LED

    lamps typically include heat dissipation elements such as heat sinks and cooling fins.

    White LED lamps have achieved market dominance in applications where high efficiency

    is important at low power levels. Some of these applications include flashlights, solar-

    powered garden or walkway lights, and bicycle lights. Monochromatic (colored) LED

  • 10

    lamps are now commercially used for traffic signal lamps, where the ability to emit bright

    monochromatic light is a desired feature, and in strings of holiday lights.

    2.2. BIPOLAR JUNCTION TRANSISTOR

    A bipolar transistor is used to amplify current or/and can be used to switch current on and off. In

    amplifying, it replaced the vacuum tubes that were formerly used in the amplification of audio

    signals and many other applications. It resembles a relay when functioning as a switching device,

    although in its off state the transistor still allows a very small amount of current flow, known

    as leakage. It is a pair of diode coupled together; this prevents current flow, unless you apply a

    current to the middle part, also known as the base of the transistor. When a current is applied to

    the base, the junction is energized and current flows through the transistor. The other connections

    on the transistor are called the collector and the emitter.

    The two configuration of transistors are PNP and NPN. The NPN needs current to be pushed into

    the base to turn the transistor on, whereas the PNP needs current to be pulled out of the base to

    turn it on. That is, the NPN requires the base to be more positive than the emitter, whereas the

    PNP requires the base to be more negative than the emitter.

    Transistors are current-driven devices; they require significant current flow to operate. Most

    times the current flow needed in the base is 50 to 100 times less than the amount flowing through

    the emitter and collector, but it is significant compared to what are called voltage-driven devices.

    2.3.RELAY

    Relays are electrically controlled switch. They are electromechanical in nature. A relay contains

    a coil, an armature, and at least one pair of contacts. Current flows through the coil, which

  • 11

    functions as an electromagnet and generates a magnetic field. This pulls the armature, which is

    often shaped as a pivoting bracket that closes (or opens) the contacts. The relay combine the

    function of a solenoid and a switch. A magnetic force pulls the switch shut or open, depending

    on the particular device.

    Markings on a relay usually indicate the coil that operates the relay and the labels NO, NC, and

    C. These abbreviations, also sometimes seen on relay, mean normally open, normally closed, and

    common, respectively. NO and NC refer to the state of the relay when current isnt flowing

    through the coil. C is a connection to both these switches.

    There are two important specs on a relay: the coil voltage and the contact ratings. The Contacts

    are often rated at a minimum as well as a maximum current. Many relays used in a power setting

    rely on a certain amount of current to be present when the switch opens. This current creates an

    arc that cleans the contacts and keeps them from corroding. Not meeting this spec can cause the

    relay to corrode. When the relay is turned on or off a clicking sound can be heard. The

    configuration of a relay is specified using the same abbreviations that apply to a switch. SP, DP,

    3P, and 4P indicates 1, 2, 3, or 4 poles -relays with more than 4 poles are not common. ST and

    DT indicate single-throw or double-throw switching. These abbreviations are usually

    concatenated, as in 3PST or SPDT. A (meaning normally open), Form B (normally closed), and

    Form C (double-throw) may be used, preceded by a number that indicates the number of poles.

    Thus 2 Form C means a DPDT relay.

    2.4.MICROCONTROLLER

    A microcontroller is a complete microprocessor-based control system built onto a single chip.

    It consist of microprocessor core, memory, and programmable input/output peripherals. Program

  • 12

    memory in the form of Ferroelectric RAM, flash memory or PROM is also often included on

    chip, as well as a typically small amount of RAM. Microcontrollers are used in automatically

    controlled products and devices, such as automobile engine control systems, implantable medical

    devices, remote controls, office machines, appliances, power tools, toys and other embedded

    systems. The integration of the microprocessor and its system reduces the size and cost

    compared to a design that uses a separate microprocessor, memory, and input/output devices,

    microcontrollers make it economical to digitally control even more devices and processes. Mixed

    signal microcontrollers are common, integrating analog components needed to control non-

    digital electronic systems.

    A Microcontroller mainly consist of the following:

    2.4.1. INSTRUCTION MEMORY

    This can be described as instruction memory ROM, or read-only memory, but due to recent

    advance in microcontroller technology there are a lot of micros that can write to their own

    instruction memory. This can be programmable memory, hard coded, Flash, or even an external

    chip that the core reads to get its instructions. The instructions are stored as digital binary digits

    that form bytes that represent instructions.

    2.4.2. DATABUS

    The databus is very essential for the transfer of data within the micro, it is the internal

    connections that allow different parts of the micro to connect internally by carrying data around

    the system. Virtually everything that happens inside a micro will at some point move through the

    databus.

  • 13

    2.4.3. INSTRUCTION DECODER

    An instruction decoder is a kind logic type circuits. It interprets the instruction that is given to it

    and sets the corresponding tasks into motion.

    Its first step is to identify which instruction that has been entered. It does this by comparing its

    binary code with an internally stored list. Once it has located the instruction it follows a built-in

    program called a microprogram. This microprogram is designed into the microprocessor by the

    manufacturer and details all the necessary steps to complete any instruction of which it is

    capable. This is the commercially sensitive and critical part of the microprocessor

    2.4.4. REGISTERS

    Registers are places to store data; they are literally the memory cells. This is the RAM inside the

    micro. It is the scratch pad for manipulating data. It can also be accessed on an external chip in

    some cases.

    2.4.5. ACCUMULATOR

    An accumulator is a type of special register that usually connects directly to the arithmetic logic

    unit (ALU). When a math function is performed on a piece of data in the accumulator, the

    answer is left in the accumulator. On a many of the newer micros, nearly any register can be used

    in a similar manner.

    2.4.6.ALU

    The arithmetic logic unit, or ALU, is a part that can perform various mathematical and logic

    operations on a piece of data. It can add, subtract, multiply, divide, and do various operations

    with logic gates AND, OR, XOR etc.

  • 14

    2.4.7. PROGRAM COUNTER

    The program counter keeps track of where the micro is in its program. The purpose of the

    program counter is to keep track of the memory address that is going to be used next.

    2.4.8. TIMER COUNTERS

    Timer counters are useful for creating a structure for code to operate in. Sometimes called real-

    time clock counters (RTCC), they are counters that usually can run from an independent source.

    They will tick at whatever interval set up for them to tick, without any other intervention.

    Sometimes they can be hooked up to external clock sources and inputs. Usually they can be set

    to generate an interrupt at a preset time.

    2.4.9. INTERRUPT

    An interrupt is a monitoring circuit that, if triggered, makes the micro stop what it is doing and

    execute a piece of code associated with the interrupt. These signals can be generated by internal

    conditions or external inputs. Typically only certain pins can drive interrupts.

    When the microprocessor is interrupted, it stores information internally about what it was doing

    at the time of the interrupt so that when the interrupt is dealt with it can return to its previous

    task.

    2.5.PROGAMMING MICROCONTROLLERS

    A microcontrollers microprocessor relies entirely on following a sequence of instructions as to

    operate and carry out its functions. Each microprocessor has a built-in list of instructions that it

    can understand. This list is called its instruction set and may consist of about a hundred or so

    instructions which must be put together in the right order to carry out the function required.

  • 15

    When the microprocessor is designed, the instruction decoder recognizes these inputs and starts

    an internal process that allows the microprocessor to carry out the instruction. This assumes that

    the microprocessor is familiar with the instruction or, to put it another way, the instruction is in a

    language that is understood by that particular microprocessor.

    2.5.1. MACHINE CODE

    The binary code that is understood by the microprocessor is called machine code and consists of

    streams of binary bits. They are fed from the RAM or ROM memory chips in blocks of 8, 16, 32

    or 64 depending on the microprocessor in use. To us the binary stream is incomprehensible.

    Machine code is not friendly or easy understanding, typing in streams of ones and zeros is

    monotonous and can lead to many mistakes, particularly when a written program contain

    thousands of such digits. Another problem is that the programmer must be aware of the internal

    structure of the microprocessor. This problems resulted in a new language called Assembly

    which overcame the most immediate failings of machine code.

    2.5.2. ASSEMBLY LANGUAGE

    Assembly language was designed to do the same work as machine code but be much easier to

    use. It replaced all the ones and zeros with letters that were easier to remember called

    mnemonics but it is still a low-level language. A mnemonic is just an aid to memory and is used

    for all assembly codes. Here are a couple of examples:

    SLA E for shift to the left, the contents of register E.

    LD B 25H load the B register with the number 25H.

    Assembler allows us to type in the assembly code, called the source code, and converts it to

    machine code referred to as object code. It can show the object code on a monitor screen or print

    it out or it can load it into the RAM ready for use. When starting the assembler, we have to state

  • 16

    the RAM starting address that we wish to use. This is normally only a matter of making sure it is

    in RAM and avoiding the other programs already installed. The object code is shown in hex

    numbers rather than binary to make it easier for us.

    An assembler can only work within the instruction set provided by the microprocessor designer.

    It cannot add any new instructions and is (almost) just a simple converter or translator between

    mnemonics and machine code.

    Assemblers are available from many sources and all provide the necessary conversion from

    source code to object code. In addition, they may provide other features that will help us in the

    programming.

    Assembly and machine code are not portable. This means that they are designed to be used on a

    particular microprocessor and are generally not able to be used on another type. They also

    require the programmer to have knowledge of the internal layout or architecture of the

    microprocessor. This has prompted the development of high level programing language.

    2.5.3. HIGH LEVEL PROGRAMMING LANGUAGES

    They were designed to improve the readability by using English words which would make it

    easier to understand and to sort out any bugs in the program. The process of removing bugs is

    called debugging. In addition, they should relieve the programmer of any need to understand the

    internal architecture of the microprocessor and so the program should be totally portable. Ideally

    the programmer should not even need to know what processor is being used. These languages are

    called high-level and are all procedural. Over the years, many languages have been invented

    just as there have been many microprocessors. Just like the microprocessors, a few languages

    had some special aptitude that made them stand out from the crowd. E.g. FORTRAN, c, c++,

    Java, Flow Code.

  • 17

    2.6.PIC MICROCONTROLLER

    PIC is family of microcontroller developed by Microchip Technology. All current models

    use Flash memory for program storage, and newer models allow the PIC to reprogram

    itself. Program memory and data memory are separated. Data memory is 8-bit, 16-bit and in

    latest models, 32-bit wide. Program instructions vary in bit-count by family of PIC, and may be

    12, 14, 16, or 24 bits long. The instruction set also varies by model, with more powerful chips

    adding instructions for digital signal processing functions.

    The hardware capabilities of PIC devices range from 8-pin DIP chips up to 100-pin SMD chips,

    with discrete I/O pins, Analog to Digital Converter and Digital to Analog Converter modules,

    and communications ports such as UART, I2C, CAN, and even USB.

    PIC devices generally feature:

    Flash memory (program memory, programmed using MPLAB devices)

    SRAM (data memory)

    EEPROM memory (programmable at run-time)

    Sleep mode (power savings)

    Watchdog timer

    Various crystal or RC oscillator configurations, or an external clock

    The PIC architecture is characterized by its multiple attributes:

    There is no distinction between memory space and register space because the RAM serves the

    job of both memory and registers, and the RAM is usually just referred to as the register file or

    simply as the registers. Devices called "programmers" are traditionally used to get program code

    into the target PIC. Most PICs that Microchip currently sell feature ICSP (In Circuit Serial

  • 18

    Programming) and/or LVP (Low Voltage Programming) capabilities, allowing the PIC to be

    programmed while it is sitting in the target circuit.

    Microchip offers programmers/debuggers under the MPLAB and PICKit series. MPLAB ICD

    and MPLAB REAL ICE are the current programmers and debuggers for professional

    engineering, while PICKit is a low-cost programmer-only line for hobbyists and students.

    PIC microcontrollers are a very convenient choice to get started in the microcontroller and

    processor field. All PICs and indeed all microprocessors and microcontrollers use binary code

    and nothing else. To make life easier for us, we use assembly language or a high level language.

    To use these languages, we need a program which is able to convert them to binary code.

    For assembly language, the required program is called an assembler and for higher level

    languages a similar job is done by a compiler. An assembler is part of the PICSTART PLUS

    development system but there are other assemblers available that will handle code for all the

    PICs. The code that we write as the input to the assembler is called source code and the code

    that is supplied by the assembler is called object code. The object code is really in binary but to

    make it easier for us, it is usually displayed on the screen in hex. A graphical programming

    language, Flowcode, exists capable of programming 8- and 16-bit PIC devices and generating

    PIC-compatible C code. It exists in numerous versions from a free trial version to a more

    complete professional edition. Or MikroC which uses the C programming language which comes

    with USB programming tools.

  • 19

    2.6.1. INTERFACING PIC

    Interfacing is the connection of two systems so they communicate with each other. PICs can be

    interfaced with a circuit or external device. In order for the PIC to communicate some of the

    methods that will be considered are:

    2.6.1.1. Analog to digital conversion (ADC)

    An analog-to-digital converter is used for converting continuous data signal to discrete digital

    quantity. The bandwidth and signal to noise ratio is considered for the analog to digital

    conversion process. The major types are:

    Flash Analog to digital conversion

    It utilizes an array of comparators sampling the input by comparing it to a reference

    voltage checking if its lower or higher. Flash ADC is very fast, and capable of

    gigahertz sampling rates.

    successive-approximation Analog to digital conversion

    It uses a comparator to successively narrow a range that contains the input voltage. At

    each successive step, the converter compares the input voltage to the output of an

    internal digital to analog converter which might represent the midpoint of a selected

    voltage range.

    Ramp-Compare Analog to digital conversion

    It produces a saw-tooth signal that ramps up or down then quickly returns to zero.

    When the ramp starts, a timer starts counting. When the ramp voltage matches the

    input, a comparator fires, and the timer's value is stored. Timed ramp converters

    require the least number of transistors. The ramp time is sensitive to temperature

    because the circuit generating the ramp is often a simple oscillator. There are two

  • 20

    solutions: using a clocked counter driving a DAC and then use the comparator to

    preserve the counter's value, or calibrate the timed ramp.

    Applications include Music recording, Digital signal processing, scientific instruments

    2.6.1.2.Digital to Analog Converter (DAC)

    Changing a group of digital bit values to an analog voltage is the reverse process of the analog to

    digital conversion. Most digital to analog converters operate by adding current together then

    converting the result into an analog voltage. The binary levels are used to switch currents on or

    off. Pulse-width modulation is the simplest method.

    Applications include motor speed control, telecommunication, inverter, audio engineering etc.

    The methods of data transmission that are considered are, serial and parallel transmission.

    Parallel Transmission

    Data is sent simultaneously along a collection of wire. There are different standards for

    parallel data transmission. The Centronics system which transmits eight bits at a time and

    employs a 36 plug and socket system being the most popular.

    Serial Transmission

    Data is sent one at a time along a wire in serial transmissions. This makes it slower than

    the parallel transmission.

    2.6.2. UART

    This stands for Universal Asynchronous Receiver/Transmitter. It is an integrated circuits that

    convert data from parallel to serial transmission so instead of having eight wires, each carrying a

    single bit at the same time, the serial transmission passes the bits, one at a time along a single

    wire. This is done by using a shift registers, parity check and buffers.

    They are used for serial communications over a computer or peripheral device serial port.

  • 21

    2.6.3.RS-232

    RS-232 is a standard for serial communication transmission of data created by the EIA

    (Electronic industries Association) committee. It is commonly used in computer serial ports for

    connecting to peripherals like printers and mice. It has been replaced USB for most of its

    application and in most personal computers.

    The Electronic Industries Association (EIA) standard RS-232-C as of 1969 defines:

    Electrical signal characteristics such as voltage levels, signaling rate, timing

    and slew-rate of signals, voltage withstand level, short-circuit behavior, and

    maximum load capacitance.

    Interface mechanical characteristics, pluggable connectors and pin

    identification.

    Functions of each circuit in the interface connector.

    Standard subsets of interface circuits for selected telecom applications.

    A UART usually contains the following components:

    a clock generator, usually a multiple of the bit rate to allow sampling in the

    middle of a bit period.

    input and output shift registers

    transmit/receive control

    read/write control logic

    transmit/receive buffers (optional)

    parallel data bus buffer (optional)

    First-in, first-out (FIFO) buffer memory (optional)

  • 22

    2.6.4. MAX232

    The MAX232 is a level converter IC for converting RS-232 serial port signal to logic values for

    use in digital circuits. It consists of two transmitters and two receivers and operate up to 120

    kbits/s. When a MAX232 IC receives a TTL level to convert, it changes a TTL logic 0 to

    between +3 and +15 V, and changes TTL logic 1 to between -3 to -15 V, and vice versa for

    converting from RS232 to TTL.

    2.7. VISUAL BASIC AND THE .NET FRAMEWORK

    The programming languages in Visual Studio run in the .NET Framework. The Framework

    provides for easier development of Web-based and Windows-based applications, allows objects

    from different languages to operate together, and standardizes how the languages refer to data

    and objects. Several third-party vendors have released versions of other programming languages

    to run in the .NET Framework, including .NET versions of APL by Dyalog, FORTRAN by

    Lahey Computer Systems, COBOL by Fujitsu Software Corporation, Pascal by the Queensland

    University of Technology (free), PERL by ActiveState, RPG by ASNA, and Java, known as

    IKVM.NET.

    The .NET languages all compile to or are translated to a common machine language, called

    Microsoft Intermediate Language (MSIL). The MSIL code, called managed code, runs in the

    Common Language Runtime (CLR), which is part of the .NET Framework.

    2.7.1VISUAL BASIC

    Visual Basic is a high-level programming language known for its simplicity. It comes with

    Visual Studio. You also can purchase Visual Basic by itself without including the other

    languages but with the .NET Framework. Visual Basic is available in an Express Edition, a

  • 23

    Standard Edition, a Professional Edition, and a Team System Edition. Anyone planning to do

    professional application development that includes the advanced features of database

    management should use the Professional Edition or the Team System Edition. The Professional

    Edition is available to educational institutions through the Microsoft Academic Alliance program

    and is the best possible deal. When a campus department purchases the Academic Alliance, the

    school can install Visual Studio on all classroom and lab computers and provide the software to

    all students and faculty at no additional charge.

    Many Visual Basic applications are developed and implemented in the commercial, hospital, and

    service fields. The designers of Visual Basic did not intend to develop a powerful language to

    access and control low level hardware in real time, and thus, by itself, Visual Basic can neither

    access nor control low level hardware. However, by using certain external interfaces, Visual

    Basic can easily and efficiently access and control low-level hardware. They are:

    Calling the Dynamic Link Libraries (DLLs) developed in C\C++

    Calling the Windows application program interface (Win32 APIs)

    Implementing the Active-X control, MSComm

    The Visual Studio environment is where projects are created and tested. A development

    environment, such as Visual Studio, is called an integrated development environment (IDE). The

    IDE consists of various tools, including a form designer, which allows effortless creation for a

    form; an editor, for entering and modifying program code; a compiler, for translating the Visual

    Basic statements into the intermediate machine code; a debugger, to help locate and correct

    program errors; an object browser, to view available classes, objects, properties, methods, and

    events; and a Help facility.

  • 24

    In versions of Visual Studio prior to .NET, each language had its own IDE. For example, to

    create a VB project the VB IDE is used, and to create a

    C++ project the C++ IDE is used. But in Visual Studio, you one IDE is used to create projects in

    any of the supported languages.

    Like the BASIC programming language, Visual Basic was designed to accommodate a steep

    learning curve. Programmers can create both simple and complex GUI applications.

    Programming in Visual Basic is a combination of visually arranging components or controls on

    a form, specifying attributes and actions for those components, and writing additional lines

    of code for more functionality. Since Visual Basic defines default attributes and actions for the

    components, a programmer can develop a simple program without writing much code. Programs

    built with earlier versions suffered performance problems, but faster computers and native code

    compilation has made this less of an issue.

    Though VB programs can be compiled into native code executables from version 5 on, they still

    require the presence of around 1 MB of runtime libraries. Runtime libraries are included by

    default in Windows 2000 and later. Earlier versions of Windows (95/98/NT), require that the

    runtime libraries be distributed with the executable.

    2.8 RELATED WORKS

    Wireless Controlled Methods via Voice and Internet (e-mail) for Home Automation

    System (R.A.Ramlee et al,2013)

    Abstract This paper presents a wireless Home Automation System (HAS) that mainly

    performed by computer. The system is designed with several control methods in order to

    control the target electrical appliances. This various control methods implemented to

    fulfill the needs of users at home even at outside. The computer application is designed in

  • 25

    Microsoft Windows OS that integrated with speech recognition voice control by using

    Microsoft Speech Application Programming Interface (SAPI). The voice control method

    provides more convenience especially to the blind and paralyzed users at home. This

    system is designed to perform short distance control by using wireless Bluetooth

    technology and long distance control by using SimpleMail Transfer Protocol (SMTP)

    email control method. The short distance control is considered as the control that

    performed inside the house. Moreover, the long distance control can be performed at

    everywhere by devices that installed with browser or email application, and also with the

    internet access. The system intended to control electrical appliances at home with

    relatively low cost design, user-friendly interface and ease of installation.

    Gui Based Remote On/Off Control And Monitoring Single Phase Lamp Using

    Microcontroller (Mohd Suhaimi B. Sulaiman, Zawawi bin Ismail Abdul

    Wahab,2010)

    Microcontrollers are very popular in electronics and computer-controlled systems

    worldwide. This paper presents the control of a microcontroller-based system using the

    computer and explains comprehensively the hardware and software parts of the

    microcontroller. Peripheral Interface Controller (PIC) software developed by Microchip

    (MPASM) is used in programming a PIC microcontroller, and Visual Basic is used in

    programming the user interface. The developed system showed that the auto-switching

    mode of transmission could be implemented via the PIC microcontroller and an RS485

    transceiver. The PIC microcontroller is chosen to implement the control unit due to its

    advantages such as high speed, Harvard and Reduced Instruction Set Computer (RISC)

    architecture, low cost and flexibility for programming. The controller unit used in the

  • 26

    mentioned processes is designed. The developed system showed that the Graphical User

    Interface (GUI) and the microcontroller successfully switched on and off a single-phase

    lamp via twisted pair cables.

    GSM Based Electrical Control System for Smart Home Application (Mohd Helmy

    Abd Wahab et al ,2010)

    This paper presents the development of GSM-based control home appliances for smart

    home system. The main aim of the prototype development is to reduce electricity

    wastage. GSM module was used for receiving short message service (SMS) from users

    mobile phone that automatically enable the controller to take any further action such as

    to switch ON and OFF the home appliances such as light, air conditioner etc. The

    system was integrated with microcontroller and GSM network interface using assembly

    language. MPLAB software was utilized to accomplish the integration. The system is

    activated when user sends the SMS to controller at home. Upon receiving the SMS

    command, the microcontroller unit then automatically controls the electrical home

    appliances by switching ON or OFF the device according to the user order. In other

    word, it read message from the mobile phone and response to control the devices

    according to the received message.

    The prototype has been successfully developed and it could provide an effective

    mechanism in utilizing the energy source efficiently

  • 27

    Computer Interfacing Through the USB Port (Building a USB Device) (Abioye

    Ayodeji Opeyemi, Nathan David,2013)

    Traditional computer interfacings (for robot control, measurements, reading and

    logging data, etc.) have been mostly achieved through the serial port or parallel

    port. However, the modern trend utilizes the USB in interfacing with the computer

    system. For instance, mobile PCs such as the laptops, mini-laptops, etc. no longer

    come with the serial or parallel port; hence project development using these computers

    becomes a challenge to the project developer whose interface knowledge is limited

    to the serial or parallel port. This is even more challenging for developing countries

    where projects of this kind would require importing some advance components

    (development boards) at extra expenses. This paper focuses on practical USB

    interfacing using PIC18F4550 as the microcontroller for the device; mikroC as the

    C language development environment for the PIC18F4550; and visual basic (VB9) in

    developing the windows based application. A USB test device was built as well as its

    windows based test application. The computer is used to generate control signals to

    switch ON or OFF some LEDs. This work presents students, lectures, researchers,

    industrialists, etc. in institutions and industries with an alternative to computer

    interfacing.

  • 28

    CHAPTER THREE: DESIGN METHODOLOGY

    The Light control system consists of the following parts:

    1. Hardware part

    2. Interfacing part

    3. Software part

    3.1 HARDWARE PART

    This is the part of the light switching system that receives the instruction to do the actually

    physical switching of the light points. It is made of the following components:

    Transformer

    Rectifier

    BD 139 Transistor

    Relay

    Lamp, Lamp Holder, Socket ( Load Module )

    LED (Light Emitting Diode)

    3.1.1 TRANSFORMER

    Transformers converts input alternating current to output voltages that can be higher or lower.

    The range from tiny impedance matching units used in audio circuits to large multi ton weighing

    ones used in power grids. The two types of cores are magnetic and air core. The magnetic core is

    the most commonly used since it is more efficient than air core. Transformers work by the

    process of mutual induction; this process involves when the primary winding is loaded with

    current, the secondary winding is induced and it draws current for the primary winding without

    there being contact. Hence, in an ideal transformer, mathematically:

  • 29

    Vp/ Vs= Np/ Ns

    A transformer can either be step-up or down-up. A step-up transformer has a higher voltage at its

    output than at its input while a step-down transformer has a higher voltage at its input than at its

    output.

    For this application a power transformer that converts 220V 50Hz to 12V of 660mA is used with

    the input connected to 220V electric supply and 12V output to a rectifier. For conversion to DC

    3.1.2 RECTIFIER

    A rectifier converts alternating current into direct current at which is what most electronic

    devices require to operate. It requires the supply of power from a transformer. Most electronics

    devices come with a rectifier contained within the power supply.

    The Light control system hardware part uses a linear regulated power supply, which converts AC

    to DC in three stages:

    1. Power transformer reduces the AC input to lower-voltage AC.

    2. A diode rectifier converts the AC to unsmoothed DC using four IN4007 diode in a

    bridge rectifier circuit.

    3. A linear voltage regulator provides a tightly controlled DC output, which it derives

    from an unregulated or poorly regulated DC input. The DC output remains constant

    regardless of the load on the regulator (within specified limits). It is a cheap, simple,

    and extremely robust component. A voltage regulator in conjunction with one or

    more capacitor, controls the DC voltage, smooths it and removes transients. The

    voltage regulator responding linearly to fluctuations in base current, at less than their

    saturation level.

  • 30

    An LM7805 voltage regulator is used. This series of fixed-voltage integrated-circuit voltage

    regulators is designed for a wide range of applications. These applications include on-card

    regulation for elimination of noise and distribution problems associated with single-point

    regulation. Each of these regulators can deliver up to 1.5 A of output current. The internal

    current-limiting and thermal-shutdown features of these regulators essentially make them

    immune to overload. In addition to use as fixed-voltage regulators, these devices can be used

    with external components to obtain adjustable output voltages and currents, and also can be used

    as the power-pass element in precision regulators.

    Fig3.1. Basic Linear Regulated Power Supply

    The theoretical DC output of the rectifier system is 16.97Volts (square root of 2 x 12 volt) but

    due to losses in practice this voltage will be less.

    3.1.3 BD139 TRANSISTOR

    The BD 139 is an NPN epitaxial silicon transistor used for medium power linear amplification

    and switching, it uses a TO-126 3L package. TO-126 is a type of semiconductor package for

    devices with three pins, such as transistors. The package is rectangular with a hole in the middle

    to allow for easy mounting and/or heat sinking. The Base Current is 0.5A.

  • 31

    This transistor is used for switching purpose when current passes to the base it allows current to

    flow between the collector and emitter. This is how current gets to the coil of the relay for lamp

    switching.

    3.1.4 RELAY

    A relay enables a signal or pulse of electricity to switch on (or switch off) a separate flow of

    electricity. Often, a relay uses a low voltage or low current to control a higher voltage and/or

    higher current. The low voltage/low current signal can be initiated by a relatively small,

    economical switch, and can be carried to the relay by relatively cheap small-gauge wire, at which

    point the relay controls a larger current near to the load.

    A JZC-20F, 10A 12VDC relay is used for the switching of the 240V light bulb load. It is a small

    size, light weight, low coil power consumption with switching capacity up to 15A and can be

    used for PC board mounting. It is suitable for household electrical appliance, automation system,

    electronic equipment, instrument, meter, telecommunication facilities and remote control

    facilities. The datasheet for the relay is shown below.

  • 32

    Fig 3.2. Relay Datasheet

    3.1.5 LAMP, LAMP HOLDER AND SOCKET (LOAD MODULE)

    Four 65W compact fluorescent lamp holder and two sockets are attached onto a board. These are

    the point the system aim to switch and monitor. Colored incandescent bulbs are used. Also U-

    tubed shaped with white light fluorescent is used in the testing phase.

    3.1.5.1. COMPACT FLUORESCENT LAMP

    A compact fluorescent lamp (CFL), also called compact fluorescent light, energy-saving light,

    and compact fluorescent tube, is a fluorescent lamp designed to replace an incandescent lamp;

    some types fit into light fixtures formerly used for incandescent lamps. The lamps use a tube

    which is curved or folded to fit into the space of an incandescent bulb, and a compact electronic

    ballast in the base of the lamp. CFLs have two main components: a magnetic or electronic ballast

  • 33

    and a gas-filled tube (also called bulb or burner). Replacement of magnetic ballasts with

    electronic ballasts has removed most of the flickering and slow starting traditionally associated

    with fluorescent lighting, and has allowed the development of smaller lamps directly

    interchangeable with more sizes of incandescent bulb.

    Fig 3.3. Picture of a Compact Fluorescent Lamp

    3.1.5.2 COLORED INCANDESCENT LAMP

    An incandescent light bulb, incandescent lamp or incandescent light globe is an electric

    light which produces light with a wire filament heated to a high temperature by an electric

    current passing through it, until it glows.

    A 230 Volts lamp is used in the design its workings is far more easier than that of fluorescent

    lamp which comes with a ballast and require some time to start up.

  • 34

    Fig 3.4. Incadescent bulb

    3.1.5.3. SOCKET

    AC power plugs and sockets are devices that allow electrically operated equipment to be

    connected to the primary alternating current (AC) power supply in a building.

    Type G plugs and sockets are used in the device. The Type G electrical plug has three

    rectangular blades in a triangular pattern and has an incorporated fuse (usually a 3 amps fuse for

    smaller appliances such as a computer and a 13 amps one for heavy duty appliances such as

    heaters).

  • 35

    Fig 3.5. G-Type Plug

    Fig 3.6. G-Type Socket

  • 36

    3.1.6 LED (LIGHT EMITTING DIODE) INDICATOR

    LED indicator is defined as a component usually 10mm or smaller in diameter, made of transparent

    or translucent epoxy or silicone, most often containing one light-emitting diode. It is purposed as

    a status indicator in a device, rather than as a source of illumination, and is sometimes referred to

    as a standard LED. The term light-emitting diode is becoming less common, as the acronym LED

    has become ubiquitous.

    An LED indicator emits light in response to a small current, typically around 20mA (but sometimes

    much less), at a voltage lower than 5VDC. The color of the light is initially determined by the

    chemical compounds used internally, and by their dopants; therefore, a water-clear LED may emit

    colored light.

    Like all semiconductor devices, LEDs can be impaired by excess forward current and may

    breakdown irreversibly if subjected to excess reverse voltage. They are also vulnerable to heats

    and to an extent static electricity. An LED will have two leads of unequal length. The longer lead

    is the anode and is connected to the more positive side of the circuit. The shorter lead serves as

    the cathode of the diode and is wired to the more negative side of a circuit.

    Fig 3.7. Four Assorted LED indicators with very specification

  • 37

    3.2 INTERFACE PART

    This part of the light control system purpose is translate the instruction from the computer to

    electric signals is used to control the circuit and also receive signals from the circuit that is use by

    the computer to monitor the light and socket points on the socket. The PIC microcontroller is the

    core of this part of the system. It is made of the following components:

    PIC18F2550 microcontroller

    Crystal oscillator

    USB connector

    3.2.1. PIC18F2550 MICROCONTROLLER

    PIC18F2550 is the microcontroller implemented for the system it is used specifically because of

    its USB capabilities. The microcontroller receives instruction in ASCII form from the computer.

    ASCII Stands for America Standard Code for Information Interchange is a character-encoding

    scheme. It encodes 128 specified characters into 7-bit binary integers. ASCII codes represents text

    in computers, communications equipment, and other devices that use text. Most modern character-

    encoding schemes are based on ASCII, though they support many additional characters. ASCII

    reserves the first 32 codes for control character: codes originally intended not to represent printable

    information but to rather to control devices that make use of ASCII.

    The PIC Features Include:

    USB V2.0 Compliant

    Low Speed (1.5 Mb/s) and Full Speed (12 Mb/s)

    Supports Control, Interrupt, Isochronous and Bulk Transfers

    Supports up to 32 Endpoints (16 bidirectional)

  • 38

    1-Kbyte Dual Access RAM for USB

    On-Chip USB Transceiver with On-Chip Voltage Regulator

    Interface for Off-Chip USB Transceiver

    Streaming Parallel Port (SPP) for USB streaming transfers (40/44-pin devices only)

    Fig 3.8. PIC 18F2550 Diagram

    The PIC18F2550 was programmed using mikroC. MikroC is a development tool for PIC

    microcontrollers. It is designed for easy use for programmers for and embedded system

    applications without compromising performance or control because of use of a high level

    language.

    //******************************************************************************

    // Byte constants

    //******************************************************************************

    unsigned char const NUM_ENDPOINTS = 2;

    unsigned char const ConfigDescr_wTotalLength = USB_CONFIG_DESCRIPTOR_LEN +

    USB_INTERF_DESCRIPTOR_LEN + USB_HID_DESCRIPTOR_LEN + (NUM_ENDPOINTS *

    USB_ENDP_DESCRIPTOR_LEN);

    unsigned char const HID_ReportDesc_len = 47;

  • 39

    unsigned char const Low_HID_ReportDesc_len = HID_ReportDesc_len;

    unsigned char const High_HID_ReportDesc_len = HID_ReportDesc_len >> 8;

    unsigned char const Low_HID_PACKET_SIZE = HID_PACKET_SIZE;

    unsigned char const High_HID_PACKET_SIZE = HID_PACKET_SIZE >> 8;

    Fig3.9. Code Snippet from MikroC

    Fig 3.10. Programmer used to program microcontroller

  • 40

    3.2.2. CRYSTAL OSCILLATOR

    A crystal oscillator uses mechanical resonance of a vibrating piezoelectric crystal to create an

    electrical signal with a very precise frequency.

    The PIC Microcontroller uses an 8 MHz crystal oscillator. The crystal oscillator serves to generate

    a clock signal for synchronizing different parts of the microcontroller.

    3.2.3. USB (UNIVERSAL SERIAL BUS)

    USB is an industry standard used to define the cables, connectors and communications protocols

    used in a bus for connection, communication and power supply between computers and electronic

    devices. USB is a four-wire interface implemented using a four-core shielded cable. Two types of

    connectors are specified and used: Type A and Type B.

    Standard A USB type is used.

    Fig 3.11. Type A USB Connector

    USB signals are bi-phase, and signals are sent from the host computer using the NRZI (non-return

    to zero inverted) data encoding technique. Pin 1 is the power supply of +5V. Pin 2 and 3 are data

    pins while 4 is the ground. The USB powers up the PIC microcontroller and also transmit data

    from and to the computer through the USB port. It is through the USB the computer and

    microcontroller communicate with each other. It carries data in ASCII form to the PIC

    microcontroller.

  • 41

    Table 3.1. Table of USB pin showing name and Color

    Pin

    Number

    Name Color

    1 +5.0V Red

    2 Data- White

    3 Data+ Green

    4 Ground Black

    3.2.3.1. USB DESCRIPTOR

    All USB devices have a hierarchy of descriptors that describe various features of the device: the

    manufacturer ID, the version of the device, the version of USB it supports, what the device is, its

    power requirements, the number and type of endpoints, and so forth.

    The most common USB descriptors are:

    -Device descriptors

    -Configuration descriptors

    -Interface descriptors

    -HID descriptors

    -Endpoint descriptors

    The USB descriptor is used during the enumeration process to identify the peripheral device to the

    host, i.e. identify the microcontroller to the PC. This has to be correct, otherwise your

    microcontroller will not be recognized and you will get a device error message. MikroC Pro comes

    with an HID descriptor tool built into the HID Terminal tool.

  • 42

    The Enumeration Process

    The steps of enumeration are:

    -When a device is plugged in, the host becomes aware of it because one of the data lines

    becomes logic high.

    - The host sends a USB reset signal to the device to place the device in a known state. The

    reset device responds to address 0.

    - The host sends a request on address 0 to the device to find out its maximum packet size

    using a Get Descriptor command.

    -The device responds by sending a small portion of the device descriptor.

    -The host sends a USB reset again.

    -The host assigns a unique address to the device and sends a Set Address request to the

    device. After the request is completed, the device assumes the new address. At this point

    the host is free to reset any other newly plugged-in devices on the bus.

    -The host sends a Get Device Descriptor request to retrieve the complete device

    descriptor, gathering information such as manufacturer, type of device, and maximum

    control packet size.

    -The host sends a Get Configuration Descriptors request to receive the devices

    configuration data, such as power requirements and the types and number of interfaces

    supported.

    -The host may request any additional descriptors from the device.

  • 43

    3.3. SOFTWARE PART

    The software part is the part on the computer, it serves the control center of the device human can

    interact with and use to operate the circuit. The software is written in Visual Basic .NET a language

    created by Microsoft. Visual Basic is an ideal choice for this project since it is simple to write and

    maintain its code. Also since the program used is not a processor intensive program.

    Sample code used for the user interface is presented below with comments (green text).

    The code command the computer to send data to the USB, the data is received by the

    microcontroller. The code on the microcontroller uses the date sent to control the circuit in this

    case switching on and off of the lights in the device.

    Public Class frmUSB ' vendor and product IDs Private Const VendorID As Integer = &H1234 'Replace with your device's Private Const ProductID As Integer = &H1 'product and vendor IDs ' read and write buffers Private Const BufferInSize As Integer = 64 'Size of the data buffer coming IN to the PC Private Const BufferOutSize As Integer = 64 'Size of the data buffer going OUT from the PC Dim BufferIn(BufferInSize) As Byte 'Received data will be stored here - the first byte in the array is unused Dim BufferOut(BufferOutSize) As Byte 'Transmitted data is stored here - the first item in the array must be 0 Dim nUnit(6) As Byte ' **************************************************************** ' when the form loads, connect to the HID controller - pass ' the form window handle so that you can receive notification ' events... '***************************************************************** Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' do not remove! ConnectToHID(Me) : Call ConnectToMCU(49) : tssDevice.Text = "DEVICE UNPLUGGED IN" 'lbl1.BackColor = Color.Gray : lbl2.BackColor = Color.Gray : lbl3.BackColor = Color.Gray 'lbl4.BackColor = Color.Gray : lbl5.BackColor = Color.Gray : lbl6.BackColor = Color.Gray radOff1.Checked = True : radOff2.Checked = True : radOff3.Checked = True radOff4.Checked = True : radOff5.Checked = True : radOff6.Checked = True

  • 44

    Dim n As Byte For n = 0 To 5 nUnit(n) = 48 Next 'changeRadio(nUnit(0), radOn1, radOff1) : changeRadio(nUnit(1), radOn2, radOff2) 'changeRadio(nUnit(2), radOn3, radOff3) : changeRadio(nUnit(3), radOn4, radOff4) 'changeRadio(nUnit(4), radOn5, radOff5) : changeRadio(nUnit(5), radOn6, radOff6) changeLabel(nUnit(0), lbl1) : changeLabel(nUnit(1), lbl2) : changeLabel(nUnit(2), lbl3) changeLabel(nUnit(3), lbl4) : changeLabel(nUnit(4), lbl5) : changeLabel(nUnit(5), lbl6) End Sub Sub changeRadio(ByVal value As Byte, ByVal radio1 As RadioButton, ByVal radio2 As RadioButton) If value = 48 Then radio2.Checked = True ElseIf value = 49 Then radio1.Checked = True End If End Sub '***************************************************************** ' disconnect from the HID controller... '***************************************************************** Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed Call ConnectToMCU(48) DisconnectFromHID() End Sub '***************************************************************** ' a HID device has been plugged in... '***************************************************************** Public Sub OnPlugged(ByVal pHandle As Integer) If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then ' ** YOUR CODE HERE ** tssDevice.Text = "DEVICE PLUGGED IN" End If End Sub '***************************************************************** ' a HID device has been unplugged... '***************************************************************** Public Sub OnUnplugged(ByVal pHandle As Integer) If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then hidSetReadNotify(hidGetHandle(VendorID, ProductID), False) ' ** YOUR CODE HERE ** tssDevice.Text = "DEVICE UNPLUGGED IN" End If End Sub '***************************************************************** ' controller changed notification - called

  • 45

    ' after ALL HID devices are plugged or unplugged '***************************************************************** Public Sub OnChanged() ' get the handle of the device we are interested in, then set ' its read notify flag to true - this ensures you get a read ' notification message when there is some data to read... Dim pHandle As Integer pHandle = hidGetHandle(VendorID, ProductID) hidSetReadNotify(hidGetHandle(VendorID, ProductID), True) End Sub '***************************************************************** ' on read event... '***************************************************************** Public Sub OnRead(ByVal pHandle As Integer) ' read the data (don't forget, pass the whole array)... If hidRead(pHandle, BufferIn(0)) Then ' ** YOUR CODE HERE ** ' first byte is the report ID, e.g. BufferIn(0) ' the other bytes are the data from the microcontroller... 'MsgBox("Received Data") nUnit(0) = AscW(BufferIn(1)) : nUnit(1) = AscW(BufferIn(2)) : nUnit(2) = AscW(BufferIn(3)) nUnit(3) = AscW(BufferIn(4)) : nUnit(4) = AscW(BufferIn(5)) : nUnit(5) = AscW(BufferIn(6)) 'changeRadio(nUnit(0), radOn1, radOff1) : changeRadio(nUnit(1), radOn2, radOff2) 'changeRadio(nUnit(2), radOn3, radOff3) : changeRadio(nUnit(3), radOn4, radOff4) 'changeRadio(nUnit(4), radOn5, radOff5) : changeRadio(nUnit(5), radOn6, radOff6) changeLabel(nUnit(0), lbl1) : changeLabel(nUnit(1), lbl2) : changeLabel(nUnit(2), lbl3) changeLabel(nUnit(3), lbl4) : changeLabel(nUnit(4), lbl5) : changeLabel(nUnit(5), lbl6) 'Call ChangeColor(BufferIn(1), lbl1) : Call ChangeColor(BufferIn(2), lbl2) : Call ChangeColor(BufferIn(3), lbl3) 'Call ChangeColor(BufferIn(4), lbl4) : Call ChangeColor(BufferIn(5), lbl5) : Call ChangeColor(BufferIn(6), lbl6) End If End Sub

    Fig.3.12. VB Sample Code

  • 46

    3.4. WORKING PRINCIPLE

    This project created for the computer control of switching system for residential lighting circuits

    consists of a personal computer for control and monitoring with USB interface for a PIC18F2550

    microcontroller circuit system connected to relays that switch on attached lamps.

    An 8 MHz crystal oscillator is connected to the PIC microcontroller to synchronize its

    components.

    The USB type A connector cord consists of four wires, red as 5v power supply, Black as Ground,

    white and green as Data- and Data+ respectively used for data transfer. The red wire is connected

    to the pin 1 of the microcontroller to power the microcontroller. The black wire is connected to

    the ground. The white wire is connected to port RC5 at pin 16 and the black one to port RC4 at

    pin 15. These consist of the input section into PIC microcontroller for the output pin 21 to 25

    for port RB0 to RB5 is each connected to the base of a six BD139 NPN transistor. The emitter is

    grounded while the collector is connected to the leg of the coil of a relay. This relay Common

    and Normally Open pin are then connected to the Neutral and Live for an electric lamp, bulb or

    socket.

    LED indicators are included between the emitter and collector of the transistor indicate on an off

    state of the transistors. Six points in total are to be switched by the relay four light points and two

    power socket points. These are mounted on a board platform for easy and clean access. Circuit

    diagram of the project is shown in Fig 3.13.

  • 47

    Fig 3.13. Circuit Diagram of Main Circuit Board

    The PIC microcontroller is controlled by the Visual Basic program on the computer as shown in

    Figure 3.13. The program achieves this by sending data to the PIC through the USB port, the

    onboard PIC program interprets the data and chooses between the ports RB0 to RB5 depending

    on what is chosen on the VB program on the PC. The Diagram of PIC indicating all its ports is

    shown in Figure 3.8.

    The signal from the PIC microcontroller gets to the base of the transistor causing current to flow

    between the emitter and collector, this excites the relay which lead to the switching on of the

    bulb and sockets.

  • 48

    Fig 3.14. Visual Basic Interface

  • 49

    CHAPTER FOUR: RESULTS AND DISCUSSIONS

    4.1. SIMULATION

    Proteus 8 is a very suitable simulation software for various designs with microcontroller. It is

    mainly popular because of availability of almost all microcontrollers in it. So it is a handy tool to

    test programs and embedded designs for electronics hobbyist. One can simulate programming of

    microcontroller in Proteus 8 Simulation Software to test the working of the code.

    For the educational user and engineering author, ISIS also excels at producing attractive

    schematics like seen in magazines. It provides total control of drawing appearance in terms of

    line widths, fill styles, colours and fonts. In addition, a system of templates allows definition in a

    house style and to copy the appearance of one drawing to another.

    Fig.4.1. Power Pack (Closed)

  • 50

    Fig 4.2. Power Pack (Open)

    Fig 4.3. Microcontroller Circuit (Closed)

  • 51

    Fig 4.4. Microcontroller Circuit (Open)

    Fig 4.5. Relay Circuit (Closed)

  • 52

    Fig 4.6. Relay Circuit (Open)

    Fig 4.7. Complete Design

  • 53

    4.2. TESTING OF THE MICROCONTROLLER

    The microcontroller used pins were tested when the user interface on the PC is used to turn on all

    the lights. This is to confirm that the computer as successfully sent data and the microcontroller

    has received it. Table is shown below

    Also there was continuity test to prevent shorting of the circuit.

    Table 4.1. PIC pin with voltage levels

    MICROCONTROLLER

    PIN

    PORT NAME VOLTAGE

    LEVEL (VOLTS)

    ON OFF

    1 RE3/MCLR/VPP 4.991 4.985

    21 RB0/AN12 5.683 0.001

    22 RB1/AN10 4.934 0.000

    23 RB2/AN8 4.327 0.000

    24 RB3/AN9 4.938 0.002

    25 RB4/AN11 5.124 0.001

    26 RB5/KBI1 4.034 0.000

    Voltage from power pack is 12.473 Volts.

    The Proteus USB Analyser is an application that displays all requests and replies to and from the

    simulated USB device. This provides an invaluable aid both to understanding the USB protocol

    and in verification of firmware implementation. The main Analyser window consists of two

    parts: the Requests List and the Requests Description as shown below.

  • 54

    Fig 4.8. USB Analyser

    The Requests list on the left hand pane of the Analyser displays all requests in tree format. There

    are three levels of requests; IRP requests (IOCTL, MJ_PNP), Transaction requests (IN, OUT,

    SETUP) and register operations associated with a given transaction.

    The request description forms the right hand side of the Analyser and provides detailed tabular

    information on the currently selected item in the Requests List. Given that the Requests list is

    granular to three levels it follows that comprehensive information can be retrieved at either the

    IRP Level, the transaction level or the register level.

    The small toolbar at the top of the Analyser provides options to start logging, stop logging and

    also to clear the log. This is particularly useful where you are interested in communications after

    the setup phase or in response to activity from the host controller.

    4.3. CHALLENGES AND LIMITATION

    The system has the various limitations, as listed below:

    Wiring is required.

    It is not portable

    Power supply is needed for the PC.

    Venerable to software hacking

    Venerable to malware

    Dependent on PC to function

  • 55

    Only limited to .Net Framework

    Challenges one can encounter when in the process of constructing this device are few and are

    listed below:

    Lot of wiring is involved, this can make the project untidy and prone to shorts.

    Short on the board can cause serious damage.

    One should be carefully to use a diode to prevent damage to the system in case of fault.

    The casing is heavy and moving the device around is strenuous.

    A lot of heat is generated by the light bulbs used.

    Noise from the relay and transformer.

  • 56

    CHAPTER FIVE: CONCLUSION AND RECOMMENDATION

    5.1. CONCLUSION

    The lightning control is a low cost, PC based system making it very. Using PIC make it low cost

    and can be easily duplicated for the purpose of mass production; simply by using same code.

    The fact that the device is PC based makes it very flexible its switching characteristics can easily

    be modified and improved upon by simply adding or change code on the PC. Also this allows the

    device to be used on any PC as long as it has the program for the device.

    Computer controlled switching as a huge significance in the world, it saves the energy, and it

    saves time and give a central control area for the operation and switching of lights especially in

    large residential areas like Hostels, barracks etc.

    Also as a student I was able to apply some of the things I learnt during the course of my study in

    the university. I also learnt a lot on Micro-controllers in general, about PIC microcontrollers,

    Visual Basic .Net, MikroC and Proteus Software.

    5.2. RECOMMENDATION

    Even with the limitations the systems flexibility more than makes up for them. The flexibility

    allows for change in the PC based software without need to change the hardware part.

    This can improve the system and overcome its limitations in the following ways:

    By programming a network capable application for the system, one can take the web

    capabilities of the system and enable remote switching from anywhere in the world.

    Timing capabilities can be added to make the system automatic.

    Antiviruses and firewalls can be installed to make the system more secure etc.

    This number of improvement and change to the system are limitless.

  • 57

    REFERENCES

    1. Abioye,A.O. (2013). Computer Interfacing Through the USB Port. International Journal

    of Engineering Research & Technology.2, 1878-1882.

    2. Alo,T.A. (2014). Light System Controlled by S.M.S. Unpublished B.Eng. Thesis,

    Department of Electrical and Electronic, Bells University of Technology, Ota.

    3. Crisp,J. (2004). Introduction to Microprocessors, 2nd Edition. Newnes, Burlington.

    4. Darren,A. (2009). Electrical Engineering 101, 2nd Edition. Elsevier, Oxford.

    5. Ibrahim,D. (2008). Advanced PIC microcontroller projects in C, 1st Edition. Newnes,

    Burlington.

    6. Mohd,H.A., Norzilawati,A., Ayob,J., Herdawatie,A., (2010). GSM Based Electrical

    Control System for Smart Home Application. Journal of Convergence Information

    Technology.5, 33-39.

    7. Mohd,S.S., Zawawi,I.A., Shaza,R.S., Nazrul,N.M.Z., Gopala,K.S.N., Kamaruzama,J.,

    (2010). Gui Based Remote On/Off Control and Monitoring Single Phase Lamp using

    Microcontroller. International Journal on Computer Science and Engineering. 2, 1401-

    1405.

    8. Platt,C. (2013). Encyclopedia of Electronic Components Volume 1, 1st Edition. OReilly,

    Sebastopol.

    9. Ramlee,R.A., Aziz,K.A.A., Leong,M.H., Othman,M.A., Sulaiman,H.A., (2013).

    Wireless Controlled Methods via Voice and Internet (e-mail) for Home Automation

    System. International Journal of Engineering and Technology.5, 3580-3587.

    10. Sclater,N. and Traister,J.E. (2003). Handbook of Electrical Design Details, 2nd Edition.

    McGraw-Hill.

  • 58

    APPENDIX A: APPARATUS

    Multi-meter

    Multi-meter combines many different measurement functions into one device. A multi-meter is a

    combination of a multi-range DC voltmeter, multi-range AC voltmeter, multi-range ammeter,

    and multi-range ohmmeter.

    Screw Driver

    A tool with a shaped tip that fits into the head of a screw to turn it.

    Pliers

    Pliers are pincers with parallel, flat, serrated jaws, used for gripping small objects or bending

    wire or cutting.

    Electric Drill

    An drill is a tool fitted with a cutting tool attachment or driving tool attachment, usually a drill

    bit or driver bit, used for boring holes in various materials or fastening various materials together

    with the use of fasteners.

    Hammer

    Hammer is a tool consisting of a heavy metal head mounted at the end of a handle, used for

    breaking things and driving in nails.

    Veroboard

    Veroboard is a brand of stripboard, a pre-formed circuit board material of copper strips on an

    insulating board.

    Soldering Iron

    A soldering iron is a hand tool used in soldering. It supplies heat to melt solder so that it can flow

    into the joint between two workpieces.

  • 59

    A soldering iron is composed of a heated metal tip and an insulated handle. Heating is often

    achieved electrically, by passing an electric current (supplied through an electrical cord or

    battery cables) through a resistive heating element.

    Soldering lead

    Solder is a fusible metal alloy used to join together metal workpieces and having a melting point

    below that of the workpiece(s).

    Programmer

    Programmer refers to a device that configures programmable non-volatile digital circuits like

    PICs and other chips. For programming a circuit, it is either inserted into a socket on top of the

    programmer, or the programmer is directly connected by an adapter to the circuit board (In-

    System Programming).

    Compiler and IDE

    A compiler is a computer program (or set of programs) that transforms source code written in

    a programming language (the source language) into another computer language (the target

    language, often having a binary form known as object code). E.g. MikroC used for compiling

    ANSI C for PIC devices.

    An integrated development environment (IDE) is a software application that provides

    comprehensive facilities to computer programmers for software development. An IDE normally

    consists of a source code editor, build automation tools and a debugger. Most modern IDEs

    have intelligent code completion.

    Some IDEs contain a compiler, interpreter, or both. E.g. Visual Studio used for Visual Basic

    .NET.

  • 60

    APPENDIX B: COST ESTIMATION

    S/N NAME QUANTITY PRICE (N)

    1 PIC18F2550 2 3000

    2 Relay 12 1200

    3 Transistor 12 600

    4 Voltage Regulator 4 480

    5 Resistor: 1K

    :100

    16

    9

    360

    60

    6 Capacitor: 100nF

    :

    8

    4

    400

    200

    7 LED: Red

    Yellow

    Green

    4

    4

    4

    40

    40

    40

    8 Bulb 10 1000

    9 Lamp Holder 12 840

    10 Socket 4 400

    11 Plug 2 200

    12 Wire 4 meters 1500

    13 Package - 6500

    14 Vero board 6 600

    15 Programmer 1 15000

    16 Soldering Iron 1 2500

    17 Soldering Lead 5 2500

    18 Software - 15000

    19 Transformer 2 3500

    20 Diode 16 800

    21 USB Cable 2 2500

    22 Miscellaneous - 4500

    Total 63760

  • 61

    APPENDIX C: WEB LINKS

    http://www.iec.ch/worldplugs/typeD.htm

    http://www.iec.ch/worldplugs/typeG.htm

    http://www.labcenter.com/products/usb.cfm

    http://www.usb.org

    http://www.microchip.com/PIC18F2550

    https://www.fairchildsemi.com/datasheets/BD/BD135.pdf