Hi, I have project to make Modbus Relay. I use Arduino Uno, TTL to RS485 (max485) module, and relay 1 CH. When programming and I upload the program to Arduino Uno, the relay work normal with no issue (use power from USB). But when I Use buck converter LM2596S Module for buck from 24 V to 5V, the relay always contact (not using power from USB). This relay use LOW trigger to contact. Here the program and the wiring diagram
#include <SoftwareSerial.h>
#include <ModbusRTUSlave.h>
const uint8_t rxPin = 10; //for RO
const uint8_t txPin = 11; //for DI
const uint8_t dePin = 13; //for DE_RE
SoftwareSerial ModbusSer(rxPin, txPin);
ModbusRTUSlave ModbusSlave(ModbusSer, dePin); // serial port, driver enable pin for rs-485 (optional)
bool coils[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // Initiation Coil Status
const int pinD4 = 4; //For Trigger Relay
void setup() {
pinMode(pinD4, OUTPUT);
ModbusSlave.configureCoils(coils, 8); // bool array of coil values, number of coils
Serial.begin(9600);
ModbusSlave.begin(2, 38400); // slave id, baud rate, config (optional)
}
void loop() {
ModbusSlave.poll();
if (coils[0] == 1)
{
digitalWrite(pinD4, LOW);
}
else
{
digitalWrite(pinD4, HIGH);
}
}
Best Regards
Caraka Tri
