Assignment 5: Micro, Meso, Macro

 

Node: node-red-contrib-sun-position
Project Description:
Using this node to calculate the position/direction of the sun relative to our designated positions. The designated location can be extremely accurate, to the extent of road and street number. The value we chose is azimuth, which is the angle of the sun to the polar north. The value is derived from node-red, sent to HiveMQ WebSocket through serial communication, and finally to the Arduino. The value is updated every 10 seconds, so the motor or pointer is slightly changing every 10 seconds. Due to technical limitations, our device can only locate the sun during the day, which is an angle from 90 degrees to 270 degrees.

Difficulties:
– As the sun position is represented by two values, azimuth and altitude, we tried to use two values to control where the sunflower is facing, so we are able to visualize the sun’s direction three-dimensionally. With Stavros’s assistance, we figured out the logic of how to send two values via MQTT and get the two values separately in the Arduino file. However, we failed to make it because of the lack of knowledge of coding in the JSON file.
– Ideally, the sunflower should be able to rotate 360 degrees to respond to the sun’s position. However, since the range of the micro servo we used is only limited to 180 degrees, we could only make the sunflower respond to the sun’s position during daylight.

The Application:
Using computation, we can build an enhanced sunflower that can detect and respond to the sun position anywhere and anytime. The installation can be displayed on the square, not only serving as a decoration but also reminding people of the existence of the sun and the relationship between the sun and our lives, especially in the evening and on rainy days.

Node-red flow file:
[{“id”:”78aaf148.b5704″,”type”:”tab”,”label”:”Flow 3″,”disabled”:false,”info”:””},{“id”:”fc962ea1.197a3″,”type”:”inject”,”z”:”78aaf148.b5704″,”name”:””,”props”:[{“p”:”payload”},{“p”:”topic”,”vt”:”str”}],”repeat”:”10″,”crontab”:””,”once”:false,”onceDelay”:0.1,”topic”:””,”payload”:””,”payloadType”:”date”,”x”:107,”y”:130,”wires”:[[“56265aeb.99f034”]]},{“id”:”56265aeb.99f034″,”type”:”sun-position”,”z”:”78aaf148.b5704″,”name”:””,”positionConfig”:”c914012.43c7f”,”rules”:[{“valueLow”:”10″,”valueLowType”:”num”,”valueHigh”:”100″,”valueHighType”:”num”}],”onlyOnChange”:”true”,”topic”:””,”outputs”:2,”start”:””,”startType”:”none”,”startOffset”:0,”startOffsetType”:”num”,”startOffsetMultiplier”:60000,”end”:””,”endType”:”none”,”endOffset”:0,”endOffsetType”:”num”,”endOffsetMultiplier”:60000,”x”:307,”y”:130,”wires”:[[“9cc2d51.4ac0828″,”28e91.9d63d16f6”],[]]},{“id”:”9cc2d51.4ac0828″,”type”:”change”,”z”:”78aaf148.b5704″,”name”:”azimuth”,”rules”:[{“t”:”set”,”p”:”payload”,”pt”:”msg”,”to”:”payload.azimuth”,”tot”:”msg”}],”action”:””,”property”:””,”from”:””,”to”:””,”reg”:false,”x”:500,”y”:170,”wires”:[[“f3b53b7f.57fbd8″,”91d6acce.93cc3″,”e866e950.a7f798”]]},{“id”:”28e91.9d63d16f6″,”type”:”change”,”z”:”78aaf148.b5704″,”name”:”altitude”,”rules”:[{“t”:”set”,”p”:”payload”,”pt”:”msg”,”to”:”payload.altitude”,”tot”:”msg”}],”action”:””,”property”:””,”from”:””,”to”:””,”reg”:false,”x”:500,”y”:240,”wires”:[[“a247766a.bd3b38”]]},{“id”:”e866e950.a7f798″,”type”:”debug”,”z”:”78aaf148.b5704″,”name”:””,”active”:true,”tosidebar”:true,”console”:false,”tostatus”:false,”complete”:”payload”,”x”:739,”y”:170,”wires”:[]},{“id”:”5b085e1b.4ec8a”,”type”:”debug”,”z”:”78aaf148.b5704″,”name”:””,”active”:true,”tosidebar”:true,”console”:false,”tostatus”:false,”complete”:”payload”,”targetType”:”msg”,”statusVal”:””,”statusType”:”auto”,”x”:730,”y”:260,”wires”:[]},{“id”:”91d6acce.93cc3″,”type”:”mqtt out”,”z”:”78aaf148.b5704″,”name”:””,”topic”:”/nyu-ima-topic/DJ”,”qos”:””,”retain”:””,”broker”:”cb6bc422.564098″,”x”:759,”y”:100,”wires”:[]},{“id”:”f3b53b7f.57fbd8″,”type”:”ui_gauge”,”z”:”78aaf148.b5704″,”name”:””,”group”:”5b339788.f1b178″,”order”:1,”width”:0,”height”:0,”gtype”:”gage”,”title”:”Azimuth”,”label”:”units”,”format”:”{{value}}”,”min”:0,”max”:”360″,”colors”:[“#00b500″,”#e6e600″,”#ca3838″],”seg1″:””,”seg2″:””,”x”:729,”y”:60,”wires”:[]},{“id”:”a247766a.bd3b38″,”type”:”ui_gauge”,”z”:”78aaf148.b5704″,”name”:””,”group”:”5b339788.f1b178″,”order”:1,”width”:0,”height”:0,”gtype”:”gage”,”title”:”Altitude”,”label”:”units”,”format”:”{{value}}”,”min”:”-90″,”max”:”90″,”colors”:[“#00b500″,”#e6e600″,”#ca3838″],”seg1″:””,”seg2″:””,”x”:720,”y”:220,”wires”:[]},{“id”:”c914012.43c7f”,”type”:”position-config”,”name”:””,”isValide”:”true”,”longitude”:”0″,”latitude”:”0″,”angleType”:”deg”,”timeZoneOffset”:99,”timeZoneDST”:0,”stateTimeFormat”:”3″,”stateDateFormat”:”12″},{“id”:”cb6bc422.564098″,”type”:”mqtt-broker”,”name”:””,”broker”:”mqtt://broker.mqttdashboard.com”,”port”:”1883″,”clientid”:”client-Stavros-Send-jny”,”usetls”:false,”compatmode”:false,”keepalive”:”60″,”cleansession”:true,”birthTopic”:”/nyu-ima-topic1/JD”,”birthQos”:”0″,”birthPayload”:””,”closeTopic”:””,”closeQos”:”0″,”closePayload”:””,”willTopic”:””,”willQos”:”0″,”willPayload”:””},{“id”:”5b339788.f1b178″,”type”:”ui_group”,”name”:”Default”,”tab”:”83c188a4.e21b08″,”order”:1,”disp”:true,”width”:”6″,”collapse”:false},{“id”:”83c188a4.e21b08″,”type”:”ui_tab”,”name”:”Home”,”icon”:”dashboard”,”disabled”:false,”hidden”:false}]

 

Arduino code:

#include <Servo.h>

int inVal = 0;
int Val = 0;

Servo servo_3;

#define DATA_PIN 9;

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
servo_3.attach(9);
}

void loop() {

if (Serial.available()) {

delay(10);
char str[10];
byte index = 0;
while (Serial.available() && index < sizeof(str) – 1) {
str[index++] = Serial.read();
str[index] = ‘\0’;
inVal = atoi(str);
}
}

if (inVal>=90 && inVal<=270){
Val = map(inVal, 90,270,180,0);
servo_3.write(Val);
}
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *