<![CDATA[alexmichinel.net - Blog]]>Fri, 26 Jan 2024 04:37:20 -0800Weebly<![CDATA[Build a pH meter for a swimming pool]]>Sun, 19 Jul 2020 20:09:18 GMThttp://alexmichinel.net/blog/build-a-ph-meter-for-a-swimming-poolPicture
It has been a very long time since my last post. I have been quite busy in last 7 years.

Last year, (Before this COVID-19 pandemic) I took some time to develop a pH meter for swimming pools using easy to get and low cost components.

One of the most important parameters to monitor and control in a swimming pool is the pH. Normally this is keep in a range between 7.2 and 7.6.

There are various methods to measure the pH in the swimming pool; the most commons are chemical titration and paper strips. Also there are digital meter at low cost.

Picture
The intention of this post is not to guide you on what you should select to measure pH in your swimming pool but to show how to spend some time developing something fun and useful at last.

The idea is (or was) to develop a device that measures the pH and sends a report that can be seen on the internet. It sounds difficult but I was able to do it, so should not be that difficult!​.

What we need.

To build the pH meter we use the following components.
  • Arduino (I used Arduino Mega 2560 controller board) with power supply. Controls all the components and run the software
  • PH Value Detection Sensor Module Monitoring Control with BNC Electrode Probe – This measure the pH.
  • LCD Display (LCD 1606 Module – with pin header). Displays measured values.
  • DS3231 RTC Module. Provides real time clock.
  • Micro SD TF Card Adapter Reader Module 6Pin SPI Interface Driver Module. This logs values and keep in a Micro SD Card
  • Micro SDCard (16GB or less is ok) – Keeps the log of values.
  • DS18B20 Waterproof Temperature Sensor – I added temperature measurement to the device. Added 2, one for ambient one for water temperature.
  • ESP8266 ESP-01S WiFi Serial Transceiver Module with 1MB Flash – This gives internet connectivity.
  • 10K Potentiometer – to adjust LCD Brightness
  • PCB Perforated Printed Circuits Boards, push buttons, resistors and cables of different colors. I used Stranded Wire 24 AWG.

I have never soldered any circuit in my life, so this was an opportunity to learn it. Thanks to a brother in my congregation that had the patience to help me and teach me. It can be frustrating at the beginning but later is real fun!!. So, you will need to use a soldering kit.

 
Other things you need
You need a computer (desktop or laptop) with an USB port to compile and upload the code in the Arduino. Also need the Arduino Programming IDE (Can download fee from the Arduino web page)

This device sends a log of the values to a FTP site. So, you will need to have your FTP site where the Arduino can connect and upload the log.


The Circuit.
In order to finally get the required circuit connected, I have gone through various trial and error… so, I will give the final sketches (this will save you a lot of time).  Below are the diagrams or tips to connect the various components.
 

A. LCD Display
The more difficult part is to wire the LCD Display, the following diagram should help:

​A more realistic view using a “Bread-board” is:
Picture
B. Push button
Push button connection is quite easy; 5 Volts need to be supplied to the button input and the output needs to be wired to the Digital Pin 3.

Please note that most common push button has 4 “legs”, for two inputs and 2 outputs, both inputs are connected and both output are also connected.  So, you need to identify with pair can be input and which can be output.

Following the figure of the button you need to supply 5V to let A (or D) and wire leg B (or C) to Digital pin 3.

During operation the button need to be hold-down for at least 2 seconds for change in displayed variable to take effect.

Picture
C. The pH Sensor Module and probe.
For the pH Sensor mole we need to supply 5V and ground to two pins as shown in the figure.

The PO pin needs to be wired to the Analog Pin A0 of the Arduino. This will send a voltage signal that will be converted to a value between 0 – 1023.

The DO and the TO pins are not being used by the code but these can be used for Alarm and Temperature reading.

The screw on top of the blue box closer to the BNC connector is the one we use when we need to adjust or zero-calibrate the module.

Picture
D. Temperature Sensors
Both Temperature sensors need to be connected as show in the figure. Common 5V and ground need to be provided.

