Raspberry Pi Appliance Timer

Disclaimer:  Working with mains current is dangerous. Use the information provided in this article/post at your own risk. Always turn off power and confirm no voltage is present on the wires you are going to work with, with a volt meter before beginning work with mains power.

This is an On/Off timer based on the Raspberry Pi. After some really high electric bills I decided I needed to do something to help reduce my burden. The first thing that came to mind that likely runs much more than necessary is the electric water heater.  The water heater is designed to constantly retain a certain temperature. However, we only use hot water one to two times daily, once in the morning and again at night.

I needed something that would give me an AM and a PM On/Off schedule. I could have bought a ready made product but I have been looking for a good project for the Raspberry Pi and since it is so much easier to use the Pi for timed projects due to the built in NTP client over the Arduino it was a no brainer.

There are  couple of different ways of writing a script to turn on and off the appliance. One way and probably the easiest is to turn on the GPIO pins based on time and then set a delay for the duration you want it on for followed by turning the GPIO pin back off. Another, the way I did it here, is to turn the GPIO pin on and off based on times rather than setting a delay. I feel like making the on and off based on the clock is more elegant and dependable.

Now, on to the Hardware I used and why.

Raspberry Pi (any model) – $35 – Where to purchase

Raspberry Pi case – $8.99 – Where to purchase – This is for the pi B+ or Pi 2. You will need a different case for the other Pi models.

240 volt to 24 volt AC transformer – $14 – Where to purchase

240 volt contactor – $21 – Where to purchase – Steps 240 volts down to 24 volts for the contactor relay.

NPN transistor – $0.12 – Where to purchase – This switches the 24 volt relay.

24 volt relay – $0.64 – Where to purchase – This switches the contactor.

3 position screw down terminal – $0.20 – Where to purchase – 5 volt and grounds terminal block.

2 position screw down terminal – $0.10 – Where to purchase – 24 volt relay terminal for switching the contactor.

Prototyping board – $0.99 – Where to purchase – To solder our components to.

LED (any color) – $0.05 – Where to purchase – To indicate whether the appliance is switched on or off.

Momentary button – $0.25 – Where to purchase – Manual timed on switch

Enclosure – $10.89 – Where to purchase – This is not the enclosure I used but it is the type you should use. Mine is one I had around from Radio Shack.

Wire – $0.00 – You should be able to find appropriate wire laying around. Cat 5 (Ethernet), Cat 3 (Phone Wire), HVAC Thermostat Wire), all will work well for the contactor control board, but just about any wire larger than 24 gauge will be fine. Just make sure that you have a few different colors so you don’t make mistakes by getting confused about what goes where. I use Cat 5 wire because you can find it everywhere these days and because there are 8 differently color coded wires in it.

Wire nuts – $10.96 – Where to purchase – Use wire nuts appropriate for the size of the wire and amount of current.

Wire Terminals – $2.98 – Where to purchase – Use wire terminals appropriate for the size of your wire and amount of current.

Crude Schematic of Contactor Control Board

Click pictures to show larger view.

These pictures are showing the bottom of the board where the pins come through.









Semi complete Project


WP_20150806_003 WP_20150814_004[1] WP_20150806_002 WP_20150806_004 WP_20150806_001 WP_20150805_005














Make the Contactor Control Board

Since the 24 volt relay is the largest component on the controller board, it should be the component you structure the rest of the components around. I placed the transistor close enough to the relay that I was able to solder it directly to the relay pin. You can use wire to connect each point on the board or make solder traces connecting it all together. You should be able to follow my crude schematic to put together the control board, but if you need further instruction please leave a comment or email me at modsbyus ‘at’ modsbyus.com. I will be more than happy to give further assistance.


Putting Together The Mains Components

The 240/24 Volt AC Transformer

This transformer has 4 wires for connecting to the mains. The black and white ones are for 120 volts and the orange and red ones are for 240 volts. Use the pair that is appropriate for your usage. The 24 volt wires are blue and yellow.

