How a Web Server on an STM32F103C8T6 can be used to control a Relay Switch

Here is the circuit showing how a Web Server on an STM32F103C8T6 can be used to control a Relay Switch:

BluePill As A Web Server With A Relay SwitchThe Fritzing code used to create that diagram/image can be downloaded here.

An ENC28J60 ethernet module is used to connect the STM32F103C8T6 (BluePill) to a network.

Here is the source code for the sketch to load into the STM32F103C8T6 (BluePill):

This is an updated and enhanced sketch from a previous post on a WEB server using both the BluePill (STM32F103C8T6) and the ENC28J60 module. It seems the UIPEthernet  library has changed since then. I had to add these lines to the code to define the correct pin settings:

The source code has the IP address and network settings for the ENC28J60 ethernet module hard coded. Those settings may need changed for use on a different network.

The relay switch can be attached to any number of AC type low current devices and turned ON/OFF by accessing the WEB server. (The relay switch can possibly handle low current DC devices as well). I used a 2N3904 NPN transistor in my circuit to allow the STM32F103CT6 to turn the relay OFF and ON. This circuit also has a red LED to visually show when the relay is ON or OFF.

The WEB server accepts several ‘commands’:

http://192.168.0.150/led

http://192.168.0.150/analog

http://192.168.0.150/switch

‘LED’ toggles the internal LED On/Off, ‘analog’ displays the analog values of the first 4 analog pins and ‘switch’ toggles the relay On/Off.  So now you know how a Web Server on an STM32F103C8T6 can be used to control a Relay Switch.

Leave a Reply

Your email address will not be published.