rurwin wrote:While not using R for relay would probably confuse the literati less, it would probably confuse newbies more. YMMV.
That's why God, or some other entity smarter than us, made parts lists/bills of materials (BOMs for newbies).
I take your point about relay diodes; there should probably be some. In my defence I have never needed or used them for 6522 VIA ports on the BBC Micro and such. Did those have more protection than the RaspPi? I don't know.
You could almost see the junctions with the naked eye in BBC Micro era components! The early days of TTL were much different from low-power Schottky and today's CMOS (complementary metal oxide semiconductor for newbies - much lower power and higher density) technology
Would a 3.3V 5mA relay develop enough back EMF to be a problem? I don't know that either, I suspect you'd probably get away with it, but a reversed diode across the coil would probably be worth the effort to fit. There is an old saying "Beware The Programmer Who Carries A Screwdriver." I am he.
Well, I shouldn't have to tell you what Murphy thinks about this ... hey, get away from that, you drunken kibitzer!
Regarding the scripts, if I had written any I would share them. I did look into how Debian handles shutdown, and I found the relevant halt utility (not the halt command) was or could be a Bash script. Similarly a script could be used for the polling utility. They would be simple matters of echo'ing to and cat'ing from the GPIO lines via the GPIO driver and the Linux filesystem.
These are easy for us to imagine, but, I think posters and commenters need to remember who the target audience of our babbling really is. I'm a bit torn between being too pedestrian (hence my verbosity) and compact and confusing, and I always wind up landing in the former camp. I don't think of it as spoon-feeding, it's more like appetite-whetting. Give them something simple that works and then hint at expansion options left to the reader. It's amazing how far and high kids can leap once they realize that tripping and falling is not only an acceptable option, it's encouraged. Getting them over that first hump is the challenge - once they make it over, they go on autopilot.
A triac would work to turn the AC on and off, but then your "safety extra-low voltage" circuit would be intimately connected to your mains circuit, since it requires a voltage relative to the A1 pin to switch. One mis-wired extension cable and your RaspPi would be live. That is of course correctable, but not I think cheaply or simply in comparison to a relay.
That's why I said opto-isolators were absolutely required.
Neither a triac nor an SCR would work to switch DC, since it would never turn off.
An SCR would work (a Triac would just be a waste of money, since half of it would never see a reverse-polarity voltage), but, you need an appropriate RC network to condition the transitions, which is what you're actually interested in, not the voltage itself. The active and passive components pretty much equal in cost what's needed to get relays to work while ensuring no back EMF problems.
The advantages of relays are they are simple, easy to understand, they have zero leakage current and almost zero on resistance, and they very effectively isolate the controlling circuit from the controlled circuit. Also you can see and hear them operate and they very rarely half-operate.
Relays wear out much sooner than active components (albeit over years even with frequent operations using today's higher-quality manufacturing). Depending on the configuration, hold current in spring-returned (momentary-contact) relays is much higher than trigger/gate current in CMOS active components (which only require a voltage at fractions of a microamp). If you can design to use bistable relays, that's fine, but, they're susceptible to vibration, so applications can be limited.
Stick LEDs and/or piezo transducers in the circuits to see/hear what's going on - they cost essentially nothing these days, and will last decades in continuous use with no mechanical issues (probably centuries in intermittent use). I'm surprised we haven't seen packages with LEDs built into the top surfaces of packages for simpler microcontrollers/microprocessors long before now.
At least that's my story, and I'm stickin' to it!