Tag Archives: Microcontroller

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

 

 

       Pinsetup:

             Analog:

                     A2 – PSI Sensor

             Digital:

                     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

DHT dht(DHTPIN, DHTTYPE);

 

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()

{

       lcd.init();

       lcd.backlight();

       dht.begin();

       pinMode(fanswitch, OUTPUT);

       pinMode(comprelay, OUTPUT);

       pinMode(13, OUTPUT);

 

       digitalWrite(fanswitch, HIGH);

       digitalWrite(comprelay, LOW);

 

       digitalWrite(13, LOW);

       Serial.begin(9600);

       delay(500);

}

 

 

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.println(sensorValue[1]);

       Serial.print(“PSI: “);

       Serial.println(psireading);

       Serial.print(“Temp: “);

       Serial.println(temp[1]);

       Serial.print(“Humidity: “);

       Serial.println(humid);

       if(psisenserror==true)

       {

              /*

                     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

              */

 

              shutdown();

              //goto ENDOFMAIN;

       }

 

       if(psireading > compressorhigh[1])

       {

              digitalWrite(comprelay, LOW);

       }

 

       if(psireading < compressorlow[1])

       {

              digitalWrite(comprelay, HIGH);

       }

       lcdprint();

       //ENDOFMAIN:;

}

 

 

void lcdprint()

{

       lcd.clear();

       lcd.print(“Current: “);

       lcd.print(psireading);

       lcd.print(” psi”);

       lcd.setCursor(0,1);

       lcd.print(“On SP: “);

       lcd.print(compressorlow[1]);

       lcd.setCursor(0,2);

       lcd.print(“Off SP: “);                         

        lcd.print(compressorhigh[1]);

 

        lcd.setCursor(0,3);

        lcd.print(“Temp: “);

        lcd.print(temp[1]);

        lcd.print(” Humid: “);

        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;

       }

       else

       {

              psisenserror = false;

              if(olderror==true)

              {

                     lcd.clear();

              }

       }

 

       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.clear();

       lcd.print(“Error!”);

       lcd.setCursor(0,1);

       lcd.print(“Wait 20 seconds”);

 

       while(delaytime > millis())

       {

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

              if(secnds!=psecnds)

              {

                     lcd.clear();

                     lcd.print(“Error!”);

                     lcd.setCursor(0,1);

                     lcd.print(“Wait “);

                     lcd.print(secnds);

                     lcd.print(” seconds”);

              }

              psecnds = secnds;

       }

 }

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.

20150719_231950

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.

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!

My Arduino Air Compressor Controller Project – Part 1

Last week, I introduced Arduinos, and mentioned that I would be discussing my air compressor controller project using an Arduino. I will try to complete this series in 5-6 posts with this introduction, details about the hardware, and details about the programming.

Disclaimer: I am providing this information for educational and informational purposes only. Although this looks simple, working with 120V and 240V components and manipulating them with projects like this can be very dangerous, potentially resulting in severe injury, death, damaged equipment, fire, and will definitely void any warranty you may have on the item(s). If you wish to perform a project like this, seek assistance from an experienced electrician first.

So why am I doing this project, when you can just pick up a new stock controller (pressure switch) for $50 – $60? The standard pressure switch for my air compressor typically starts the air compressor when the air pressure drops below 90 psi, and stops when it reaches around 135 psi. It becomes somewhat problematic when trying to run air tools in the 110-120 psi range – when it drops below 100 psi, the air tool just doesn’t get the power it needs, requiring constant adjustment. Yes, you can manually set these pressure switches to cycle on sooner, but leaving it like that will drastically increase the start/stop cycles on the compressor, causing it to ware out much quicker.

20150628_160320

My compressor and compressor motor

So, for this project my goal is to create a microcontroller for my compressor that allows me to change the start/stop points of my compressor, safely. The first step in a project like this is to figure out how it works, so you can figure out what you need in order to control it. Normal household compressors are relatively simple – they use a 120 or 240 volt AC induction motor which are controlled by a mechanical pressure switch. The mechanical pressure switch is what I am replacing, so I won’t get into the other aspects of the compressor.

The motor on my compressor is a 240V motor, so it has 2 terminal leads and a ground. The ground is always connected, but the two leads are what the pressure switch controls – it is what my new controller has to do, switch those two terminal leads on/off to start/stop the compressor (it is possible to control it by switching just one terminal lead, but it is just not a good idea as one motor lead will always be ‘hot’).

Now that we know the basics for how to control the start/stop of this compressor, I’ll move on to safety. Most people should already be aware of the hazards of electricity, but this introduces another hazard – over pressurization of the pressure vessel (air compressor tank). I wish it weren’t so, but mechanical and electrical components fail – there is a possibility that the device we use as a switch could fail, leaving the compressor running, over pressurizing the tank, causing it to rupture.

