Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

Saturday, June 2, 2018

Plot a waveform and the sum of its harmonics in Excel


I made this spreadsheet to prove that a square wave is made by the sum of a fundamental sinewave and its odd harmonics. So, to transmit a digital signal you need a bandwidth much larger than the digital clock of the transmission. Adding more harmonics improve the shape of the squarewave, but it requires more bandwidth. In the following spreadsheet you can enter amplitude and frequency of the digital signal, and the bandwidth. The spreadsheet calculates values up to 14 harmonics. All the harmonics outside the bandwidth will be ignored. Also, you can select "odd", "even" or "all" harmonics. Just to see what happens.
The amplitude of the harmonics is the entered amplitude times 2 / (π x n), where n is the number of the harmonic.


Here I have a 100 Hz signal transmitted over a 5000 Hz bandwidth. As you can see, the square wave is pretty good.

Here you can see what you would see on a spectrum analyser:



Now I reduced the bandwidth to 1000Hz, so I only have 4 odd harmonics, and the square wave is not looking as good

The spectrum shows that only 4 odd harmonics plus the fundamental are in the bandwidth:

Now I selected all the harmonics (odd+even)

Sunday, August 10, 2014

Binary to Gray, Gray to binary conversion


During my PLC course I had to convert binary numbers to Gray code and viceversa. I made this spreadsheet to help me with that.





Matrix solver (Cramer's rule)

This spreadsheet solve three equations with three variables using the matrix method (Cramer's rule).



Thursday, August 7, 2014

Brewduino

PURPOSE

I just finished testing my new experiment: a device that keeps the temperature of a fermenter between two set values and display and record the data over time. It takes about 6-7 days to ferment a home brew beer, and the temperature must be kept between 18 and 24 degrees (it can change slightly depending on the beer). If it's too cold the fermentation stops, if it's too warm the beer goes bad. I bought a 30W heating belt to wrap the fermenter, but I wanted it to go on and off automatically when needed, so I set up my Arduino Uno, a temperature sensor (DHT11) and a relay to control the AC current using a DC signal of 5 Volts. Additionally I attached an LCD to see the temperature read by the sensor and compare it with the analog thermometer, just to double check. I also like to analyse data so I attached an SD card module to record the temperature and state of the heating belt (on and off) over time.

SCHEMATICS



As you can see from the schematics, I'm using pin 5 to send the signal to the relay that controls the AC power to the heating belt. I decided to switch the active wire (brown): switching the neutral (blue) would work exactly the same but it wouldn't be safe in case of a fault. You can set the relay "normally open" (it will activate the circuit when the signal is present), or "normally closed" (it will stop the circuit when the signal is present) using different pins.
The SD card module uses 4 pins that are set in the relative library, so I didn't change them: they are 13,12,11,10 plus power and ground. These modules are supposed to work with both 3,3V and 5V but I can't get it to work with 5V so I had to use 3,3V. 
The sensor DHT11 has its own library and it only uses one pin (in this case pin 3) plus power and ground.
The connection of the LCD is always the same, with the potentiometer to control the brightness.

SKETCH

#include <LiquidCrystal.h>
#include <DHT11.h>
#include <SD.h>

LiquidCrystal lcd(9, 8, 7, 6, 4, 2);

int pin=3;
DHT11 dht11(pin); 

const int chipSelect = 10;
int t,h;

long previousMillis = 0;
long interval = 30000;

void setup(){
  Serial.begin(9600);
  pinMode(10, OUTPUT);
  pinMode(5, OUTPUT);
  lcd.begin(16, 2);
  if (!SD.begin(chipSelect)) {
    return;
  }
}

void loop(){
  int err;
  float temp, humi;
  if((err=dht11.read(humi, temp))==0)
  {
    t = (int) temp;
    h = (int) humi;
    
  lcd.print(t);

  if(t < 19){digitalWrite(5,HIGH);}
  if(t > 21){digitalWrite(5,LOW);}
    
  int state = digitalRead(5);
  lcd.setCursor(8, 0);
  lcd.print(state);

//  Serial.println(dataString);

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    
    String dataString = "";
    dataString += "temperature:";
    dataString += String(t);
    dataString += ",";
    dataString += "humidity:";
    dataString += String(h);
    dataString += ",";
    dataString += String(state);
        
    File dataFile = SD.open("datalog.txt", FILE_WRITE);
    if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    }
    previousMillis = currentMillis;   
   }
  }
    delay(1000);
    lcd.clear();
}


