The first one I want to talk about is actually also related to robotics (granted, very little I do isn't related to robots, but still). One of the things that is a constant hassle for me is ambient infrared radiation. I tend to use IR distance and surface sensors frequently in my projects. Mainly, because they're cheap, reliable, and small. However, they tend to act up in areas when there's a lot of infrared light, due to incandescent lights or the sun. Such inconvenience!
One of the biggest problems with this is that people can't see IR, but the robot can, and so there's all these invisible zones where the sensors don't work quite right. What's more, these zones are pretty capricious about the net effect they have on the robot- a wall that flickers in and out of existence, and randomly changes position will, of course, make a wall-following routine go haywire. This interference can cause strange behavior which can be tough to pinpoint the cause of. I've gotten pretty good at noting when the robot is off the reservation, in terms of operation of a good program under broken circumstances versus a control scheme which is just flawed. However, the profile for a failure due to IR noise versus low battery versus loose wires can be pretty similar.
To that end, I made up this guy:
Technically, this isn't a particularly advanced device, especially from an electronics standpoint, because it rel ies pretty heavily on the processing of the MCU. This is mostly to make it compact (I didn't want to make it permanent, though I don't recollect exactly why, so it's on a breadboard); if I'd wanted to be really fancy, I could've used a comparator/summation setup with a counter that ticks up until the sum is above the measured value, then switches to a count down. But that'd be like 4 extra chips, so I went with the easy way!
The next one I want to talk about is a little more complex, despite being much smaller, and is probably less interesting in the sense of possessing pizzaz, but I feel pretty good about it. Here it is in schematic and rat's nest soldered form:
This protection effect is achieved by setting up two voltage controlled switches in parallel. The simple one is formed by the diode and resistors, which will be an active current path when the voltage difference between the two supplies is greater than the voltage drop associated with the diode (for this reason, you can use schottky low-drop diodes to make the power loss less, or rectifier diodes to make the reverse protection safer). This allows current to flow from the high to low voltage with a safe loss, albeit with a bit of power factor sacrifice (which could be reduced with Op-amp isolators, but the purpose of this circuit was to be minimally small). In the other direction, we have a PNP transistor configured to act as a saturated switch which is held open when only the lower voltage power supply is connected, allowing a low-loss current to flow to the right hand side load. When the higher voltage supply is connected, the switch is effectively disabled, preventing direct flow between the two supplies. The switch biasing is controlled by the voltage divider network on the base of the PNP transistor.
This circuit is specifically designed to be a minimally small protection element, and naturally has some limits as a result. First and foremost, as mentioned before, both current flow modes which support only one supply come with a power loss, due to components between the source and the load. This loss can be reduced by lowering the value of the divider resistors, and reducing the voltage drop on the diode. Naturally, reducing the power loss limits the effectiveness of the protection. That brings us to the second limitation- the circuit can only balance sources with a limited difference in voltage between them. This is a result of the fact that the switches aren't actually switches, but current-controlled devices, meaning that the difference in voltage between the two sources actually determines the leakage current that will flow into the lower voltage source.
Reducing the voltage drop and resistor values will then increase the quiescent leakage current- your total efficiency is thus limited by how much reverse current your lower source can tolerate. In practice, tuned for balancing a 5 (USB) and 6 (AA battery) volt pair of supplies with a tolerable reverse current of 3mA resulted in a current delivery capacity of about 500mA at about a 7% power loss, which worked well for the desired application.
For my third and final (for now) circuit I'd like to look at, we've got another infrared thing! As I mentioned earlier, one of the problems with these sensors is that there's a ton of ambient IR out and about in the world. One way to combat this is to ramp up the power until the light that's emitted for sensing is much brighter than the ambient levels. Obviously, this isn't so good, since it'll burn a lot of power, but also that's kind of difficult to do outside- what with the sun and all. Instead, the approach I took was to introduce a signal to the emitted light. Tuned 38.4 kHz IR receivers are fairly common, as the receiving element for remote controls.
Using one of those, and a modulated output, we can make an emitter/detector pair which is sensitive specifically to the narrow band around 38.4 kHz, of which there is very little in random environmental sources. The actual emitter/receiver pair ended up looking like this:
Proximity sensors are nice, and one that's immune to ambient light is pretty useful, but really it'd be preferable to have one with a distance indication instead of just a yea/nay output, especially considering that the 'distance' will be strongly dependent on the reflectivity of what the sensor is looking at. This will apply to a distance sensor as well, but a ranged value is more easy to calibrate- the binary sensor is simply de facto calibrated by the physical parameters.
To convert this binary sensor into a ranging distance sensor, I decided to modulate the power delivered to the emitter using pulse width modulation, locked at the receiver frequency. With PWM, the net power level supplied to the LED is variable. Reducing the emission power will adjust the distance which will trigger the receiver. Consequently, we can cycle through a scale of powers, and note the minimum power at which triggering is observed. This will correspond to a distance to an object: the lower power at which enough light is reflected to trigger the sensor, the closer the object is.
Mathematically, we can model this using the inverse square law- at the emitter, the light emitted will have a given intensity, related to the power delivered. This power is some value determined by hardware, voltages, etc. We'll just call it P0. From this initial point, the light travels out, diminishing in intensity by the inverse square law.
Knowing that, we can write out an equation for the power delivered to the emitter in terms of distance to the surface, because we found the approximate solution point at which Pr equals the threshold triggering power (notable, because the received power being greater than the threshold power is the trigger condition, but our ranging control seeks the equality power). At this point, it gets interesting, because the duty cycle of the PWM (the independent parameter which is controlled to adjust the power) is inverse-square proportional to the average power, because power is (approximately) proportional to voltage supplied, squared. This is an approximation because an LED is an non-linear element, but works out because the voltage drop across the LED, when including a bias resistor in series (which is the standard setup anyway) is approximately constant, and so the PWM signal is essentially modulating the current delivered, which is also square proportional to the power.
So, we can say that all these conversions result in a simplified equation:
What we end up with is a sensor which is at a pulsed frequency which makes it mostly immune to natural levels of IR and interference, and can detect and output a measurement of distance based on the control system driving it. It might be worthy to note that you could also use a feedback controller which directly adjusted the current to the LED, such as a transistor or op amp inverter, but I find it's easier and more compact to control it with PWM from a microcontroller, considering that it's PWM onto an already frequency modulated signal.
Really looking at it, this post isn't actually much about circuits themselves (in the middle it got kinda EE analysis-ish) but more on applications of electronic things. I wonder, now that I've done all the work, if I should have taken parts one and two and made a post about Infrared sensing, and saved the middle for an actual electronics post! Oh well, one of the advantages of writing for yourself is the ability to just put it together however you want- I'm going to exercise that right presently.