1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Light control system for smart home

Discussion in 'Microcontrollers' started by lebohangmaphothoane, Sep 15, 2009.

  1. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    part four which is the last part is to use USART(Universal Asynchronous Receive and Transmit) where by the lights can be turned on or off, and the blinds can be closed or opened by the user using computer interface. The cable i will be using is RS232 to conect the computer and the circuit. That is the input comes from the computer interface. i would be glad if u can provide me with the reliable materials of USART or links.
     
  2. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    I'll pass you my USART tutorial code later today ( if not on monday ) !
     
  3. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    As promised...
     

    Attached Files:

  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,808
    Likes:
    135
    Location:
    morristown,tn

    That looks good birdman0 good work
     
  6. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    birdman0 i thought it was internet problems yesterday while i tried to download the link about (PIR232) but even today after downloading it, when i open the pdf it says the file is damaged. could you please post it again. but as for the UART.asm file i have download it and it is alright
     
  7. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    oh! i have got that link
     
  8. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    In page 3 it is stated what happens if the body passes infront of the sensor, so what i want to know is how much output voltage does the sensor output if there is a body passing in front of the sensor. i need that output voltage so that i can make ADC and turn on the LED. In page 5 it says output mv(2)= 3900, does it mean it output 3.9 volts. if that is the case will i be correct to say if the ouput voltage is creater than 2.5 volts it means there is motion detected hence i can turn on the LED and the code will still be the same as that one where i used the light sensor.
     
  9. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    Why not test it out? You want USART, so get that working, then send the ADC value to your computer and adjust from there :)
     
  10. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    hi birdman0_0 i think before monday i will show you the code i wrote using USART its because im still working on how to turn a unipolar stepper motor clockwise and anti clockwise direction. Besides that i have to read about USART and understand how it works
     
  11. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    No rush my friend :)
     
  12. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    please take a look at this link Jones on Stepping Motor Types
    it says to rotate the unipolar motor continuously, we just apply power to the two windings in sequence. Assuming positive logic, where a 1 means turning on the current through a motor winding. in the code below i have applied this sequence :Winding 1a 1000100010001000100010001
    Winding 1b 0010001000100010001000100
    Winding 2a 0100010001000100010001000
    Winding 2b 0001000100010001000100010


    but the motor does not rotate as animated GIF of figure 1.2 . what is wrong with the code

    Code (text):
       

    ;Author : LEBOHANG MAPHOTHOANE
    ;PROGRAM FUNCTION:turning motor


        list        P=16F877a

        include    "P16F877a.inc"
                    __config 0x3D18
        ;errorlevel -302, -207;suppress message 302 from the list
     ;Declarations:

        CBLOCK 20h   ; Temporary storage                
                     pos
                     dc1
                     dc2
                     delay
                  ENDC



         
         
        org     0x0000
        goto Start 

    ;Program Start:

    Start
        call Init             ;sets the values of ADCON0 and ADCON1
                                           ;initialize porta

    Main          
               
        ;clockwise
           movlw b'0001'
           movwf PORTB
           call wait
           clrf PORTB

           movlw b'0100'
           movwf PORTB
           call wait
           clrf PORTB

           movlw b'0010'
           movwf PORTB
           call wait
           clrf PORTB
           
           movlw b'1000'
           movwf PORTB
           call wait
           clrf PORTB
           goto Main
           

    wait     movlw   4       ; Outer loop iteration count
              movwf   dc1      
    dl1       clrf    dc2            ; Initialize inner loop
    dl2       nop
              nop
              decfsz  dc2,F        
              goto    dl2
              decfsz  dc1,F
              goto    dl1
              return







    ;Subroutines:
               
    Init


                  clrw                    ; Zero.

                  movwf   PORTB           ; Ensure PORTB is zero before we enable it.
                  bsf     STATUS,RP0      ; Select Bank 1
                  movlw   0xF0            ; Set port B bits 0-3 as outputs
                  movwf   TRISB           ; Set TRISB register.          
                                                                   
                  bcf     STATUS,RP0      ; Select Bank 0
                               
       
       
     
       
        return

        END





     

     






     
     
  13. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    Does anything happen when you run the program in hardware?
     
  14. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    the program when i built it on Mplab it says zero errors.I used ISIS 7 Professional to construct circuit diagram and when i run it, the motor do not rotate the way i want it to rotate, it rotates one step about 30 degrees and it stops, but i want it to rotate continuously until i stop it
     
  15. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    circuit.jpg The circiut diagram looks like this. can u try it and upload my code and see if it will work
     
  16. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    I used 5volts to power motor and pic16f877a
     
  17. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    :)i have figured the problem, the delay subroutine was not correct. now that i have corrected the delay subroutine at lest it can turn 180 degrees clockwise
    Code (text):

    ;Author : LEBOHANG MAPHOTHOANE
    ;PROGRAM FUNCTION:turning motor


        list        P=16F877a

        include    "P16F877a.inc"
                    __config 0x3D18
        ;errorlevel -302, -207;suppress message 302 from the list
     ;Declarations:

        CBLOCK 20h   ; Temporary storage                
                   
                     dc1
                 
                   
                  ENDC



         
         
        org     0x0000
        goto Init  

    ;Program Start:

    ;Start
     ;   call Init             ;sets the values of ADCON0 and ADCON1
                                           ;initialize porta
     
    wait      movlw   5    ; Outer loop iteration count
    d11       movwf   dc1        

              decfsz  dc1,F        
              goto    $-1
              return



    ;Subroutines:
               
    Init


                  clrw                    ; Zero.

                  movwf   PORTB           ; Ensure PORTB is zero before we enable it.
                  bsf     STATUS,RP0      ; Select Bank 1
                  movlw   0xF0            ; Set port B bits 0-3 as outputs
                  movwf   TRISB           ; Set TRISB register.          
                                                                   
                  bcf     STATUS,RP0      ; Select Bank 0
               
     
       
    Main          

       
    clockwise
    ;1-----------------------
           movlw b'0001'
           movwf PORTB
           call wait

           movlw b'0100'
           movwf PORTB
           call wait
       
           movlw b'0010'
           movwf PORTB
           call wait
       
           movlw b'1000'
           movwf PORTB
           call wait
          ; goto Main


          end




     



     
     
  18. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    im looking forward know to have the input from the computer rotating the motor whereby i will use USART
     
  19. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    Which program are you going to use on the computer?
     
  20. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    birdman0 i want to make a simple comuter interface which looks like that one on the picture. if i click the box (clockwise) then the motor must rotate clockwise or if i click anticlockwise then the motor must rotate anticlockwise. im not sure which programing software i must use between visual studio C++ or axampp to make such interface. i have read about USART and how to send data through rs232 cable.i think these two diagrams can easily explain to you what im trying to say. i want to control the motor on the circuit board using computer where by connection between the computer and the circuit board is made by rs232 serail cable
     

    Attached Files:

    • cpu.jpg
      cpu.jpg
      File size:
      13.1 KB
      Views:
      132
    • CPU1.jpg
      CPU1.jpg
      File size:
      46.2 KB
      Views:
      161
  21. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    Computer causes an Rx interrupt, then makes the pic do a forward or reverse loop based on what you chose.
     

Share This Page