Controlling KMTronic RS485 ModBus Relays by Loxone Miniserver and ModBus extension
DS18B20 Temperature Logger v1.0
NETBOARD
#include <UIPEthernet.h>
#include <OneWire.h>
OneWire ds(2); // on pin 2
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
EthernetServer server = EthernetServer(80);
void setup()
{
Serial.begin(9600);
uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
IPAddress myIP(192,168,1,189);
Ethernet.begin(mac,myIP);
server.begin();
}
void loop()
{
size_t size;
if (EthernetClient client = server.available())
{
while((size = client.available()) > 0)
{
uint8_t* msg = (uint8_t*)malloc(size);
size = client.read(msg,size);
Serial.write(msg,size);
free(msg);
}
DS1820();
client.println("<?xml version='1.0' encoding='UTF-8'?>");
client.println("<response>");
client.println("<sensor1>");
// ID
client.println("<id>");
for ( i = 0; i < 9; i++) { // we need 9 bytes
client.print(addr[i], HEX);
}
client.println("</id>");
// Temperature
client.println("<temp>");
client.println(celsius);
client.println("</temp>");
client.println("</sensor1>");
client.println("<version>");
client.println("<model>KMtronic DS1820 Temperature Logger</model>");
client.println("<ver>1.0</ver>");
client.println("</version>");
client.println("</response>");
client.stop();
}
}
void DS1820()
{
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}
Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr[i], HEX);
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
Serial.print(" Data = ");
Serial.print(present, HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");
}
How to Control a single relay through a USB port
A general purpose USB Relay controller for connection to a PC's USB port using VCP (Virtual COM port). Control devices using your PC. USB Relay controller allows a PC to control a single external device using simple RS232 commands. Relay is fully powered from the USB bus. Free download USB relay board control software.
USB Relay Module is great for controlling your devices through USB without any USB protocol knowledge.
This modules plugs in to your design seamlessly. Individual relay can be controlled by simple commands.
Drivers are available to work with the following operating systems:
Windows Server 2008 R2, Windows 7, Windows 7 x64, Windows Server 2008,
Windows Server 2008 x64, Windows Vista, Windows Vista x64, Windows Server 2003,
Windows Server 2003 x64, Windows XP, Windows XP x64, Windows 2000, Windows ME,
Windows 98, Linux, Mac OS X, Mac OS 9, Mac OS 8, Windows CE.NET (Version 4.2 and greater)
Communication Parameters:
8 Data, 1 Stop, No Parity
Baud rate : 9600
Commands:
OFF command: FF 01 00 (HEX) or 255 1 0 (DEC)
ON command: FF 01 01 (HEX) or 255 1 1 (DEC)
Meta tags: usb channel control, usb circuit relay, usb comand a realy, usb computer controlled relays, usb connection relay, usb connection to relay card, usb control boards, usb control device, usb controled relay, usb controler 12v, usb controllable relay card, usb controlled bnc relay, usb controlled dc relay, usb controlled relay board, usb controlled relay linux, usb controller rs232, usb controller с реле, usb detect relay contact, usb device command relay, usb device control by pc (relay), usb easy relay
Install UIPEthernet Arduino Ethernet library
1. Download the Arduino Software:
http://www.arduino.cc/en/Main/Software
2. Download UIPEthernet Arduino Ethernet library for ENC28J60:
https://github.com/ntruchsess/arduino_uip
https://github.com/ntruchsess/arduino_uip/archive/master.zip
3.
4.
KMTronic LAN Ethernet IP 8 channels UDP Relay board
Manufacturer:
KMTronic LTD
Features:
- Each relay has an LED to indicate when it is operated.
- Relay outputs can be used to turn ON/OFF lights, motors and other devices.
Specifications:
Relays have Normally Open (NO) and
Normally Closed (NC) Contacts each capable of switching max:
- 12VDC/15A
- 24VDC/15A
- 125VAC/15A
- 250VAC/10A
Supply:
Requires external 12 volt DC / 1000mA power supply
Operation Range:
Industrial (0°C to +80°C)
Dimensions:
108 mm / 150 mm / 25 mm (connectors mounted)
Default:
IP address: 192.168.1.199
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.1.1
UDP Port: 12345
UDP Commands:
FF0000 - Status Read command
FF0100 - Relay 1 OFF command
FF0101 - Relay 1 ON command
FF0200 - Relay 2 OFF command
FF0201 - Relay 2 ON command
FF0300 - Relay 3 OFF command
FF0301 - Relay 3 ON command
FF0400 - Relay 4 OFF command
FF0401 - Relay 4 ON command
FF0500 - Relay 5 OFF command
FF0501 - Relay 5 ON command
FF0600 - Relay 6 OFF command
FF0601 - Relay 6 ON command
FF0700 - Relay 7 OFF command
FF0701 - Relay 7 ON command
FF0800 - Relay 8 OFF command
FF0801 - Relay 8 ON command
FFE000 - All relays OFF command
FFE0FF - All relays ON command
UDP Test Software example including source code (C#):
KMTronic UDP Test Software.zip
KMTronic UDP Test Software Source Code.zip
KMTronic LAN Ethernet IP 2 channels UDP Relay board
Manufacturer:
KMTronic LTD
Features:
- Each relay has an LED to indicate when it is operated.
- Relay outputs can be used to turn ON/OFF lights, motors and other devices.
Specifications:
Relays have Normally Open (NO) and
Normally Closed (NC) Contacts each capable of switching max:
- 12VDC/15A
- 24VDC/15A
- 125VAC/15A
- 250VAC/10A
Supply:
Requires external 12 volt DC / 500mA power supply
Operation Range:
Industrial (0°C to +80°C)
Dimensions:
105 mm / 51 mm / 20 mm (connectors mounted)
Default:
IP address: 192.168.1.199
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.1.1
UDP Port: 12345
UDP Commands:
FF0000 - Status Read command
FF0100 - Relay 1 OFF command
FF0101 - Relay 1 ON command
FF0200 - Relay 2 OFF command
FF0201 - Relay 2 ON command
FFE000 - All relays OFF command
FFE003 - All relays ON command
UDP Test Software example including source code (C#):
KMTronic UDP Test Software.zip
KMTronic UDP Test Software Source Code.zip
Customers and Partners
Programmers using our products range from individuals
and small businesses to universities, large corporations,
and government agencies.
Here is a partial list of customers who have purchased
KMtronic products for their commercial
and in-house development needs.
If you or your company uses KMtronic's product
please send mail to us and we'll be glad to post a link
back to your web site.
http://www.peekelectronics.co.uk
us-boards - electronic boards manufacturer
Buy online electronic controllers and relay boards
www.Riedon.com
Each Riedon resistor is crafted at the highest quality to ensure reliable and rugged performance
www.pi-tec.com
Museum Exhibit Design, Manufacture and Installation
We use your USB relays in our product. We designed a sound level measuring system in combination with labview software. When a sound level limit is exceeded, the KMtronic USB relay is energised which turns on a signaling device. Greeting from The Netherland, Walter Hennissen
Android home automation software
Our Solutions could ease your life !
RS485 8 Channel Relay Controller
The general purpose of RS-485 Eight Channel Relay Controller. Control devices using your PC.
Features:
Option to change the ID (from ID 01 to ID 15) manually through a DIP Switch placed near RS485 connector.
Manufacturer:
KMtronic LTD
Complete including:
One RS485 8 channels relay board
Dimensions:
KMTronic_8Relay_Dimension.pdf
Relay specifications:
Relays have Normally Open (NO) and
Normally Closed (NC) Contacts each capable
of switching max:
- 12VDC/15A
- 24VDC/15A
- 125VAC/15A
- 250VAC/10A
Relay datasheed:
www.info.kmtronic.com/manuals/RAS.pdf
Supply:
Required power 12VDC/1000mA
Operation Range:
0°C to +80°C
Communication Parameters:
8 Data, 1 Stop, No Parity
Baud rate : 9600
Commands:
OFF command : FF xx 00 (HEX) or 255 xx 0 (DEC)
ON command : FF xx 01 (HEX) or 255 xx 1 (DEC)
Full list commands:
www.info.kmtronic.com/kmtronic-rs485-relays-commands.html
Software Examples:
www.info.kmtronic.com/usb-rs232-rs485-relays.html
.
USB One Channel Relay BOX for DC Power
A general purpose Relay board for connection to a PC's USB port using VCP (Virtual COM port). Control devices using your PC. USB Relay controller allows a PC to control external devices using simple RS232 commands. Relay is fully powered from the USB bus.
Manufacturer:
KMtronic LTD
Features:
- Fully assembled and tested
- Fully powered from USB
- For 12V/24VDC 2A max.
- Can be used with LabVIEW, ProfiLab, DAQFactory, TestPoint, DASYLab, VEE
USB to serial interface:
FTDI FT232RL Chip
www.ftdichip.com/Products/ICs/FT232R.htm
Complete including:
One USB relay board
Dimensions (PCB board):
100 mm / 58 mm / 24 mm
Cable specifications:
Capable of switching max:
- 12VDC/2A
- 24VDC/2A
Connectors:
Connector Type A: 2.1mm DC Socket
Connector Type B: 2.1mm DC Plug
Cable Length 40-45 cm
Relay datasheed:
www.info.kmtronic.com/manuals/RAS.pdf
Supply:
Fully powered from USB
Operation Range:
0°C to +80°C
Drivers :
All Windows systems, Windows RT, Linux,
Mac OS 8, Mac OS 9, Mac OS X,
Android, Raspberry Pi, Arduino ADK,
Arduino with USB Host Shield...
www.ftdichip.com/FTDrivers.htm
Communication Parameters:
8 Data, 1 Stop, No Parity
Baud rate : 9600
Commands:
“FF 01 00” (HEX) or “255,1,0” (DEC) - OFF command
“FF 01 01” (HEX) or “255,1,1” (DEC) - ON command
“FF 01 03” (HEX) or “255,1,3” (DEC) - Status request
NOTE : Each command consists in 3 binary bytes (shown in hexadecimal below) without any space!
Windows Test software:
www.info.kmtronic.com/kmtronic-usb-relay-test-software.html
Customers projects:
www.info.kmtronic.com/kmtronic-customers-projects.html
Software Examples:
www.info.kmtronic.com/usb-rs232-rs485-relays.html
.
USB Host Relay board: Keyboard example

Example control relays using USB Keyboard.
For project you need USB Host Relay board, 12VDC power and USB Keyboard.
Select from Tools -> Arduino AVR Boards -> Arduino Mega ADK
Then select com port.
After upload sketch when you press key '8' first relay turn ON, when press key '2' turn OFF.
Using keyboard you can control all relays using one key, or using combinations.
Some ideas:
- When you type "1234" and ENTER this to turn ON relay 1. Using this you can make simple Door Opener.
- When you press "1" board execute combination for simple automation. Turn ON relay 1, after 10 sec turn OFF and turns ON relays 2 and 3… When you press button "2" this run other combination.
- Build universal relay timer. When you type "45" and ENTER relay 1 turn ON and turn OFF after 45 seconds
- and many more
Example code
