Accéder au contenu principal

PLC with ARDUINO (ATmega 328p)

Contents
INTRODUCTION
TECHNICAL SPECIFICATIONS
CHANGES COMPARED TO THE PREVIOUS VERSION (V4)
ELECTRONIC SCHEMATIC
PCB BOARD DESIGN - Order now at JLCPCB
LIST OF ELECTRONIC COMPONENTS
STEPS TO UPLOAD A PROGRAM
EXTERNAL PARTS AND CONNECTIONS
LIST OF EXTERNAL TERMINALS AND ATMEGA328P-AU
10 TEST CODES
10.1 OUTPUTS
10.2 INPUTS AND OUTPUTS
10.3 ANALOG INPUTS
10.4 SERIAL PLOTER
10.5 REAL TIME CLOCK (RTC)
INTRODUCTION

At the beginning of this year 2020 a video of the PLC V4 was published. whose device still had to be improved, therefore, for this version 4.1, a Real Time Clock and a DC DC step down source have been integrated.

PLC with arduino (ATmega328p AU) V4.1, is a programmable logic controller that was designed by Electroall, whose circuit is based on the SIEMENS S7 1200 CPU1214c PLC device with relay outputs. Initially, the current version will have a 24VDC power supply like all industrial devices. In addition, it includes a Real Time Clock (RTC). Secondly, in this version there will be 8 digital inputs of 12-24VDC and 2 analog inputs of 0 to 5V . As for the outputs, there will be 8 outputs (relay).

For the control system, the ATmega328P AU (SMD) microcontroller will be used, since this µC can be easily programmed in the arudino IDE. On the other hand, this PLC will be programmed directly by computer - PLC V4.1. Finally, this device has the principles of high isolation similar to most industrial devices, both in the phase of the inputs and the outputs.


TECHNICAL SPECIFICATIONS

  1. Supply voltage ………………………. ………… 24VDC
  2. Supply current …………………. …………… 100mA
  3. DC source - DC step down ………………………………… .Yes
  4. Real Time Clock …………………………………………… Yes
  5. 12-24VDC digital inputs ………………………. …… 8
  6. 0-5V analog inputs ……………………………… ..2
  7. Direct Programming ……………………………………… ..Computer - PLC V4.1
  8. Programming environment ……………………… .. ……… ..Arduino IDE
  9. Environmental conditions min ……………………….….-10 °
  10. Environmental conditions max ………………… .. ……… .55 °
  11. RLY outputs ………………………………………………………… 8
  12. AC output voltage …………………………………………. …… 250V
  13. AC current ……………………………………………………… .5A
  14. DC voltage ………………………………………………………… 30V
  15. DC current ……………………………………………………… 5A
  16. Dimensions ……………………………………………………… .100x100mm
  17.  Recessed ………………………………………………………… Yes

ELECTRONIC SCHEMATIC



ELECTRONIC COMPONENT LIST

STEPS TO UPLOAD A PROGRAM

  • STEP 1: UPLOAD BOOT MANAGER (BOOTLOADER)

    To be able to use a new microcontroller (atmega328p-U), it is necessary to upload a boot loader, also called "BOOTLOADER", this will make it easier for us to upload programs in future occasions.

    finally to burn the bootloader it will have to be done through the ICSP pins, which would practically be the pins [(MOSI = 11) (MISO = PIN12) (SCK = PIN13) (Slave = PIN10)]. To upload and burn the bootloader we will need an Arduino UNO or MEGA and make the following connections (ARDUINO UNO - PLC).







STEP 2: UPLOAD THE PROGRAM; PC - PLC

After having uploaded the bootloader, we will finally be able to upload any program as we normally do through the serial port.



STEP 2: UPLOAD THE PROGRAM; PC - PLC  

After having uploaded the bootloader, we will finally be able to upload any program as we normally do through the serial port.

EXTERNAL PARTS AND CONNECTIONS








LIST OF EXTERNAL TERMINALS AND ATMEGA328P-AU
TEST CODES

