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

How to set a alarm for my real tiime clock?

Discussion in 'Microcontrollers' started by IsaacChuah90, Oct 3, 2011.

  1. Rusttree

    Rusttree Member

    Joined:
    May 28, 2006
    Messages:
    276
    Likes:
    2
    Location:
    Phoenix, AZ
    And it shows 0V when you take your hand away?
     
  2. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    Ya.It shows 0V when my hand is away.
     
  3. Rusttree

    Rusttree Member

    Joined:
    May 28, 2006
    Messages:
    276
    Likes:
    2
    Location:
    Phoenix, AZ
    What is your supply voltage to the PIC? 4V may be enough to trigger a digital high on RC6. According to table 17.2 on page 178 of your datasheet, you need to achieve 0.8Vdd or more for the Schmitt Trigger to register high.

    Back to your code. You put this if-conditional:
    Code (text):

    if (motion==1)
    {
        buffer=1;
    }
    else if (motion==0)
    {
        buffer=0;
    }
     
    What's the value in the "else if" part? Do you really need it?
     
    Last edited: Oct 17, 2011
  4. dave

    Dave New Member

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


     
  5. lgsg89

    lgsg89 New Member

    Joined:
    Oct 2, 2011
    Messages:
    9
    Likes:
    0

    can you write the code in mikroC???
     
  6. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    Rusttree,the supply voltage is 5V.I'm not sure the "else if" part is necessary needed for me or not because I'm not very good in writing coding,this is the coding I tried to write for it.Can you correct me?Any way to write recommended?
     
    Last edited: Oct 17, 2011
  7. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    Rusttree,I think the "else if" part is not needed for me.I write it for testing purpose.What I want to achieve is when the alarm is activated,I can use the sensor to switch off the alarm.
     
  8. Rusttree

    Rusttree Member

    Joined:
    May 28, 2006
    Messages:
    276
    Likes:
    2
    Location:
    Phoenix, AZ
    That may be a problem. The digital input on RC6 needs to be at least 0.8Vdd. If Vdd is 5V, then 0.8Vdd = 4V. But you're saying the sensor typically registers just under 4V, so it may not trigger a digital high on the pin. So you have to fix that before you fix your code.

    You have to two options:
    1. Learn the ADC (Analog to Digital Converter) module on the PIC. There are tons of tutorials online to teach you that. This would require no external components.
    2. Implement a amplifier of some kind. For example, a transistor would work well here.
     
  9. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    Rusttree,just now I have measured the voltage of the sensor again.The voltage is greater than 4V after I have adjusted it.It is because there is a part for me to adjust the sensitivity,it can affect the voltage of the sensor.So now still need to implement an amplifier for it?
     
  10. Rusttree

    Rusttree Member

    Joined:
    May 28, 2006
    Messages:
    276
    Likes:
    2
    Location:
    Phoenix, AZ
    Nope, as along as it consistently reads above 4V, you're good. You can use it as a digital input on RC6.

    So back to the code, you're correct, the "else if" part is unnecessary. After you wave your hand over the sensor, there's no need to set "buffer" back to 0. "buffer" will stay equal to 1 after you take your hand away, which will prevent the buzzer from activating again.

    Test that out and see if it works.
     
  11. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    So I remove the "else if" part.So just left
    Code (text):
    if (motion==1)
    { buffer=1;
    }
    Is it right?Then the alarm part need to change also?
    Code (text):
    if ((clkmin==alarmMin) && (clkhrs==alarmHrs) && (buffer==0))
    {
         buzzer=1; 
    }
    else
    {
         buzzer=0;
    }
     
    The (buffer==0) need to change?
     
    Last edited: Oct 17, 2011
  12. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    Rusttree,it's works.
     
  13. Rusttree

    Rusttree Member

    Joined:
    May 28, 2006
    Messages:
    276
    Likes:
    2
    Location:
    Phoenix, AZ
    That's great!

    Now, there's one more thing to consider. As you have it now, the alarm will deactivate any time you wave your hand near the sensor. Even if the buzzer isn't on. Is that ok? Or do you want the sensor to deactivate the alarm only when the buzzer is on?
     
    Last edited: Oct 17, 2011
  14. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    I hope the sensor can deactivate the alarm only when the buzzer is on.Any thing need to modify?Besides,I found one problem I'm facing now.As I set the alarm time to 1 minutes,when it reached 00:01,the buzzer does not on but after I turn off the voltage supply and turn on it again immediately,the buzzer is on.Is it unstable or is because there is a coding "if ((clkmin==alarmMin) && (clkhrs==alarmHrs) && (buffer==0))"?
     
    Last edited: Oct 17, 2011
  15. Rusttree

    Rusttree Member

    Joined:
    May 28, 2006
    Messages:
    276
    Likes:
    2
    Location:
    Phoenix, AZ
    If you want the alarm to deactivate only when the buzzer is on, then you'll have to move the logic that checks the sensor inside the if-statement that activates the alarm. In other words, only check the sensor when the alarm is on. See if you can figure out how to do that.

    Post your latest code and let's see if we can troubleshoot this problem you're describing.
     
  16. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    I have attached the latest code here.Everything I'm written is at the "Read RTC function" there.I have tested it many times,the alarm still not stable.Because as I said at the previous post,when the alarm time is reached the alarm is in a deactivated mode(buzzer off).Besides,I can't get the idea how to move the logic that checks the sensor.
     

    Attached Files:

    • alarm.c
      File size:
      15.1 KB
      Views:
      72
    Last edited: Oct 17, 2011
  17. Rusttree

    Rusttree Member

    Joined:
    May 28, 2006
    Messages:
    276
    Likes:
    2
    Location:
    Phoenix, AZ
    Let's see a photo of the LCD screen when you first turn it on.
     
  18. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    This is the photo of my LCD when I turn on the power.Anything that is regarding to that?
     

    Attached Files:

    • 009.JPG
      009.JPG
      File size:
      1.5 MB
      Views:
      63
  19. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    The alarm now is stable again after I tested it 3 times.I think the coding there can solve this problem if only check the sensor when the alarm is on.
     
    Last edited: Oct 17, 2011
  20. Rusttree

    Rusttree Member

    Joined:
    May 28, 2006
    Messages:
    276
    Likes:
    2
    Location:
    Phoenix, AZ
    Ok, not sure why you were having problems before.

    Now, think about the conditions that are true when the alarm is on. The clock hours and alarm hours are equal, the clock minutes and alarm minutes are equal, and the motion sensor is inactive. Don't you already have an if-statement that checks for exactly those conditions? So if you moved the motion sensor logic into that if-statement, then the program will only check the motion sensor when the alarm is on.
     
  21. IsaacChuah90

    IsaacChuah90 New Member

    Joined:
    Oct 3, 2011
    Messages:
    66
    Likes:
    0
    Oh.I got what you mean.So the coding is
    Code (text):
    if ( (clkmin==alarmMin) && (clkhrs=alarmHrs) && (motion==1) )
    {
        buzzer=1;
    }
    Is it right?If I want to introduce a snooze features inside the alarm can right?
     
    Last edited: Oct 17, 2011

Share This Page