Tuesday, December 23, 2014

In this post, I'll be showing you how to do an alarm. Its pretty simple.

Since this is an alarm, There's pretty much a lot of purpose in using it. It really depends totally on how you decide to implement or place it at. For my case, I'm using it as an incoming person detector. The alarm simply goes off when someone is coming into my room or when the door gets close or open. Let's get started!

Components required:
   1) Arduino Uno (along with its cable)
   2) USB Port Type B. ( You can change this, If you prefer to use USB Type A, go ahead)
   3) Some jumper wires
   4) 5V Magnetic Buzzer
   5) LED (Any colour, I chose red)
   6) PCB Slide Switch
   7) Attiny 85
   8) 8 Pin IC Holder
   9) Strip Board
   10) Female Pin Header ( I used the snap-able type. I find it easier to use that)
   11) Ultrasonic Sensor (Parallax ping sensor)

Tools required:
   1) Solder wire and tool
   2) Wire Cutter

Step 1)

The pinout for AtTiny 85 are as follow. Do take note that pin 1 and 8 are the side nearest to the notch or dot.

Pin 1-3 of the chip will not be connected.

Pin 4 of the chip will be the ground, It will be connected to the ground from the power source, led, buzzer and ultrasonic sensor.

Pin 5 of the chip will be connected to the Anode of the Led. The Cathode of the Led will be connected to the anode of the buzzer. The cathode of the buzzer will be connected to the ground. This way, the buzzer will buzz when the Led turns on.

Pin 6 of the chip will be connected to the UltraSonic Sensor (Sensor Pin).

Pin 7 of the chip will not be connected.

Pin 8 of the chip will be the Vcc or where the Vcc from your Type B USB Port will be going to. A switch should be placed between this pin and the Vcc from the USB Port.

Step 2)

Break at the necassary places to avoid the circuit from crossing each other. Mine consists of 7 break point.

After all connections is done, you should have  something like this. Note, this is my layout, yours may be different. As long as the components are connected according to the steps above, it should be working fine.

Step 3)
Install your arduino as ISP . Refer to my previous post. The AtTiny can now be programmed with the shield and Arduino. Copy the code below to your Arduino IDE and upload to your AtTiny. Proper steps for downloading to the AtTiny can be found in my previous post.

                                                     Copy code from below this line onwards:
const int pingPin = 1;

void setup() {
  pinMode(0, OUTPUT);            //Led

void loop()
  long duration, inches, cm;

  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);        
  digitalWrite(pingPin, HIGH);
  digitalWrite(pingPin, LOW);

  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  if(cm<50 && cm>20)
  digitalWrite(0, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(200);              // wait for a second
  digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
  delay(200);              // wait for a second
  else if(cm<20)
  digitalWrite(0, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(80);              // wait for a second
  digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
  delay(80);              // wait for a second


long microsecondsToInches(long microseconds)
  return microseconds / 74 / 2;

long microsecondsToCentimeters(long microseconds)
  return microseconds / 29 / 2;
                                                             Copy code till above this line

Upload the code to your AtTiny 85.

Step 4)
   Your board shall now work as follows: I've not connected the buzzer in the video.

Step 5)
As mine is an incoming people sensor. I'm placing it near my room door.

This is the final outcome. My very own alarm that alerts me when someone is approaching or entering the room.

Hope you'll give this project a try. Cheers!

Wednesday, December 17, 2014

In this post I'll be showing you how to use your AtTiny Shield with an Arduino Uno. Its really not that hard.

Things required:
1) AtTiny Shield (Refer to my previous post on how to create this)
2) Arduino Uno
3) Arduino IDE Environment
4) USB Cable

Step 1
   Connect the Arduino Uno to your computer and ensure that the board is set as Arduino Uno.

Step 2
   Click on Files followed by examples followed by ArduinoISP.

Step 3
   Click on upload. (Note: At this point there should be nothing connected to your Arduino other than the USB Cable.)

Step 4
   Once the upload is complete, remove USB from Computer. Mount the AtTiny Shield on the Arduino Uno. Do not forget to mount your AtTiny chip on the shield. I've forgotten to mount it in the picture below. Reconnect the USB to your computer.

Step 5
   Click on Tools>Board and click on the appropriate AtTiny that you are using. For my case, It would be AtTiny 85.

Step 6
   Click on tools>Programmer followed by Arduino as ISP.

Step 7
   You may now upload your AtTiny code. However, do take note. Upon uploading, the following error will occur:

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

Do not be panic. It is safe to ignore this error. Your AtTiny is now ready for use. Cheers!
In one of my previous post, I shared how to create an AtTiny Shield. You might be wondering how do you prepare the Arduino IDE so that it is usable with the Shield. I''m going to cover that in this post. It can be quite complicated. I've included screenshot for better understanding.

Things required:
1) Arduino IDE Environment
2) attiny-master.zip

Step 1
   Click on the "attiny-master.zip" link above and download it. Save it to somewhere where it is easy to find. We're going to need it later.

Step 2
   Start your Arduino IDE Environment and click on File followed by Preferences.

Step 3
   Open that exact same directory of your "Sketchbook Location" on your computer file explorer. Create a new folder and name it "hardware". (Note: You don't have to create a new folder if a folder named hardware has already existed)

Step 4
   Extract the content of the zip file (attiny-master.zip) into the hardware folder. Note: A folder named "attiny" and NOT "attiny-master" should be in the hardware folder. You should have a directory of something like this:

Step 5
   Close any Arduino IDE Software if you have it running. Restart the Arduino IDE. Click on Tools followed by Board. You should have the all the AtTiny option there.

Basically, that's about  it. Your Arduino Software is now ready to program AtTiny chips.