The yellow wire is going to connect to the relay terminal on the control board and then you make a connection from the other position on the relay terminal to one side of the contactor. The blue wire goes directly to the other side of the contactor.

The Enclosure

Depending on the enclosure you choose for your project, mounting will be different. You need to make sure that your Raspberry Pi is mounted in its own case outside of the enclosure for the mains components. The EMD (electro magnetic discharge) from the contactor opening and closing can cause damage to your Raspberry Pi and can also cause unexpected unclean shut downs.  You can put the timed override switch and status LED mounted through the enclosure.

The Raspberry Pi

I highly recommend using a Pi case for your Raspberry Pi. It will protect your Pi from all sorts of damage and it looks nicer.

We are going to use GPIO pins 17, 24, and 27 and 3 ground pins.

17 and one ground pin is wired to the timed override switch.

24 and one ground pin is wired to the LED. The long leg of the LED goes to the GPIO 24 pin.

27 goes to the control position on the 3 position terminal block which is connected to pin 1 of the transistor.

A third ground goes to the ground position of the 3 position terminal block which is connected to pin 2 of the transistor.

You will need a constant 5 volt supply for the relay which goes to the 5VDC position of the 3 position terminal block. You can use a 5 volt pin from the Raspberry Pi but I don’t recommend it for this project. Whenever you turn off a coil or motor it sends back high voltage spikes that can damage your Raspberry Pi. I suggest finding a 5 volt power supply to use. The positive line of the 5 volts goes to the 5VDC position of the 3 position terminal block and the ground or negative of the power supply goes to the ground position of the 3 position terminal block.


The Python Program That Runs it

You can download it Download ApplianceTimer.py

?View Code PYTHON
# Raspberry Pi custom appliance timer
# import GPIO module
import RPi.GPIO as GPIO
# set up GPIO pins as outputs
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Button
GPIO.setup(27, GPIO.OUT) # Appliance 5/25 volt relay
GPIO.setup(24, GPIO.OUT)# LED
state = 0
button = GPIO.input(17)
# import date and time modules
import datetime
import time
# Enter the times you want the appliance to turn on and off for
# each day of the week.
MonAMOn  = datetime.time(hour=5)
MonAMOff = datetime.time(hour=7)
MonPMOn  = datetime.time(hour=16)
MonPMOff = datetime.time(hour=22)
TueAMOn  = datetime.time(hour=5)
TueAMOff = datetime.time(hour=7)
TuePMOn  = datetime.time(hour=16)
TuePMOff = datetime.time(hour=22)
WedAMOn  = datetime.time(hour=5)
WedAMOff = datetime.time(hour=7)
WedPMOn  = datetime.time(hour=16)
WedPMOff = datetime.time(hour=22)
ThuAMOn  = datetime.time(hour=5)
ThuAMOff = datetime.time(hour=7)
ThuPMOn  = datetime.time(hour=16)
ThuPMOff = datetime.time(hour=22)
FriAMOn  = datetime.time(hour=5)
FriAMOff = datetime.time(hour=7)
FriPMOn  = datetime.time(hour=16)
FriPMOff = datetime.time(hour=22)
SatAMOn  = datetime.time(hour=5)
SatAMOff = datetime.time(hour=7)
SatPMOn  = datetime.time(hour=16)
SatPMOff = datetime.time(hour=22)
SunAMOn  = datetime.time(hour=5)
SunAMOff = datetime.time(hour=7)
SunPMOn  = datetime.time(hour=16)
SunPMOff = datetime.time(hour=22)
# Store these times in an array for easy access later.
OnTimeAM = [MonAMOn, TueAMOn, WedAMOn, ThuAMOn, FriAMOn, SatAMOn, SunPMOn]
OnTimePM = [MonPMOn, TuePMOn, WedPMOn, ThuPMOn, FriPMOn, SatPMOn, SunPMOn]
OffTimeAM = [MonAMOff, TueAMOff, WedAMOff, ThuAMOff, FriAMOff, SatAMOff, SunAMOff]
OffTimePM = [MonPMOff, TuePMOff, WedPMOff, ThuPMOff, FriPMOff, SatPMOff, SunAMOff]
# Start the loop that will run until you stop the program or turn off your Raspberry Pi.
while True:
    button = GPIO.input(17)
    global state
    if button == 0:
        #print('button', button)
        state = 1
        #print('state', state)
    if state == 1:
        GPIO.output(24, True)
        GPIO.output(27, True)
        time.sleep(3600) #3600
        state = 0
        GPIO.output(24, False)
        GPIO.output(27, False)
    # get the current time in hours, minutes and seconds
    currTime = datetime.datetime.now()
    # get the current day of the week (0=Monday, 1=Tuesday, 2=Wednesday...)
    currDay = datetime.date.today().weekday()
        #Check to see if it's time to run the appliance for the AM hours
    while (currTime.hour >= OnTimeAM[currDay].hour and currTime.hour <= OffTimeAM[currDay].hour): # set the GPIO pin to HIGH GPIO.output(24, True) GPIO.output(27, True) time.sleep(60) currTime = datetime.datetime.now() currDay = datetime.date.today().weekday() else: if (currTime.hour >= OffTimeAM[currDay].hour - 1):
            GPIO.output(24, False)
            GPIO.output(27, False)
    #Check to see if it's time to run the appliance for the PM hours
    while (currTime.hour >= OnTimePM[currDay].hour and currTime.hour <= OffTimePM[currDay].hour): GPIO.output(24, True) GPIO.output(27, True) time.sleep(60) currDay = datetime.date.today().weekday() currTime = datetime.datetime.now() else: if (currTime.hour >= OffTimePM[currDay].hour - 1):
            GPIO.output(24, False)
            GPIO.output(27, False)

