Resistive Security Loops

Perhaps the most basic form of electronic security system involves a buzzer or bell set to go off if a loop of wire is cut. Sensors, such as door position switches and sliding window contacts, can be inserted into this loop, breaking the circuit if a window or door is opened. When the loop is cut (say, by a window switch opening), an alarm bell can be made to ring.

Naive_sm

A simple, naive security system. (Click for larger.)

This simple approach, though effective, has a weakness. If a nefarious individual wished to circumvent this protection, he or she need only expose a section of cable, short it in two places (who knows which side of the wire goes to the alarm), and then cut it between the two shorts. Whether the security system was on the right or left side of the cut, the loop would still be complete, and current would still flow. Make these shorts on either side of a door or window sensor, and you can then open the door or window without triggering the alarm. In addition, all of the sensors “downstream” of the cut are now taken out of action.

Naive_defeated_step1_sm

First, the thief shorts the wire on both sides of the switch (he doesn’t know which end goes to the alarm system)…

Naive_defeated_step2_sm

…then, the wires are cut, and the window is opened. (Click for larger.)

What can be done to detect such dastardly meddling? Plenty. Rather than making a simple current loop, an end-of-loop resistor can be incorporated, and the system set to monitor the loop for a specific expected resistance. Any would-be burglar would then have to not just short the cable, but provide the appropriate resistance. Without prior knowledge of the system, this would be essentially impossible; it would be quite tricky even if given a schematic, wiring layout diagrams, and a good portable electronics lab. Even if the correct resistance (and direction to the control box) were known, inserting a fake end-of-loop resistor while maintaining a constant line resistance would be very difficult.

Far_rx_sm

This one is harder to defeat. (Click for larger.)

far_rx_tampered_sm

Here, a thief has tried to defeat the added-resistor system, but the electronics sense a dead short and trigger a tamper alarm. ARF ARF — GOTCHA! (Click for larger.)

However, a security system is only as good as its weakest link –including the installer. Loop resistors do not, by themselves, somehow imbue the wire with magical properties which make it immune to tampering. If placed at the near end of the loop (I.E. in the box), the loop resistors add nothing to the system security. Whether the wire is shorted or not, the resistance will always be there.

Local_rx_defeated_sm

Even with the resistor in the loop, the thief can safely disable this system with the simple shorting technique. Moral of the story: don’t put your loop resistances right at the box. (Click for larger.)

In other words, this is how it’s not done:

Loop resistances done wrong. Those 2.2k resistors (red/red/red) should be at the far end of the loop. (Click for larger.)

Note to self: Re-wire security system the right way.

 

Posted in Electronics | Leave a comment

CNC Etch-A-Sketch

I think pretty much everyone I know had an Etch-A-Sketch as a kid — or at least, had a friend who did. Ohio Art’s simple but classic design was a well-deserved success, and even served as a “laptop” for Dilbert’s boss.

20939.strip.zoom_sm

Of course, one major problem with the Etch-A-Sketch is that it is notoriously difficult to draw anything accurately, unless you have superhuman coordination. Drawing simple horizontal and vertical lines is simple, of course — but drawing circles and similar curves is frustrating and slow, and the results usually end up looking like something a kindergartner with ADHD scribbled while high on Pixie Stick powder.

But this is 2014. We have Arduinos! We have stepper motors! This is a problem that can be solved!

spiral_sm

A spiral design, created by an Arduino-powered Etch-A-Sketch. (Click for larger.)

I took a Pocket Etch-A-Sketch that I found in a thrift store, added a pair of gears from a disassembled printer, and mounted it in a 3D printed frame that I designed in Google SketchUp. I then mounted two stepper motors to the frame, and connected them to an Adafruit motor control shield mounted on an Arduino Uno.

hardware_sm

The overall hardware setup, showing the custom frame and the Arduino+motor shield combination. (The Arduino Uno is hiding under the motor shield.)

A close-up of the gear mechanism and stepper mounting. (Click for larger.)

A close-up of the gear mechanism and stepper mounting. (Click for larger.)

Here is the Arduino sketch to run everything. (You’ll need the stepper motor library from Adafruit, as well.)

Here is a video of the AutoSketch doing its thing…

Posted in Arduino, C, Coding, Digital, Nostalgia, Toys | Tagged , , , , , | Leave a comment

Components: LEDs

Just about every electronic device produced in the past twenty years or so uses one or more light-emitting diodes (LEDs). They are typically used as indicators (for power status, low-battery warnings, caps lock and number lock on keyboards, etc), but are also sometimes used to provide lighting (display backlights, “flash” lighting on digital cameras, as flashlights, etc.)

An assortment of LED types.

An assortment of LED types. (Click for larger)

LEDs, in terms of light produced per watt consumed, are many times more efficient than incandescent light bulbs. They generate almost no heat, so nearly all of the power they consume goes directly into producing light. Because of this and other factors (for one thing, they’re extremely reliable when properly used), they have increasingly been used as replacements for incandescent light bulbs for indication and illumination.

If you look closely at modern traffic lights, you might notice that they are made up of a collection of dots, rather than a single glass lens. In place of a light bulb drawing hundreds of watts, a couple dozen LEDs do the same job while using far less power and requiring far less maintenance. Brake lights and tail lights on cars are also good candidates for LEDs, since reliability is important for those applications.

LEDs are also relatively inexpensive: a red or green indicator LED typically costs just a few cents when purchased in bulk. More exotic LEDs can cost a few dollars or more — with the price increasing greatly as the power increases (there’s still not a huge market for really high power LEDs, and they’re somewhat tricky to manufacture, so the economy of scale isn’t quite there yet.)

