New Beginnings

Hello everyone!


I originally started this blog as a part of a project for my EMBA.  At the time I was living in Indiana.  Since then, I have changed jobs twice, and moved to two different locations – its been a hectic last couple of years.  Due to my career and life changes, I abandoned my blogging.  However, I have noticed a decent amount of activity and interest, so I am picking it back up with some current projects.


My next project will be a water box for a portable AC.  I recently moved to the Portland, Oregon area, and found very few houses and even apartments have AC systems installed – due to the weather they aren’t needed as much as other areas.  However, in a 3 story place, the 3rd story gets very hot.  So, I decided to go with a portable AC unit for now.


For those of you who have never used a portable AC unit, the problem is that when you cool air it causes condensation, and water builds up.  The AC units have tanks in them, and when they fill up they shut down.  Then you have to roll it over to the bathroom, or someplace, pick it up and drain it out.  So, instead of that, I am building a water box that the AC unit will drain into, and when the water level gets to a couple inches, I’ll have it pumped out the window.


Currently, I have the system functioning, but it is not complete.  I have created my wooden water box – the wood inside has been stained with a polyurethane stain (PolyShades), and all corners/cracks have been sealed with a standard silicone.  I have not finished the outside of the box yet (I am waiting to get my controls system finalized before I finish it).  I am using a 12 VDC pump I picked up on Amazon ( ), a 5/16 hose from HomeDepot, an old 12 VDC adapter I had laying around, an Arduino Mega (an overkill, but I didn’t have any of the smaller boards on hand), and a 4 channel relay shield I picked up from RadioShack (You really only need 1 channel for this project, but the shield was just more convenient as it mounts directly on the Arduino – you can find some 1 channels cheap on Amazon ).


I am running into issues with direct contact sensors – sensors that are sitting in the water.  My first sensor I made from various parts, corroded very quickly.  I am now using a water sensor I picked up on amazon ( ).  The sensor worked well, but it is picking up some corrosion/scaling, which is causing indication issues.  I’m not sure whats causing the issue, as I figured the condensation would be fairly pure water, but I am assuming it is coming from either the polyurethane, the silicone sealant, a combination of the both, or even maybe a reaction of the urethane and the silicone.


Due to the direct-contact sensor issue, I am going to switch to a non-contact method, using an ultrasonic sensor, which you can also find online at Amazon, such as these .  I am  busy working, but I should be able to complete this modification next week, and will have more to post with some better pictures, code, and directions.


Picture of the AC unit on top of the water box:

Water-box - 1.jpeg


A picture inside of the water-box.  Don’t mind the messy wires – that was caused from changing sensors out, and some uncertainty of success.  You can see the pump, and the sensor (red circuit board towards the bottom).  You should be able to see the corrosion/buildup on the lower portion of the sensor:

Water-box - Inside 1

My Arduino Air Compressor Controller Project – Finally Functional!

Good news: The controller is finally functional!!!

Air Compressor Controller

As of now, the controller is reading the tank pressure, and the temperature and humidity inside the box, and displaying on the LCD.

Compressor Display

The temperature is reading close to the local current weather, but the humidity is reading low – 24% compared to the online weather info of 50%.  The device is is located in my garage, so I expect it to be somewhat different than the actual weather, but I currently do not have anything else to compare the humidity reading to.

Current Weather

I picked up a good, manual pressure gage for verifying the electronic pressure transducer.  The pressure is consistently reading about 3 psi low throughout its entire range, which may be caused by increasing the length of wire from the sensor (causing a very small voltage drop).  Since the pressure difference is the same, instead of changing the conversion constant in the calculation from my previous post, I am just going to add 3 psi to its reading.

Pressure Gage Reading

Currently, I just have the compressor set to start at 100 psi and stop at 130 psi, without being able to change it.  I have also included a shutdown function that ensures the compressor is shut off if there is an error detected from the pressure transducer (a low or high reading out of range).  I have posted all of the current code at the bottom of this page.

