Here we have 4 different projects about Power line communication using KQ-130F / KQ-330 and Arduino.
Parts list:
Arduino board
Power line communication module KQ-130F / KQ-330
FTDI (USB to TTL serial converter)
LCD 16X2 with I2C
Common mode chock
Power Supply 5V 1A
Filtering Circuit:
First Project:
This code sending "Hello" to the receiver every 2 seconds
Receiver Circuit:
Transmitter Circuit:
Watch this video for more details:
VIDEO
Code:
void setup () {
Serial . begin ( 9600 ); // To Computer
Serial1 . begin ( 9600 ); // To KQ-130/330
}
void loop () {
// Send "Hello" to the power line
Serial1 . println ( "Hello" );
// If the module receives something from the power line, print it to the screen
while ( Serial1 . available ()) {
Serial . write ( Serial1 . read ());
}
delay ( 2000 );
}
Second Project:
This code control 5 LEDs (Red, green, blue, yellow and white) using serial command.
For example to turn on the Red you have to write " RED ON " in serial monitor
To turn off the Red you have to write " RED OFF " in serial monitor
The same thing for other colors.
You can also turn on all LEDs at the same time using this command " ALL ON "
const int RED = 2 ;
const int GREEN = 3 ;
const int BLUE = 4 ;
const int WHITE = 5 ;
const int YELLOW = 6 ;
void setup () {
Serial . begin ( 9600 );
Serial1 . begin ( 9600 );
pinMode (RED, OUTPUT);
pinMode (GREEN, OUTPUT);
pinMode (BLUE, OUTPUT);
pinMode (WHITE, OUTPUT);
pinMode (YELLOW, OUTPUT);
Serial . println ( "System Ready: Sending ALL-ON / ALL-OFF now supported." );
}
void loop () {
if ( Serial1 . available () > 0 ) {
String burst = Serial1 . readStringUntil ( ' \n ' );
burst . toUpperCase ();
// --- MASTER COMMANDS (ALL) ---
if ( burst . indexOf ( "ALL" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) {
digitalWrite (RED, HIGH);
digitalWrite (GREEN, HIGH);
digitalWrite (BLUE, HIGH);
digitalWrite (WHITE, HIGH);
digitalWrite (YELLOW, HIGH);
}
else if ( burst . indexOf ( "OFF" ) != - 1 ) {
digitalWrite (RED, LOW);
digitalWrite (GREEN, LOW);
digitalWrite (BLUE, LOW);
digitalWrite (WHITE, LOW);
digitalWrite (YELLOW, LOW);
}
}
// --- INDIVIDUAL COLORS ---
// RED
if ( burst . indexOf ( "RED" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) digitalWrite (RED, HIGH);
else if ( burst . indexOf ( "OFF" ) != - 1 ) digitalWrite (RED, LOW);
}
// GREEN
if ( burst . indexOf ( "GREEN" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) digitalWrite (GREEN, HIGH);
else if ( burst . indexOf ( "OFF" ) != - 1 ) digitalWrite (GREEN, LOW);
}
// BLUE
if ( burst . indexOf ( "BLUE" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) digitalWrite (BLUE, HIGH);
else if ( burst . indexOf ( "OFF" ) != - 1 ) digitalWrite (BLUE, LOW);
}
// WHITE
if ( burst . indexOf ( "WHITE" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) digitalWrite (WHITE, HIGH);
else if ( burst . indexOf ( "OFF" ) != - 1 ) digitalWrite (WHITE, LOW);
}
// YELLOW
if ( burst . indexOf ( "YELLOW" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) digitalWrite (YELLOW, HIGH);
else if ( burst . indexOf ( "OFF" ) != - 1 ) digitalWrite (YELLOW, LOW);
}
// Clear buffer for the next burst
while ( Serial1 . available () > 0 ) Serial1 . read ();
}
}
Third Project:
This code is similar to the previous one, except i used a relay instead of white LED and connect it to 220V AC light bulb.
To turn on the light bulb you have to write " Lamp ON " in serial monitor
const int RED = 2 ;
const int GREEN = 3 ;
const int BLUE = 4 ;
const int LAMP = 5 ; // Changed from WHITE to LAMP
const int YELLOW = 6 ;
void setup () {
Serial . begin ( 9600 );
Serial1 . begin ( 9600 );
pinMode (RED, OUTPUT);
pinMode (GREEN, OUTPUT);
pinMode (BLUE, OUTPUT);
pinMode (LAMP, OUTPUT);
pinMode (YELLOW, OUTPUT);
// Normal situation: All LEDs OFF, Lamp pin HIGH (OFF for active-low)
digitalWrite (RED, LOW);
digitalWrite (GREEN, LOW);
digitalWrite (BLUE, LOW);
digitalWrite (YELLOW, LOW);
digitalWrite (LAMP, HIGH); // LAMP starts HIGH (Normal/Off)
Serial . println ( "System Ready. Lamp is currently HIGH (OFF)." );
}
void loop () {
if ( Serial1 . available () > 0 ) {
String burst = Serial1 . readStringUntil ( ' \n ' );
burst . toUpperCase ();
// --- MASTER COMMANDS (ALL) ---
if ( burst . indexOf ( "ALL" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) {
digitalWrite (RED, HIGH);
digitalWrite (GREEN, HIGH);
digitalWrite (BLUE, HIGH);
digitalWrite (YELLOW, HIGH);
digitalWrite (LAMP, LOW); // Inverse: On = LOW
}
else if ( burst . indexOf ( "OFF" ) != - 1 ) {
digitalWrite (RED, LOW);
digitalWrite (GREEN, LOW);
digitalWrite (BLUE, LOW);
digitalWrite (YELLOW, LOW);
digitalWrite (LAMP, HIGH); // Inverse: Off = HIGH
}
}
// --- INDIVIDUAL CONTROL ---
// LAMP (Inverse Logic)
if ( burst . indexOf ( "LAMP" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) digitalWrite (LAMP, LOW);
else if ( burst . indexOf ( "OFF" ) != - 1 ) digitalWrite (LAMP, HIGH);
}
// RED
if ( burst . indexOf ( "RED" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) digitalWrite (RED, HIGH);
else if ( burst . indexOf ( "OFF" ) != - 1 ) digitalWrite (RED, LOW);
}
// GREEN
if ( burst . indexOf ( "GREEN" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) digitalWrite (GREEN, HIGH);
else if ( burst . indexOf ( "OFF" ) != - 1 ) digitalWrite (GREEN, LOW);
}
// BLUE
if ( burst . indexOf ( "BLUE" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) digitalWrite (BLUE, HIGH);
else if ( burst . indexOf ( "OFF" ) != - 1 ) digitalWrite (BLUE, LOW);
}
// YELLOW
if ( burst . indexOf ( "YELLOW" ) != - 1 ) {
if ( burst . indexOf ( "ON" ) != - 1 ) digitalWrite (YELLOW, HIGH);
else if ( burst . indexOf ( "OFF" ) != - 1 ) digitalWrite (YELLOW, LOW);
}
// Clear buffer
while ( Serial1 . available () > 0 ) Serial1 . read ();
}
}
4th project:
This is a pager so when you write a message, it appears on the 16x2 LCD.
You need to start and end your message with two brackets like this [[ Your message here ]] .
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x 27 , 16 , 2 );
const int buzzerPin = 7 ;
String currentMsg = "" ;
void setup () {
Serial . begin ( 9600 );
Serial1 . begin ( 9600 );
pinMode (buzzerPin, OUTPUT);
digitalWrite (buzzerPin, LOW);
lcd . init ();
lcd . backlight ();
lcd . print ( "Triple Beep Mode" );
delay ( 1500 );
lcd . clear ();
}
void loop () {
if ( Serial1 . available () > 0 ) {
String raw = Serial1 . readStringUntil ( ' \n ' );
int startIdx = raw . indexOf ( "[[" );
int endIdx = raw . indexOf ( "]]" );
if (startIdx != - 1 && endIdx != - 1 && endIdx > startIdx) {
String cleanMsg = raw . substring (startIdx + 2 , endIdx);
String filteredMsg = "" ;
for ( int i = 0 ; i < cleanMsg . length (); i++) {
if ( cleanMsg [i] >= 32 && cleanMsg [i] <= 126 ) {
filteredMsg += cleanMsg [i];
}
}
if ( filteredMsg . length () > 0 && filteredMsg . length () <= 32 ) {
// Only alert if the message is new
if (filteredMsg != currentMsg) {
updateLCD (filteredMsg);
playTripleBeep ();
}
}
}
}
}
void updateLCD (String msg) {
currentMsg = msg;
lcd . clear ();
if ( msg . length () <= 16 ) {
lcd . setCursor ( 0 , 0 );
lcd . print (msg);
} else {
lcd . setCursor ( 0 , 0 );
lcd . print ( msg . substring ( 0 , 16 ));
lcd . setCursor ( 0 , 1 );
lcd . print ( msg . substring ( 16 , 32 ));
}
}
// The new, less annoying notification sound
void playTripleBeep () {
for ( int i = 0 ; i < 3 ; i++) {
digitalWrite (buzzerPin, HIGH);
delay ( 150 ); // Short beep
digitalWrite (buzzerPin, LOW);
delay ( 100 ); // Short silence between beeps
}
}