PCM Wk Final 14: Putting it All Together

For this last week, the focus was on all the physical computation and software that was still needed for the interactive. The list includes: a.) finishing all the web pages for the 4 buttons, b.) getting rid of the p5js slider and having it read the analog read serial value, c.) hooking up the buttons with the pages, d.) getting the switches to turn on and off at the right times, e.) the battery function

Almost all wip and final code can be found (still being updated): https://github.com/emilylin-itp/solar

a.) Video below shows the solar cell schematic page working: got rid of the slider, and replaced the slider variable with the variable received from arduino/ serial.

b.)Video below shows the voltage generator page working: arduino is reading the amount of light hitting the solar panel then sending out that variable to p5js which maps it and draws a bar graph.

 

**** IMPORTANT NOTE! To have the ipad change with the buttons when connected to the webpage via “ip address: local host” you must add this to the js code: “serial = new p5.SerialPort(“ip address”);” This was a big issue, until it wasn’t. Thank you to Professor Shawn Van Every for helping out with that!

c.) Web pages:

On the icm side, I was working on developing these 4 web pages.  See this ICM post for more details:

d.) Circuit diagram and notes(without the battery light leds)

This was my first time fritzing, so not sure if it was done properly. Also the 9v is supposed to be 12v but couldn’t find it in the list of components. In the future, I will have to spend more time fritzing because I’m not sure if I have all the right components in here.

fritzing version of circuit

circuit

this below is an updated circuit photo after batteries were added:

IMG_5323.jpg

Attached is a note to self on what each pin on my Arduino Uno has been used for (we managed to use almost all the pins! This is a first for me!) Also included are notes on the order of my console log readings.

 

e.) Switches for the Handle:

To create the switches, copper tape was put on the sides of each arm, on both the arm and the block that stopped the arm. This created a push button effect, where the copper tape would short each other and complete the circuit. Thank you Professor Tom for the super helpful advice, this method worked out great. There was also wires attached that went to analog pins (analog only because there were not enough digital pins available). The analog pins were connected to resistors that connected to ground.

 

 

c.) Battery Charging/Discharging: this feature was worked on separately from the entire code and physical form that was already set up. Eventually this was combined at the end.

For the battery, the function is that it should be charging (going from bottom to top continuously) until the handle hits the right switch. when handle hits the right switch the battery will discharge and turn on the lights from top to bottom (continuously as well). when the battery is being discharged the house lights will also turn on.

Below is  the code to have the battery charge and discharge based on whether or not the sun is turned on or off. A good reference code was the digital hour glass project of the “Arduino Uno” book:

//SUN control
const int transistorPin = 7; // connected to the base of the transistor
const int leftBar = A4; // connected to the left switch for SUN
const int rightBar = A5; // connected to the right switch for SUN

//button pins
const int button1 = 13;
const int button2 = 12;
const int button3 = 11;
const int button4 = 10;

//house & solar cell pins
const int houseLED1 = 3;
const int houseLED2 = 5;
const int scPin1 = A0;
const int scPin2 = A1;

const int numReadings = 10;
int solareadings[numReadings]; // the readings from the analog input from solar cells
int readIndex = 0; // the index of the current reading
int solarTotal = 0; // the running total
int solarSmooth = 0; // the average smoothed by 10 measurements

//battery parameters

int batBar1 = 2;
int batBar2 = 4;
int batBar3 = 6;
int batBar4 = 8;
int batBars[4] = {batBar1,batBar2,batBar3,batBar4};
unsigned long previousTime = 0;
long interval1 = 2000;
long interval2 = 1000;
int k=0;
int j=4;
//
void setup() {
//configure the digital input:
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
pinMode(transistorPin, OUTPUT);
pinMode(houseLED1,OUTPUT);
pinMode(houseLED2,OUTPUT);
pinMode(batBar1, OUTPUT);
pinMode(batBar2, OUTPUT);
pinMode(batBar3, OUTPUT);
pinMode(batBar4, OUTPUT);

Serial.begin(9600);

for (int thisReading = 0; thisReading < numReadings; thisReading++) {
solareadings[thisReading] = 0;
}
}
void loop() {

unsigned long currentTime = millis();

//SUN control with the left and right switches + battery charge/discharge
int leftSW = analogRead(leftBar);
int rightSW = analogRead(rightBar);

if (leftSW > 600){
digitalWrite(transistorPin, LOW);
for (int n=0; n < 4; n++){
digitalWrite(batBars[n],LOW);
}
//switch to starting page and turn on light and charge battery
k=0;
} else if (rightSW > 600){
digitalWrite(transistorPin, LOW);
if (currentTime - previousTime > interval2) {
previousTime = currentTime;
if (k <= 4){
for (int n=0; n < 4; n++){
digitalWrite(batBars[n],HIGH);
k=5;
}
}
digitalWrite(batBars[j],LOW);
if (j >= 1){
j--;
} else {
j=4;
k=0;
}
}

//switch to battery pg and turn off light and discharge battery
} else{
digitalWrite(transistorPin, HIGH);
if (currentTime - previousTime > interval1) {
previousTime = currentTime;
digitalWrite(batBars[k],HIGH);
if (k <= 3){
k++;
} else if(k = 4){
k=0;
for (int n=0; n < 4; n++){
digitalWrite(batBars[n],LOW);
}
}
}
j=4;
}

Serial.print(currentTime);
Serial.print(",");
Serial.println(previousTime);
Serial.print(k);
Serial.print(",");
Serial.println(j);

// // read the right switch location
// Serial.print(rightSW);
// Serial.print(",");
//
// // read the left switch location
// Serial.print(leftSW);
// Serial.print(",");

}"

