Continue to Site

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.

  • 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.

How to set a alarm for my real tiime clock?

Status
Not open for further replies.
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:
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:
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:
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.
 
Rusttree,the supply voltage is 5V.
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.
 
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?
 
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.
 
So I remove the "else if" part.So just left
Code:
if (motion==1)
{ buffer=1;
}
Is it right?Then the alarm part need to change also?
Code:
if ((clkmin==alarmMin) && (clkhrs==alarmHrs) && (buffer==0))
{
     buzzer=1;	
}
else 
{
     buzzer=0;
}
The (buffer==0) need to change?
 
Last edited:
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:
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:
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.
 
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.
 

Attachments

  • alarm.c
    15.1 KB · Views: 145
Last edited:
This is the photo of my LCD when I turn on the power.Anything that is regarding to that?
 

Attachments

  • 009.JPG
    009.JPG
    1.5 MB · Views: 122
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:
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.
 
Oh.I got what you mean.So the coding is
Code:
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:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top