Search This Blog

Sunday 15 September 2013

http://hotels.juaxoo.com
 Cheap Hotels Online

Binary Clock Using Arduino

100_0991.JPG


For my clock, I have the display set on the top of the container. I use it on my workbench which I am usually standing at, so this way is easier to see.  It also creates a nice luminous effect when the lights are down low or off, casting the blue color upwards into the room.

You can select a container to your liking and place the clock face how it best fits your needs.

Step 1: Component Shopping List

Below is a list of all the items that you will need in order to complete this project.  I have tried to include places where you can order from as well as optional components that you may want to pick up.

This list is for surface mount items.  If you decide to go with through-hole components, the resources I have listed all sell them as well and you can just do a search on the component.

What You Need:
  1. ATmega168 with Arduino Bootloader  
  2. 10K Resistor 
  3. 220 Ohm Resistor 
  4. 22pF Capacitor 
  5. 10uF Capacitor 
  6. Pushbutton Switch 
  7. LM78L05AC Voltage Regulator
  8. 13 LED's. I used Blue, but you can use any color.
  9. 16MHz Crystal
  10. DC Power Jack Connector
  11. If you don't already have one, an Arduino Board.
  12. PC Board (Perf Board/Proto Board).
  13. Optional Protoboard 
  14. Project Container.
  15. Translucent Acrylic - I picked up some white translucent acrylic.
  16. x2 SPDT Pushbuttons

Step 2: 8421 Binary and 24 Hour Time

leds1.png

binary-example.png

First, lets take a look at how to understand the 8421 Binary system.  Your clock is going to have two columns for the "hours" and two columns for the "minutes".

We are using a 24 hour time system.

With that said, if it were 8 AM, the time is 0800 hours and if it were 8 PM, the time would be read as 20:00 hours.  In US Army basic training, when you first learn this time system, they taught us to just count backwards by 2 for PM times. So for example, if I was told to be in formation by 2100 hours. In my head I was thinking 2100 - so 1, 0, 9 and knew they meant 9 PM.

Or if we were off work  at 1630 hours, in my head I was thinking 1630 - so 6, 5, 4 and knew the day was over at 4:30 PM. I hope that makes sense, I felt the need to explain for anyone who is not use to telling time with this method.

Looking at the 8421 Binary Example image, in the first column of the hour leds, if the first led was lit up, its value would be worth 1 and in the second column if the 4th(top) led was lit, its value would be worth 8. Therefore you would have 18.

Now with the minute leds, lets say the first column has the third led and the first led lit up. This value would be 4+1=5. The second column, third led is lit up would give a value of 4. So together you would have 54.

The overall time would read as 18:54 which would be 6:54 PM

Look at the second image example. The time is 21:37