Disconnected Testing

You should run a dry test without the mains connected to the contactor. You don’t want to damage anything or hurt yourself. As long as you can push the override switch and it stays on for the expected amount of time and it comes on and goes off properly for a specified time period then you are good to go.

Bringing it All Together

Its time to hook up the mains (240 or 110 Volts) to the contactor. The feed lines go to one side and the lines to your appliance go to the other side. Use the pictures above as a reference. As always you should follow all safety procedures for dealing with main current and if you don’t know what you are doing then you have no business messing with it. YOU CAN KILL YOURSELF OR OTHERS!

Live Testing

After hooking in the mains and your appliance its time to give it a real test. Set and AM and a PM time for short durations during a time you can monitor it. Turn everything on, boot up the PI, test out the override switch and the timed functions.

Set it and Forget it

The easiest way I have found to set a python script to start when you boot the Pi is to set it as a Cron job using Webmin.

HARDWARE_HACKS has a great tutorial on how to setup Webmin. Follow that then return here for the Cron Job how to.

If you have Webmin setup and you are logged in click on System then Scheduled Cron Jobs







Now click on Create a New Scheduled Cron Job.

It should look like this. The only difference is that for the Command that you put in the path for your python script.

python /home/pi/Desktop/RevisedWHTimer.py








Now Just

sudo reboot

and you are all done! It should come on and go off based on the schedule you set.

Special Note:

The Raspberry Pi does not do well with improper shutdowns. It will cause system corruption. For the sake of all the hard work you just went through, run this on a UPS or some type of reliable battery system.

Getting Started with the Raspberry Pi

I Got My Raspberry Pi, Now What?

This is a great platform to work with. You have many options when choosing a micro computer. The Raspberry Pi has a large community that makes it easy to work with this hardware. If you have trouble with the hardware or with the scripting or programming for the Pi you can head over to the Raspberry Pi Forum where there is always someone happy to help without being rude and condescending. Unlike most other forums I have encountered, the atmosphere there is refreshing and full of welcome.

What you Need

  • Raspberry Pi
  • Class 10 Micro SD Card (Others will work but this is recommended.)
  • 5 Volt 2 Amp with a Micro USB 5pin Male
  • A computer
  • A Micro SD Adapter and maybe a USB to SD Adapter as well depending on your needs.
  • SD Formatter – Get it at sdcard.org
  • Win32 Disk Imager – Get it at sourceforge.net
  • Raspbian (The Operating System) – Get it at raspberrypi.org
  • Adafruit Pi Finder – Get it at GitHub
  • WinRAR – Get it at win-rar.com
  • Putty – Get it at chiark.greenend.org.uk
  • AngryIPScanner – Get it at angryip.org (Optional)
  • A Ethernet connection to your network (internet access)

