Monday, November 23, 2015

MAKING A 12 HR BINARY CLOCK BY USING ARDUINO NANO,DS1307RTC AND I2C

MAKING A 12 HR BINARY CLOCK BY USING ARDUINO NANO,DS1307RTC AND I2C

This is very simple project in which we use the speaker and display Hour and Minutes and only display 12 Hour clock.  
The basic set-up resistors 11 and connected to an Arduino Nano nanotechnology through I2C , RTC is attached to a DS1307 and two buttons to adjust the hours and minutes , with the active supply of 5volts using a " dumb " Speaker is engaged in LED USB Powered Speaker
.
Step 1: The LED board
 LED


   
So I am using 5mm green LED to start with and resistors as well as all long 17 wide and 17 tracks are soldered on a small piece of breadboard. 470ohm resistors and resistors and links to the rest of you but I breadboard 3 soldered on the right side you can see in the pictures where resistance to the feet of track-side (wrong side) were soldered onto other tracks, I stripped insulation of single core wire cover them using
. The track breaks many as there are a good look at the photos
Under some resistors . All resistors tracks 3 RTC and breadboard Arduino Nano , which allows to get to the ground are ground , which means that is a common ground .

It is not too difficult to accomplish , as I was not in much detail about the billboard , and you may wish to change the spacing . 11 LEDs is not true ( a 470ohm resistor ) through nanotechnology connected to the 12 pin 2 define the order in which you sketch them as long as you put the order
.
I LEDs and resistors and the link was completed after I soldered the wires of different colors to the edge and then checked each LED work .
Just in case you do not understand binary clocks , right column, middle column of tens of minutes ( 0-5 ) and the Left Column hours ( 1-12 ) displays displays ( 0-9 ) minute display units is . In all cases, the third LED is worth 1 4 is worth another 2 and 4 , 8, is worth to you the numbers are published in the column connecting the LED to get time
.
You know I take the wrong resistor value and managed to solder it in place that can be seen in one of the pictures above . I 've seen it and I have linked it changed .
Step 2: The Aduino Nano.
 Arduino Nano

 Arduino Nano

LED board once was complete and I used double-sided foam tape to work checked and resistors stuck on top of the Arduino Nano. So at this stage I do not worry about just neatly pin order in place all soldered, wired breadboard connected to the input pin looped, Nano breadboard final connection is to keep the ground clean again, I choose digital pin 2 pins next to the ground.

Step 3: RTC DS1307 connected via i2C  

Next to wire the RTC module, Tiny I2C DS1307 RTC clock module is brought from eBay and the cost was about £ 1.00. This pin A4 and A5 (A5 and A4 SDA SCL) on nano connects via I2C. The module also needs a land and 5volt, ground and 5 volts from breadboard A4 was next to the VCC pin. Long wires "are about 5 foam will be used for the RTC module speaker.
Step 4: Hour and minute adjust buttons.    


Button, they are a bit too big for what I had laying around and I like black, but that's what I was doing and they are mounted on the back as it really does not matter . I button on either side of the cable insertion hole is chosen to mount. Then I drilled holes in the feet and on 9mm and so I think they saw 12mm hole had to be filed for aligning the right size. If the wires were connected (via inline resistors) button and nanotechnology (nano ground and "RAW") 4 core speaker and the USB cable to the relevant connection
Button single pole , normally open ( momentary off ) are . Button is pressed when they 5volts through a 10K resistor pulled down to the ground and are set so that they are wired . A 1K resistor on each input is for Nanotechnology .
I pictures, connect it to switch unless you have a clear path and connections with heatshrink covering shorts as you should not have any problems with the wires as shown, decided to connect resistors. Pin A0 and A1 hours 14 minutes to adjust and the two buttons is a button for another 15 to 14 by adding pin numbers can be configured to digital, which A0 and A1 connect, each button to watch just a minute or an hour or so to say.
Step 5: Fitting the clock into the speaker    



Speaker of the house , ideal for LED seen and I watch as speakers were amplified voltage can use USB for power . Amplifier and 5 volts " slave " clock speaker of the house was being used was not the place to watch a USB speaker , I have an extra pair of wires from the amplified was going to run , although the slave speaker 5 volt supply .
I had a light bulb moment , and I use an old USB keyboard cable and can replace existing 2- wire cable is realized . This means a little more work but I think it was worth it . I must point out one thing you have 4 wires of plastic fibers within each core of the cable should not use a mouse ? So it 's a little harder to work with .
Keyboard cable diameter is slightly larger , but the core is in them and a large diameter fibers are . You pictures I made at the end of each 4 connections can see . In the picture you can see the difference in the mouse cable and keyboard cable , mouse cable and green wire strands in each core is plastic , red wire and copper from the keyboard is conventional .
LEDs in the slave speaker to mount the first tape I masked marked out in front with 11 holes . I used the breadboard is good because the spacing and even between LEDs in each column each other than " 0.4 " with 0.5 column . LED there is no one in that position , take care not to get carried away as the middle of the top LED drill out !
Drilling thinking masking tape helps to prevent the drill bit and you start with a 2mm drill , a drilling before you can check everything is in line , and then I finally have a 5 mm use the 3.3mm drill to drill in steps like this.
Step 6: The Arduino NANO program explained and libraries needed/


     
I have a simple decimal to binary code using binary clock programed. RTC is the zero hour, so I checked the first to overcome this problem and if it is worth more than 13 hours, then set it to 12 in 24-hour format is a time value as Although I had some problems when I subtract 24 hours out of 12. Then we come to the time setting, the hour and minute "raw" are adjusted by adding a bar code, 60 for each hour for a minute and 3600 is added.

