--> Project III - 6. Control 8 Channel Relay with Delphi Apps on PC (Arduino Based) | basic arduino tutorial

Wednesday, August 9, 2017

Project III - 6. Control 8 Channel Relay with Delphi Apps on PC (Arduino Based)

| Wednesday, August 9, 2017
Control 8 Channel Relay with Delphi Apps on PC




Arduino UNO controls on-off 8 relays through programs on computers. Programs on computers is made by using delphi applications (programs already on Download link on the end of this page). Relay is used as a switch that can disconnect and connect DC / AC current or voltage. And the result of serial data read will be shown on LCD 2X16.


Hardware Requirement
  • PC / Laptop with delphi program installed (availavle on the Download link)
  • Relay Module with 8 Channel
  • Arduino UNO
  • Power supply +5 Volt
  • Jumper

Relay with 8 Channel | Source

Block Diagram


Schematic


Arduino - LCD Wiring



Arduino - Relay Wiring




Source Code/Sketch
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
char b;
void setup(){
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(4, 0);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 0);
digitalWrite(9, 0);
digitalWrite(10, 0);
digitalWrite(11, 0);
Serial.begin(9600);
lcd.begin(16,2);
lcd.print("Kontrol 8 Relay");
lcd.setCursor(0,1);
lcd.print(" via Delphi");
delay(2000);
lcd.setCursor(0,1);
lcd.print("Tunggu Koneksi..");
do{
b = Serial.read();
}
while(b != 'R');
lcd.setCursor(0,1);
lcd.print("Koneksi OK ");
}
void loop(){
b = Serial.read();
switch(b){
//---------------------------Perintah Relay ON
case 'A': lcd.setCursor(0,1);
lcd.print("Relay 1 ON ");
digitalWrite(4, 1); // Relay1 on
break;
case 'B': lcd.setCursor(0,1);
lcd.print("Relay 2 ON ");
digitalWrite(5, 1); // Relay2 on
break;
case 'C': lcd.setCursor(0,1);
lcd.print("Relay 3 ON ");
digitalWrite(6, 1); // Relay3 on
break;
case 'D': lcd.setCursor(0,1);
lcd.print("Relay 4 ON ");
digitalWrite(7, 1); // Relay4 on
break;
case 'E': lcd.setCursor(0,1);
lcd.print("Relay 5 ON ");
digitalWrite(8, 1); // Relay5 on
break;
case 'F': lcd.setCursor(0,1);
lcd.print("Relay 6 ON ");
digitalWrite(9, 1); // Relay6 on
break;
case 'G': lcd.setCursor(0,1);
lcd.print("Relay 7 ON ");
digitalWrite(10, 1); // Relay7 on
break;
case 'H': lcd.setCursor(0,1);
lcd.print("Relay 8 ON ");
digitalWrite(11, 1); // Relay8 on
break;
//-------------------------- Perintah Relay OFF
case 'a': lcd.setCursor(0,1);
lcd.print("Relay 1 OFF ");
digitalWrite(4, 0); // Relay1 off
break;
case 'b': lcd.setCursor(0,1);
lcd.print("Relay 2 OFF ");
digitalWrite(5, 0); // Relay2 off
break;
case 'c': lcd.setCursor(0,1);
lcd.print("Relay 3 OFF ");
digitalWrite(6, 0); // Relay3 off
break;
case 'd': lcd.setCursor(0,1);
lcd.print("Relay 4 OFF ");
digitalWrite(7, 0); // Relay4 off
break;
case 'e': lcd.setCursor(0,1);
lcd.print("Relay 5 OFF ");
digitalWrite(8, 0); // Relay5 off
break;
case 'f': lcd.setCursor(0,1);
lcd.print("Relay 6 OFF ");
digitalWrite(9, 0); // Relay6 off
break;
case 'g': lcd.setCursor(0,1);
lcd.print("Relay 7 OFF ");
digitalWrite(10, 0); // Relay7 off
break;
case 'h': lcd.setCursor(0,1);
lcd.print("Relay 8 OFF ");
digitalWrite(11, 0); // Relay8 off
break;
//----------------------------koneksi
case 'R': lcd.setCursor(0,1);
lcd.print("Koneksi OK ");
break;
case 'r': lcd.setCursor(0,1);
lcd.print("Koneksi OFF ");
break;
}
}


How it Works

1. Connect the Arduino with Peripherals needed
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino

4. Initial display during 2 second



5. Waiting for connection between PC and Arduino



    * Tunggu Koneksi (Bahasa Indonesia) --> Waiting for connection 
6. Connect Arduino to USB Port on your PC / Laptop
7. Open the Delphi program that you've been downloaded (On the end of this page)


8.  Set your serial port number of Arduino by select the setup button on the program.


9. Every computer / PC or laptop have a different serial port number, so you've to select one which
    Arduino  connected on it

10. Set the baud rate value by 9600, and just ignore the other column :) and then click Ok.
11. Click Connect button to begin the controlling, The LCD 16*2 will display like an image below


       * Koneksi OK --> Connected
12. Select on which button of the relay you want to controll it by click on its button.
13. When the button is clicked, for example the relay 1 button, LCD will display

      so do the other button


Video for Project III - 6. Control 8 Channel Relay with Delphi Apps on PC (Arduino Based)



Download required file

Related Posts

2 comments:

  1. hi thanks for that so much useful tutorial
    can I ask you to send me the full program to edit it as I has 12 relays
    Thanks in advance

    ReplyDelete
  2. Hi, I am have trouble with the relays running wild. Please see my post at
    https://forum.arduino.cc/t/run-away-relays-when-external-power-applied/896918

    ReplyDelete