First AVR Project: Ultrasonic sensor tester
October 25, 2014
OK, these are just baby steps, but I have completed my first non-Arduino micro-controller project. It is exactly twice as complicated as a blinking LED. Basically it is a board for testing HC-SR04 ultrasonic sensors. The code simply takes a measurement from the sensor and then blinks an LED with a frequency that is proportional to the reading from the sensor. In other words, as the sensor gets closer to an object then the LED flashes faster.
So what is the point of this? Well, it does actually have two practical uses for me. Primarily it is a convenient way to test a sensor to see if it is working (much quicker than grabbing the laptop, an Arduino and a breadboard and putting together a temporary circuit). I discovered a secondary benefit too, where I can walk around and point this at different surfaces and at different angles to get a better understanding of how well these sensors work in practice.
The main purpose though was just so that I could actually complete a simple AVR project. I have a tendency to take on projects that are just beyond my current ability and then get frustrated when I can't make them work right away, although I do usually learn a lot in the process.
For this project I used an ATtiny85 (costing anywhere from less than $1 to more than $3 depending on where you buy them and how many you buy) and I could have used a lower memory version like the ATtiny25 I'm sure since the code is so simple. Unfortunately I somehow lost the github repo that contained this code.
The board also has headers for connecting an AVR programmer so that I can reprogram the chip in the future.
Here's the complete bill of materials:
- ATtiny25/45/85 (I used an ATtiny85 because that's what I had already)
- DC Barrel Power jack (like this one)
- 5V Voltage Regulator. I used an LD111750V. You could also use an LM7850 but the pins are in a different order so watch out for that!
- 6-pin female header for connecting AVR programmer
- 4-pin female header for connecting HC-SR04 sensor
- LED
- Resistor (330 ohm)
- Half-size standard breadboard or solderable breadboard
For both the female headers I just cut some headers like this down to size.
Here is the circuit diagram (also checked into the git repo).
This is only the second circuit diagram I have produced in Eagle so far, so I am still learning. Hopefully this is accurate and makes sense!