Intro: IOT123 - SR04 DISTANCE TRIGGER BRICK
The IOT123 BRICKS are DIY modular units that can be mashed up with other IOT123 BRICKS, to add functionality to a node or wearable. They are based on the inch square, double-sided protoboards with interconnected through holes.
In developing an OLED ID Tag, I needed to make my design as energy efficient as possible. One approach was to only display the tag if there was someone nearby (think ComiCon or Exhibition booths). The sensors themselves can draw a lot of current, so this needed to be optimized. Originally I started with a Sharp IR sensor, but bricked my only one during a development spike.
I believe there are many scenarios where low power sensing is required, so I made the design fairly generic where the hardware sensor and the associated code could be swapped out easily. Also serial pins (TX/RX) have been broken out so as to debug the ATTINY85 during development. When a predefined (runtime assignable via a momentary button) value is reached, a pin is sent HIGH, to wake the HOST MCU. When not triggering/sensing, the ATTINY/SR04 are sleeping/powered down.
The mashup has been coined a BRICK as a nod to the ubiquitous Keyes bricks.
Step 1: Materials and Tools
This design can be packaged any way you like but I suggest you use the 1" format protoboards to take advantage of the future modules.
There is a full Bill of Material and Sourcing list.
- SR04 Ultrasonic rangefinder (1)
- 1" Double sided protoboard (1)
- 8 Pin DIL IC Socket (optional)
- ATTINY85 20PU (1)
- 2N7000 mosfet (1)
- Hookup wire (~10)
- 10K resistors (2)
- 1K resistor (1)
- Male header right angled (5P)
- Solder Iron (1)
- Solder (1)
Step 2: Program the ATtiny85
Use the included source; compile and program to the ATtiny85. You may find more details in these instructables:
Step 3: Assembling the Generic Circuit
This design is meant for any sensors that provide analog values and can sleep periodically. Therefore the generic assembly is detailed separately.
There are a few occasions where soldering on the other side of a through hole is obstructed. When this is the case, I soldered a dob on the target through hole, then from the side melt the solder and push the exposed hookup wire into center hole, hold and remove heat.
- On the rear, insert the momentary button, DIL IC Socket, 2N7000 (leave outer leg long), and male headers and solder off on front side.
- On the rear, thread a stripped red hookup wire through RED2, into RED1 on the front and solder off. Trace the other side into RED3 and solder.
- On the rear, with black hookup wire, trace and solder BLACK1 to BLACK2.
- On the front, bend the leg of BLACK3 to BLACK4 and solder.
- On the front, with yellow hookup wire, trace and solder YELLOW1 to YELLOW2, YELLOW3 to YELLOW4, YELLOW5 to YELLOW6.
- On the front, with a 1K resistors, trace and solder GREY1 to GREY2.
- On the front, with 10K resistors, trace and solder GREY3 to GREY4 and GREY5 to GREY6.
Step 4: Assembling the SR04 Circuit
These steps can be mixed-in with the above step as you are dealing with the RED/YELLOW wires. The steps have been structured like this for modularity.
- On the rear, with red hookup wire, trace and solder RED4 to RED5.
- On the front, with yellow hookup wire, trace and solder YELLOW7 to YELLOW8 and YELLOW9 to YELLOW10.
On the front, insert SR04.Gnd into ORANGE1, SR04.Eccho into ORANGE2, SR04.Trig into ORANGE3, SR04.Vcc into ORANGE4 and solder.
Step 5: Testing the Circuit
The trigger distance is set during the first 10 seconds on boot (with the momentary button) and used on reboot if not changed. The range is divided by 10 and each button press starts at the minimum and increases with these units. 1 press is about 10cm, 2 presses 50cm, 3 presses 90cm and so on.
Using Software Serial:
- Use the hookup guide on TTL-232 Jig above.
- Follow instructions for using SoftwareSerial.
- Watch the video: SR04 TRIGGER BRICK CONSOLE OUTPUT.
Using a LED Indicator for the Trigger:
- Use the breadboard layout above.
- Watch the video: SR04 TRIGGER BRICK LED OUTPUT.
Step 6: Next Steps
- The position of the HOST MCU connections can be varied to anywhere on the board where the circuit still follows the schematic.
- The SERIAL connections are not needed at all.
The position of the SENSOR connections can be varied to anywhere on the board where the circuit still follows the schematic.
Try the generic circuit with other sensors that seem a good fit.