I still have more improvements to add in the near future:

  • Creating a menu to:
    • Change the start/stop pressure settings
    • Change the fan start/stop temperature settings
    • Change the duration allowed for the compressor to run
    • Change the standby time & pressure set points
    • Change the LCD update time
  • Add the ability to cycle the fan on/off at temperature set points (right now it just stays running)
  • Add a time shutoff to prevent the compressor from running continuously in the event of a line rupture or other issue when no one is present
  • Add a standby feature when the compressor is not needed – reduced pressure set points and turns off the LCD backlight
  • Log the running hours in the Flash memory (memory that is not lost when power is lost)

Thanks for joining me in this series again!  Please leave comments and check back again soon for some more code updates and download links for all the files (coming soon)!

Current Code:


       Analog Resolution is 0-1023 (204.8 per volt or 0.004883v per resolution)

       Pressure sensor is linear:

              0 psi = 0.5v = 102.4

              200 psi = 4.5v = 921.6





                     A2 – PSI Sensor


                     D4 – Menu Switch

                     D6 – Up Switch

                     D7 – Down Switch

                     D8 – DH11 Temperature

                     D9 – Compressor Relay

                     D10 – Fan

                     D20 – 2004 Display-SDA

                     D21 – 2004 Display-SCL




#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display


#include “DHT.h”

#define DHTPIN 8     // what pin we’re connected to

#define DHTTYPE DHT11   // DHT 11



double psiconvt(double);


const double psiconversion = 0.004883;

const int PsiSensorPin = A2;

const int menuswitch = 4;

const int upswitch = 6;

const int downswitch = 7;

const int comprelay = 9;

const int fanswitch = 10;

const long debounceDelay = 50;   // the debounce time; increase if the output flickers


int reading;

int lastMenuState = LOW;

int lastUpState = LOW;

int lastDownState = LOW;

int MenuPosition = 0;


// these variables are for the settings that can be changed

int backlightdelay = 1800000; // 1,800,000 is 30 minutes

int lcddelay = 2000;   // delay between updating the LCD – minimizes flickering

int maxruntime = 600000; // 600,000 = 10 minutes – minimizes the chance for overheating

int pausetime = 300000; // 300,000 = 5 minutes – provides cool down time

int compressorlow[2] = {100, 100}; // temperature to start the compressor

int compressorhigh[2] = {130, 130}; // temperature to stop the compressor

int fanlow[2] = {90, 90}; // temperature to shut the fan off

int fanhigh[2] = {100, 100}; // temperature to start the fan


// these variables are for storing the readings and data

int temp[2] = {0, 0};

int humid = 0;

int sensorValue[2] = {0, 0};

double psireading = 0;

bool psisenserror = false;


// these long variables are for timing the delays

long lastlcddelaytime = 0;

long lastMDebounceTime = 0;

long lastUDebounceTime = 0;

long lastDDebounceTime = 0;

long menuTime = 0;



void setup()





       pinMode(fanswitch, OUTPUT);

       pinMode(comprelay, OUTPUT);

       pinMode(13, OUTPUT);


       digitalWrite(fanswitch, HIGH);

       digitalWrite(comprelay, LOW);


       digitalWrite(13, LOW);






void loop()



       if(millis() > menuTime)


              MenuPosition = 0;



       sensorValue[1] = analogRead(PsiSensorPin);

       psireading = psiconvt(sensorValue[1]);

       temp[1] = dht.readTemperature() * 1.8 + 32.0;

       humid = dht.readHumidity();


       // send the sensor data to the computer, through serial, if connected

       Serial.print(“SensorValue: “);


       Serial.print(“PSI: “);


       Serial.print(“Temp: “);


       Serial.print(“Humidity: “);





                     There’s an error with the PSI transducer – shutdown the compressor

                                  – gives error message and counts down 20 seconds

                           go to the label ENDOFMAIN to bypass the rest of the code and restart the loop




              //goto ENDOFMAIN;



       if(psireading > compressorhigh[1])


              digitalWrite(comprelay, LOW);



       if(psireading < compressorlow[1])


              digitalWrite(comprelay, HIGH);