To write the sketch I had to include the 3 libraries to control the LCD, DHT11 and SD module. I had to use pin 9,8,7,6,4,2 to control the LCD because I'm using 13,12,11,10 to control the SD module (and I can't change that unless I change the library). The "chipSelect" is pin 10 in the Arduino Uno (it's different in the Mega). Pin 3 is used by the sensor and pin 5 is the pin that controls the relay.
The sketch itself is pretty simple, I took parts from the datalogger sketch. I had to introduce a different kind of delay: I want the program to run every second, but to record data on the SD only every 30 seconds. To do that I can't use the function delay(30000), because it would stop the whole program for 30 seconds. I'm using the function millis() that counts the milliseconds passed since the start of the program. This value is compared to the set interval and when it's larger than that, it execute the part of the program that writes the data into "datalog.txt" on the SD card.
The function digitalRead() can also read an output pin. For example here I'm reading the state of pin 5, even though I'm using it as an output.

TEST

Because I don't want to waste beer, I filled up the fermenter with water for the purpose of this test. 


When you deal with higher voltages it's a good idea to enclose your devices in a box. 


After about 4 days I stopped the device and analized the data recorded on the SD card: I had 10545 values that correspond at about 88 hours of recording. As you can see from the chart, the temperature was kept between 19 and 21 degrees (the analog thermometer was reading the same). The last number in the log is the state of the heater (0=off, 1=on). The same value is displayed on the LCD, next to the temperature.

I imported this data into Excel and plotted a chart of temperature over time: as you can see the first day I had it set to keep the temperature between 18 and 24 degrees. The blue line indicates the temperature. The red line shows when the heater was on.


The heat belt was on for 11 hours to increase the temperature to 24 degrees, and the temperature decreased quickly after the heat belt went off. Then I changed the settings to make it work more efficiently: I just want to keep the temperatures over 18 degrees, so I set it to start the heat belt when the temp was under 19 and to stop when it was over 21. The second night it went on for a shorter time, enough to increase the temperature by 2 degrees (about 2 hours), the third night it didn't even go on because it wasn't cold enough and the fourth night it went on about 2.5 hours.

Analyzing data is useful to understand if the device is working efficiently or it can be improved. For example, I can observe that it takes about 1.5 hours to increase 23 liters by one degree, using about 30W of power.
I also plugged in a power meter at the heat belt to check the consumption: it uses maximum 40W power and at the end of the experiment the total energy consumption was about 680Wh.

Friday, May 23, 2014

Vectors operation in Excel


I made this spreadsheet to help me calculate the return current in unbalanced three phase loads. In this case the data to enter is the power factor and the magnitude of the current in each phase. The table will show the return current in complex number, polar and rectangular form. The chart will show the vector representing the current in the neutral conductor (in black).


The next spreadsheet calculates and plots the voltages across a resistor and an inductor (it can be easily changed to capacitor) in a series circuit. 


Wednesday, April 9, 2014

Plot sine waves with Excel


During my study I had to draw and calculate sine waves pretty often. I used Excel to plot them and calculate their sums or product.

This first file calculates and plots 3 sine waves in the same chart from their function (amplitude, frequency, shift and offset):


Download the file


The second file calculates and plots 2 sine waves from their function and their product, very useful to see the usage of power when voltage and current are not in phase:


Download the file


The third file calculates and plots 2 sine waves from their function and their sum. It also plots the phasor diagram at 0 degrees:


Download the file

Solar Microgrid


Today I’m sharing with you a project I’m particularly proud of. As final stage of my Renewable Energy course I was asked to complete a project of a stand-alone, hybrid system. Stand-alone means that the plant is not connected to the grid, like in a remote area. Hybrid means that more than one source of energy is used. In this case I designed a 27kW solar system with a backup diesel generator.
A microgrid is an independent grid where more than one unit can produce and use the power of the grid.
The purpose of the system is to power the irrigation system of a cherry farm, the owner’s house, a shed, and the farmstay for workers. The farm really exists and I worked in it, in Griffith NSW. It’s grid connected but I designed this system pretending that it wasn’t.
This is the final diagram of the complete system:

  

LOAD ASSESSMENT


The first step of a power system design is a load assessment. This stage allows us to understand the needs and the size of the system, but also to improve the energy consumption. In this case I was able to reduce it up to 30% in summer, improving the efficiency of the air conditioning.

  

Decreasing the energy consumption decrease the size of the system and of the components.
The next chart shows the load assessment of the 4 units (pump, house, shed and farmstay) combined, in different seasons.



DESIGN

To design this system I followed the Australian standards and the Clean Energy Council guidelines but I exceeded their requirements. I created a complex spreadsheet to help me in future design of this size.
The microgrid is a 3 phase system, the loads are spread across the phases equally, and only the irrigation pump uses the 3 phase power.
The following charts compare the power used in each phase at different time.



The system is designed to be expanded easily in the future.
In good weather conditions the sun (daytime) and the batteries (nightime) are enough to power all the loads. The generator starts automatically to power the loads and recharge the batteries in rainy days.
To calculate a perfect system I analysed the solar data (from NASA) and the load across the year and I considered the worst scenario. In this spreadsheet you can see the comparison between the load and the energy from the sun:


I also compared the performance of my arrays at different angles. I calculated that changing the tilt of the array just twice a year the annual output of the system increase considerably. To do that, we need an adjustable tilt array. The following chart compares the energy output of the system with a different tilt:
  

I made the following spreadsheet to help me in matching the inverter with the array, using the calculation suggested by the Australian standards and CEC. It also calculates the size of cables and circuit breakers. I need 6 inverters to collect the power from the 3 arrays and put it on the 3 phase grid.




ARRAY SIZE

To calculate the distances between the arrays (needed to calculate the length of cables and the voltage drop), avoiding shading between 10am and 2 pm, I made a spreadsheet that can be used in any area in Australia. You just insert the size and number of panels in the array, the tilt of the array, and the latitude of the location. The result will be the minimum distance between arrays to avoid shading when the system is more productive.



I copied the formula from the Clean Energy Council tech info released in March 2010. For some reason it’s not on their website anymore so you can download it here.



CUSTOMER MANUAL

As a final task I was required to write a customer manual, according to the Australian standards. It’s written in simple words to explain the basics of how the system works. It has to include important instructions and procedures.


Wednesday, February 12, 2014

Low-pass filter and integrator in Excel


Today I want to publish a couple of useful spreadsheet I made to solve electrical circuits.
The first is an integrator circuit: a pulsing DC voltage charges a capacitor in steps. This spreadsheet calculates the voltages across the capacitor over time. It's a pretty complex formula to do it manually.

Download the file

The second spreadsheet calculates the frequency response in a series RLC circuit, in this case the voltage is taken across the capacitor, therefore it's a low-pass filter.

Download the file