The main key in preventing these bad things from happening, is by getting the properly rated equipment/material. In the image below, you will see my compressor motor is rated for 240V at 15 amps – The switch I use must meet or exceed this rating, failure to do so will definitely result in the switch failing. It is also important to use the proper internal wiring and any other parts/components that will support the voltage and current (amp) that will be flowing through it.

My compressor motor name plate

My compressor motor name plate

Preventing the over pressurization can be done with a pressure release – a valve held shut by mechanical means, such as a spring, that will open at a certain pressure set point to reduce the pressure. The safety relief must be rated for the proper pressure, and flow – it will do no good if the air compressor can supply more air than the relief can release. Most air compressors only output a small volume of air, so most pressure reliefs you find will suffice, just make sure. You can see in the picture below, that my air compressor is rated to output a volume of 10.3 SCFM at 90 psi (at a higher pressure, like 130 psi, it will output a lower volume). Also, it is important to note that the sticker on my compressor states 135 max psi, I looked up the details which state it is capable of 150 psi, and the tank is also rated for 150 psi. So, I need to get a pressure relief for 150 psi or less, that is capable of relieving 10.3 SCFM or more.

20150628_193643

My compressor main label

Pressure vessel name plate

Pressure vessel name plate

Next week I will continue posting about this project, moving into discussing the hardware I’ve chosen for my controller. Thanks for reading and following my blog! Please leave comments, and check back next week for more!

Arduino – Inspiring creativity and innovation of technology through learning

This blog, I would like to talk about one of my hobbies – microcontrollers, specifically, Arduinos.

ArduinoMega2560_R3_Front_450px

Arduino Mega 2560

So just what exactly is an Arduino you ask – they are an open-source microcontroller that offers a relatively inexpensive way to learn about microcontrollers and build your own automation systems. There are many other development boards, just to name a few raspberry pi, Intel’s Galileo, even Samsung is getting ready to launch their ARTIK. While these are all great options, I prefer Arduino because there is a lot more documentation and examples available for them, they are easier to setup, and they are an actual microcontroller not a microcomputer (I will discuss the difference later).

What can you do with an Arduino? An Arduino is essentially an I/O (input/output) hardware device that has its own microcontroller. There are numerous different versions of Arduinos, but they range from having 14 digital and 6 analog pins, up to 54 digital and 16 input pins. The digital pins can be used as inputs or outputs, while the analog pins are only for input (except on their Due model, which has a couple of analog outputs). Basically, you use these analog and digital pins on the Arduino to read devices (temperatures, pressures, distance sensors, etc…), then have the microcontroller control a device (servos, motors, switches, send a signal, etc…). Most Arduinos also come with USB connectivity, and have the ability for serial, IC2, and other types of electrical communications – meaning that you can link multiple Arduinos together and to other devices, including computers. Some of the things Arduinos have been used for include:

You can find many, many other projects people have completed with Arduinos, and listed for everyone to see with instructions (http://playground.arduino.cc/Projects/ArduinoUsers).

How do you get started, what does it take, how much does it cost? In order to program an Arduino, you need to have a computer with USB – Arduino has their programming software available for Windows, Mac OS X, and Linux. You must download the Arduino IDE (free), from Arduino’s website. Depending on your electrical engineering desire, you can actually get started learning about Arduinos with starter kits that typically start out around $50 (which you can find on Amazon and EBay). Starter kits typically contain one of the Arduino boards (usually the UNO), some electrical components (LEDs, resistors, switches), electromechanical devices (motors, servos), and an instruction manual (could be printed or some are available online). The official Arduino Starter Kit, which is currently unavailable (I believe they are upgrading it), is $89.90. If you’re ambitious, and want to start off on your own, without a starter kit, you can pick up the Arduino official Arduino boards, such as the UNO (one of their most popular boards) for around $25. Arduinos are an open-source hardware/software device, so you can also find a lot of knockoffs for cheaper on EBay, Amazon, and other places. However, I recommend purchasing from Arduino if possible, as they are the inventors and leaders of this project, providing us with continuous hardware and software improvements.

Seeing how quickly our technology is changing, I highly recommend looking into Arduino’s, as it will give you a deeper understanding of how technology is controlling devices – it will give you a new perspective of your electronics. I would also highly recommend them for families – teaching children these things at a fairly young age could be invaluable in their development and potential career paths.

Thanks for reading my blog post! If you are interested in Arduinos, join me next week, I will discuss one of my Arduino projects – a motor controller for my 220V air compressor.