void lcdprint()



       lcd.print(“Current: “);


       lcd.print(” psi”);


       lcd.print(“On SP: “);



       lcd.print(“Off SP: “);                         




        lcd.print(“Temp: “);


        lcd.print(” Humid: “);



       sensorValue[2] = sensorValue[1];

       temp[2] = temp[1];





double psiconvt(double psi)


       bool olderror = psisenserror;

       double c1;

       double c2; 

       double val = 0; 

       c1 = psi * psiconversion; 


              The psi sensor starts at 0.5V – anything less is an error with the sensor

              The psi sensor ends at 4.5V – anything more is an error with the sensor 

              Therefore, if it is out side of those parameters, throw an error



       if(c1 < 0.46)


              psisenserror = true;


       else if(c1 > 4.54)


              psisenserror = true;




              psisenserror = false;







       c2 = c1 – 0.47;

       val = c2 * 50;


val == val + 3;

       return val;




void shutdown()


       digitalWrite(comprelay, LOW);

       long delaytime = millis() + 20000;

       int secnds;

       int psecnds = 0;





       lcd.print(“Wait 20 seconds”);


       while(delaytime > millis())


              secnds = (delaytime – millis()) / 1000;






                     lcd.print(“Wait “);


                     lcd.print(” seconds”);


              psecnds = secnds;



My Arduino Air Compressor Controller Project – Beginning of Coding!

Thanks for joining me again!

I have good news – the Arduino controller is almost all put together! All that is left for hooking it up is to hook up the 3 wires for the sensor, which won’t take very long, and screw the front cover in. It’s not perfect (I wish I would’ve got a slightly larger box), but it will work:

Air Compressor Controller - 1

For this blog, I would like to start getting into the programming code for this project. First, as I mentioned in my first blog post about Arduinos, you must download the Arduino IDE. The Arduino IDE (Integrated Development Environment) provides a simple platform for writing your code, even provides us with many different examples, and it is used to load the program onto the Arduino through USB. The program code is written in C, which I can provide more information about in the future. Arduino calls the program code a sketch.

There are other options for writing the programs, such as using Microsoft’s Visual Studio with the Visual Micro add-in (which is my personal favorite). Using Visual Studio is a quite a bit more complex to initially get setup and get projects started, so for this blog series I’m just sticking with the Arduino IDE.

The following is a screenshot of the Arduino IDE, with the Blink example, which is installed as the default sketch on all Arduino microcontrollers:

Arduino Blink Sketch

A couple of things to notice with this sketch:

  • We can include comments in our code to help with documentation and for instructional purposes. The compiler will ignore the comments as if they weren’t there, but they are still displayed in the IDE.
    • One line comment “//” – this can be used anywhere in the code, including after a statement, as shown towards the bottom of the sketch. Everything after the // will be ignored by the complier.
    • A multi-line comment begins with “/*” and ends with “*/” – everything in between the start/end designators will be ignored.
  • The Arduino has 2 key functions that it runs:
    • Setup – the Arduino runs this code when it is first turned on. It is used for setting various parameters to prepare the board for the main program
    • Loop – This is the main part of the program for the Arduino – it runs through this function in a continuous loop.

To start out our sketch, I am going to begin with a separate function to calculate the pressure – If you remember, on my post about the hardware I am using a 200 psi linear pressure transducer, which varies the output from 0.5 volts at 0 psi, to 4.5 volts at 200 psi. So, we just need to setup a simple calculation to make it easy to determine what the actual pressure is, based on the output voltage of the pressure transducer. However, to make it a little more complicated, the Arduino doesn’t give us the voltage, it gives us a numerical value from 0 at 0 volts, to 1023 at 5 volts.

So the first thing this code is going to need to do is convert the 0-1023 Arduino value to a voltage. This is pretty simple. For 5 volts, there is a range of 1024 values (Note: 0 is a value here, so it’s 1024, not 1023). Therefore, for each 1 value step of the Arduino’s analog value is equal to 5/1024 = 0.004883 volts. So 205 = 1 volt, 410 = 2 volts…

