Light & Interactivity : 💡 Final Floor Fixture (Floor Entrance) part II Week 7




First, we started testing my connection to the HUB. We connected to column 6, the success command response was definitely a great way to start the morning.



lastscan": "2022-03-04T15:51:22


"31": {

"state": {

"on": true,

"bri": 254,

"hue": 8417,

"sat": 140,

"effect": "none",

Our light was #31 - We checked out a Philips Hue lightbulb from the ER (I7549). Light #31 became ChriLo



-------


https://vimeo.com/showcase/6916443 - The videos were super helpful

HUE control - We had to capture the light from another HUB.

Troubleshooting the Connection with WPA - it took a bit a time to connect, I had to go back to the NYU computer registration website to make sure my Arduino was connected. It was connected, I worked on the connection the day before but only after visiting the site website again I was able to connect. Not sure if it this was an unrelated event but it worked.

Arduino Address:

MAC: 4C:11:AE:91:81:E4




Light Design/Construction

Christina and I are both interested in sustainability so we used mostly paper materials we found on the Junk Shelf. One man's trash is another man's treasure. In this case the treasure is a functioning lamp.




After our research we came to the conclusion that the space we got assigned is very hectic and difficult to focus. We wanted to work on a standing light, to create some focus on the plants and create a little Zen garden effect.





                                             




Arduino: We wanted to use a potentiometer and a switch. The potentiometer allows us to dim the light and the Switch is to turn on/off the light.

  • Board:  To keep the components on I soldered the potentiometer to the wires.
Useful links :


Testing the potentiometer

void setup() {
  Serial.begin(9600);
}
 
void loop() {
  int analogValue = analogRead(A0)/4; // read the sensor value
  Serial.println (analogValue);          // send the value serially as a binary value
}

---------
Program the Microcontroller to Read a Sensor Threshold Crossing // tipping point

int lastSensorState = LOW;   // sensor's previous state
int threshold = 512;   // an arbitrary threshold value
 
void setup() {
  Serial.begin(9600);
}
 
void loop() {
  // read the sensor:
  int sensorState = analogRead(A0);
 
  // if it's above the threshold:
  if (sensorState >= threshold) {
    // check that the previous value was below the threshold:
     if (lastSensorState < threshold) {
        // the sensor just crossed the threshold
        Serial.println("Sensor crossed the threshold");
     }
  }
  // save button state for next comparison:
  lastSensorState = sensorState;
}




  • Code: Special thanks to Wasif you helped us develop the code
//ER LIGHT BULB I744
// LIGH #31 NAME ChriLo

#include <SPI.h>
//#include <WiFi101.h>
#include <WiFiNINA.h>
#include <ArduinoHttpClient.h>
#include "arduino_secrets.h"

char hueHubIP[] = "172.22.151.181";  // IP address of the HUE bridge
String hueUserName = "e0pYvbu1tK1yPgiIWb08zCKzJhAuoDHR2fHffeMZ"; // hue bridge username

WiFiClient wifi;
HttpClient httpClient = HttpClient(wifi, hueHubIP);

long lastRequest = 0;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);

  // attempt to connect to Wifi network:
  while ( WiFi.status() != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(SECRET_SSID);
    // Connect to WPA/WPA2 network:
    WiFi.begin(SECRET_SSID, SECRET_PASS);
  }

  // you're connected now, so print out the data:
  Serial.print("You're connected to the network IP = ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);
}

int currentBrightnessLevel;
int previousBrightnessLevel = -1;
bool hasChanged = false;

void loop() {
  delay(2000);
  // Reading value from potentiometer
  // Threshold into 10 buckets

  int potentiometer = analogRead(A0);
  currentBrightnessLevel = map(potentiometer, 0, 1023, 0, 20); // FIXME this might be a mapping issue for full brightness
  
  // If no previousBrightness is set, set it
  if (previousBrightnessLevel == -1) {
    previousBrightnessLevel = currentBrightnessLevel;
  }
  
  // Detect change in state
  hasChanged = currentBrightnessLevel != previousBrightnessLevel;


//Debug  
//  Serial.print("potentiometer: ");
//  Serial.println(potentiometer);
//  Serial.print("currentBrightnessLevel: ");
//  Serial.println(currentBrightnessLevel);
//  Serial.print("previousBrightnessLevel: ");
//  Serial.println(previousBrightnessLevel);
//  Serial.print("hasChanged: ");
//  Serial.println(hasChanged);

  // Send a request every 3000 (3 seconds)
  if (millis() - lastRequest > 5) { // time it takes 
    // Don't do anything if state hasn't changed
    if (!hasChanged) {
      return;
    }

    // Dim Light & Update Previous & Current
    int brightness = currentBrightnessLevel * 20;
    dimLight(brightness);
    previousBrightnessLevel = currentBrightnessLevel;
    
    lastRequest = millis();
  }
}


void dimLight(int brightness) {
  Serial.println("Dimming Light: ");

  // HTTP Request - Light API
  String request = "/api/" + hueUserName;
  request += "/lights/31/state";

  // JSON Request - Message Body
  String contentType = "application/json";
  String hueCmd = "{\"on\": true, \"bri\": BRIGHTNESS}"; // {"on": true, "bri": BRIGHTNESS}
  String bri = String(brightness);
  hueCmd.replace("BRIGHTNESS", bri);

  // Debug
  // see what assembled to send
//  Serial.print("PUT request to server: ");
//  Serial.println(request);
//  Serial.print("JSON command to server: ");

  // HTTP Request
  // make the PUT request to the hub
  httpClient.put(request, contentType, hueCmd);

  // HTTP Response
  //read the status code and body of the response
  int statusCode = httpClient.responseStatusCode();
  String response = httpClient.responseBody();
//  Serial.println("");
//  Serial.println("Response");
//  Serial.println(response);
}

FINAL 







Popular posts from this blog

Socially Engaged Art and Digital Practice week 8

Socially Engaged Art and Digital Practice : week 3

Socially Engaged Art and Digital Practice week 6