OUTPUTS
// DIGITAL OUTPUTS
int Q0_0 = 10 ;
int Q0_1 = 11 ;
int Q0_2 = 12 ;
int Q0_3 = 13 ;
int Q0_4 = 14 ;
int Q0_5 = 15 ;
int Q0_6 = 16 ;
int Q0_7 = 17 ;
void setup () {
// DIGITAL OUTPUTS
pinMode ( Q0_0, OUTPUT ) ;
pinMode ( Q0_1, OUTPUT ) ;
pinMode ( Q0_2, OUTPUT ) ;
pinMode ( Q0_3, OUTPUT ) ;
pinMode ( Q0_4, OUTPUT ) ;
pinMode ( Q0_5, OUTPUT ) ;
pinMode ( Q0_6, OUTPUT ) ;
pinMode ( Q0_7, OUTPUT ) ;
}
void loop () {
digitalWrite ( Q0_0, 1 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_0, 0 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_1, 1 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_1, 0 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_2, 1 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_2, 0 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_3, 1 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_3, 0 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_4, 1 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_4, 0 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_5, 1 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_5, 0 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_6, 1 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_6, 0 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_7, 1 ) ;
delay ( 1000 ) ;
digitalWrite ( Q0_7, 0 ) ;
delay ( 1000 ) ;
}
INPUTS AND OUTPUTS
// DIGITAL TICKETS
int i0_0 = 2;
int i0_1 = 3;
int i0_2 = 4;
int i0_3 = 5;
int i0_4 = 6;
int i0_5 = 7;
int i0_6 = 8;
int i0_7 = 9;
// DIGITAL OUTPUTS
int Q0_0 = 10;
int Q0_1 = 11;
int Q0_2 = 12;
int Q0_3 = 13;
int Q0_4 = 14;
int Q0_5 = 15;
int Q0_6 = 16;
int Q0_7 = 17;
void setup () {
//DIGITAL TICKETS
pinMode ( i0_0, INPUT ) ;
pinMode ( i0_1, INPUT ) ;
pinMode ( i0_2, INPUT ) ;
pinMode ( i0_3, INPUT ) ;
pinMode ( i0_4, INPUT ) ;
pinMode ( i0_5, INPUT ) ;
pinMode ( i0_6, INPUT ) ;
pinMode ( i0_7, INPUT ) ;
// DIGITAL OUTPUTS
pinMode ( Q0_0, OUTPUT ) ;
pinMode ( Q0_1, OUTPUT ) ;
pinMode ( Q0_2, OUTPUT ) ;
pinMode ( Q0_3, OUTPUT ) ;
pinMode ( Q0_4, OUTPUT ) ;
pinMode ( Q0_5, OUTPUT ) ;
pinMode ( Q0_6, OUTPUT ) ;
pinMode ( Q0_7, OUTPUT ) ;
}
void loop () {
// READING OF DIGITAL INPUTS
int I0_0 = digitalRead ( i0_0 ) ;
int I0_1 = digitalRead ( i0_1 ) ;
int I0_2 = digitalRead ( i0_2 ) ;
int I0_3 = digitalRead ( i0_3 ) ;
int I0_4 = digitalRead ( i0_4 ) ;
int I0_5 = digitalRead ( i0_5 ) ;
int I0_6 = digitalRead ( i0_6 ) ;
int I0_7 = digitalRead ( i0_7 ) ;
// TURNING ON THE OUTPUTS ACCORDING TO THE RESPECTIVE INPUTS
if ( I0_0 == 1 ) digitalWrite ( Q0_0, 1 ) ;
else digitalWrite ( Q0_0, 0 ) ;
if ( I0_1 == 1 ) digitalWrite ( Q0_1, 1 ) ;
else digitalWrite ( Q0_1, 0 ) ;
if ( I0_2 == 1 ) digitalWrite ( Q0_2, 1 ) ;
else digitalWrite ( Q0_2, 0 ) ;
if ( I0_3 == 1 ) digitalWrite ( Q0_3, 1 ) ;
else digitalWrite ( Q0_3, 0 ) ;
if ( I0_4 == 1 ) digitalWrite ( Q0_4, 1 ) ;
else digitalWrite ( Q0_4, 0 ) ;
if ( I0_5 == 1 ) digitalWrite ( Q0_5, 1 ) ;
else digitalWrite ( Q0_5, 0 ) ;
if ( I0_6 == 1 ) digitalWrite ( Q0_6, 1 ) ;
else digitalWrite ( Q0_6, 0 ) ;
if ( I0_7 == 1 ) digitalWrite ( Q0_7, 1 ) ;
else digitalWrite ( Q0_7, 0 ) ;
}
ANALOG INPUTS
// DIGITAL OUTPUTS
int Q0_0 = 10;
int Q0_1 = 11;
int Q0_2 = 12;
int Q0_3 = 13;
int Q0_4 = 14;
int Q0_5 = 15;
int Q0_6 = 16;
int Q0_7 = 17;
void setup () {
pinMode ( Q0_0, OUTPUT ) ;
pinMode ( Q0_1, OUTPUT ) ;
pinMode ( Q0_2, OUTPUT ) ;
pinMode ( Q0_3, OUTPUT ) ;
pinMode ( Q0_4, OUTPUT ) ;
pinMode ( Q0_5, OUTPUT ) ;
pinMode ( Q0_6, OUTPUT ) ;
pinMode ( Q0_7, OUTPUT ) ;
}
void loop () {
// ANALOG INPUT AI0
if ( analogRead ( A6 )> = 250 ) digitalWrite ( Q0_0,1 ) ;
else digitalWrite ( Q0_0,0 ) ;
if ( analogRead ( A6 )> = 500 ) digitalWrite ( Q0_1,1 ) ;
else digitalWrite ( Q0_1,0 ) ;
if ( analogRead ( A6 )> = 750 ) digitalWrite ( Q0_2,1 ) ;
else digitalWrite ( Q0_2,0 ) ;
if ( analogRead ( A6 )> = 1000 ) digitalWrite ( Q0_3,1 ) ;
else digitalWrite ( Q0_3,0 ) ;
// ANALOG INPUT AI1
if ( analogRead ( A7 )> = 250 ) digitalWrite ( Q0_4,1 ) ;
else digitalWrite ( Q0_4,0 ) ;
if ( analogRead ( A7 )> = 500 ) digitalWrite ( Q0_5,1 ) ;
else digitalWrite ( Q0_5,0 ) ;
if ( analogRead ( A7 )> = 750 ) digitalWrite ( Q0_6,1 ) ;
else digitalWrite ( Q0_6,0 ) ;
if ( analogRead ( A7 )> = 1000 ) digitalWrite ( Q0_7,1 ) ;
else digitalWrite ( Q0_7,0 ) ;
}
SERIAL PLOTER
void setup () {
Serial. begin ( 9600 ) ;
pinMode ( 10, OUTPUT ) ;
pinMode ( 11, OUTPUT ) ;
pinMode ( 12, OUTPUT ) ;
pinMode ( 13, OUTPUT ) ;
pinMode ( 14, OUTPUT ) ;
pinMode ( 15, OUTPUT ) ;
pinMode ( 16, OUTPUT ) ;
pinMode ( 17, OUTPUT ) ;
}
void loop () {
Serial. println ( analogRead ( A6 )) ;
//Serial.println(analogRead(A7));
}
REAL TIME CLOCK (RTC)











