Peter Ma
Published © LGPL

WIZnet S2E Light Control

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

IntermediateFull instructions provided10 hours1,182

Things used in this project

Hardware components

WIZ750SR
WIZnet WIZ750SR
×1
Philips hue
Philips hue
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

WIZ750SR Wire Frame

WIZ750SR Wire Frame
Screen shot 2018 07 09 at 2 44 31 pm a7orihltxe

Code

Local nodejs code

JavaScript
Local nodejs code
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');
});

Arduino Code

Arduino
Arduino code
#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);
}

Credits

Peter Ma

Peter Ma

20 projects • 76 followers
Prototype Hacker, Intel Software Innovator, Hackathon Goer, World Traveler, Ecological balancer, integrationist, technologist, futurist.
Contact

Comments