PIC16F628A Programmable Digital Timer

TimerOP1

Programmable relays find use in numerous automation applications such as automatic street light control, watering and pump control, HVAC, home automation, power plants automation in industries, etc. This article describes how to build a fully functional, one-channel programmable relay switch using the PIC16F628A microcontroller. It allows you to set both ON and OFF time. The maximum time interval that you can set for on and off operations is 99 hours and 59 minutes. Another interesting feature of this project is it offers cyclic option, which means you can choose to run it in a continuous loop of ON and OFF cycles. The device can be programmed through 4 push switches. The programming menu and device status are displayed on a 16×2 character LCD. The timing resolution of this relay timer is 1 minute. The timer also saves the user inputs to its internal EEPROM so that it can retain these values after any power supply interrupt. Here are the summary of the features that this timer device has:

  • Microcontroller powered timer switch
  • OFF and ON time setup for the relay operation
  • Option for cyclic run
  • ON/OFF timing range: 0 to 99 hours and 59 minutes
  • 1 minute timing resolution
  • Interactive user interface using 4 tact switches and a character LCD
  • Buzzer alarm
  • On-board +5V voltage regulator

Circuit diagram

The hardware part of this project is very simple.  The entire circuit runs off a regulated 5V power supply derived using the popular LM7805 linear regulator chip (Figure 1).  To minimize the heat dissipation in the voltage regulator, the recommended input DC voltage to LM7805 is 9V, which can be easily obtained from a DC wall adapter. Diode D1 (1N4001) is used for reverse polarity protection in the circuit. S1 is a slide switch for turning the power supply on and off.

Figure 2 depicts the input and output setup. There are five tact switches in this project: one for microcontroller reset, and four for user inputs. The four input switches are named as Menu/+, Select, Enter, and Start/Stop. Their functions will be described in the software section. The status of the 4 input switches is read by the PIC16F628A microcontroller through ports RA2, RA3, RA4, and RB0. The output LCD is a standard HD44780-based display and is driven in 4-bit mode. The pin assignments for the LCD data and control signals are shown in Figure 2. S2 is another slide switch that allows manual control of the LCD backlight.

The output relay switch is driven through a NPN transistor (2N2222). The project also includes a DC buzzer that beeps when the relay switch changes its status. The relay and buzzer circuits are shown in Figure 3.

The PIC16F628A microcontroller runs at 4.0 MHz using an external resonator. The I/O pins of PIC16F628A, the resonator connection, and the in-circuit serial programmer (ICSP) header are shown in Figure 4.

Figure1_PowerSupply
Figure 1. Regulated +5V power supply unit
Figure2_IOcircuit
Figure 2.  I/O circuit with PIC16F628A pin assignments

Figure3_RelayBuzzer
Figure 3. Relay and buzzer control circuit
Figure4_MCU
Figure 4. PIC16F628A resonator and ICSP header connections
The PIC16F628A pin assignments for the LCD, switches, relay and buzzer circuits are listed in the following table.
IO
The following figure shows the complete relay timer circuit soldered on a general-purpose prototyping board.
CompleteAssembledBoard

Software

The programmable relay timer gets inputs from the 4 push buttons. Their functions are described as follows:

Menu/+ : This button allows you to navigate between various menu options such as ON time setup, OFF time setup, and Cyclic option setup. These options are displayed on the LCD. This button also serves as digit increment during time setup. The time is set in HH:MM format, which gives the minimum value of timing interval to be 1 min.

Select : This allows you to choose a displayed menu option as well as individual hour and minute digits. The selected digit is incremented by 1 when Menu/+ button is pressed.

Enter: When the appropriate hour and minutes are set, pressing the Enter button finalizes the time. The Cyclic option is also entered using this button.

Start/Stop: This push button is to start and stop the timer. If the timer is already on, you can stop it at anytime during its operation by pressing this button.

Now let’s see how it works. Suppose, the relay switch is needed to be turned on after 15 minutes for 10 minutes. This means the OFF time is 15 minutes and ON time is 10 minutes. Once the timer is started after entering the above times, the device will be turned on after 15 minutes and remained on for 20 minutes. After that it will be turned off again. If the Cyclic option is selected to 1, the timer will run in a loop and after another 15 minutes of OFF time, the relay will be turned on for next 10 minutes, and so on.

The firmware for this project is developed using mikroC Pro for PIC compiler from mikroElektronika. The time keeping is achieved using the Timer 0 module built inside the PIC16F628A. The Timer0 interrupt is enabled and run with 1:256 prescaler value to create a precise 500 ms (half-second) duration. The colon symbol between HH and MM digits blinks at 1 Hz. The half-second delay is looped 120 times to construct a minute-duration. You can download the complete project files including the source code and compiled HEX file in the attached file.

Photos

TitlePicture

TimerOP2

The following video shows the timer device in action.

 

Keynotes:

  • The function of the buzzer is to notify the user with a beeping sound whenever the relay is switched on and off.
  • In case of power failure, the timer will retrieve the user selected ON and OFF times from the EEPROM. But the timer will be stopped and won’t run until the user presses the Start
  • All circuit diagrams used in this project are original and drawn by the author using the EasyEDA schematic editor. EasyEDA is a free online CAD tool for circuit layout, PCB design, and simulation.

Author: Raj Bhatt (electronics enthusiast, and hardware maker, and founder of Embedded Lab; visit my Tindie store)

