Introduction: RPI - 8 IO PLC With ATTiny85 Watch Dog

This Project is the starting of a big project which control a big process in low cost. I choose raspberry pi and its my first project in pi. I already work with i/o controllers for my official project, and also work with some plc and scada. But here when use raspberry pi we can able to save data in the pi data base and also have GPIO pins for io controllers. But for process we want some isolated Outputs to safe guard the raspberry pi. First i design the circuit in the prototype board and after complete the project i make a sketch and print pcb.

Step 1: Materials Required

For Control

  1. Raspberry Pi 4.
  2. 24V dc power supply.
  3. 24V Relay module.
  4. Keyboard, Mouse and Monitor.

For PCB bill of Material

  1. 10K Resistor 1/4watts - 1
  2. 1K Ohms Resistor 1/4watts - 9
  3. 330ohms Resistor 1/4Watts - 8
  4. 4.7K Resistor 1/2 watts - 1
  5. 10K 9 Pin Resistor SIP 1/4watts - 1
  6. 1N4004 Diode - 1
  7. 2N2222 Transistor - 1
  8. IDC-Header_2x20_P2.54mm - 1
  9. 5V relay - 1
  10. Attiny85 IC - 1
  11. RTC Module - 1
  12. Red LED 5mm - 1
  13. ULN2803A IC - 1
  14. Female Header -0.25
  15. 8 Pin ic base-1
  16. 18 pin ic base-1
  17. 9 Pin Pluggable Screw Terminal Block Connector - Right Angle - 5.08mm Pitch - 2EDG5.08 - Set of M+F-2
  18. 5085 Plug In Type Screw Terminal Connector - 2 Pin - 5.08mm Pitch - Set of M+F - Right Angle Male Connector-1

Step 2: Symmetric Diagram

1) Use Pi GPIO pins 17,27,22,5,6,13,19,26 for input.

2) For Output use pins 24,25,8,7,12,16,20,21.

3) Use 2N2222 Transistor to control the 24V dc Output Voltage.

4) Use pin 18 for Watch Dog.

5) All the output pins power supply go through the watch dog relay.

Step 3: Develop Prototype

As usual I develop a circuit board in a proto type board and solder the track and component and test the circuit and found ok. So want to develop the pcb print layout. I search for more than 3 free software and finally found Kicad is the best of all kind.

Step 4: Kicad Introduction

Kicad is a open source PCB design software. So open Kicad in a browser and download for your os. Install the Application. After installation open the Kicad app in the pc. In the file menu click New -> Project in the save dialogue box enter the name and click ok. Your project with a Schematic and PCB file opened.

Step 5: Design Schematic

Double click the sch file and it open in another application for circuit design. Design as per plan. For create PCB click tools menu and click Update PCB from Schematic. It shows a small circuit i cant able to visible. I am new to pcb design i dont know how to work, but complete the pcb and check it sucess.

Step 6: Design the PCB

1) After design the PCB we able to show and hide the layers in the PCB.

2) Lot of components available for PCB development.

Step 7: 3D Viewer

Click view and click 3D Viewer. Another screen show the 3d view of the design. Rotate the board and conform the layout.

Step 8: Gerber and Drill File

In the file menu click plot, Plot dialogue box opened. In the bottom of the dialogue box click generated drill files. Now the generate drill file dialogue box open. Click the Generate drill file in the Generate drill file dialogue box. It save the drill file in the specified location. Now in the plot dialogue box click plot and it saves each layer in separate file. Now the gerber file and drill file exported. Send this file to the pcb printers for print.

Step 9: Check Gerber and Drill File

In the main form click the Gerber viewer, Gerberview form opens. In the file menu click open Gerber Files, in the open box select all the files. Each layer is show seperate in the left side Layers manager. By remove the tick in the layer manager we hide that layer. Click file open drill excellon file and select the exported drill file. Hide other layers and see the drill only.

Now the files ready to print.

Step 10: Select the PCB Printer Service Provider

I check more than 5 online pcb printer service provider and got quote. When compare to others EPS PCB Technologies is very cheap and the boards are all very fine. This board is a single layer board.

Step 11: PCB Received

I received the PCB in 5 Days and found all ok. Check all the lines and found ok. But for components it take some more days.

Step 12: Solder the PCB

I never take photos of components separately. Its very compatible when compare to the prototype. Also only 30 minutes to complete the single board. For both IC Attiny85 Ic and ULN2803A Ic have ic base 8 pin and 18 pin base. So after complete the circuit we insert the IC. Before insert the Attiny85 IC it want to program.

Step 13: Attiny85 Programming - Watch Dog

I Use arduino uno to program the ATTINY85 IC. Lot of instructables available to explain how to upload program to Attiny85. Please check it.

The main concept of watch dog program is pin 3 to read the input from raspberry pi pin no18 and use pin2 to control the relay. Input pin has a sequence of high and low from pi, if there is no change in the pin for set secs then the output relay swicth off and this relay NO terminal is the path for all relay 24v supply. So if this relay switch off all the 8 pins switch off.

Step 14: Control Setup

Connect the Raspberry pi with the IO control board using 40 pin ribbon cable. Connect the 24V Dc power supply to the IO controller board. In the controller Board there are two sides, top one is Digital input side and bottom one is Digital output side. So for input take the common out put form the right side first pin and if short with all other 8 pins it reads the input. For output right side pin is 24V dc common get from watch dog relay and all the other 8 pins are the ground pins, connect a 24V relay module to the output pins with common positive. Now the setup is complete.

Step 15: Raspberry Pi Python Programming

I use python to develop the program. Use leafpad for programming. In the terminal type leafpad IOcontroller.py. This open a new file in the dir. Compile the program, the program contain lot of small functions. For Watch dog a small function is available at each cycle this function called, so if program hanged to closed then it switch off the all the output. Currently i program to show how it works so if a pin is input is read then a output pin is trigger. If progam closed then the watch dog Attiny85 close the relay. After complete the program In terminal type python3 IOcontroller.py, this run the program it show the visual of which pin is read in the display form and the out put pin trigger is visual in the relay module. See the next video in action.

Step 16: Working Video

1) When the program on the watch dog relay ON.

2) When the input signal is sense then the output realy ON and Off when input remove.

3) When input is sense and the output relay is ON, at that time when program close with in few seconds all the relay switch off.

Step 17: Not End Its Start

After this i develop this program lot and lot more. May explain in the next instructables. So for what i did is

1) Use the USB to 485 convertor to read data from other instruments in pi.

2) Save that data in mysql data base in pi.

3) As per the data received and input switches on status, turn on off the lamps and motors for control.

Its is a perfect low cost automation system with 8 inputs and output with data from other instruments also.Thank you all for reading it.

Lot more to enjoy...............Don't forgot to comment and encourage me friends.

PCB Challenge

Participated in the
PCB Challenge