Showing posts with label Raspberry Pi. Show all posts
Showing posts with label Raspberry Pi. Show all posts

Wednesday, 30 March 2016

Switching Mains Loads with Relays

I want to control the external lights around my home from a small computer to provide a bit of automation. The plan is to use an Arduino, and have it switch the lights on and off via relays. There are plenty of low cost relay boards to choose from. Most seem to be clones of the same basic designs which offer either 2, 4 or 8 relays. Here's a typical 4 way board:

4 Way Relay Board
4 Way Relay Board
This board has a 2.54mm pitch pin header with 6 pins - ground, +5VDC power and 4 inputs that control the coils of the 4 relays. Each relay is provided with an individual 3 way screw terminal block that is wired to its common, normally open and normally closed contacts. Note that these terminals are big enough for 1-1.5mm solid wire and the relays are rated for up to 10 Amps. My advice is to stay way below this.

The inputs are protected from the "heavy lifting" of energising the relay coils by opto-isolators. Grounding an input pin allows current to flow from the +5VDC supply through a current limiting resistor, a surface mount red LED, and then the LED within the opto-isolator. The forward current is about 2mA in this situation so it's fine to directly connect these inputs to digital I/Os on an Arduino. The relay coils are wired to the +5VDC supply and the opto-isolator phototransistor collectors, and each is provided with a usual flyback diode. (Note that the +5VDC supply might get in the way of using one of these boards with a Raspberry Pi; these use 3.3V digital I/Os and could be damaged by higher voltages.)

So far I've built a box with an 8 way relay board and connected it to 8 external lamps. A small AC-DC module provides +5VDC locally; I will locate the control system elsewhere, with the link to the relay box containing just relay control lines and ground in a multi-core cable.

8 Way Relay Board - Driving Lights
8 Way Relay Board - Driving Lights
Working on electrical installations can be dangerous and is heavily regulated by law. Consult a qualified electrician!

Monday, 22 February 2016

Raspbian Jessie Lite

A new lightweight version of Raspbian Jessie has been released. It looks promising for “headless” applications (no monitor, keyboard or mouse). I fired it up on my Raspberry Pi Model B.

You can get Raspbian Jessie Lite from here. At the time of writing, the version was dated 2016-02-09 and the kernel version was 4.1. The ZIP download weighed in at 365MB. This contained a similarly sized compressed IMG file. Next, I had to write this image to SD card.

Note that choosing a reliable SD card is something of a science, with guidance available from various sources. For example, see here. I chose an 8GByte Lexar micro SD card that came bundled with an SD card adapter. I bought it from Amazon because of their no-fuss returns policy:

Lexas 8GB microSDHC card with SD adapter
Lexas 8GB microSDHC card with SD adapter
The procedure for writing to image to SD cards can be found  here. I followed the Windows recipe, first extracting the IMG from the ZIP, and then running Win32DiskImager to write the IMG to my SD card:

Win32DiskImager application
Win32DiskImager application

It took a few minutes to get these steps done. I then inserted the freshly written SD card in the Pi, connected it to the HDMI input of my monitor, and plugged in an ethernet cable. Boot messages appeared on the monitor within a couple of seconds of power on. The login prompt appeared after maybe 20-30 seconds:

First Boot
First Boot

I then switched my monitor back to displaying the output from my desktop PC, aiming to use an ssh client to interact with the now fully headless Pi. There are plenty to choose from; my favourite is PuTTY.

To make life easier on my LAN, I use static IP addresses for various devices, such as my NAS, and including my Raspberry Pi. To do this, I reserve an address in my DHCP server’s configuration, linking the device's MAC address to a fixed IP address. For the Pi I chose 192.168.1.9, as shown on the PuTTY configuration dialog:


PuTTY Launch Window
PuTTY Launch Window

After double-clicking the raspberrypi entry (to Open it), I blew past the ensuing security warning by clicking Yes. A terminal window then appeared, and I was then able to log in with the usual default credentials (username = pi, password = raspberry):

PuTTY Terminal Window
PuTTY Terminal Window

Many images assume a 2GB SD card and size things accordingly, meaning wasted space on larger cards. I checked, and this was indeed the case:

       
pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.3G  912M  281M  77% /
devtmpfs        214M     0  214M   0% /dev
tmpfs           218M     0  218M   0% /dev/shm
tmpfs           218M  4.4M  214M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           218M     0  218M   0% /sys/fs/cgroup
/dev/mmcblk0p1   60M   20M   41M  34% /boot


raspi-config can be used to fix this:

       
pi@raspberrypi:~ $ sudo raspi-config


You simply highlight option 1 and hit Enter...

raspi-config in action
raspi-config in action

...and a few seconds later you can reboot and the job is done. I did this, and checked the outcome:

       
pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.3G  913M  6.1G  13% /
devtmpfs        214M     0  214M   0% /dev
tmpfs           218M     0  218M   0% /dev/shm
tmpfs           218M  4.4M  214M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           218M     0  218M   0% /sys/fs/cgroup
/dev/mmcblk0p1   60M   20M   41M  34% /boot


Notice that /dev/root now has 6.1G available.

I will be trying to use the resulting setup for a few embedded projects.