Install WINRAR

You will need this or some other archive tool to extract everything you have downloaded. I suggest that you extract everything to a familiar place like your Desktop to make it easy to find. You should create a folder to extract the Adafruit Pi Finder to since there are a lot of files.


Preparing the SD Card

Open SD Formatter










It should find your SD card automatically but you need to verify that the drive letter shown is in fact the drive letter of your SD card. If you format the wrong drive you will erase EVERYTHING. Go to your explorer and verify drive letters there.

Choose the Option button and select Format Size Adjustment to ON. Then click OK then Format. Say OK to the two warnings to Format your SD card.

Install the OS to the SD Card

Open Win32 Disk Imager.





Browse to and select the img file you extracted from the file you downloaded from raspberrypi.org.

Click on Write and wait for it to complete. After its finished safely eject the SD card and insert it into the Pi.

First Boot

Plug in your Ethernet (internet) cable to the Pi then the power cable.

Wait a moment for the Pi to boot, then open the Adafruit Pi Finder by double clicking the PiBootstrap.exe file. Then click on Find My Pi!.

PiFinder PiFinderAfterFind








Once it finds your Pi open Putty and type in the IP address of your Pi. I don’t suggest using this tool for anything other than finding the IP address of your Pi. Terminal works most of the time but its frustrating when it doesn’t. The webide is still in beta and has some bugs in the installation.











The default username is ‘pi’ and the default password is ‘raspberry’. You will not see any characters being printed on the screen when you are inputting the password, this is normal.

Now run

sudo raspi-config

This will take to a window like this.








There is no mouse support in this menu. Use the Up,Down,Left,Right,TAB, and Enter keys of your keyboard to navigate.

Press enter on the first option to Expand Filesystem.

After that has finished you will be returned to this menu. Now choose Change User Password. You don’t want your project bamboozled by the internet bullies.

If you wish to automatically go straight to the desktop or to Scratch then make your selection in Enable Boot to Desktop/Scratch.

Next, Set your timezone and keyboard options in Internationalisation Options.

Now If you have the Raspberry Pi Camera module choose Enable Camera. If you are going to use a webcam there is no need to do this step.

If you wish to get the full potential out of your Pi then go to Overclock and choose the option you want for your Pi.

We’re getting close to the end now.

Go to Advanced Options.








Here you are going to set options that are specific to you individual needs. To have continued access using SSH (Putty) you need to enable SSH. Without SSH you must have an HDMI display hooked up to your PI. After each edit in this menu you will likely be returned to the main menu, just go back to Advance options to get back and finsh your optional configurations. Once you are done and back to the main menu select Finish. You should be prompted to reboot. Go ahead and do that now.

Once your Pi has rebooted restart your Putty session and log in.

Now is a good time to make sure that your Raspberry Pi is up to date.



sudo apt-get update


sudo apt-get upgrade

This will take a while. Once it is done reboot your Pi again.

sudo reboot

Once your Pi has rebooted restart your Putty session and log in again.

Static Network Config (OPTIONAL)

You may wish to configure a static IP configuration on your Pi to make it easier to find and work on in the future.

First you need to determine a suitable IP address to use. If you know how to find this out by logging into your router then do that.


Install and open Angry IP Scanner and click on Start.

This will return a list of all the IP addresses on your network, active and inactive.

Typically your router will only give out up to 50 addresses by DHCP. The rest can be used for static assignment. You need to choose an inactive IP outside of you DHCP range. This can be determined by examining the results of the IP Scanner results. Usually your DHCP will either start at 2 and end somewhere around 50 or start around 100 and go to 150 or 200. If your results have IP addresses in the lower range then use something above 100. Otherwise use something between 2 and 49. Examples:,, ect..