Next, we want to check for errors in our pressure reading – If something happened to our pressure transducer, and we aren’t getting a good reading we don’t want to keep the compressor running. This pressure transducer outputs a minimum of 0.5 – so if the voltage is less than 0.5 it is more than likely shorted out. On the high side, 5 volts are being applied to it, and its max output is 4.5 – so if it is reading above 4.5 it also means something is wrong and giving us a bad reading.

Lastly, is the voltage to pressure conversion: 4/200 = 50psi/volt (the voltage range is from 0.5 to 4.5 volts, which is only a range of 4). Therefore, for each 1 volt outputted from the pressure transducer above 0.5, is 50 pounds.

There are many different ways you could perform this conversion, but I have included the conversion part of my code for this project at the end of this blog post – please look at it, and provide comments and feedback. If you would like the actual sketch files, please reach out to me through one of the social media links.

Thanks for joining me again! Hopefully we will have my air compressor running again by next week! I’ll be working on the full code, and will be posting it later this week – Please check back in!

double psiconvt(double psi)


                bool olderror = psisenserror;

                double c1;

                double c2;

                double val = 0;

                c1 = psi * 0.004883;


                                The psi sensor starts at 0.5V – anything less is an error with the sensor

                                The psi sensor ends at 4.5V – anything more is an error with the sensor

                                Therefore, if it is outside of those parameters, throw an error


                if(c1 < 0.46)


                                psisenserror = true;


                else if(c1 > 4.54)


                                psisenserror = true;




                                psisenserror = false;


                c2 = c1 – 0.5;

                val = c2 * 50;

                return val;


My Arduino Air Compressor Controller Project – Tools

Welcome back to my Arduino Air Compressor Controller Project!

I know last week I stated that we were going to begin moving to code this week, but I have some bad news… My project box cracked down the front, and it’s not safe continuing with the box – it is housing 240 volts, and it is going on a piece of equipment with a lot of vibration.


So, I have a new aluminum box, that is much sturdier, and I am working on getting all the parts switched over and mounted on it, as well as doing some upgrades (a larger display 20 character by 4 line display, instead of the 16 character by 2 line display).

New aluminum box

Since we’re not ready to move on to code yet, I figured it would be a good time to take a step back look at the tools I used to create the prototype board and assemble the controller. So, for this project the necessary electrical tools include:

  • Mini nipps – tremendously helpful when soldering new components on boards – they make it really easy to cut off the excess wire protruding from the bottom of the board
  • Multimeter – not entirely required, but highly recommended – it will help troubleshoot problems
  • Pencil tip Soldering iron – for finer electronics, I recommend using a low wattage, pencil tip soldering iron – the pencil tip makes it easier to work with the smaller boards, and the lower wattage prevents it from getting too hot and damaging delicate components
  • Wire stripper/combo tool – there are nicer, separate wire cutters and wire strippers you can purchase, but these type are cheap, and they work

You really don’t have to have anything special or expensive. Most people swear by more expensive multi meters, like the Fluke brand (which are very nice), but for most hobbyist, a cheap Wal-Mart multi meter will do – at this level you really don’t need to worry about being precise.  You can pick all of these up for under $50, and you can find everything but the mini nippers at Wal-Mart or a hardware store.

Also, you need a few more basic tools:

  • Screwdriver (both phillips and slotted) – this will depend on the hardware (nuts and bolts) you choose
  • Mini pliers – This set includes mini nippers
  • Dremel – or a cheaper clone will suffice
  • Drill with drill bits – any drill will do, but make sure that you have or get bits specifically for the nuts and bolts you will be using.

If you really get into electronics as a hobby, you may look into getting a desoldering iron (very handy for fixing soldering mistakes or repurposing boards), and a hot re-work station. The hot re-work station is really for SMD’s (surface mounted devices), which I find the occasional need for, but I also use it for heat shrink and other things, and most of them come with a temperature controlled soldering iron (another must for the hobbyist).

Again, I apologize for not getting into some code yet, but I promise we will get into some code in my next blog in this series. Thanks for joining me, and please check back later for more.