if (digitalRead(setM) == HIGH)
{
unsigned long j = RTC.get();
j = j + 60;
RTC.set(j);
}
if (digitalRead(setH) == HIGH)
{
unsigned long j = RTC.get();
j = j + 3600;
RTC.set(j);
}
There you load this code into your Arduino, so this is a small problem with the code, and there is nothing you notebook / Libraries / DS1307RTC / setTime file "setTime" sketch using the RTC to determine may need what happens. Once you need to buy a new RTC modules, if I can work out what the time is right to check the serial monitor loaded Click "Start" and it will not be active. Then binaryRTC code and reload everything should work.
Step 7: The full Program.


   
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>
const int setH = 14; //button for hour increase
const int setM = 15; // button for minute increase
const int UnitMin01 = 12;
const int UnitMin02 = 9;
const int UnitMin04 = 8;
const int UnitMin08 = 7;
const int UnitTen01 = 2;
const int UnitTen02 = 11;
const int UnitTen04 = 10;
const int UnitHrs01 = 3;
const int UnitHrs02 = 4;
const int UnitHrs04 = 5;
const int UnitHrs08 = 6;
void setup()
{
delay(200);
pinMode(setH, INPUT);
pinMode(setM, INPUT);
pinMode(UnitMin01, OUTPUT);
pinMode(UnitMin02, OUTPUT);
pinMode(UnitMin04, OUTPUT);
pinMode(UnitMin08, OUTPUT);
pinMode(UnitTen01, OUTPUT);
pinMode(UnitTen02, OUTPUT);
pinMode(UnitTen04, OUTPUT);
pinMode(UnitHrs01, OUTPUT);
pinMode(UnitHrs02, OUTPUT);
pinMode(UnitHrs04, OUTPUT);
pinMode(UnitHrs08, OUTPUT);
}
void loop()
{
tmElements_t tm;
if (RTC.read(tm))
{
if (digitalRead(setM) == HIGH)
{
unsigned long j = RTC.get();
j = j + 60;
RTC.set(j);
}
if (digitalRead(setH) == HIGH)
{
unsigned long j = RTC.get();
j = j + 3600;
RTC.set(j);
}
binaryOutputHours(tm.Hour);
binaryOutputMinutes(tm.Minute);
}
delay(1000);
}
void binaryOutputHours(int number)
{
if (number == 0)
{
number = 12;
}
if (number >= 13)
{
number = number - 12;
}
setBinaryHours(number);
}
void binaryOutputMinutes(int number)
{
if (number >= 10)
{
int tens = number/10;
int units = number - (tens*10);
setBinaryMins(units);
setBinaryTens(tens);

}
else
{
int tens = 0;
int units = number;
setBinaryMins(units);
setBinaryTens(tens);
}
}
void setBinaryMins(int units)
{
if (units >= 8)
{
digitalWrite(UnitMin08, HIGH);
units = units - 8;
}
else
{
digitalWrite(UnitMin08, LOW);
}
if (units >= 4)
{
digitalWrite(UnitMin04, HIGH);
units = units - 4;
}
else
{
digitalWrite(UnitMin04, LOW);
}
if (units >= 2)
{
digitalWrite(UnitMin02, HIGH);
units = units - 2;
}
else
{
digitalWrite(UnitMin02, LOW);
}
if (units >= 1)
{
digitalWrite(UnitMin01, HIGH);
units = units - 1;
}
else
{
digitalWrite(UnitMin01, LOW);
}
}
void setBinaryTens(int tens)
{
if (tens >= 4)
{
digitalWrite(UnitTen04, HIGH);
tens = tens - 4;
}
else
{
digitalWrite(UnitTen04, LOW);
}
if (tens >= 2)
{
digitalWrite(UnitTen02, HIGH);
tens = tens - 2;
}
else
{
digitalWrite(UnitTen02, LOW);
}
if (tens >= 1)
{
digitalWrite(UnitTen01, HIGH);
tens = tens - 1;
}
else
{
digitalWrite(UnitTen01, LOW);
}
}
void setBinaryHours(int hours)
{
if (hours >= 8)
{
digitalWrite(UnitHrs08, HIGH);
hours = hours - 8;
}
else
{
digitalWrite(UnitHrs08, LOW);
}
if (hours >= 4)
{
digitalWrite(UnitHrs04, HIGH);
hours = hours - 4;
}
else
{
digitalWrite(UnitHrs04, LOW);
}
if (hours >= 2)
{
digitalWrite(UnitHrs02, HIGH);
hours = hours - 2;
}
else
{
digitalWrite(UnitHrs02, LOW);
}
if (hours >= 1)
{
digitalWrite(UnitHrs01, HIGH);
hours = hours - 1;
}
else
{
digitalWrite(UnitHrs01, LOW);
}
}

No comments:

Post a Comment