Julian Rogers Home RPi relay program Electronics projects Home

Under construction

Using VNC on a PC to remotely control things with a Raspberry Pi including switching relays

Virtual Network Computing (VNC) enables a computer to remotely view another computer’s desktop and transmit keyboard input and mouse movements and clicks etc. I have come rather late to this particular party but it seems a very good way to easily set up a remote control system.

Simply put, A Raspberry Pi running a Python program can control stuff using its GPIO pins via the usual transistors, relays etc. If the Python program runs a graphical interface such as Tkinter, then remote control can be easily achieved through VNC.

VNC window showing desktop of Raspberry Pi running Tkinter which controls the boiler.

VNC window which allows various remote desktops to be opened with a double click.

In the past, I have used Arduinos or similar to control individual systems (for example, the central heating boiler) and used a PC or a Raspberry Pi to supervise their operation over wifi using UDP.

In a new project, I want to control the heating in our guest bedroom. Specifically I want to be able to control the (hot water) radiator, the hot towel rail, the local hot water supply and supplementary electric heating which may be necessary when the weather is particularly cold. A Raspberry Pi with three or four relays and an I2C temperature sensor should, I hope, do the trick.

The picture below show a bread board arrangement with a Python program running on an old(Ish) Pi. The Pi’s GPIO 4 (Broadcom numbering scheme) is driving a relay via one element of a ULN2003 Darlington transistor array.

The Pi is running “headless” (with no monitor - or keyboard, mouse etc.) The VNC viewer allows the video output of the Pi to be displayed on a PC screen. Pressing the buttons turns GPIO pins on the Pi on or off.

Relay

ULN2003

The Python program to control this system is next…

When running headless, the desktop defaults to a small size (800 by 600 as I remember). If you are running a program that needs more space, you need to edit config.txt on the Pi. (See RPI documentation for details.)

Open a terminal window then:

   sudo nano /boot/config.txt

That will bring up the config.txt file in nano for editing.

Set the following:

   hdmi_force+hotplug=1

   hdmi_ignore_edid=0xa5000080

   hdmi_group=2

   hdmi_mode=16

The hit F3 to save and F2 to quit nano.

Finally sudo reboot to reboot and make the changes effective.

VNC viewer will run on a PC, an Android tablet and on a Raspberry Pi. On the left, is an RPi and “Official” touch screen combination (you might need a magnifying glass or a trip to Specsavers for this one!) All three are monitoring my Greenhouse Controller, which involves a Pi and an Adafruit Feather. It is possible to monitor on the PC the Pi monitoring another Pi (and so on ad infinitum)!

(When I first started using VNC, VNC viewer was not available in the distribution and I couldn’t seem to download it. However, in the current distribution it is all present and correct.)

VNC viewer on other systems