Also, the circuit requires a 4.7 Ohm resistor wired from the 5V supply to the Digital Signal from the Temperature sensors. This wire after the resistor needs to be connected to the Digital Pin 2 of the Arduino.

Picture
E. DS3231 RTC Module (Real time clock).
The connection of the RTC is quite simple, need to provide 5V and Ground to the respective pins. The SDA needs to be wired to the SDA pin in Arduino and the  SCL to the SCL pin in the Arduino. Also need to provide the required battery.


Picture
F. Micro SDCard Module
Need to supply 5V and Ground to the Micro SDCard. The rest of pin need to be connected as follows:

MOSI to pin 50
MISO to pin 51
CLK to pin 52
CS to pin 53


Picture
G. ESP8266 ESP-01 WiFi Serial Transceiver Module
Connect as follows:
RX — TX 1 (Pin 18)
TX — RX 1 (Pin 19)
GND — GND
GPIO 0  - GND
VCC – 3.3V
CH_PD – 3.3V

It is very important to connect to 3.3 Volts supply. 5V will damage the ESP8266 Module.

Picture

The Code
Download the code from the following link:

pHmonitorCode.txt

Note that you will need to install some libraries. I have placed those libraries in zip file downloadable from the following links:

Arduino-Temperature-Control-Library-master.zip
ESP8266wifi-master.zip
OneWire-2.3.4.zip
Timermaster.zip
 

Once you download them you can install them following the instruction to import zip libraries in Arduino IDE.

You need to customize several code lines. In lines 30 to 34 and 439, 440, 444 you need to type the information required for your wifi connection and your FTP server.
Now you are ready to compile the code and upload it in the Arduino.

It is important to set the process clock right, likely the DS3231 RTC Module will be out of time/date. To set the time of the clock you need to “uncomment” line 87 (removing the characters //) so that when compiling and running the code for first time the clock will be set to the current compiling time. After doing this, you need to set line 87 back as comment code (adding again //) and compile/run the program so that the time is not reset anymore. The DS3231 will keep the time from now on. Any time you need to set the time of the device you will need to follow the steps described in this paragraph.


How does this work?
You probably can find better way to “wrap” these device. I used a plastic container and put all circuits inside. As this will likely be installed outdoor proper protection to avoid ingress of water or moisture must be considered.

This device will read the pH and 2 temperatures (one can be ambient temperature the other the water temperature).

The push button is used to change what is shown in the LCD display. By default should the last 5 readings of pH. By pressing the bush button you then can display:
  • Temperature sensor 1 in oC and oF
  • Temperature sensor 2 in oC and oF
  • pH Values (default at startup – Displays last 5 values)
  • pH sensor (Raw data from the sensor a number between 0 and 1023 related to the voltage)
  • File size (Log size in bytes)
  • Wifi Status (Ok or NA – for Not Available)
 
The code is set to take pH reading every 3 minutes and send a report to the FTP site every 30 minutes. You can change that by tweaking lines 46 and 48 in the code.

An example of the report can be seen at:

www.alexmichinel.com/Pooldata/SHORTLOG.TXT

​You can make it more elaborated by modifying the code… The sky is the limit!!

Picture
Calibration
Likely you need to calibrate the pH sensor. There are two type of calibration, the zero and the range.

The zero calibration is done by carefully turning the screw in the pH control module (Scree is located on top of the blue box closer to the BNC connector). The idea is to have a reading of 7pH (or about 521 raw sensor reading) when there is 0 Voltage from the sensor. This can be achieve by jumping the core wire and the shield in the BNC connector of the pH controller module and moving the proper screw to get about 521 raw count from the sensor.

For the range calibration you prepare solutions with known pH. I prefer to use pH calibration Buffer Powder. Prepare solutions for 9.18 and 6.86 and find the lineal relation between the Raw pH value from sensor and the pH. The slop and the bias of the lineal relationship can be input in the code in lines 60 and 61 (variables mVal and bVal)  
 

Conclusion
All this may sound complex… but it is really fun and entertaining. Requires patience and determination to complete the task!! You can surely do it too!!
There are many references and links in the internet that can help you in every step of the way.
 

References:
Arduino Web page (www.arduino.cc)


]]>
<![CDATA[Considering Feedforward Strategy for Process Control]]>Tue, 09 Jul 2013 07:26:37 GMThttp://alexmichinel.net/blog/considering-feedforward-strategy-for-process-controlPicture
The use of feedback control strategies is one of the most common ways to control a process, but it is important to consider that feedback control is an error-driven strategy; correction to any upset in the process we want to control depends on the error or difference between the desired value of the “controlled” variable and its current value.