Mini Arduino Lux Meter

FFXIA2JIN3EHHKH.MEDIUM

Here is a nice build of a LUX meter using BH1750 sensor and a Nokia 5110 LCD. The meter is controlled by an Arduino Pro Mini and is powered by a Li-Ion battery. The LCD backlight is controlled according to environment light and there is graphing capability of the measured light intensity.

That’s when I realized that I had an unused BH1750 light meter module laying around, which I bought some time ago but never used it. So I grabbed an Arduino, a Nokia 5110 LCD, wired everything up on a breadboard and had a functioning lux meter within a few hours. To make it a bit more fancy, I added some graphing functionality and made the LCD backlight switch on/off depending on the light level.

Mini Arduino Lux Meter – [Link]

Control ESP8266 over the internet

F8H4C1WIN3EI8A1.MEDIUM

Here is a basic tutorial on how to control ESP8266 over the internet using two buttons on a browser window. The article goes through Arduino IDE configuration and example code is included.

There are but a few things better than (succesfully) programming and using your Arduino. Surely one of those things is using your ESP8266 as an Arduino with WiFi!

Control ESP8266 over the internet – [Link]

DIY Morning Feed With LED Matrix

FS676X3IN4QEF6N.LARGE

Here is a LED matrix able to show useful information such as weather forecast, temperature and stock updates. The matrix is controlled by a Particle Photon board.

You wake up in the morning. You’re groggy. You grab your phone lazily and start browsing. You check the weather, your stocks, your instagram. Before you know it, you’re running late! Do your mornings look like this too? We’ve been there! We wanted to streamline our mornings so we built a morning feed so that we can get all the info while we brush our teeth.

DIY Morning Feed With LED Matrix – [Link]

Low-side I/V sensing IC, with internal power calculation

160411edne-maxim

Maxim Integrated has posted details of the MAX44299, a low-side current, voltage, and power monitoring circuit that provides an analogue output current proportional to the measured current, voltage, and the internally calculated instantaneous power. The power monitor offers high precision and integration in tiny size.

Instantaneous power is calculated internally by multiplying the load current and a fraction of the load voltage set by an external resistive divider. All three outputs are scaled to a full-scale current of 100 µA. An additional output current of 100 µA is available at the reference (REF) output; this current can be used to create a reference voltage for the ADC that is being used to measure the power, voltage, and current signals.

Low-side I/V sensing IC, with internal power calculation – [Link]

PiDrive – 314GB hard disk for the Raspberry Pi

20160404121510_2016-04-04---Pi-drive

Western Digital have launched the WD PiDrive, a hard disk specially designed for the Raspberry Pi with a storage space of 314 GB. The engineers have modified the magnetic recording system and electronics to suit the characteristics of the RPi, and reduced the current consumption.

The recommended retail price is $ 45,81 but a discount is available.

PiDrive – 314GB hard disk for the Raspberry Pi – [Link]

ESP8266 + I2S = Software-based 10-Base-T Ethernet Driver

ethernet_controller

cnlohr @ github.com wanted to have an Ethernet interface for ESP8266 so he build one. more details on hackaday.

This is a relatively unreliable and coincidentally functional ESP8266 Ethernet driver. It only uses two pins on the ESP, the I2S pins, but does provide Ethernet. It does all its own manchester encoding/decoding, framing, FCS, etc. It mimics the ENC424J600 stack found in avrcraft and borrows the IP, ARP, UDP and TCP stacks from that project, too.

ESP8266 + I2S = Software-based 10-Base-T Ethernet Driver – [Link]

WiGPSFi – ESP8266 + GPS module

image-3

euerdesign.de has connected the ESP8266 to an GPS and a SD-Card to scan networks – coded a MySQL-DB with some PHP parsers and dynamic maps – and get fascinated by all the 2,4 GHz radiation arround him.

In this blogpost, you can only read about finding and printing out maps with WiFi-Accesspoints and not how to crack them! I did not connected to any of this WiFis and you should also refrain. The ESP is only listening passivly!

WiGPSFi – ESP8266 + GPS module – [Link]

LoRaONE: the LoRa® IoT development board

LoRaONE

LoRaONE is a new board to help you develop IoT applications fast and with ease. It’s an Arduino compatible board packed with features and sensors, making it the ideal solution for makers and creators that can’t wait to make the Internet of Things a reality. It is easy to program, connected to its surroundings through numerous sensors and ready to go.

This board is based on our successful Autonomo. It has a proven 32 bit Arduino compatible platform that is currently the first choice of millions of programmers around the world. Not only is it versatile, it is also extremely small, measuring only 40 x 25 millimeters. One of the characteristics of ARM Cortex M0 based boards is that they can be programmed to run extremely energy efficient, which is essential for your next IoT-project.

LoRaONE: the LoRa® IoT development board – [Link]

Troubleshooting I2C for Arduino and nRF51822

i2ctest_arduino_nrf51dk

bitknitting.wordpress.com documented his efforts to transmit data over the I2C interface and analyze traffic using a USB login analyzer.

The goal of this post is to transmit data over the I2C interface. Confirmation that the data was transferred will be output of the SDA/SCL lines when my Saleae Logic Analyzer is inserted between the I2C slave (I will be using Adafruit’s ADS1015 BoB…it could be any I2C chip at this point, I just needed a destination to transmit data to).

Troubleshooting I2C for Arduino and nRF51822 – [Link]

TOP PCB Companies