Tuesday, 10 May 2016

Always together

Dear all,

Valentine's gift can be a joyous shopping spree or headache issue for anyone in a relationship. I am so sorry if you're not a great maker or you hate so much on hands-on stuff. My mindset sticks on uniqueness of a present no matter how exorbitant the price is. Anyway, price tag challenges me as well(unless my budget is loose enough).

My girlfriend once introduced me a mobile app which can count the number of day the couple has been together. All you can do is try download one from playstore and install it. It perfectly suits for those including me who doesn't have a good memory regarding anniversary date. You can even set it to alert you on the coming meaningful days that you're going to celebrate with your loved one. I used it until now too. How about making one which is not based on the app?




In previous blog (http://kentronicx.blogspot.my/2016/01/desoldering-from-scratch.html), I have broken and dissembled many unused objects and toys. One of my favorite thing is a digital stop watch. Deep inside, it has a small cylindrical shaped part with silver colour body which I have no idea about it. After searching it via Google, its name was 32.768 kHz Quartz Crystal. 

Quartz Crystal

The internal part it can be found online.


How about analog watch or analog clock? Our ancestor must have experience of using the winding type. I removed the cap of my current watch. I found this inside too.


A quartz clock is actually which uses an electronic oscillator that is regulated by quartz crystal to keep track of time. 
  • It creates signal with a very precise frequency.
  • More accurate than conventional mechanical clock.
  • As a piezoelectric materials, it would accumulates electrical charges across the planes inside when mechanical stress is applied. 
  • Its size does not changes much as temperature varies. 
  • In deeper explanation, the resonance frequency will not alters significantly when the surrounding temperature changes widely. 
  • The quartz also has very low coefficient of thermal expansion.
  • The way of cutting on the quartz is one of the determining factor of oscillating frequency of the particular crystal.
  • The common or desired frequency of oscillation is precisely 32,768 Hz. The value is high enough where normal human's auditory range lies in between 20Hz to 20,000Hz.
  • The optimum operating temperature is between 25 to 28 degrees Celsius.
  • Oscillatory frequency is about inversely proportional to changes in temperature. Changes of 1 degree Celsius causes it to run slower by 1.1 second per year. Meanwhile, deviation of 10 degree Celsius causes it to run even slower by 110 seconds per year.
Real Time Clock (aka RTC)

Ever wonder why does your PC or smartphone does not reset the date and time back to the original setting whenever you switch it off? It only resets whenever you remove the battery. The similar concept used is RTC.

RTC is a computer clock which keeps track of the current time. It comprises of DS1307, Pull up resistors, quartz oscillator, coin cell battery and decoupling capacitor.


  • It permits any microcontroller project to maintain a track of time even user tends to reprogrammed it or the battery runs low.
  • It communicates via I2C connection.
  • The coin cell used can support the entire RTC for several years.


  • It has no problem to deal with inconsistent number days in a month or an extra day in a leap year.
  • Normally, it has a built-in power-sense circuit which detects power failures. If it happens, it would automatically switch back to the original date.
  • Do not apply solder over it exceeding 10 seconds!



Block diagram within DS1307.


The sample setup of circuit using DS1307 and few components.




Thanks to advancement of embedded technology. All we have is an assembled set named tiny RTC I2C module.



UNIX

It is also known as epoch time. A system which shows instants in time, describe as the number of seconds that have elapsed since midnight (00:00) of Thursday, 1st January 1970 without considering leap seconds. Thus, it does not represent the real of UTC. It is a single-signed number which shows increments every seconds, without determining year, month or hour.
  • 1 day have 24 hours.
  • 1 hour equals to 3,600 seconds.
  • In one day, we have 86,400 seconds to spend.

With this RTC module and simple understanding of UNIX time, we can start building up the internal architecture of making a day counter. All we need is to download the RTC library from the link below. It was created by David H. Brown. 


Once the library is loaded into the IDE, do restart the software. There's a file named RealTimeClockDS1307_Test. It can be used to inspect the RTC whether is working.

Display

System display is the part where information is disclosed to the user and hence creating a simple human machine interface. The information unit is usually takes in the form of character or word. For example, we have bar graph, LCD and 7 segment display. In my current project, I am using 7 segment display to display the day passed.

7 segment display is similar to any LED. It comprises of seven LEDs. 

It normally has two types of 7 segment display which are common anode and common cathode. They look identical in structure. How do we distinguish them properly?



There is a library made to configure four 7 segment displays using Arduino. The link can be found here:

7 Segment Display: 

Download it and insert into the IDE. You can test the function with a pre-compiled file.

Assembly

Finally, assemble the circuit with the skill you have mastered along the way. I have created the most simple one which looks like this:




The circuit looks daunting at first but once you have completed it, you'll know how simple it is.


Next discussion is about the code, you can retrieved it from this link:


Precaution:

There's a catch when you have done everything. If you have found the date and time reset back to the original condition, check your RTC properly. Otherwise, there is a section has to be commented after you have uploaded the initial code. 

  if (! rtc.isrunning()) 
  {
  Serial.println("RTC is NOT running!");
 //rtc.adjust(DateTime(2016, 2, 16, 17, 23, 30));
  }

Accidentally swapping wires connected to pin A4 and A5 will resulted in the following statement display in Serial Monitor:

FF-1F-3F 1F:7F:7FP 

Further improvement:

You can complete the design within days or even hours. What else can be done to the circuit?
  • Remove the Atmega 328 microcontroller from arduino and put it into a breadboard. You can buy another one to replace it. A constant 5 V dc source with few components is enough to fire up the Arduino again.  

       You can have little reference here: 
       http://kentronicx.blogspot.my/2016/01/breadboarding-arduino-uno.html
  • Fabricate the whole design into PCB. It looks better and neater compared to placing it on a breadboard. 
  • Add more effect to the display unit. It can display time and date at certain interval and revert back to the counting system. I guess a timer or interrupt libraries would help.
  • Include a small beeper to alert user. Most people are forgetful about anniversary and some important dates. 

I have went through many mistakes and troubleshooting process in understanding and getting all these done. Below are useful resources where I always refer to:
Thank you.

No comments:

Post a Comment