By the other hand, the feedforward control strategies use the knowledge of the process behavior to take action before a perturbation to the process has any effect on the controlled variable.

Several methods has been discussed to implement a feedforward control strategy, one of them is explained by Soundar Ramchamdram (1).  He uses steady-state models of the process to determinate the value that the manipulated variable should has to compensate the effect of perturbations on the controlled variable. He successfully demonstrated that Process-Model-Based control was appropriate to control the trays temperature in a typical wastewater column.

A simple example.

To give an example of the advantage that a feedforward strategy can have  over a pure feedback control, let’s have a look on a very simple system; consider a tank were we want to control the level, as shown in figure (No 1). This is a typical first order system.

Picture
We would like to keep the level of the tank under control.  The Feed flow can vary and the Outlet flow will be manipulated through a control valve.

Modeling the Process.

To simulate the process, MATLAB 5.1 can be used. This requires the process equations and the transfer function of the process representation in a block diagram.

The equations that describe this process are as follows:

Fi = Fo + A(dH/dt)          (1)

Where, Fi is the inlet flow, Fo is the outlet flow, A is the transversal  area of the thank and H is the height of liquid in the tank.

It is assumed that at the initial stead-state the process parameters are: H=2m, A=5m2 , Fi and Fo are 0.2m3/seg.

Laplace can be applied to find the transfer functions of the process.

Fi(S) = Fo(S) +ASH(S)       (2)

H(S) = (Fi(S) – Fo(S)) / (A S).   (3)

The figure (No 2) shows the resulting transfer function for the tank system. Using SIMULINK of MATLAB 5.1 this process can be dynamically simulated to study the effect of perturbations in the inlet flow on the tank level.

Picture
The figures (No 3) and (No 4) show the response to a step and to a sinusoidal function as perturbation to the inlet flow respectably.  Note that graphics show variation from initial steady-state in meters.

The sinusoidal function applied on the inlet flow had amplitude of 0.05m3/sec and a frequency of 0.1. 
Picture
Controlling the system with a feedback strategy

As discussed above, feedback control is the most common strategy used to control a desired variable. So, this kind of strategy was tested on the modeled system.  The controlled variable is the tank level and the manipulated variable is the outlet flow handled through the control valve.

The control strategy used can be observed in the figure (No 5)

Picture
This control strategy was tested with two different kind of perturbation on the inlet flow. The figure (No 6) shows the block diagram used to simulate the control strategy. Note that the control valve has a transfer function like a first order process.  This is to have a better approximation to what really happens with the valve positioning in response to a signal from the level controller.

Picture
The strategy was exposed to a change in inlet flow of 0.05m3/seg. The response to this perturbation can be seen in the figure (No 7).

The maximum overshot obtained was about 2% in the level.  The gain and the integral time used for the PID were 0.5 and 0.2 respectively. This set of tuning parameters can be improved, but they will not be adequate for the next  perturbation that this strategy was  tested against lately.
The strategy was then tested with a sinusoidal inlet flow. It can be observed in the figure (No 8) that the strategy can not control properly this perturbation.

The level kept fluctuating around the set-point; the amount of the fluctuation was about ±5%.

 Other tests were carried out such as changes in the level set-point and the combination of changes in the set-point and the introduction of perturbations in the inlet flow.

Picture
Improving with a Feedforward strategy.

A feedforward strategy was designed to evaluate its performance under the same perturbations that the feedback strategy was exposed.

The process diagram of the strategy can be seen in the figure (No 9)


