Introduction: HC-SR04 Reader Module to Relieve Arduino
HC-SR04 ultrasonic distance sensor is very popular in robotics. Basically, any object avoiding robot uses this sensor. And it is great of course, easy to use cheap and accurate but once you start building more complex robots you can start to see a problem and this problem is time. It takes a lot of time to measure distance with this sensor, there are some alternatives like sharp sensors that can detect objects super fast but output of them is binary so you can detect if there is an object within specified range but you don't know how far. For some robots those sensors are perfect but there is another problem - price. They are almost 10 times more expensive than HC-SR04. So here I started thinking about combining those two together. And I come up with an idea for a module that you can plug to the HC-SR04 and delegate the task of reading the distance to the Attiny microcontroller, output can be binary and your main microprocessor is relieved! Simple but beautiful solution and cheap at the same time :) Want to know where you can use such sensor? Keep reading or watch a video.
JLCPCB 10 boards for $2: https://jlcpcb.com
Step 1: List of Parts
List of parts is not very long, you can find most of them at any local electronic shop, there are also links to online stores if I found something:
- HC-SR04
- Attiny45/85
- Potentiometer
- Breakaway headers Female and Male
- 1206 SMD resistor (better to buy in a kit)
- 1206 LED
You will also need some tools like:
If you want to buy a PCB for this project, check out my Tindie store:
Step 2: PCB, Schematic and Files
Above you can find all of the files including schematic and PCB design, there are also Gerber files that you can use to manufacture this PCB. Feel free to modify the files for your own needs remember that all of my projects are shared as noncommercial so you can't sell them.
Schematic is super simple, there are just a few components, you can use it to mount everything on PCB properly.
If you don't want to use PCB for this project you can connect all of that on a breadboard, it will be a little bit bigger but if you can't solder that's the easiest way for you!
Step 3: Soldering
Soldering is pretty straightforward. Start with the smallest components (resistor and LED) and then move on to bigger and bigger ones, that way it will be simpler for you to solder all of that. Make sure that polarity is right for all of the components and that there are no any shorts. If you don't want to use PCB for this project and you want to connect all of that on a breadboard just skip this step and follow the schematic from step above.
Step 4: Upload a Code
Once everything is soldered on the PCB we can upload a program to the Attiny. To do so we have to connect USBasp programmer (or any other that works with Arduino IDE) to the microcontroller. Code can be found on my Github. To upload it you need to add Attiny boards to your Arduino IDE, you can find a lot of tutorials online about that, so I wouldn't explain it right there. Of course, you can change values in the code or even it's function to suit your needs.
Step 5: Test and Adjust
When your program is ready you can plug in HC-SR04 module (take a look at the photos above to plug it correctly, otherwise you can damage the board).
You can power it with the voltage between 4V and 5V. LED on the board will light up when the distance is smaller than the distance that you set with the potentiometer. To change the distance you can use a screwdriver. When everything is working fine you can move on to the next step. If it is not, check your soldering and make sure that your circuit and my schematic matches.
Step 6: Possible Applications
Congrat's that you made it to the last step! To use this module with an Arduino you have to connect VCC of the module to Arduino's 5V, GND of the module to Arduino's GND and out pin of the module to any of the Arduino pins.
How can you use it? Well, the possibilities are endless. You can use it for your robotics project, as I am going to do for my next project, more about that soon :) You can modify the code, connect a servo to it and control the servo directly from this board. You can modify it and use it without any additional, external microcontroller. It is a small board with a lot of potential and it will make my next project a lot easier.
I hope you enjoyed reading this instrucatble :) Don't forget to check out my video about this project and subscribe to my channel! Thanks for reading, happy making!