Now that you know what IP address you are going to use.
Go back to your Putty session and type in

route -n

This will give an output something like this.
This shows us the Gateway, and netmask. Take note of these.

Example:  Netmask: Gateway:

So now you have an IP address, Gateway address, and a  Netmask.

Now we have the information we need to configure a static IP address.
Now type in

sudo nano /etc/network/interfaces

You will see something like this.









Change it to look like this using your IP information.

auto lo

iface lo inet loopback
iface eth0 inet static

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp








Then hit Ctrl+o to save it and Ctrl+x to exit

Now reboot

sudo reboot

If you would like to be able to log into your Pi’s desktop remotely See my Post Raspberry Pi VNC Server Setup.

Raspberry Pi VNC Server Setup

Seeting up Remote Access With Tight VNC

Open a terminal if you are logged into your Pi with a connected display or Use Putty to SSH into your Pi if you are working on it over the network or remotely.

Type in

Sudo apt-get update

Now type in

Sudo apt-get install tightvncserver

When asked

After this operation, 9,988 kB of additional disk space will be used.
Do you want to continue [Y/n]?

answer with ‘y’


Sudo vncserver

It will ask you for a password to use for the VNC access twice. Just type in the same password both times. This will be the password you will have to enter each time you access your Pi over VNC.
It will also ask if you want to enter a view only password. I don’t use that so I always say no, but if you want to be able to view without control you do it then.
When its done you should see something like this.








Now you will need to download and install the Tight VNC Viewer on your computer.

Get it at tightvnc.com

Once installed open it up and type the IP address of your Pi succeeded by :1 and hit Enter


You should be prompted for your password and after entering your password you will be greeted with the view and control of your Pi’s desktop.

VNC-Access VNC-desktop

Playing with the Raspberry Pi

So, I have been holding off on getting the Raspberry Pi for quite a while. Why? Well honestly, it was because I was a bit intimidated by it. I have been using and programming on the Arduino platform for a couple of years. I made a few projects like a wireless temperature monitor, a thermostat, and a couple of other tidbits. I struggled my way through a good bit of it since I haven’t had any proper training in programming. With a lot of help and criticism from the guys in the Arduino forum I made it through each one of my projects less one.

You can see why moving to a more complicated and more powerful platform would be a little scary. Alas, I decided it was time to try something new. I was bored with struggling  through the same things and figured that if I’m going to struggle any way why not do it the next step up.

I bought the Raspberry Pi a couple of weeks ago and I have been surprised at every turn! Not only is it much easier to program in python but this tiny computer is so incredibly versatile.  I have written a basic program to flash and LED as well as a “Hello World” and built an HTPC with RaspBMC.

The Raspberry Pi isn’t powerful enough to run Windows but there are custom Linux images that run great. This little computer even has an HDMI output built right in and it is pretty much no fuss to use it.

My next step is to work through all the learning material on raspberrypi.org and grasp as much understanding about writing in python as possible. There are other sites to learn from as well. There are huge online communities and plenty of published guides and tutorials to follow. I am really looking forward to working with this platform in the coming year!

I will document each of my projects on here and hope that you get the most out of it. I am anxious to see what we can come up with and hope to hear your thoughts on each progressive project I make.

433 MHz Wireless temperature Monitor with I2C LCD

Usinga 433 MHz transmitter and receiver ,  a Dallas DS18B20, and a 16×2 LCD with an  i2c / SPI character LCD backpack we can make a simple wireless temperature monitor. I’m not going to go into the construction of the hardware here since there is plenty of resources out there for that already.


Antenna are a big deal! There is a ton of antenna theory and math out there for you to figure it out but it would be difficult for anyone not already involved in antennas. So, I’m going to tell you what I did.

I got 2 stainless steel whips and magnetic bases from a local 2-way radio supplier and cut the whips to 13 1/4 inches. No coil is needed for this. I get about 60 feet through walls and floors. On the transmitter I am using 12 volts so that I can transmit at full power. I am just using one of the 5 volt pins of the Uno to power the receiver.


Transmitter Code