The results obtained with the feed-forward control strategy are better than the obtained with the feedback strategy. In the figures (No 10) and (No 11), can be observed the response of the system to two kinds of perturbation; one step and one sinusoidal function respectively.
Picture
Basically in this strategy two errors are controlled at once; the error between the measured outlet flow and its set-point, and the error between the current level and its set-point.

The steady-state of this system tells that the inlet flow to the tank must be equal to the outlet flow from the tank.  For this reason the inlet flow is send as set-point to the outlet flow controller to take action in advance, before the level is actually perturbed by the inlet flow upset.

Any error in the level will be corrected by the same outlet flow controlled since the error between the current level and its set-point is added to the error discussed above.

In the figure (No 10), can be observed that the maximum overshot obtained is less than 0.3% significantly less than the 2% obtained with the feedback strategy.

In the figure (No 11) it is shown that the level will be oscillating around the set-point about ±0.5% which is less than the 5% resulting in the feedback strategy.


What is against.

“Nothing is better for nothing”; Having a better strategy should involve some extra cost.  In this case the installation of flow instruments at the inlet and outlet of the tank involve some extra costs. How important is to keep the controlled variable with a permissible error is the key question to evaluate if the extra cost involved in a better strategy is profitable.

In the real life.

This designed strategy can be implemented in a real application such as bottom of a distillation column, where the inlet flow will be proportional to the column feed flow. In most of the cases of distillation columns the feed and bottom flows are measured, so this strategy will not represent an extra cost.

Another implementation could be in boilers and evaporators, where a steady level of condensate is very important.

It will be very interesting to evaluate the performance of the discussed strategy in processes with delays or a higher order.

Conclusion

Feedforward control strategies have a better performance than pure feedback control strategies when implemented on processes of first order, but this improvement can involve some extra costs.  The balance between the profitability of a better strategy and the importance of having a very steady controlled variable, is the key point to choose or design the control strategy.

Literature:
1.  Soundar Ramchandran, “Consider Steady-State Models for Process Control”, Chemical Engineering Progress, Feb-1998, pp 75 – 81.

2.  Katsuhiko Ogata, “Ingenieria de Control Moderna”. 3rd Edition, 1997, pp 9 – 40

3. S. Majhi; D.P. Atherton, “Online tuning of controllers for and unstable FOPDT process”, IEE Proc.-Control Theory Appl., Vol 147 No 4, July 2000, pp. 421 – 427.
]]>
<![CDATA[The difficult task of selecting a technology]]>Tue, 02 Jul 2013 09:54:21 GMThttp://alexmichinel.net/blog/the-difficult-task-of-selecting-a-technologyPicture
Inevitably, in a point in time when you are handling world scale petrochemical projects, it will be necessary to select the technology required by your project.

Technology selection is not an easy task; the most common life like example is to try to pick only one fruit up from a basket full of delicious, juicy looking fruits. In the example, you may try two or more of the fruits, but in technology selection you have only one chance to select the right one.

Your selection not only has to make you happy but also the project owners/sponsors that are likely to demand an optimal investment (Capital expenditure - CAPEX) and operating cost (Operating expenditure - OPEX). Also, the future maintenance and operating team would like a reliable plant and easy to operate and maintain.  Additionally, government and environmental bodies will be having one (or two) eyes on you to ensure the regulations compliance of the plant.  Now you can see that making everybody happy is not going to be easy.

To accomplish the difficult task of selecting the proper technology a methodic approach must be adopted. Evaluation and comparison among the options on measurable criteria will be the key to the optimal technology selection.

Following, I will give some guidelines to make a methodic technology evaluation. There are several ways to approach the evaluation, but I think that this approach is methodic enough and covers most of the points important in the technology evaluation and selection.

To start, find the list of licensor offering the latest technology and shortlist 3 to 5 of them (if available). Too many technologies can bring excessive complexity, time and cost to the evaluation process. The pre-selection criteria can be their market share, or latest licensing developments. Some owners/sponsors are ready to select new technologies, others prefer proven and widely used. This is an important criterion to apply to the first cut of shortlisted technologies.   