Here is a very rough circuit diagram sketch for how I would wire up and solder the the batteries. I had help from Professor Tom to help me understand what was needed for the leds to switch on and off.

Also, I looked at this helpful lab on transistors for guidance: https://itp.nyu.edu/physcomp/labs/motors-and-transistors/using-a-transistor-to-control-high-current-loads-with-an-arduino/

super rough battery sketch

The yellow leds were put in series on 1 row. There are 2 rows per pcb. The power side is connected to the 220 ohm resistor. Then the 2 rows in the pcb were shorted to each other and I attached a wire to both the power and ground side.

Here are some photos of the process of putting together the led battery lights.

 

Each pcb board has a transistor paired with it. I connected the negative side to the wire connected to the collector of the transistor. There was a white wire attached to the base of the emitter that is plugged into the digital pins: 2, 4, 6, 8. The black wire is attached to the emitter of the transistor which was all shorted together and plugged into the ground of the dc adapter. the positive side of the leds were then plugged into the positive of the dc adapter.

 

This slideshow requires JavaScript.

Another 12 volt dc power (separate from the 12 volt dc power for the light source) was used to light up this many leds. One hiccup that happened was the soldering connections. It took so much more time than I thought it would to make these connections and having to see which leds were not soldered properly; therefor affecting all the leds that it is in series with. I also discovered that it is VERY important to solder well and make sure there is a good connection between the wire and the components. The battery lights wouldn’t light up many times, and I had to use the multimeter to check which ones were not connected properly. There are many hiccups to using leds like this, and I almost think it would have been better use led strips, despite how great this dotted yellow light look.

 

Here is the battery charging in the full setup:

 

f.) Close to final versions:

Video below shows buttons working but with major delays between ipad and desktop screens.

 

Below is the latest video but the ipad is not placed properly in the setup, just wanted to show the delay between ipad and Desktop)

 

g.) Solder to PCB for extra security: tried to be extra careful to completely replicate the breadboard version to the pcb version. It is important that I had a multimeter on hand to check all the connections when soldering.

h.) Reflections:

With my current skill sets, this project was a lot for me to handle in the given time frame but I certainly learned a lot and feel as though I pushed myself.  I probably wouldn’t have taken this idea on if I weren’t at ITP (with all the great professors and people as resources) and if I didn’t have insight from my partner Kasra, who has done materials research on solar cells. I also wouldn’t have felt comfortable doing this without the advice from Professor Tom and Jeff who are very well versed in solar energy. It is important to me that the project was accurate yet fun to play with. Throughout the process I constantly felt myself short on solar energy knowledge. I couldn’t quite decide what to do with certain interactions because I myself was not very familiar with it. It required more research on my end, and with a short timeline I didn’t think I did a good job of learning everything to learn about solar energy. I’m really looking forward to taking the “Energy” course next semester and am hoping that it’ll help me feel more comfortable and well versed in designing for energy-related topics. Even though I was asking the experts around me, my lack of knowledge on this topic made me think this “exhibit” piece was not as educational nor accurate as it could have been.

Another thing I need to watch out for is timing between fabrication and physical computing. I got really into the build and thoroughly enjoyed making the structure for my piece. It was so fun to be in the wood shop learning new tools, making measurements, sketching out diagrams and models. I loved refurbishing my parent’s old furniture, and i think ITP has reminded me of how much I love to make in 3d forms. I spent a lot of time and gave a lot of attention to the fabrication and physical design. But towards the end of the project, I was regretting not allowing myself more time on coding the pcomp side of things. I was rushing through this part, trying to get all the interactions I wanted done (i.e. buttons, switches, battery). I would’ve really enjoyed taking it slower to learn and code with arduino. Coding is fun, but there is still a learning curve for me so it often takes longer than I expect it will. When I’m tied for time I asked people for help, when I wish I could’ve solved it myself (if I had just given myself more time to code). I need to remind myself that it’s important to do the tasks that are harder for myself first, rather than later.