// {== [=======> (RTC AND TEMPERATURE) <=======] ==}
#include <Wire.h>
#include "Sodaq_DS3231.h"
char Weekday [] [ 4 ] = { "Sun" , "Mon" , "Tue" , "Wed" , "Thu" , "Fri" , "Sat" } ;
int Q0_0 = 10;
int Q0_1 = 11;
int Q0_2 = 12;
int Q0_3 = 13;
int Q0_4 = 14;
int Q0_5 = 15;
int Q0_6 = 16;
int Q0_7 = 17;
// The line sets the date, time and day of the week, the line must be deleted in the second load
// Example 2020 August 05, 9:00:00 day 1-Monday (0 = Sun, 1 = Mon, 2 = Tue, 3 = Wed, 4 = Thu, 5 = Fri, 6 = Sat)
// DateTime dt (2020, 8, 5, 20, 40, 00, 2);
void setup ()
{
Serial. begin ( 9600 ) ;
Wire. begin () ;
rtc. begin () ;
// The line sets the date, time and day of the week, the line must be deleted in the second load
//rtc.setDateTime(dt);
pinMode ( Q0_0, OUTPUT ) ;
pinMode ( Q0_1, OUTPUT ) ;
pinMode ( Q0_2, OUTPUT ) ;
pinMode ( Q0_3, OUTPUT ) ;
pinMode ( Q0_4, OUTPUT ) ;
pinMode ( Q0_5, OUTPUT ) ;
pinMode ( Q0_6, OUTPUT ) ;
pinMode ( Q0_7, OUTPUT ) ;
}
void loop () {
DateTime now = rtc. now () ;
Serial. print ( now. date () , DEC ) ;
Serial. print ( '/' ) ;
Serial. print ( now. month () , DEC ) ;
Serial. print ( '' ) ;
Serial. print ( now. hour () , DEC ) ;
Serial. print ( ':' ) ;
Serial. print ( now. minute () , DEC ) ;
Serial. print ( ':' ) ;
Serial. print ( now. second () , DEC ) ;
Serial. print ( '' ) ;
Serial. println ( DayWeek [ now. dayOfWeek ()]) ;
delay ( 1000 ) ;
if (( now. hour () == 20 ) && ( now. minute () == 20 )) {
digitalWrite ( Q0_0, 1 ) ;
if (( now. second ()> = 30 )) {
digitalWrite ( Q0_1, 1 ) ;
}
}
else {
digitalWrite ( Q0_0, 0 ) ;
digitalWrite ( Q0_1, 0 ) ;
}
}

