-
Aug 11th, 2024, 10:12 AM
#1
Interfacing VB6 with a physical relay
Ok, I've got an idea I'd like to pursue. Let me outline the idea, and then I'll provide the need for it.
Here's a standard two-pole single-throw relay:
I know what to do with Terminals A1, A2, B1, & B2. And just as an FYI, they'll be very low voltage and amperage.
My problem is how to activate the coil terminals from VB6. Obviously, the relay will require some kind of voltage, but I haven't purchased the relay, so I'm very flexible on that. But, I'd like to supply that voltage based on decisions made by a VB6 program.
So, has anyone done anything similar to this before? I'm not sure if I should be thinking USB or possibly an RS232 card, or something else (maybe some dedicated card).
The rationale/need for this.
As some of you know, I've got a solar farm with 32 panels on it. When the sun is out (and relatively high), I make enough electricity to completely run my house. In fact, when the HVAC isn't running, I'm selling most of it back to TVA (Tennessee Valley Authority). But, here's the rub. TVA pays me ten-cents-on-the-dollar for what I pay my local utility for the same amount.
Ok, more of the rub. On a partly cloudy day (of which there are many), my solar production drops dramatically when the sun goes behind a cloud. And also, on summer days like today, my HVAC is frequently kicking on-and-off.
If I could synchronize the HVAC coming on when the sun is NOT behind a cloud, I could save lots of money.
How would I synchronize? Well, that part isn't as bad as you'd think. I've got a solar production monitor (in VB6) all up and running:
As you can see, with neither HVAC running, I'm making 5,000.6 surplus watts, selling them to TVA for ten-cents-on-the-dollar. I'd MUCH rather just use that electricity, rather than buy it back a few minutes later for 10X what I just sold it for.
So, when my HVAC wants to turn on, I could ask my solar production log files if production is high enough (or if it's been high enough in, say, the last 20 minutes). If it's been high enough in the last 20 minutes but it's not right now, I might just wait and see if it goes back up (sun coming out from behind a cloud). This would take some heuristic tinkering to optimize, but that'd be the fun part. Also, I'd need to put in some "time-of-day" considerations, and let the HVAC run at night. But that's all pretty easy stuff for VB6.
So, the big unknown for me is how to open-and-close a relay with VB6.
Any experiences or ideas you'd like to share would be much appreciated.
Last edited by Elroy; Aug 11th, 2024 at 10:20 AM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Aug 11th, 2024, 10:39 AM
#2
Re: Interfacing VB6 with a physical relay
Hmmm, I'm thinking maybe something like this:
However, I've never messed with sending signals to a USB port from VB6. I think it comes with some C examples. Ideally, it'd come with a little DLL and some API documentation.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Aug 11th, 2024, 11:48 AM
#3
Lively Member
Re: Interfacing VB6 with a physical relay
There is CH340 chip on that board. It is USB-To-Serial converter. You can send commands to the relays via serial port very easy.
-
Aug 11th, 2024, 12:09 PM
#4
Re: Interfacing VB6 with a physical relay
Originally Posted by Zann
There is CH340 chip on that board. It is USB-To-Serial converter. You can send commands to the relays via serial port very easy.
So, even though I connect that board to my computer via a USB cable, I can still interface to it like it's a serial port?
I can't find any documentation for that board. I just found it on Amazon. It's only $10, so I may just chance it. I think I'll wait a bit to see if anyone else has done this kind of thing.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Aug 11th, 2024, 12:13 PM
#5
Lively Member
Re: Interfacing VB6 with a physical relay
Originally Posted by Elroy
So, even though I connect that board to my computer via a USB cable, I can still interface to it like it's a serial port?
Yes, correct.
I found this
LC USB switch protocol:
Data (1) --- starting identity (the default is 0xA0)
Data (2) --- switch address code (default is 0x01, identifying the first channel switch)
Data (3) --- Operating Data (0x00 to "Off", 0x01 "On")
Data (4) --- checksum
Example:
Open USB switch: A0 01 01 A2
Close USB switch: A0 01 00 A1
You only need to send 4 bytes to control the relay.
-
Aug 11th, 2024, 12:49 PM
#6
Fanatic Member
Re: Interfacing VB6 with a physical relay
Arduino-based boards(<$10) mostly use CH340 chip, which basically acts as a serial port dongle to the PC. Every time you plug it in and out(not sure about restarting), it uses a different COM port, so you need to loop(and trap the error) to find the correct one. You send it commands from VB6 using the COMM Control, and on Arduino, you use Serial.Read() to read one byte at a time. Typically the Arduino code is only 10 lines for your use case, and we probably will write it for you.
There are Arduino-based boards that use the ESP32 WiFi chip(~$12), and that's another way to talk to it, using MS Winsock control.
However, HVAC usually use high current, and you need a big relay. There are relays with different name called "contactor". They are designed for high currents. Thermostats are typically low voltage(up to 24V AC). They send 24v signal to a contactor which is inside the HVAC. Here is what it looks like:
https://www.homedepot.com/s/contactor?NCNI-5
If you are adventurous, for historical reasons modern thermostats send 24VAC signal to turn heating/cooling on/off. Some HVAC systems have a reverse valve if they use the same heat pump for heating and cooling, the reverse switch is used to change heat pumping direction, so you get cooling instead of heating. See thermostat wire colors here:
https://en.wikipedia.org/wiki/Thermo...lt_thermostats
Cooling typically use the Yellow wire, and if you open your HVAC cover, to see how the thermostat connect to it, you will see it goes to a connector, with labels. The one for cooling is labeled Y.
I think there are Arduino based thermostats out there, with full source code, but it might be too much work.
-
Aug 11th, 2024, 01:07 PM
#7
Lively Member
Re: Interfacing VB6 with a physical relay
You have tons of options to do that. Take a look form example to devices with Tasmota firmware, you can manage those devices using a very easy api, WiFi integrated so you can manage remote devices inside (or outside) your lan, etc.
-
Aug 11th, 2024, 01:13 PM
#8
Fanatic Member
Re: Interfacing VB6 with a physical relay
Here is a Youtube video showing how to interface Arduino to a Contactor:
https://www.youtube.com/watch?v=M4Zsklj5_FQ
He's using a simple relay connecting to a 24VAC transformer so that is forwarded to the contactor. You can buy a 24VAC adapter from Amazon:
https://www.amazon.com/s?k=24vac+power+supply
-
Aug 11th, 2024, 01:15 PM
#9
Fanatic Member
Re: Interfacing VB6 with a physical relay
Originally Posted by zx81sp
You have tons of options to do that. Take a look form example to devices with Tasmota firmware, you can manage those devices using a very easy api, WiFi integrated so you can manage remote devices inside (or outside) your lan, etc.
As far as I know, these are typically up to 15A WiFi outlets, and HVAC uses like 30A.
-
Aug 11th, 2024, 01:19 PM
#10
Re: Interfacing VB6 with a physical relay
Originally Posted by qvb6
However, HVAC usually use high current, and you need a big relay. There are relays with different name called "contactor". They are designed for high currents. Thermostats are typically low voltage(up to 24V AC). They send 24v signal to a contactor which is inside the HVAC.
Yes, I'll just be tapping into the Yellow (cool signal) wire of my thermostats. Yeah, they're 24v, but very low amperage. I'm sure pretty much any relay I got would handle it.
Actually, I've already tapped into those Yellow wires (of both my HVAC units) for another purpose. And fortunately, they're all in the hallway directly opposite my office, and where the computer is that'd be handling this. I've already got a box on the wall that something like 20 ethernet wires run into. A few more wires would be simple.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Aug 12th, 2024, 09:51 AM
#11
Re: Interfacing VB6 with a physical relay
If you do not leave the interface board always connected, there is a way to limit the number of virtual serial ports that can be created also.
-
Aug 13th, 2024, 02:21 AM
#12
Lively Member
Re: Interfacing VB6 with a physical relay
Originally Posted by qvb6
As far as I know, these are typically up to 15A WiFi outlets, and HVAC uses like 30A.
You have boards with 30A relays, one, two, four channels...or just in Amazon, you have a lot of them with 30A relays for less than 15$.
-
Aug 13th, 2024, 09:40 AM
#13
Fanatic Member
Re: Interfacing VB6 with a physical relay
Originally Posted by zx81sp
You have boards with 30A relays, one, two, four channels...or just in Amazon, you have a lot of them with 30A relays for less than 15$.
This is beyond the scope of this forum, but I will say that relays are not suitable for high inrush current, they cause arcing and faster degradation of contacts, while contactors are designed to prevent arcing, so they last longer, and they are very close to the price of relays. Please see the GIF animation in this page, which shows a cutaway contactor in operation:
https://en.wikipedia.org/wiki/Contactor
I won't trust Amazon with this, just in case they carry counterfeit or poor quality products. I only found one 30A relay, with bad reviews, like it stopped working after few months, or solder everywhere on the PCB. If you buy form them, look for UL listed, and lookup the number to make sure it's registered by the same company, or spend few dollars more and buy from a reliable source.
-
Aug 13th, 2024, 02:34 PM
#14
Lively Member
Re: Interfacing VB6 with a physical relay
Elroy, look at this board. It has 2 relays controlled via LAN. There is VB6 source code at the bottom of the page.
Link
-
Aug 13th, 2024, 05:05 PM
#15
Re: Interfacing VB6 with a physical relay
Originally Posted by Zann
Elroy, look at this board. It has 2 relays controlled via LAN. There is VB6 source code at the bottom of the page.
Ohhhh, I like the idea of controlling it over my LAN. That idea alone is worth this entire thread. All my routers and switches are on shelves on the wall directly behind where my thermostat wires run, so this would be easy.
Also, interestingly, the device you recommended comes with VB6 source code. I downloaded it and took a look.
Sadly, that exact device is out of stock on Amazon, but there is a newer model:
This is interesting enough that I might pull the trigger on this project soon. If controlling that thing is as simple as it seems, I can see my way through getting this done.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Aug 14th, 2024, 01:31 AM
#16
Re: Interfacing VB6 with a physical relay
How do you setup IP address/mask on such headless devices I’m wondering or are they using DHCP by default?
-
Aug 14th, 2024, 01:51 AM
#17
Lively Member
Re: Interfacing VB6 with a physical relay
There is Config Utility software.
Connect to default IP address 192.168.1.100 then change it to your needs.
-
Aug 14th, 2024, 08:49 AM
#18
Fanatic Member
Re: Interfacing VB6 with a physical relay
Originally Posted by wqweto
How do you setup IP address/mask on such headless devices I’m wondering or are they using DHCP by default?
If you are making your own device, you can auto detect such device from VB by using broadcast packets. You use UDP in this case, and send to "255.255.255.255", but you also need to pick a port number that no one uses. You need to call setsockopt() and specify SO_BROADCAST. The device in return could send a broadcast back, to the same port. If both are on the same subnet, then the device can just reply back to the sender IP directly, instead of broadcast.
Also, samples that come with WiFi chips such as ESP32 send diagnostic data through the serial port/USB chip, which the PC sees as a COM port. It prints the IP address that it got from a router there. Arduino IDE includes a serial terminal viewer under Tools-->Serial Monitor, so you can see the IP during development.
-
Aug 14th, 2024, 09:17 AM
#19
Re: Interfacing VB6 with a physical relay
Oh goodness. Y'all are giving me concerns.
Yeah, I guess I assumed they had DHCP built in, and that I could just go through and ping reasonable IPs and find it. That's the way I'm finding my Curb energy monitoring device (and I've got that all worked out ... see thread here). I just assumed (maybe wrong) that I could do the same with this device.
I'm not crazy about the idea of a static IP, because I hate keeping track of those things. Not even my NAS box nor anything on my LAN is static these days.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Aug 14th, 2024, 10:07 AM
#20
Fanatic Member
Re: Interfacing VB6 with a physical relay
Sorry, I was giving an alternative idea how to auto detect an IP address without doing a scan, but it requires that the device's firmware responds to broadcast packets. This would make it easy to configure for the end user who may not know how to use their router admin pages. It would work whether there is a router(using DHCP) or not, so you get less tech support requests. Basically I was explaining how to make a tool like in the picture that Zann posted.
-
Aug 14th, 2024, 10:19 AM
#21
Re: Interfacing VB6 with a physical relay
DHCP for "server" devices is not a very good idea though i.e. printers, routers, relays, etc. has to be discoverable on predetermined addresses IMO.
cheers,
</wqw>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|