#include <OneWire.h> //This temperature sensor requires a 4.7k Ohm resistor across its pins 2 and three!!!!
#include <DallasTemperature.h>
#include <Wire.h>
#include <VirtualWire.h>
int ledPin = 13;//Set up the TX indicator pin 13 as LedPin
int Sensor1Data;//initialize the use of the variable Sensor1Data
//int sensorValue = 0;  // variable to store the value coming from the sensor If using analog sensor
float currentTemp = 0;//to store decimal value coming from the temp sensor
// RF Transmission container
//char Sensor1CharMsg[4]; 
// Trying to use 5 instead to fit trailing null char 
// go back to 4 if this does not work. 
char Sensor1CharMsg[5]; 

//This temperature sensor requires a 4.7k Ohm resistor across its pins 2 and three!!!! Thats the middle pin and the GND pin
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

DeviceAddress insideThermometer = { 0x28, 0xE4, 0x10, 0x74, 0x03, 0x00, 0x00, 0xD5 };
// DeviceAddress outsideThermometer = { 0x28, 0x20, 0x04, 0xA8, 0x02, 0x00, 0x00, 0x4D };

void setup()
  pinMode(ledPin, OUTPUT);//Set the ledPin as an output
  Serial.begin(9600);//initialize serial communication
  Serial.print("TX Start");//Print TX Start in the serial terminal
  // VirtualWire 
    // Initialise the IO and ISR
    // Required for DR3100
    // Bits per sec
    vw_setup(300);	//Set VirtualWire communication speed
// Start up the library
// set the resolution to 9 bit (good enough?)
sensors.setResolution(insideThermometer, 9);
// sensors.setResolution(outsideThermometer, 9);

void loop(void)

sensors.requestTemperatures();  //Get temperature from the temp Sensor

float tempC = sensors.getTempC(insideThermometer);
if (tempC == -127.00) {
Serial.print("Error");//Print Error if we read -127else {
// lcd.print(tempC);
// lcd.print("/");
Sensor1Data = (DallasTemperature::toFahrenheit(tempC));//Set Sensor1Data as the Celcius to Fahrenheit Conversion
Serial.print(Sensor1Data); //Print the converted temp in the serial terminal
// Integer to ASCII
digitalWrite(13, true); // Turn on a light to show transmitting
 vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));//Send the data collected

 vw_wait_tx(); // Wait until the whole message is gone
 digitalWrite(13, false); // Turn off a light after transmission
 delay(200);//Wait 200 Milliseconds and then go back to program start


Receiver Code


#include <Wire.h>

#include <Adafruit_MCP23008.h>
#include <LiquidCrystal.h>


Sensor Receiver 
By Markus Ulfberg 2012-07-06

Gets a sensor reading 0-1023 in a char array
from RF Transmitter unit via VirtualWire 
converts char array back to integer


#include <VirtualWire.h>

// LED's
int ledPin = 13;//Set up pin 13 as the recieve indicator
int ActionLED = 4;//Set up pin for LED 

// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);
// Sensors 
int Sensor1Data;//initialize the variable Sensor1Data for use

// RF Transmission container
 char Sensor1CharMsg[4]; 
// Trying to use 5 instead to fit trailing null char 
// go back to 4 if this does not work. 
//char Sensor1CharMsg[5]; 

void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);//Initialize serial communication
  Serial.print("RX Start");//Print RX Start in the Serial Terminal 

  // sets the digital pin as output
  pinMode(ledPin, OUTPUT);//Set the ledPin as an Output
  pinMode(ActionLED, OUTPUT);//Se up the ActionLED pin as an Output
  digitalWrite(ActionLED, LOW);//Set the ActionLED LOW 'off'

    // VirtualWire 
    // Initialise the IO and ISR
    // Required for DR3100
    // Bits per sec
    vw_setup(300);//Set up VirualWire Communication Speed	 

    // Start the receiver PLL running

} // END void setup

