Ultrasonic Range Finder with an ATtiny85 (With Shield)
Iím here to show you how to use a HC-SR04 Ultrasonic Range Finder with an ATtiny85 as well as programming the ATtiny85 using the wonderful shield that randofo created.

List of materials:
ATtiny85 Programming Library
Arduino Uno
HC-SR04 Ultrasonic Range Finder and Library
Jumper Wires
Breadboard
ATtiny85

Step 1: Program the Arduino

Ultrasonic Range Finder with an ATtiny85 (With Shield)
Ultrasonic Range Finder with an ATtiny85 (With Shield)
Before you connect your shield to the Arduino Uno, youíll want to make sure youíve put your Arduino Uno into itís ISP mode, to do this load up your Arduino IDE and once itís loaded go to File > Examples > ArduinoISP, now connect your Arduino up to your PC and upload the ISP sketch.

Step 2: Connect The Shield

Ultrasonic Range Finder with an ATtiny85 (With Shield)
Ultrasonic Range Finder with an ATtiny85 (With Shield)
Ultrasonic Range Finder with an ATtiny85 (With Shield)
Take your Arduino Uno and clip the shield in place, then take your ATtiny85 IC and put it in the correct way into the DIP-8 Socket on the shield.

Step 3: Program the ATtiny85

Ultrasonic Range Finder with an ATtiny85 (With Shield)
Ultrasonic Range Finder with an ATtiny85 (With Shield)
Now that youíve put the Arduino into its Programming state, and connected the shield, itís time to program the ATtiny85 chip, now Iíll show you how to make the LED on the board blink.

Go to this link and follow those instructions to get the core library for ATtinyís loaded into the Arduino IDE, Once youíve done that then copy the code below into the IDE and upload it (Once youíve selected the correct board.)

/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */ void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(0, OUTPUT); } void loop() { digitalWrite(0, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(0, LOW); // set the LED off delay(1000); // wait for a second }

Step 4: The Real Magic

Ultrasonic Range Finder with an ATtiny85 (With Shield)
Ultrasonic Range Finder with an ATtiny85 (With Shield)
Ultrasonic Range Finder with an ATtiny85 (With Shield)
Ultrasonic Range Finder with an ATtiny85 (With Shield)
Ultrasonic Range Finder with an ATtiny85 (With Shield)
If you managed to get this far without causing any issues or having any problems youíre doing good, itís time to hook up the HC-SR04 now.

Weíll start off with the power circuit first.

Connect jumpers from VCC (Pin 8 on the ATtiny) and Ground (Pin 4) to the breadboard, make sure theyíre 2 holes apart (See image 7 for reference).

Now connect two more jumpers between the VCC and Ground and hook one up to Analogue Input 3 (Pin 2) and another to Analogue Input 1 (Pin 7).

Now connect your HC-SR04 Ultrasonic Range Finder, having the Ďeyesí facing you the four pins should read "VCC, TRIG, ECHO, GND" TRIG goes to Analogue Input 1 and ECHO goes to Analogue Input 3.

Step 5: The Code

Ultrasonic Range Finder with an ATtiny85 (With Shield)
Ultrasonic Range Finder with an ATtiny85 (With Shield)
Youíll need to get the HC-SR0R Library, Once youíve gotten the library install it (Make sure the Arduino IDE is closed).

Once everything is configured and wired up, upload the following sketch.

#include "Ultrasonic.h" int LED1 = 0; // LED1 Pin int TRIG = 2; // Trigger Pin int ECHO = 3; // Echo Pin int Range; // The range of the object from the HC-SR04 Ultarsonic Module int Dist; // The Distance value Ultrasonic ultrasonic(TRIG,ECHO); // Create and initialize the Ultrasonic object. void setup() { pinMode(LED1, OUTPUT); Dist = 2; } void loop() { //Range = ultrasonic.Ranging(CM); // Range is calculated in Centimeters. Range = ultrasonic.Ranging(INC); // Range is calculated in Inches. if (Range Dist) { digitalWrite(LED1, LOW); } }
If an object comes within 2 inches of the range finder the LED will light up.

There is a lot of room for improvement like for example every now and again the LED will light up for no reason, I believe this could be from a false reading from the range finder, but all in all, this is a pretty good ATtiny85 Project to get you started.
 
 

Tag cloud

make build easy simple arduino making homemade solar laser printed portable cheap mini building custom cardboard wooden create super lego turn paracord chocolate your paper light intel