Using LEDs in a circuit is somewhat trickier than simply using a light bulb — although not much. A light bulb is basically just a low-value resistor whose resistive element gets hot enough to glow. They are, to some extent, self-regulating: a light bulb’s resistance increases as it gets hotter, limiting current flow through it somewhat. Given a light bulb of the proper voltage rating, it can simply be connected across the terminals of a battery or power supply.

An incandescent lamp circuit

LEDs, on the other hand, require a bit more finesse. First of all, they are diodes — which means that they only allow a significant amount of current to pass in one direction. The cathode of the diode (typically, the shorter lead on the LED package) must be connected to the negative side of the power source. Otherwise, no current will flow.

The forward-biased LED conducts current; the reversed-biased one doesn’t.

In addition, diodes (including LEDs) always have a characteristic “voltage drop.” A simple way of understanding this is that the diode will “try” to limit the difference in voltage across its terminals to no more than this “voltage drop.” It does this by lowering its effective resistance as the amount of current increases (see “Ohm’s Law”), so that the voltage drop remains nearly constant.

The problem is that too much current will burn out the diode. If an LED were connected across a pair of C-cell flashlight batteries (which produce roughly 3V in series), the voltage would be significantly more than the LED “wants” to see. It would lower its resistance until the voltage drop across the LED matched this built-in limit. By this time, the current flow would be so high that the LED would get very hot and quickly burn out with a brightly-colored flash. (If you’re lucky, you might even get to see the Magic Blue Smoke escaping. Once the Magic Blue Smoke is gone, the component is ruined.)

Without a current-limiting resistor, the LED will allow too much current to pass, and will be destroyed.

The solution to this is to put a resistor (typically 470 ohms) in series with the LED. This gives the rest of the voltage drop somewhere to go, and limits the current in the circuit to a value the LED can handle (typically 20mA or so, for a standard 5mm LED.) With the addition of a resistor (about 1 cent, in bulk) an LED can make a good, easy-to-use indicator for a circuit.

An LED on a breadboard, with a 470-ohm current-limiting resistor. (Click for larger.)

To calculate the correct size of the resistor, check the LED data sheet for the correct current that should flow through the LED. Then find the typical voltage-drop value from the datasheet (usually larger for blue and white LEDs; smaller for red LEDs). With these two values (voltage drop and current), you can calculate the correct series resistor as follows:

R = (V_t - V_led) / I_led

This calculation works by determining what the voltage drop should be across the resistor (that is, the total voltage minus the LED’s voltage drop per the datasheet.) This is divided by the current that should flow through the LED, to give the required resistance. (Remember Ohm’s Law?)

When connecting more than one LED (such as in a seven-segment numeric LED display), it’s best to provide a separate resistor for each LED. That way, the brightness of the LEDs remains constant regardless of how many LEDs are lit at one time. With all LEDs sharing a single current-limiting resistor, LED brightness will decrease if more than one is lit at a time.

Posted in Building blocks, Components, Electronics, Fundamentals, HOW-TO | Tagged , , , , , , , , , | Leave a comment

Using a 16×2 LCD display

One of the most popular standard peripherals for microcontroller projects is the ubiquitous 16×2 text LCD display. These displays are useful for the display of information generated by a device (temperatures, voltages, statuses etc.) In addition, they can make debugging a lot easier, by providing a play-by-play description of what is going on.

[16x2 LCD display]

A typical 16×2 text LCD display. (Image courtesy of Wikipedia.)

Here is a description of how to connect and use these displays, for PIC and similar microcontrollers. (PIC code is provided as an example.)

8-bit mode is described here. Most of these displays can also run in 4-bit mode if needed, which can save four GPIO pins.

If you’re using an Arduino, the instructions are slightly different (and also slightly easier): check out the Arduino LiquidCrystal tutorial for directions.

Hardware connection:

A standard parallel 16×2 LCD has a sixteen-pin interface. Numbered from 1 to 16, these typically are:

  • Ground
  • Vcc (typically 5V, but sometimes 3.3V)
  • Contrast
  • R/S
  • R/W
  • E
  • D0 through D7
  • Backlight anode
  • Backlight cathode

Ground and Vcc are connected as you would expect. Contrast is connected to a 10k potentiometer between Ground and Vcc. Connect R/S, R/W, and E to three GPIO pins on your microcontroller. Connect D0 through D7 to the corresponding pins on a single-byte port if using a PIC or similar microcontroller (I typically use PORTD on a PIC16F887).  If you’re short one pin, R/W can generally just be grounded instead of being connected to the microcontroller. (Most LCD functions don’t rely on reading data back from the LCD.)


LCD_sm

Control and data bytes are sent to the display, one byte at a time, by strobing the E line low. If the R/S line is low, the bytes are interpreted as control codes. If R/S is high, the bytes are interpreted as data to be displayed (in ASCII).

To set up the display, a sequence of control codes should be sent. There are various (minimum) delay requirements after each control code. Here is the sequence to get the display up and running:

  • Set R/S low
  • Start off with E high
  • Send a byte of 0x38:
    • Place 0x38 on the data bus (D0 through D7)
    • Strobe E low for 1ms (conservative, but works)
    • Wait 200ms
  • In the same way, send the following bytes in this order:
    • 0x0C
    • 0x01
    • 0x06
    • 0x02
  • Raise the R/S pin to go into data mode
  • Send the data to be displayed as ASCII bytes, one byte at a time.

Here is an LCD driver library, written in assembly for 8-bit PIC microcontrollers. It relies on delay routines from a delay library that I wrote. Both may be freely re-used for noncommercial purposes, as long as attribution information is kept. (CC BY-NC-SA).

 

 

Posted in Arduino, Building blocks, Digital, Electronics, HOW-TO, PIC Microcontrollers | Tagged , , , , , , , , , | Leave a comment