# Sainsmart 16 Channel USB relay

**URL:** <https://forum.xojo.com/t/sainsmart-16-channel-usb-relay/76731>\
**Category:** Extras\
**Created:** [August 3, 2023, 5:22pm UTC](https://forum.xojo.com/t/sainsmart-16-channel-usb-relay/76731 "2023-08-03T17:22:09Z")\
**Posts on this page:** 5\
**Page:** 3

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [August 9, 2023, 12:31am UTC](https://forum.xojo.com/t/sainsmart-16-channel-usb-relay/76731/42 "2023-08-09T00:31:42Z")

</div>

> [@Paul\_Rodman](#):
>
> Didn’t you need to prefix the string with “:”?

That’s the “3A” at the beginning of outString. Python allows you to mix ascii characters (“:FE05”) with hex-escaped and special characters (\r\n).

That said, though, you should be able to send the original strings without encoding to hex.

This should work

> [@Jean-Yves\_Pochez](#):
>
> SerialConnection1.Write ":FE050000FF00FE”+chr(13)+chr(10)

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [August 9, 2023, 7:06am UTC](https://forum.xojo.com/t/sainsmart-16-channel-usb-relay/76731/43 "2023-08-09T07:06:16Z")

</div>

> [@Tim\_Hare](#):
>
> This should work
> 
> > [@Jean-Yves\_Pochez](#):
> >
> > SerialConnection1.Write ":FE050000FF00FE”+chr(13)+chr(10)

I think too, but OP said this did not work. the decodehex approach is essentially the same.

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [August 9, 2023, 7:08am UTC](https://forum.xojo.com/t/sainsmart-16-channel-usb-relay/76731/44 "2023-08-09T07:08:05Z")

</div>

> [@Michael\_Knudsen](#):
>
> but it seems to be rather inconsistent in the way it operates.  
> For example calling the same relay to turn off several times in a row can actually cause it to turn on.  
> Or calling realy1 on, then after few seconds off sometimes are inresponsive. Then trying again turns it off.
> 
> I think your code works flawless but the relay is simply not of good enough quality?

I think more of a bad firmware in the microcontroller on the board. these are entry level relays, but they do the job mostly.  
why in the first place do you have to send such a complicated string to power some relays ?  
at what frequancy does this bad behavior happen ? relay are not meant to be switched too fast.

---

<div class="post-metadata">

**Author:** ![Michael\_Knudsen](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@Michael\_Knudsen](https://forum.xojo.com/u/Michael_Knudsen)\
**Post date:** [September 9, 2023, 10:19am UTC](https://forum.xojo.com/t/sainsmart-16-channel-usb-relay/76731/45 "2023-09-09T10:19:12Z")

</div>

Sorry for the delay, but I have spent some time fiddling with the code and testing it.  
the outputs the code generates are consistant and correct, but the relay board indeed seems to have bad firmware.  
So the hunt begins for a high quality 16 channel relay.  
Thanks anyway for your support all 🙂

Btw. for people creating hobby projects this relay will probably be usefull and in this tread there is now the code to get it running so have fun guys 😃

---

<div class="post-metadata">

**Author:** ![Daniel\_Mullins](https://forum.xojo.com/user_avatar/forum.xojo.com/daniel_mullins/32/15747_2.png) [@Daniel\_Mullins](https://forum.xojo.com/u/Daniel_Mullins)\
**Post date:** [October 30, 2023, 5:04am UTC](https://forum.xojo.com/t/sainsmart-16-channel-usb-relay/76731/46 "2023-10-30T05:04:14Z")

</div>

> [@Jean-Yves\_Pochez](#):
>
> ink more of a bad firmware in the microcontroller on the board. these are entry level relays, but they do the job mostly.  
> why in the first place do you have to send such a complicated string to power some relays ?  
> at what frequancy does this bad behavior happen ? relay are not meant to be switched too fast.

Can you attempt to create the strings to send, and paste them into say, putty connected to the serial instead, to see if there is some other serial software issue with Xojo happening?

[Previous page](https://forum.xojo.com/t/sainsmart-16-channel-usb-relay/76731.md?page=2)