Now that you have pre-selected a group of 3 to 5 technologies, you can request technical and commercial information from the licensor. Your company likely would have to execute Non-disclosure Agreements (NDA) with all licensor to protect secrecy of both, your project and the licensor information.

 You should request to all the licensor the information in the same manner; the same information and, as much as possible, in the same format. Some project could request only the Technical Information Packages (TIPs) and later a commercial offer after the technical part’s scope is fully defined and understood.

The technological issues to be studied and compared depend a lot on the type of plant or process, in general the request of information to licensors should include: 
  • Process Description
  • Description of the advantage points of the proposed technology.
  • Process flow diagram including the operating conditions of major equipment.
  • Raw Material and Products specification
  • Overall Material balance.
  • Emission and effluent quantities and composition.
  • Utility consumption normal, peak and guaranteed specific consumption
  • Summary of catalysts and chemicals required for the processes. Indicating the first fill quantity, consumption, design life, costs per unit, recommended suppliers etc.
  • List of proprietary chemicals and processes. Budgetary pricing.
  • Reference list and information on licensor’s market share.
  • Sized equipment list with enough details for estimating budgetary cost.
  • Total Installed Cost (TIC +/-30% accuracy)
  • Technical Service Agreements (TSAs) Modalities and cost
  • Training / Technology transfer Plan
  • Typical Project schedule
  • Approved Engineering Procurement and Construction (EPC) contractors.

Keep in mind that your source of information will not only be from licensors; Your will need to visit some operating plants, search in public domain and consult colleagues working with the shortlisted technologies if your team does not have experience with them. Typically you can find trough the plants visit and other interactions a more realistic picture than the one given by the licensors.

In a petrochemical project it is of utmost importance safety and environmental compliance. For this reason the environmental impact of the technologies should be evaluated and compared. Issues like total emission; cost of treatment should be evaluated.

The operability of the processes should be assessed based in the simplicity of flowsheeting, equipment count, typical on stream factors, and how fast and safe the process can be recovered from an unexpected shutdown.  Also, Manning required can be analyzed to assess the complexity of the processes and an partial view of the direct fixed cost.

An important aspect to be evaluated and compared is the reliability of the technologies. Instrument dependency and general maintenance requirements in term of frequency, time and resources are part of reliability aspects to be analyzed.

The capability of the licensor to keep the technology up-to-date and to constantly improve in the technology are parameters that should be seriously considered. You don’t want to end selecting a technology that can become obsolete in a short period.

Also, the pro-activeness and willingness of the licensor to provide affordable and prompt technical support during project execution as well as during the commercial operation of the plant is a very important parameter to evaluate and compare licensors.

Last, but not least at all, is the initial estimate of CAPEX and OPEX. Typically, OPEX can be estimated with great amount of accuracy with the information given on consumption by licensor and some homework done to get the pricing. Some licensor can provide even to some extend the operating cost but the best is to estimate it yourself. 

On the other hand, CAPEX is one of the parameters most difficult to estimate at this early stage of the project. Comparing CAPEX estimates given by different licensors becomes an activity with a lot of uncertainty. Firstly, as the estimated given by licensor is not binding, their calculation use to be too optimistic. It required a lot of work to bring all of the estimates from all of the licensor to a meaningful comparative stage. In some cases it results a better option to look for third party independent evaluation to get a better inside on the CAPEX of each technology. As mention earlier, this parameter will be very important to owners/sponsors, so it needs special care.

Picture
There are some other qualitative kind of parameters that can be analyzed and compared, like some special technical features, execution schedule, EPC availability that add to the evaluation the final touches and make it deeper.

Finally, your may like try to give a more quantitative look to the evaluation by assigning weightage to each evaluation criteria and marking each technology according to a ranking. The outcome of this exercise can be very interesting and can show you how sensitive is your selected technology to changes on view on the evaluation criteria.

I hope these guidelines help you in your next technology evaluation. I am quite sure that you would agree that choosing what fruit to eat is much easier.

Good luck.

]]>