Step 3: Creating the Arduino Binary Clock PCB
You have a few options with this step.  You could use your Arduino board and run all the components to it.  This option however, you wont have access to your Arduino as long as you are using the clock :(              so you would have to buy another one.

You can Build Your Own Arduino onto a piece of Protoboard, and then run the connection wires to a seperate protoboard that has the LED's on it.  This was the method that I used for my first clock design.

A better approach would be to etch your own copper PCB.  The second clock that I designed I went with this method.  There are pleanty of Instructables on how to do this.  Since this method requires more equipment, I am going to keep with the first clock design for instruction purposes. Later or on your own you can research other methods if you would like to attempt etching your own PCB.

Once you have the protoboard that will be used as your Arduino completed. Use your actual Arduino board, and upload the sketch supplied at the end of this tutorial.  Pop that chip out, and place it in the protoboard Arduino.

The resistors and leds will be connected from the second protoboard, down to your designed Arduino board. Follow the attached schematic with this step.

Arduino Pin 1 connects to Resistor 1 which connects to LED 1, which connects to GND.
Arduino Pin 2 connects to Resistor 2 which connects to LED 2, which connects to GND.
* repeat this process for all 13 resistors, pins and led's.

SOLDERING TIP.
Place a tiny and thin layer of solder onto the area that you are going to be soldering to first, then with one hand holding the soldering iron, and the other using a pair of tweezers, place the component onto the area to be soldered to. Hold it down with the tweezers, and then reheat the solder. Keep pressure applied with the tweezers and move the solder iron away. Now you can let go with the tweezers and the part will be connected into place. More Instructables for soldering.

Step 4: Clock Case

100_0966.JPG

The next step is to measure out and cut the acrylic. I cut slightly over the amount of the protoboards so that I had room to move the location of the LED's around to be fairly centered.
For the clock housing, I selected a box that had a deep lid. This allowed me to be able to fit the protoboards into it, and still have room to make a flat cover to hide everything once the lid is opened.I drew out a square pattern for where the face will be, then drilled a hole into the corner. This allowed me to use a small copping saw to then cut out the shape. The cuts are kind of rough, so I added trim molding around the opening to hide this. It also makes it look more finished.


After I sanded and stained the box, I placed the acrylic and components in and measured where the pushbuttons and power jack were located. With a drill bit and counter sink, I made the holes for them. Carefully insert your arduino binary clock boards into the lid.

Step 5: Arduino Sketch

*/
int second=0, minute=0, hour=0; //start the time on 00:00:00
int munit,hunit,valm=0,valh=0,ledstats,i;
void setup() { //set outputs and inputs
pinMode(1, OUTPUT);pinMode(2, OUTPUT);pinMode(3, OUTPUT);pinMode(4, OUTPUT);pinMode(5, OUTPUT);
pinMode(6, OUTPUT);pinMode(7, OUTPUT);pinMode(8, OUTPUT);pinMode(9, OUTPUT);pinMode(10, OUTPUT);
pinMode(11, OUTPUT);pinMode(12, OUTPUT);pinMode(13, OUTPUT);
pinMode(0, INPUT);
}
void loop() {
static unsigned long lastTick = 0; // set up a local variable to hold the last time we moved forward one second
// (static variables are initialized once and keep their values between function calls)
// move forward one second every 1000 milliseconds
if (millis() - lastTick >= 1000) {
 lastTick = millis();
 second++;
}
// move forward one minute every 60 seconds
 if (second >= 60) {
 minute++;
 second = 0; // reset seconds to zero
}
// move forward one hour every 60 minutes
if (minute >=60) {
 hour++;
 minute = 0; // reset minutes to zero
}
if (hour >=24) {
 hour=0;
 minute = 0; // reset minutes to zero
}
 munit = minute%10; //sets the variable munit and hunit for the unit digits
 hunit = hour%10;

 ledstats = digitalRead(0);  // read input value, for setting leds off, but keeping count
 if (ledstats == LOW) {
  
 for(i=1;i<=13;i++){
 digitalWrite(i, LOW);}

 } else  {
 //minutes units
 if(munit == 1 || munit == 3 || munit == 5 || munit == 7 || munit == 9) {  digitalWrite(1, HIGH);} else {  digitalWrite(1,LOW);}
 if(munit == 2 || munit == 3 || munit == 6 || munit == 7) {digitalWrite(2, HIGH);} else {digitalWrite(2,LOW);}
 if(munit == 4 || munit == 5 || munit == 6 || munit == 7) {digitalWrite(3, HIGH);} else {digitalWrite(3,LOW);}
 if(munit == 8 || munit == 9) {digitalWrite(4, HIGH);} else {digitalWrite(4,LOW);}
 //minutes
 if((minute >= 10 && minute < 20) || (minute >= 30 && minute < 40) || (minute >= 50 && minute < 60))  {digitalWrite(5, HIGH);} else {digitalWrite(5,LOW);}
 if(minute >= 20 && minute < 40)  {digitalWrite(6, HIGH);} else {digitalWrite(6,LOW);}
 if(minute >= 40 && minute < 60) {digitalWrite(7, HIGH);} else {digitalWrite(7,LOW);}
 //hour units
 if(hunit == 1 || hunit == 3 || hunit == 5 || hunit == 7 || hunit == 9) {digitalWrite(8, HIGH);} else {digitalWrite(8,LOW);}
 if(hunit == 2 || hunit == 3 || hunit == 6 || hunit == 7) {digitalWrite(9, HIGH);} else {digitalWrite(9,LOW);}
 if(hunit == 4 || hunit == 5 || hunit == 6 || hunit == 7) {digitalWrite(10, HIGH);} else {digitalWrite(10,LOW);}
 if(hunit == 8 || hunit == 9) {digitalWrite(11, HIGH);} else {digitalWrite(11,LOW);}
 //hour
 if(hour >= 10 && hour < 20)  {digitalWrite(12, HIGH);} else {digitalWrite(12,LOW);}
 if(hour >= 20 && hour < 24)  {digitalWrite(13, HIGH);} else {digitalWrite(13,LOW);}
 }
 valm = analogRead(0);    // add one minute when pressed
  if(valm<800) {
  minute++;
  second=0;
  delay(250);
 }

 valh = analogRead(5);    // add one hour when pressed
  if(valh<800) {
  hour++;
  second=0;
  delay(250);
 }

}

Creating an Electronic Die

Our goal is to light one of six LEDs randomly to mimic the throw of a die.
We’ll choose a random number between 1 and 6, and then turn on the
corresponding LED to indicate the result. We’ll create a function to select
one of six LEDs on the Arduino randomly and to keep the LED on for a
certain period of time. When the Arduino running the sketch is turned on
or reset, it should rapidly show random LEDs for a specified period of time
and then gradually slow until the final LED is lit. The LED matching the
resulting randomly chosen number will stay on until the Arduino is reset
orturned off.
The Hardware
To build the die, we’ll need the following hardware:
Six LEDs of any color (LED1 to LED6)
One 560 W resistor (R1)
Various connecting wires
One medium-sized breadboard
Arduino and USB cable
The Schematic
Because only one LED will be lit at a time, a single current-limiting resistor
can go between the cathodes of the LEDs and GND. Figure 6-2 shows the
schematic for our die.


Here’s the sketch for our die:

void setup()
{
 randomSeed(analogRead(0)); // seed the random number generator
 for ( int z = 1 ; z < 7 ; z++ ) // LEDs on pins 1-6 are output
 {
 pinMode(z, OUTPUT);
 }
}
void randomLED(int del)
{
 int r;
 r = random(1, 7); // get a random number from 1 to 6
 digitalWrite(r, HIGH); // output to the matching LED on digital pin 1-6
 if (del > 0)
 {
u delay(del); // hold the LED on for the delay received
 }
v else if (del == 0)
 {
 do // the delay entered was zero, hold the LED on
forever
 {}
w while (1);
 }
 digitalWrite(r, LOW); // turn off the LED
}
void loop()
{
 int a;
 // cycle the LEDs around for effect
 for ( a = 0 ; a < 100 ; a++ )
 {
 randomLED(50);
 }
 // slow down
x for ( a = 1 ; a <= 10 ; a++ )
 {
 randomLED(a * 100);
 }
 // and stop at the final random number and LED
 randomLED(0);
}
Here we use a loop in void setup() to activate the digital output pins.
The function randomLED() receives an integer that is used in the delay()
function at u to keep the LED turned on for the selected time. If the 3
value of the delay received at v is 0, then the function keeps the LED
turned on indefinitely, because we use
 do {} while (1);
at w, which loops forever, because 1 is always 1.
To “roll the die,” we reset the Arduino to restart the sketch. To create
a decreasingly slow change in the LEDs before the final value is displayed,
at x we first display a random LED 100 times for 50 milliseconds each time.
Next, we slow it down by increasing the delay between LED flashes from
100 to 1,000 milliseconds, with each flash lasting 100 milliseconds. The
purpose of this is to simulate the “slowing down” of a die before it finally
settles on a value, at which point the Arduino displays the outcome of the
roll by keeping one LED lit with this last line:
 randomLED(0);
Modifying the Sketch
We can tinker with this project in many ways. For example, we could add
another six LEDs to roll two dice at once, or perhaps display the result
using only the built-in LED by blinking it a number of times to indicate the
result of the roll. Use your imagination and new skills to have some fun

Saturday 14 September 2013

Lesson 1 >>Arduino

Do you have everything you need?
Not much is needed for this lesson, just a USB cable and an Arduino. If you have an older Arduino you may
 also need an LED. Any LED is fine as long as it looks sorta like the photo, with a plastic bulb and two legs
Make sure you've gone through First BLog!
Download the Software
The first thing to do is download the Arduino software.
Go to the Arduino Software Download page and grab the right file for your OS. As of Sept 2007 the version is 009 but you should use whatever is most recent.
The packages are quite large, 30-50 MB so it may take a while to finish
Unpack and Install
Extract the package onto the Desktop

Windows

Windows
Startup!
Double click the Arduino software icon

Windows
To open up the workspace
I think I get the red error text shown because I already have Arduino installed. Either way, it isn't a problem
 if you do or don't see it.
Select chip
The first step is to configure the Arduino software for the correct chip. Almost all Arduinos use the
ATmega168, but there's a chance you have an ATmega8. Look for the chip on the Arduino that looks
like this:

If the text says ATMEGA8-16P then you have an atmega8 chip. If the text says ATMEGA168-20P
 then you have an atmega168 chip. If it says "ATMEGA328P-20P" you have an atmega328p chip
Make sure the correct chip is selected (this picture is really old, will be fixed soon). This preference is
 saved so you only have to set it once, the program will remember next time it's run.
Select port
Next, its time to configure the Serial Port (also known as the COM Port). Go back to last POST remind
 yourself of which port it is. On a PC it will probably be something like COM3 or COM4

Windows port selection
This preference is saved so you only have to set it once, the program will remember next time it's run.
However, if you have multiple Arduino's, they may be assigned difference COM ports. So every time
you plug in a new Arduino, double check that the correct port is selected.
Open blink sketch
Sketches are little scripts that you can send to the Arduino to tell it how to act. Let's open up an Example Sketch. Go to the File menu -> Sketchbook -> Examples -> Digital -> Blink
The window should now look like this, with a bunch of text in the formerly empty white space and the tab Blink above it
Verify / Compile
The first step to getting a Sketch ready for transfer over to the arduino is to Verify/Compile it. That means check it over for mistakes (sort of like editing) and then translate it into an application that is compatible
 with the Arduino hardware.
After a few seconds, you should see the message Done compiling. in the Status Bar and Binary 
Sketch Size: in the Notification area. This means the sketch was well-written and is ready for
 uploading to the Arduino board!
Reset (NG only)
To tell the Arduino that it should prepare itself for a new Sketch upload, you must reset the board. Diecimila Arduino's have built-in auto-reset capability, so you don't need to do anything. Older Arduinos, such as
 NG, must be manually reset before uploading a sketch. To do that simply press the black button on the
 right hand side of the board, shown here.
Upload
Now it's time to upload. Make sure the Arduino is plugged in, the green light is on and the correct
Serial Port is selected.
If you have an NG Arduino, press the Reset Button now, just before you select the Upload menu item.
Select Upload to I/O Board from the File menu
After a few seconds you should get this screen, with the message Done uploading. in the status bar.
If you get the following error message "avrdude: stk500_getsync(): not in sync: resp=0x00" that
means that the Arduino is not responding
Then check the following:
  • If you have a NG Arduino, did you press reset just before selecting Upload menu item?
  • Is the correct Serial Port selected?
  • Is the correct driver installed?
  • Is the chip inserted into the Arduino properly? (If you built your own arduino or have burned the
  •  bootloader on yourself)
  • Does the chip have the correct bootloader on it? (If you built your own arduino or have burned the bootloader on yourself)
If you get the following error message:
It means you dont have a serial port selected, go back and verify that the correct driver is installed (Last Post)
and that you have the correct serial port selected in the menu.
If you get the following error Expected signature for ATMEGA
Then you have either the incorrect chip selected in the Tools menu or the wrong bootloader burned onto
 the chip
If you get the following error: can't open device "COM10": The system cannot find the file specified 
(under Windows, COM port value may vary)
It means that you have too many COM ports (maybe you've got 9 Arduinos?) You should make sure that
the port is numbered as low as possible. You can use a program like FTClean to clear out old COM ports
you aren't using anymore. Once you've cleaned out the ports, you'll have to reinstall the driver again
Alternately, if you're sure that the ports are not used for something else but are left over from other
 USB devices, you can simply change the COM port using theDevice Manager. Select the USB device
 in the Device Manager, right click and select Properties
Then click Advanced... and in the next window change the COM port to something like COM4 or COM5.
 Don't forget to select the new port name in the Arduino software. The lower port names may
say (in use) but as long as the other USB devices aren't plugged in, it shouldn't be a problem. This is
 a little riskier than just using FTClean...
Video of all steps
Here is a video showing the timing of the steps described so far.

Insert LED (NG Arduinos)
Some older Arduinos don't have a built in LED, its easy to tell if yours does or not
If you have a Diecimila or other Arduino with a built in LED you will see a translucent part as shown
If you have an NG rev C or other Arduino without an LED, the translucent part will not be there, and
 instead you will see two silver dots
If you don't have an LED, you'll need to add your own. Any LED will do, as long as it has two legs and
kinda looks like the one shown here. LEDs are directionalcomponents. That means if you put it in
backwards it
will not work! To help you put the LED in right, the LED factory cuts the legs at different lengths.
The longer leg goes in the hole marked 13 and the shorter one goes in the hole marked GND
Watch!
If you have a Diecimila Arduino, the upload process is quite fast, just start the Upload from the software.
The board will automatically reset itself, transfer the sketch and start the sketch. The little translucent LED
 will start blinking
Video thumbnail. Click to play.
If you have an NG arduino, make sure the LED is inserted as indicated before. Here is a video of the entire uploading process. Right after I press the Reset Button I start the sketch upload. There is a short wait
 while the software prepares to transfer the sketch. Then the two small orange lights blink, indicating the
 sketch is being transfered. When its done, there is a 7 second delay until the sketch starts.
Video thumbnail. Click to play.
If you don't get a blinking LED, make sure you put the part in the right way, in the correct holes, and
 perhaps try a different LED as it may be bad.

Begin With Adruino

USB Cable. Standard A-B cable is required. Any length is OK.


    9V DC power plug with 2.1mm barrel plug, positive tip (Optonal)

Assembled Arduino board, preferrably an Uno, Diecimila or Duemilanove (or  whatever the latest version is) but NG is OK too


YOU REQUIRE ABOVE THINGS TO START WITH


Preparing the Arduino!
Take your Arduino out of its protective bag. Look at it and make sure it looks kinda like this:

Diecimila Arduino
Or like this:

NG Arduino

OK, now that you are satisfied that your Arduino looks good, put the rubber bumpers on the bottom of
 the board. This will protect your Arduino from spills and dirty tables. If your table is made out of metal,
 this is essential!
Download & Install Drivers
Depending on which Arduino and which OS you have there are different instructions
Power up! (USB)

Now we are ready for the moment of truth, it's time to plug your Arduino in and power it up. The most
 common way to do this is to plug one end of the USB cable into the Arduino and the other end into a
computer. The computer will then power the Arduino.
The jumper-setting step is only for Diecimila and OLDER arduinos! Make sure the Power Jumper
is set correctly. Right next to the USB jack, there is a jumper with 3 pins. If the jumper is on the two pins
 nearest USB jack, that means you are planning to power the Arduino via the USB cable. If it's on the two
 pins nearer the DC Jack then it means you are planning to power the Arduino using a 9V battery or wall
 adapter.
You'll want it set as shown in the picture above.
Make sure your cable is a A-B cable. One end should be thin, rectangular. The other end should be square.

Plug the thin end into your computer

Make sure that the USB cable is plugged in directly to a computer port. Sometimes monitors or keyboards
 have a USB port you can plug into. Most of the time this is fine, but I strongly suggest you plug it directly
 into the computer as that will eliminate any possible problems. Same goes for USB hubs.
Later on, once you've verified you can power the Arduino and upload sketches no problem, then you can try plugging it into other ports.
Plug the square end into your Arduino

And a few blinking orange lights, on the left side.
If you're plugging it into a Mac or Linux machine, you may not get as much blinking from the orange lights.
 The video is from plugging into a Windows computer.
If no lights or blinking occurs, double check:
  • Is the USB cable plugged into the computer and into the Arduino?
  • Is the computer on?
  • Is the jumper set correctly?
  • Try another USB port, USB cable, and computer
If you still can't get it working, your Arduino may be faulty.
Next its time to install the driver! Follow these links for instructions for each of the supported operating
 systems
Power up! (9V DC, optional!)
Another way to power up the Arduino is to plug in a battery or wall adapter into the DC jack.
Verify that you have a 9V DC 100-500mA power adapter, with a 2.1mm barrel plug and positive tip.
If the box doesn't have any information about the adapter, you can look for these clues
Make sure the symbol near the bottom of the label is present. It means that the outside of the plug is negative
 and the inside is positive. A center-negative plug will not work with the Arduino.
To verify the DC plug is the right shape, just try plugging it in. If it doesn't fit or is wobbly, it's the wrong
kind.
The jumper-setting step is only for Diecimila and OLDER arduinos! Make sure the Power Jumper
 is set correctly. The jumper should be set so that it connects the two pins close to the DC jack
Plug in the adapter and verify you get the green light!
If not, double check:
  • Is the DC adapter plugged in?
  • Is the DC adapter the right kind? Check voltage, polarity, plug size, etc.
  • Is the jumper set correctly?
  • Try another adapter.
If you still can't get it working, your Arduino may be faulty.

Friday 13 September 2013

Ponyprog Circuit for AVR

Ponyprog Circuit for AVR & PIC16F8


Comments:
All resistors are 1/4W.The circuit is powered by 9...15V DC or AC. When In Circuit Programming (ISP) connectors are used, is possible the programmer to be powered from target’s power source. Diodes D2 and D6 protect the regulator LM7805, when target’s power is used.
' XTAL JUMP ' is used to cut XTAL when the AVR has internal RC oscillator enabled.
'FAMILY JUMP' is used to select which ATMEL’s family to program, AVR series (ATtinyXX, AT90SXXXX, ATmegaXXX) or 8051 series (AT89Sxxxx).
‘PIC JUMP’ is used to switch between Microchip’s PIC and ATMEL’s microcontrollers. With jumper ON only PIC can be programmed, while OFF can program ATMEL’s microcontrollers. If you don’t need to program PICs, you can leave their board area unsoldered. The PCB has been designed so that DIP sockets or ZIF sockets can be used. Because of its cost, it is recommended that only one ZIF is used combined with some pin-arrays to switch between the four different places.
The board must be connected to a PC COM port through a 9 pin to pin cable and work with the below application:
'PonyProg2000 - Serial Device Programmer
Copyright (C) 1997-2001 by Claudio Lanconelli
E-mail: lancos@libero.it
Download last version of PonyProg2000 at the address:
http://www.LancOS.com '.
Supported microcontrollers are:
ATMEL’s AVR series
ATtiny12, ATtiny15, AT90S1200, AT90S1200A, AT90S2233, AT90S2313, AT90S2323, AT90S2343, AT90S4414, AT90S4433, AT90S4434, AT90S8515, AT90S8535, ATmega8, ATmega16, ATmega161, ATmega163, ATmega323, ATMEL’s 8051 series, AT89S53, AT89S8252
MICROCHIP’s PIC series
PIC16x83, PIC16x84, PIC16F84A
And some other programmable ICs (memories, microcontrollers) which Ponyprog support but need a board adapter to be programmed through ISP connectors. For more information see Claudio Lanconelli site .