Commentaires

Posts les plus consultés de ce blog

Home

Deep Learning is a  superpower .  With  it you can make a computer  see ,  synthesize novel  art , translate  languages ,  render a medical  diagnosis , or build pieces of a  car that can  drive itself . If that isn’t a  superpower, I don’t know what is. What is deep learning? The field of artificial intelligence is essentially when machines can do tasks that typically require human intelligence. It encompasses machine learning, where machines can learn by experience and acquire skills without human involvement. Deep learning is a subset of machine learning where artificial neural networks, algorithms inspired by the human brain, learn from large amounts of data. Similarly to how we learn from experience, the deep learning algorithm would perform a task repeatedly, each time tweaking it a little to improve the outcome. We refer to ‘deep learning’ because the neural networks have various (deep) layers that enable learning. Just about any problem that require

Covid-19 Detection With Images Analysis And Machine Learning DL4J

In this presentation, you will try learn how to automatically detect COVID-19 in a hand-created X-ray image dataset using Deeplearning4j and talk about And talking about an experiment that I did using the technique of object detection to capture the Covid virus through pictures of infected cells. But it did not produce good results due to the lack of pictures of the affected cells. Meaning that the two techniques can be applied to technical assistance for health professionals In this application, we will rely on a database of positive and negative images diagnosed by the doctor Joseph Cohen’s, which has uploaded on  github  platform. You can view it through the   link  . We will rely on DL4J framework to create the neural network according to the following plan: 1-Build the neural network 2- Train the model the net 3- Save & Loading the model of our neural network 4- Test the neural network against unsigned  images 1-Buildin The neural Network : At this poin

DL4j Spring Boot

1. Introduction: In this article, we'll create a simple neural network with the  deeplearning4j  (dl4j) library – a modern and powerful tool for machine learning. Before we get started, not that this guide doesn't require a profound knowledge of linear algebra, statistics, machine learning theory and lots of other topics necessary for a well-grounded ML engineer. 2. What Is Deep Learning ? Neural networks are computational models that consist of interconnected layers of nodes. Nodes are neuron-like processors of numeric data. They take data from their inputs, apply some weights and functions to these data and send the results to outputs. Such network can be trained with some examples of the source data. Training essentially is saving some numeric state (weights) in the nodes which later affects the computation. Training examples may contain data items with features and certain known classes of these items (for instance, “this set of 16×16 pixels contains a hand-

Understanding Neural Network

Understanding Neural Network What is a neural network? Figure 1: What is a Neural Network? The neural network is a system that mimics a human brain structure. Figure 1 presents a multi-layer feedforward Neural Network structure, which contains an input layer (green), hidden layers (pink) and an output layer (orange). Each layer contains multiple nodes indicated by a small circle, for example, input nodes are in green, hidden nodes are in pink, and output nodes are in orange. Nodes in different layers can connect to each other, and the connection strength between two nodes is called a weight between these nodes. The connection flow is started from the input layer to hidden layers, and then to the output layer. Each node in a hidden layer can accept input connections from a previously hidden layer or input layer. These input connections will be summed and fed to a special function called activation function to form its node's output. As a result, only hidden la