---
title: "WIZnet S2E Light Control"
url: "https://maker.wiznet.io/WIZnet/projects/wiznet-s2e-light-control/"
markdown_url: "https://maker.wiznet.io/WIZnet/projects/wiznet-s2e-light-control/md"
type: "UCC: User Created Content"
author: "Peter Ma"
author_url: "https://www.hackster.io/s2elighting/wiznet-s2e-light-control-1cd468"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Peter Ma"
original_url: "https://www.hackster.io/s2elighting/wiznet-s2e-light-control-1cd468"
published: "2023-02-12"
language: "en"
hardware: ["WIZnet WIZ750SR-100"]
likes: 3
views: 304
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# WIZnet S2E Light Control

> Using Arduino and WIZ750SR to control the smart building lighting system.

Original author: Peter Ma (source: https://www.hackster.io/s2elighting/wiznet-s2e-light-control-1cd468)

## Components

- **WIZnet WIZ750SR-100** x 1 ([docs](https://docs.wiznet.io/Product/S2E-Module/WIZ750SR-1xx-Series/WIZ750SR-100/))

## Article

### **Why Smart Lighting?**

Currently all the smart lighting is mainly controlled using apps, because of the Internet of Things situation, when sometimes no longer have the option of just turning the light on, especially when internet is off. My house is filled with smart lighting system, and just about 2 weeks ago when I couldn’t find my phone, I couldn’t turn any of my lights on.

![Philips Hue App](https://hackster.imgix.net/uploads/attachments/518637/install-meet-hue-philips-hue-light-system_GAjCC9b7gm.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Philips Hue App

This guide writes a step by step procedure on how to control your lights the old fashioned way using S2E and Rotary control for brightness.

### **Step 1: Gather Components**

Components for this application is very simple and all provided by hackster through 2 different challenges. All you need to purchase is a Philips Hue lightbulb, in this project we will use Philips Hue Go, but any Philips Hue bulb would work.

- Infineon’s 3D magnetic 2GO kit & Rotator Knob

- WIZ750SR S2E Kit

- Arduino Uno or 101

- Seeed Base Shield

- Seeed Rotary Angle Sensor

![Components](https://hackster.imgix.net/uploads/attachments/519520/img_20180708_231723_hxrwc4YrQ1.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

Components

### **Step 2: Connect the WIZ750SR**

With developer edition, we first can power up the WIZ750SR through micro-usb port. when everything is connected, we should see green LED on for connected to the ethernet, blue LED on for EtherNet add on working and red led on for device being powered on as figure below.

![WIZ750SR powered on](https://hackster.imgix.net/uploads/attachments/518647/img_20180623_011445__1__lnquLcxg7T.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

WIZ750SR powered on

After powering on we can download the configuration tool from <https://github.com/Wiznet/WIZnet-S2E-Tool-GUI>to check whether the device is working. Easiest way here is to go through IP allocation via DHCP, then go back to static to auto fill out the Network configuration

![WIZnet S2E Configuration Tool](https://hackster.imgix.net/uploads/attachments/518649/success_oYFS9YqJx6.PNG?auto=compress%2Cformat&w=740&h=555&fit=max)

WIZnet S2E Configuration Tool

The USB to UART driver can be downloaded if you are using the usb port. The Micro usb port that powers up the board will be the CP210x USB to UART Bridge used for debugging.

<https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers>

![UART Bridge](https://hackster.imgix.net/uploads/attachments/518650/uart_TgC0Rrz2HI.PNG?auto=compress%2Cformat&w=740&h=555&fit=max)

UART Bridge

We can use debug port to test out termite to test out the serial port, which can be downloaded from <https://www.compuphase.com/software_termite.htm>we should receive all the messages sending to COM port via debug usb

![How Termite works](https://hackster.imgix.net/uploads/attachments/518651/termite_DKVVtkQ7TI.PNG?auto=compress%2Cformat&w=740&h=555&fit=max)

How Termite works

As for the ethernet side we used ioninja’s tcp server listening <http://ioninja.com/plugins/tcp-listener.html>Once that’s successful we can test out whether these are in Sync, this allows to communicate from Serial to Ethernet

![Termite and IO Ninja](https://hackster.imgix.net/uploads/attachments/518648/sync_wTu2b98CU1.PNG?auto=compress%2Cformat&w=740&h=555&fit=max)

Termite and IO Ninja

### **Step 3: Program the Arduino**

We first need to get rotary knob to work, using following Arduino code we can easily record it through port A1

```plaintext
#define ROTARY_ANGLE_SENSOR A0
#define LED 3  //the Grove - LED is connected to PWM pin D3 of Arduino
#define ADC_REF 5 //reference voltage of ADC is 5v.If the Vcc switch on the seeeduino
                  //board switches to 3V3, the ADC_REF should be 3.3
#define GROVE_VCC 5 //VCC of the grove interface is normally 5v
#define FULL_ANGLE 300 //full value of the rotary angle is 300 degrees
int incomingByte = 0;   // for incoming serial data
void setup() {
// initialize the LED pin as an output:
Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
pinMode(ROTARY_ANGLE_SENSOR, INPUT);
pinMode(LED,OUTPUT);   
}
void loop() {
  float voltage;
  int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
  voltage = (float)sensor_value*ADC_REF/1023;
  float degrees = (voltage*FULL_ANGLE)/GROVE_VCC;
  //Serial.println("The angle between the mark and the starting position:");
  Serial.println(degrees);
  delay(100);
}
```

From here we can get the rotary running.

Rotary on Arduino

### **Step 4: Connect WIZ750SR to Arduino**

Since we’ve gotten the lock to work, we are now ready to setup the WIZ750SR, we can connect the WIZ750SR to Arduino UNO with relay like the image below. Arduino UNO only have Serial port that’s basically pin 0 and 1 for RX and TX

![Rotary Arduino to WizNET](https://hackster.imgix.net/uploads/attachments/519978/screen_shot_2018-07-09_at_2_44_31_pm_K8jP9B1GDp.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Rotary Arduino to WizNET

We can use following Arduino code to send rotary information to s2e.

```plaintext
#include <SoftwareSerial.h>
#define ROTARY_ANGLE_SENSOR A0
#define ADC_REF 5 //reference voltage of ADC is 5v.If the Vcc switch on the seeeduino                  //board switches to 3V3, the ADC_REF should be 3.3
#define GROVE_VCC 5 //VCC of the grove interface is normally 5v
#define FULL_ANGLE 300 //full value of the rotary angle is 300 degrees
int incomingByte = 0;   // for incoming serial data
float previous = 0;
char degreebuffer[20];
void setup() {
// initialize the LED pin as an output:
 Serial.begin(115200);     // opens serial port, sets data rate to 9600 bps
 pinMode(ROTARY_ANGLE_SENSOR, INPUT);
 //mySerial.begin(115200);
}
void loop() {
 float voltage;
 int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
 voltage = (float)sensor_value*ADC_REF/1023;
 float degrees = (voltage*FULL_ANGLE)/GROVE_VCC;
 //Serial.println("The angle between the mark and the starting position:");
 if(degrees != previous)
 {
   dtostrf(degrees, 0, 2, degreebuffer);
   Serial.write(degreebuffer);
   Serial.write('n');
 }
 previous = degrees;
 delay(100);
}
```

### **Step 5: Program Philips Hue**

To program hue, we first need to find out the ip of the Philips Hue Hub by visiting

<https://discovery.meethue.com/>

Once we find our internal ip we can go to

http://&lt;bridge ip address>/debug/clip.html

From here we can post to API and put message body type as

```plaintext
{"devicetype":"WIZNet_Controller#user"}
```

When we send message as a POST we should get a message like the link below, but that just means we have to click the link button to get the result

![First try](https://hackster.imgix.net/uploads/attachments/520179/screen_shot_2018-07-09_at_8_25_59_pm_7FNiClByUF.png?auto=compress%2Cformat&w=740&h=555&fit=max)

First try

We need to click on the Link button below

![Hue Hub Button](https://hackster.imgix.net/uploads/attachments/520181/hue_hub_V00ES0wnEH.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

Hue Hub Button

After clicking it we need to POST again to get our UserId

![Getting UserId](https://hackster.imgix.net/uploads/attachments/520182/screen_shot_2018-07-09_at_8_27_44_pm_l9cORlL4Pc.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Getting UserId

After that you can run the command

http://&lt;bridge ip address>/api/{userid}/lights to get all the lights you need

And for this example we will be using Hue Go. Use PUT method to test this out.

```plaintext
PUT http://<bridge ip address>/api/<username>/lights/1/state
{"bri":254}
```

We can try it on Postman

![Postman](https://hackster.imgix.net/uploads/attachments/520186/screen_shot_2018-07-09_at_8_39_16_pm_uTR8axWeA8.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Postman

Once this works we can move onto next step

![Lights connected](https://hackster.imgix.net/uploads/attachments/520188/img_20180709_204142_Xw03byUU1w.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

Lights connected

### **Step 6: Set Up Local Server on Your Computer**

We can create server code on almost any computer, as both WIZ750SR and Hue is operating on local network. The code below should work to get the entire operation running.

```plaintext
var http = require('http');
var net = require('net');
var client = new net.Socket();
client.connect(5000, '192.168.1.81', function() {
 console.log('Connected');
});
client.on('data', function(data) {
 if(!String(data).includes(";") || String(data).length < 3)
 {
   return;
 }
 var nums = String(data).split(';');
 var num;
 if(nums.length >=2)
 {
   num = parseFloat(nums[nums.length-2]);
 }
 else if(nums.length == 1)
 {
  num = parseFloat(nums[0]); 
 }
 var brightness = String(Math.floor(num/300*254));
 var options = {
   host: '<bridge ip address>',
   port: 80,
   path: 'api/<username>/lights/1/state',
   method: 'PUT'
 };
 var req = http.request(options, function(res) {
   console.log('STATUS: ' + res.statusCode);
   console.log('HEADERS: ' + JSON.stringify(res.headers));
   res.setEncoding('utf8');
   res.on('data', function (chunk) {
     console.log('BODY: ' + chunk);
   });
 });
 req.on('error', function(e) {
   console.log('problem with request: ' + e.message);
 });
 req.write('{"bri":' + brightness + '}');
 req.end();
 console.log('Received: ' + String(data));
 console.log('bri: ' + brightness);
});
client.on('close', function() {
 console.log('Connection closed');
});
```

Simply run this program in node and everything should work.

---

Source: https://maker.wiznet.io/WIZnet/projects/wiznet-s2e-light-control/