void loop(){
  //Unsigned Integer of 8 bit length buffer Max Message Length
    uint8_t buf[VW_MAX_MESSAGE_LEN];
  //Unsigned Integer of 8 bit length buffer length Max Message Length
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    // Non-blocking
    if (vw_get_message(buf, &buflen)) 
	int i;//initialize the variable i
        // Turn on a light to show received good message 
        digitalWrite(13, true); 
        lcd.setCursor(1, 0);
	lcd.print("Remote Temp: ");//Print Remote Temp: in the serial terminal
        // Message with a good checksum received, dump it. 
        for (i = 0; i < buflen; i++)//Use the variable i to store bytes from message and if i is less than the buffer length then increase byte storage.
          // Fill Sensor1CharMsg Char array with corresponding 
          // chars from buffer.   
         Sensor1CharMsg[i] = char(buf[i]);//Senso1CharMsg[i] is the variable to represent char(buf[i]);, char(buf[i]); is charactor buffer storage

        // Null terminate the char array
        // This needs to be done otherwise problems will occur
        // when the incoming messages has less digits than the
        // one before. 
        Sensor1CharMsg[buflen] = '\0';//clear it to fill again.

        // Sensor1Data is atoi (ASCII to Integer) from Sensor1CharMsg
        Sensor1Data = atoi(Sensor1CharMsg);

        // DEBUG 

        lcd.println(Sensor1Data); //Print Sensor1Data in the serial Terminal

        // END DEBUG

        // Turn off light to and await next message 
        digitalWrite(13, false);
        //If Sensor1Data (temp) is less than 75 degrees turn on the ActionLED
        if (Sensor1Data < 75)
          digitalWrite(ActionLED, HIGH);
    } //If Sensor1Data (temp)is more than 75 degrees turn off ActionLE
        else if (Sensor1Data > 75)
          digitalWrite(ActionLED, LOW);


Bread board power wires


This may seem a little trivial for a post, but I did it so I thought I would share.

I took a regulated 12 volt power supply and added a regulated 5 volt and adjustable supplies to it. I used some old speaker terminals I had around for the facing connections on the power supply. I wanted to have some wires that I didn’t have to screw down so I got some banana clips and male header pins to make my own wires that will work with the bread board and the power supply easily.

I got the banana clips and male headers from Tayda Electronics.



How to use a Triac to switch AC Voltage on and off (Simple)

This is a simple explanation of how to use a triac and opto isolator to switch AC voltages on and off to a device (load). The opto isolator is used to give a physical separation between the low voltage and the high voltage circuits. The Arduino is optional. You can substitute the signal coming from the Arduino with any 5 volt DC signal voltage. This cannot be used for dimming lights.  The opto isolator I used is a M0c3041. Take notice that in the schematic the opto isolator has a triac and not just a switching transistor. This is essential piece. It allows current to flow in both directions when the opto isolator is switched on.  Please feel free to ask questions.

Triac_Schematic Triac_Switch_bb

Join the Forum discussion on this post

Review: Vintronics LCD, RTC, Button Shield

A good general purpose shield for incorporating an LCD, buttons and a real time clock (RTC) into any Arduino Uno or other compatible Arduino product.












This neatly laid out  shield incorporates a 16×2 LCD shield with a white LED back light with stand offs for raising it above the other components on the board, a DS1307 RTC with battery backup for memory, and three tact switches.

The tact switches are set up for easy novice use. You don’t need to  debounce these because they each have a different resister value.  So they are read with analogRead(); to get the specific analog value associated with  each switch and then an if statement is used to create an action or function for the switch to control.

The LCD is also great for the novice Arduino programmer since it the most common LCD to use with an Arduino, uses the most common LCD library, and does not use I2C. Also, the LCD is easily interchangeable with other LCD’s that use  a 16 pin header. Just unscrew the stand offs and remove the LCD to replace with the one of your choice.

The RTC feature isn’t as novice friendly. However, that is no fault of this shield’s design. The DS1307 RTC uses I2C for its interface and has many libraries around the Web. Just choose the library that best suits your needs (with a little Googling), or use the one suggested by Vinduino of Vintronics. There is a little bit of a learning curve associated with the RTC, but it is worth your time if you ever want to incorporate time or timing into your Arduino project.

