[SOLVED]
Guys i am trying to use an esp32 with KQ-330 power line communication mode to send a signal over the power lines of he house to turn on and off a bulb continuiusly.
my circuit is really simple:-
Esp32 --> Kq-330(transmit)-----Power line-----Kq-330(receive)-->arduino uno-->relay-->bulb(on/off)
The problem:-
I unable to establish a successful serial communication with the Kq-330 module with the esp32 on the transmission side.
To check whether the Kq-330 module was working fine i used a simple usb to ttl converter with a serial terminal emulator(tera term)
to send serial data to the KQ-330 module and it worked like a charm.
But serial communication doesn't seem to work with esp32, i followed all the specification given in the specs sheet(9600bps, 8bit 1 stop bit).The datasheet for KQ-330 is attached
As for the connection:
- the 5v of KQ-330 is connected to Vin of ESP-32 ,
- gnd of KQ-330 to gnd of ESP-32
3.RX of KQ-330 to TX of ESP 32
Since the project works with serial terminal and usb converter i guess there is no problem on the arduino (reveiving) side. And the esp32 is also fine, as i checked it by sending and receiving the data between the usart1 and usart2 of esp32 and it was working
The code of both the ends is given below
ESP32 CODE FOR TRANSMISSION:
HardwareSerial Sender(1); // Define a Serial port instance called 'Sender' using serial port 1
void setup() {
Serial.begin(9600); // Define and start serial monitor
Sender.begin(9600, SERIAL_8N1, 13, 12); // Define and start Sender serial port
}
void loop() {
Sender.write('t'); // command to turn bulb on
delay(500);
Sender.write('o'); // command to turn bulb off
delay(500);
}
ARDUINO UNO CODE RECEIVING END(ignore the lcd code):-
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
int ADC1_PIN = A4;
int ADC1_VAL;
int ADC2_PIN = A2;
int ADC2_VAL;
int ADC3_PIN = A3;
int ADC3_VAL;
int ADC4_PIN = A1;
int ADC4_VAL;
int ADC5_PIN = A0;
int ADC5_VAL;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
// Print a message to the LCD.
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
lcd.print(" WELCOME ");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" POWER LINE ");
lcd.setCursor(0, 1);
lcd.print(" COMMUNICATION ");
delay(1000);
digitalWrite(7,HIGH);
digitalWrite(6,HIGH);
lcd.clear();
}
void loop() {
String readString;
String Q;
while (Serial.available()){
delay(10);
if(Serial.available()>0){
char c = Serial.read();
if (isControl(c)){
break;
}
readString += c;
}
}
Q = readString;
lcd.setCursor(0, 0);
lcd.print(" HOME ");
lcd.setCursor(0, 1);
lcd.print(" AUTOMATION ");
delay(10);
if (Q=="o"){
digitalWrite(6,HIGH);
}
if (Q=="t"){
digitalWrite(6,LOW);
}
}
20140619104969976997.zh-CN.en.pdf (557 KB)