Our Electric Grid – Renewable Energy Sources, Part 3

Welcome back! This week I am beginning to focus on some of my concerns about renewable energy, which will continue into next week, and will move into discussing some of the negatives that aren’t being publicized – Again, I am not against renewable energy, but I’m afraid that we are pushing for something, which we really don’t understand the consequences. Personally, I believe we should continue to focus on renewable energy, while studying it – I believe our best bet is for us to have a balanced power portfolio among the different power sources.

In my first post in this series, I asked if anyone new which type of generation source caused the largest immediate death toll – I bet a lot of people immediately think of nuclear, but that would be incorrect. The largest catastrophe in power generation history goes to hydro-electric. In August of 1975, the Banqiao Dam in China failed after a record flood, resulting in 26,000 people dying immediately, and an estimated 145,000 people died from epidemics caused by water contamination.

In contrast, only one nuclear accident has been attributed to more than ten deaths. That would be the Chernobyl disaster in Russia on April 26, 1986. I’m sure people have heard all kinds of numbers about the Chernobyl disaster, however, there were 31 deaths that occurred within a short time after the disaster, 2 immediately died from explosions, one from a heart attack, and 28 first responders died from Acute Radiation Sickness (or syndrome).

The World Nuclear Organization has claimed that the death toll will roughly be between 4,000 and 9,200 (between emergency and recovery workers, and residents in the contaminated territories). Now I will also say that there are also people saying that the official reports are drastically underestimated, and claim that as many as a million people have died from Chernobyl ( – I don’t know, but the official report is less than 10,000 total.—Appendix-2–Health-Impacts/

I believe Chernobyl was a terrible disaster, and is worse in some aspects than the Banqiao Dam due to victims facing mutations, mutations in their children, cancer, and among other issues. My goal with this information is to inform people that we underestimate a lot of risk, and take many things for granted without thinking about it or researching it – just following the news…

Please join me next week for more!

My Arduino Air Compressor Controller Project – Assembly of Control Board

Well, I’ve made some progress on our Arduino project!

I have my control board 100% assembled and functionally tested (without the Arduino). All that is left for the hardware is attaching the push button switches, the pressure sensor, mounting my project box to the compressor, and wiring up the power line to my terminal strip. Then we will begin working on the programming for the Arduino!

Compressor Project Box - 1

The following is a rough sketch of the circuitry so you can visualize it a little better. Note: I created this with fritzing, which has a limited amount of pre-built components – so, the components shown are just for illustration, not all of them are identical to the components I am using.

Compressor Controller - Breadboard Sketch

At the top left, you will see my connector for the 12 volt power supply, which will ultimately supply power for the entire device. The controller fan, and the air compressor relay will be powered from the 12V bus through the transistors.

Right next to the 12V power supply is a voltage regulator – it takes an input from 5-60 volts and regulates it to a stable 5 volts. The regulator’s 5 volt output will supply power to everything else – I chose to power the devices (pressure switch and LCD) directly from the regulator output instead of from the Arduino because of the Arduino’s limited max output of 500 ma – The Arduino is fully capable of powering all these devices from its power source. I just chose to avoid it as a fault in one of the devices could exceed the power output of the Arduino, potentially damaging the Arduino.

Just below the voltage regulator are two transistors. I am using these transistors as switches – to turn them on all you have to do is supply a small voltage/current to the base of the transistor. This will allow current to flow through the transistor, completing the circuit path for the device (the relay and fan). To turn it off, you apply 0 volts, or ground to the base of these transistors and it will shut them off. This can be easily performed by the Arduino’s digital outputs, which can turn off and on (0 volts and 5 volts).

Below the transistors are my three push button switches. These switches will be used as a menu, up, and down buttons to allow me to change my setpoints, and look at different things; temperature & humidity inside the box, status of the fan & relay, current tank pressure, the amount of time the compressor has ran, and the current setpoints. They are connected to the 5 volt bus, so when they are pressed they send a 5 volt signal to the digital pins on the Arduino, which we will program it to monitor and respond accordingly. There is a resistor on the output of the switch to drive it to 0 volts – sometimes these switches float, and have non-zero values when not pressed. I can provide more information about transistors later – they are really cool, and are capable of doing many different things for us.

Underneath the three pushbuttons, is our temperature and humidity sensor. This sensor is powered by the 5 volt bus, and uses a single buss data communication to relay the information. Luckily there is a program library for this, and we don’t have to create any special codes for this communication – one of the great things about Arduinos. Since it is a digital communication, it is hooked up to one of the digital pins.

At the bottom right of the breadboard, you will see a pressure sensor (this is not the same as my 3 wire sensor, but it was all fritzing had in its parts list). The pressure sensor is powered by 5 volts (mine has a +5 volt wire, a ground, and a sensor output). The pressure sensor sends a linear output from 0.5 volts at 0 psi, to 4.5 volts at its max rating (200 psi in our case). The reason it is 0.5 – 4.5 instead of 0-5 is to allow us to detect shorts and opens, which could either give a 0 or 5 volt out. Since this sensor gives a differing voltage output, analog, it is attached to one of the Arduino’s analog input pins.

Now, to the right of the breadboard, at the top, I have the fan and relay. Both of which are being controlled by their own transistors, which will be controlled through the Arduino.

Below the relay is the Arduino, our microcontroller.

To the far right is our 16 X 2 LCD (16 characters by 2 line liquid crystal display). This will be powered from the output of the voltage regulator. Its backlight is the largest load on our 5 volt bus. The LCD will be used to display the information I mentioned earlier about the buttons.

Thanks for joining me again! Next week I will have it completely assembled, and we will begin playing with some code!!! Please follow me and join me next week for more!

Our Electric Grid – Renewable Energy Sources, Part 2

Alright, back to my original question I always get asked – Why can’t we just go to all renewable sources of power immediately?  My previous blog post on Renewable Energy

Before I get started, I want to be clear – I am not against renewable energy. I just wish to explain why it isn’t easily feasible to quickly convert, and impossible to completely convert to 100% renewable sources. I would also like to express some of my concerns (in a future article) about renewable energy that I have not seen addressed yet.

The primary problem is that the most sought after renewable sources (wind and solar) do not provide a stable power generation throughout the day – their output varies with their power source. As the sun fades from clouds or other causes, the power generated from solar panels fade away with it, and as the wind dies down, wind turbines power generation die down with it. Also, our power demand fluctuates throughout the day as well:

Summer Load and Wind Availability

The black dotted line is the average electrical demand, the solid black line is the summer electrical demand, and the red doted and dashed lines is the electrical generation available through wind. If you notice, it is exactly opposite – the wind turbines are at their minimum generation abilities around the peak energy demand times.


Now, on a normal day, solar power follows the demand relatively closely, but it actually begins dropping off at the very peak of the power demand.

These graphs are smoothed out, and are over a large scale. In a localized area the demand is much more chaotic – fluctuating by the second.

Even though solar and wind look like they can balance each other, their variations can wreak havoc on the electric grid – every time you flip on a light switch, you change the demand on the system and something somewhere has to be available to increase the power generation instantaneously. Essentially, this means that a coal or nuclear plant has to be backed down from generating 100% of its capabilities, to be able to provide for those fluctuations.

What does that mean? Significantly higher costs. When you ask anyone how much it costs for solar power, all you will hear in return, is the purchase price of the panels, the necessary equipment, and the cost of installation. However, this added volatility to the grid causes larger plants to reduce their generation, but having to keep that power generation readily available to create a buffer for the variations caused by the solar panels. Although this is not a direct cost to you, it is a cost that our society has to account for (also discussed for wind here:

A lot of the information we have today has changed drastically over the years – especially for renewable energy. Before the last ten years or so, there just weren’t nearly as many facilities. Therefore, we didn’t have the large dataset of information that we have today.

Please join me again next week on this topic – I will introduce some of my personal concerns about solar and wind power that I haven’t seen discussed yet. Please follow me and leave comments!