Personally, I prefer the LCD to use an I2C rather than directly connecting the 16 pin header to the Arduino. I like keeping the digital I|O ports for other peripherals. I2C saves those valuable I|O ports by only using the Arduino’s SCL and SDA ports (A5, and A4) for two wire communication.  Also, although this IS a great novice shield, the use of analog values to read a switch slows down things a bit. You have to press the tact switch for a little less than a half a second to get a read from it based on the example code provided for the shield. However, this may be sped up a bit with a little coding finesse.

So, if you are new to Arduino or just want a well made, easy to work with shield, then this is the one for you. So many board developers forget about building shields that are easier for a novice to get started with. Thanks Vincent Kok at Vintronics for this great shield . Good work!

Links to the developer:








How to properly detach/turn off a servo with arduino.

Lets say that you have a project that uses a servo and runs on battery. Currently there is no way in code to turn off an analog servo. Some say to use the detach command. This doesn’t work. Analog servos aren’t designed to be powered and not have a pulse being sent to them. So, what happens when you use the detach command with an analog servo?

When you do servo.detach(); you turn off the 5 volt pulses that control the servos position. When an analog servo looses pwm signal it will hold a position. The position held will vary from servo to servo. So, what we have is a servo constantly drawing power from our precious limited power source.

So, what can we do to mitigate this annoying issue?

Lets start with the code.

#include <servo.h>
int servoPin = 9;
int UsrBtn = 4; //Button to activate program loop
int tranPin = 7; //Transister base pin

Servo servo;

int angle = 0; // servo position in degrees

void setup()

pinMode(UsrBtn, INPUT);  //Set UsrBtn as an input
pinMode(tranPin, OUTPUT); //Set tranPin as an output

void loop()
servo.attach(servoPin); //Start the servo library on the servoPin
int letMeBe = digitalRead(UsrBtn); //letMeBe is a digital read of the UsrBtn

if (letMeBe == 1) //if letMeBe (UsrBtn) is high
digitalWrite(tranPin, HIGH); //make tranPin high

// scan from 0 to 180 degrees
for(angle = 0; angle < 180; angle++) { servo.write(angle); delay(4); } // now scan back from 180 to 0 degrees for(angle = 180; angle > 0; angle–)
else if (letMeBe == 0) //else if letMeBe is low
digitalWrite(tranPin, LOW); //make the tranPin low

servo.detach(); //stop sending pulses to reserve power on the Arduino.



It was pointed out that I may have used the wrong transistor here. I will test and update. Sorry if this has caused anyone any issues. 12/15/14

Now for the hardware. In order to completely turn off the servo so that it isn’t drawing unnecessarily on the battery, we need to use a general purpose NPN switching transistor. I used a 2N4401.

From the Arduino: Pin 7 goes to the base of the transistor.

From the transistor emitter: To the power pin of the servo.

From 5 volts: to the collector of the transistor.

From servo ground pin to ground.

What we have done is set a pin in code as an output (tranPin) that we activate right before we tell the servo what to do. This turns the power on to the power pin of the servo. Then when our servo has finished the job set in loop we set the tranPin low. That turns power to the servo back off.

Please comment with questions of head over to our forum to have a discussion.
Join the Forum discussion on this post

Use the FTDI Basic Breakout Board to program an Atmega328P-PU With Optiboot.

This is if you want to program your breadboard arduino and have an atmega328P-PU with the Optiboot bootloader already on the chip. The biggest issue I have found with breadboarding any chip is that they don’t always want to fully seat into the breadboard. In my experience, I find that pressing firmly down on the chip while uploading saves a ton of trouble!

The LED attached to pin 19 (D13) of the chip is there just as an example. I usually upload the example Blink sketch first to verify that I am able to upload a sketch since it gives me visual confirmation.


If you are using an oscillator.

Note: the caps with the oscillator are pF, NOT uF. Sorry.



If you want to use the FTDI Basic Breakout Board for timing.



Join the Forum discussion on this post

Helping Others With What We Know

%d bloggers like this: