Author Topic: PID Arduino Control by ElectroMech  (Read 9996 times)

0 Members and 1 Guest are viewing this topic.

Offline ShiFu

  • eParrot.org
  • Admin
  • Posts: 1984
PID Arduino Control by ElectroMech
« on: December 14, 2018, 08:42:39 AM »
Today we welcome a new member from Freelancer who is here to help us with this project. Welcome ElectroMech!

The Project:

Hardware: Arduino Uno, DS18B20 temperature sensor, 16x2 LCD display shield and servo motor.   

Objective: PID control of the servo motor to open and close a valve to regulate the temperature inside a condenser.   
We are cooling a hot condenser with cool water.     
The temperature SetPoint must maintain a temperature difference of no more than one degree C (I know, this is also hardware dependent).     
The display shield is used as a Menu to set the PID parameters and provide user input, to be stored in memory, and provide visual output of the target SetPoint as well as the actual real-time temperature.

This is a group effort so all questions and comments are appreciated.



This is the hardware that was sourced through a Chinese website that you probably don't have access to so I've tried to provide links with pictures below of the hardware.

1. Arduino Uno
no need for links, commonly available

2. DS18B20 temperature sensor
no need for links, commonly available

3. Screw Shield (or order directly from Adafruit, or make your own)   

https://www.aliexpress.com/item/Proto-Screw-Shield-Assembled-prototype-terminal-expansion-board-For-Arduino-UNO-MEGA2560-One/32839587971.html?spm=2114.search0104.3.29.7e8e5193PCKBay&ws_ab_test=searchweb0_0,searchweb201602_3_10065_10068_10890_5730315_319_10546_317_10548_10696_453_10084_454_10083_10618_5729215_10307_538_537_536_10059_10884_10887_100031_321_322_10103-10890,searchweb201603_51,ppcSwitch_0&algo_expid=b4fa1c7b-b330-4f0c-8431-a9c16048b9e6-4&algo_pvid=b4fa1c7b-b330-4f0c-8431-a9c16048b9e6

(general)

https://www.aliexpress.com/wholesale?catId=0&initiative_id=AS_20181215043309&SearchText=arduino+screw+shield

(Adafruit)

https://www.adafruit.com/product/196

4.
servo tester

https://www.aliexpress.com/item/Multi-Servo-Tester-3CH-ECS-Consistency-Speed-Controler-Power-Channel-CCPM-Meter-Master-Checker-RC-Dron/32915282482.html?spm=2114.search0104.3.1.542c4eb69gkt7B&ws_ab_test=searchweb0_0,searchweb201602_3_10065_10068_10890_5730315_319_10546_317_10548_10696_453_10084_454_10083_10618_5729215_10307_538_537_536_10059_10884_10887_100031_321_322_10103-5729215,searchweb201603_51,ppcSwitch_0&algo_expid=a07a8b2c-b56b-40af-82d0-5647a81df430-0&algo_pvid=a07a8b2c-b56b-40af-82d0-5647a81df430

(general)

https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20181215043307&SearchText=servo+tester

5. servo reverser

https://www.aliexpress.com/item/RC-Servo-Signal-Reverser-Rotation-for-JR-Futaba-Aeroplane-V-Tail/32492084783.html?spm=2114.search0104.3.15.1c432e3byO4w8C&ws_ab_test=searchweb0_0,searchweb201602_3_10065_10068_10890_5730315_319_10546_317_10548_10696_453_10084_454_10083_10618_5729215_10307_538_537_536_10059_10884_10887_100031_321_322_10103,searchweb201603_51,ppcSwitch_0&algo_expid=8b223164-39cd-4144-b8d6-5cb48e4c18af-2&algo_pvid=8b223164-39cd-4144-b8d6-5cb48e4c18af

(general)

https://www.aliexpress.com/wholesale?catId=0&initiative_id=AS_20181215043146&SearchText=servo+reverser


6. display shield

https://www.aliexpress.com/item/LCD-Keypad-Shield-LCD1602-LCD-1602-Module-Display-For-Arduino-ATMEGA328-ATMEGA2560-raspberry-pi-UNO-blue/32334900048.html?spm=2114.search0104.3.1.7b40761a5N9noU&ws_ab_test=searchweb0_0,searchweb201602_3_10065_10068_10890_5730315_319_10546_317_10548_10696_453_10084_454_10083_10618_5729215_10307_538_537_536_10059_10884_10887_100031_321_322_10103-10890,searchweb201603_51,ppcSwitch_0&algo_expid=7e51132d-1d63-41fa-abc8-bca2c03b1ede-0&algo_pvid=7e51132d-1d63-41fa-abc8-bca2c03b1ede

(general)

https://www.aliexpress.com/wholesale?catId=0&initiative_id=AS_20181215043027&SearchText=arduino+display+shield

7. servo   20kg metal  (this is what i'm using),  180 degree

https://www.aliexpress.com/item/JX-PDI-6221MG-PDI-6221MG-20KG-Large-Torque-180-360-Degree-Digital-Servo-For-RC-Models/32902639315.html?spm=2114.search0104.3.8.63ac123aQD0JmO&ws_ab_test=searchweb0_0,searchweb201602_3_10065_10068_10890_5730315_319_10546_317_10548_10696_453_10084_454_10083_10618_5729215_10307_538_537_536_10059_10884_10887_100031_321_322_10103,searchweb201603_51,ppcSwitch_0&algo_expid=9b0c8efe-ec94-450f-9e85-198c98995d63-1&algo_pvid=9b0c8efe-ec94-450f-9e85-198c98995d63


(general)

https://www.aliexpress.com/wholesale?catId=0&initiative_id=AS_20181215042930&SearchText=20kg+servo

8. power supply,  6 vdc 3 amp

(I can't help here, its country specific. Very cheap for me about $2 in China but you need to source your own.)

9. metal servo plate 25T

https://www.aliexpress.com/item/JMT-1X-CNC-Aluminum-Alloy-Servo-Plate-Round-Disc-Horn-for-Futaba-TOWER-Series-25T-24T/32840021459.html?spm=2114.10010108.1000014.1.edfc33fbAU77tQ&gps-id=pcDetailBottomMoreOtherSeller&scm=1007.13338.112237.000000000000000&scm_id=1007.13338.112237.000000000000000&scm-url=1007.13338.112237.000000000000000&pvid=02a508f7-5a14-41b3-8ee0-a71af6d43c24

(general)

https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20181215042928&SearchText=t25+metal+servo+plate
Stay calm and follow the screaming people.

Offline ElectroMech

  • Posts: 7
Re: PID Arduino Control by ElectroMech
« Reply #1 on: December 14, 2018, 08:57:41 AM »
Hi All I am Engr. Shahbaz Zafar , from freelancer here to help you all in it

Offline ShiFu

  • eParrot.org
  • Admin
  • Posts: 1984
Re: PID Arduino Control by ElectroMech
« Reply #2 on: December 14, 2018, 09:10:40 AM »
Welcome ElectroMech, can I call you EM for short?

I am using the Adafruit screw shield, Arduino Uno, DS18B20 temperature sensor, 16x2 display shield and an inexpensive servo to operate a valve to control the flow of cool water to regulate the temperature of a condenser. 

If you have any questions about the hardware or need links to those parts, please ask.

Stay calm and follow the screaming people.

Offline ShiFu

  • eParrot.org
  • Admin
  • Posts: 1984
Re: PID Arduino Control by ElectroMech
« Reply #3 on: December 14, 2018, 11:11:07 AM »
Attached is some code that does not quite work well enough but probably because it was using a stepper motor instead of a servo.
We had a lot of problems with the limit switches and mostly could not accept the temperature overshoot. 

You may find something useful in the menu section. 
Stay calm and follow the screaming people.

Offline ketel3

  • Admin
  • Posts: 1377
  • Eparrot.org
Re: PID Arduino Control by ElectroMech
« Reply #4 on: December 14, 2018, 01:07:33 PM »
Welcome EM,great you are here,let see if a fresh vieuw on the project can help us forward.
Some how this has to work as there are already exiting systems ,unfortunate,not available for us.
Happy coding  :)
Better bad weather than no weather

Offline ElectroMech

  • Posts: 7
Re: PID Arduino Control by ElectroMech
« Reply #5 on: December 14, 2018, 07:38:06 PM »
Tomorrow i will post update with code

Offline cyclops

  • Posts: 37
Re: PID Arduino Control by ElectroMech
« Reply #6 on: December 14, 2018, 08:36:58 PM »
Thanks for looking at this guys, I have ordered everything on the list and look forward to receiving them :)

Offline ShiFu

  • eParrot.org
  • Admin
  • Posts: 1984
Re: PID Arduino Control by ElectroMech
« Reply #7 on: December 15, 2018, 07:02:34 AM »
cyclops, please give a review of the parts and their costs when you receive them.
Stay calm and follow the screaming people.

Offline ketel3

  • Admin
  • Posts: 1377
  • Eparrot.org
Re: PID Arduino Control by ElectroMech
« Reply #8 on: December 15, 2018, 01:30:25 PM »
Yes as we here in Europe have not the chance to purchase at the same prices as Shifu.
So to compare ,would be nice.
Better bad weather than no weather

Offline ShiFu

  • eParrot.org
  • Admin
  • Posts: 1984
Re: PID Arduino Control by ElectroMech
« Reply #9 on: December 15, 2018, 01:55:42 PM »
Yes, K3, and hopefully he gets them quickly, not weeks or months.
Stay calm and follow the screaming people.

Offline ElectroMech

  • Posts: 7
Re: PID Arduino Control by ElectroMech
« Reply #10 on: December 15, 2018, 09:32:34 PM »
The working code is attached in the file and i will upload the wiring diagram too then a videos

Offline ketel3

  • Admin
  • Posts: 1377
  • Eparrot.org
Re: PID Arduino Control by ElectroMech
« Reply #11 on: December 15, 2018, 09:36:22 PM »
Great thanks ,EM see forward for the video,and let see as Shifu starts testing,as I do not expect him to try it before a couple of hours due to the time now in China.

Hope you had a great coding time,and it is always a pleasure as things work out as you wanted.

kind regards K3
Better bad weather than no weather

Offline ShiFu

  • eParrot.org
  • Admin
  • Posts: 1984
Re: PID Arduino Control by ElectroMech
« Reply #12 on: December 16, 2018, 06:18:35 AM »
This first test code is a start. It still needs a bit of work and EM will be addressing those. 
First, we need Cooling Mode, not Heating Mode. We are needing to add cold water to the system to regulate the condenser temperature.
Then we need higher setpoint resolution than whole numbers. Something like 86.2 C instead of 85, 86 or 87 C.
And I'm still confused where the actual PID calculations happen. And if those parameters will be user adjustable.

The menu forces you to single click one degree at a time. So adjusting the setpoint from 80 to 20 is 60 button clicks.
And upon a reset, those valves are not stored. You start over from 80 (or whatever the system default setting is). 

Control of the servo motor has not been implemented yet. So for now, this cannot be tested. 

But it is a start. 
Stay calm and follow the screaming people.

Offline ketel3

  • Admin
  • Posts: 1377
  • Eparrot.org
Re: PID Arduino Control by ElectroMech
« Reply #13 on: December 16, 2018, 10:02:08 PM »
Hi Shifu,
The problem for me is I do not use such a system ,so it did not realy looked into the working of it.
Controling the deplegmator cooling is complete different from my system.

It is useless for now if I write here how it has to work on a LM as I can decribe that very well,but it will not contribute but only make it more difficult.

Have to look into your system  ;)

EDIT:
Maybe this artikel I was reading a while ago can give some new idea's .
The pid may work better if the vapor temp at column top  was used to control the output ?


I'm noodling through a concept that I recently saw at a micro-distillery that I visited. Their hybrid column was set up so the coolant to the dephlegmator was controlled by the temperature of the vapor at the top of the column. They had a controller box that they could set the threshold temperature to turn on the coolant. I asked whether they were controlling the temperature of the coolant, and the distiller said no, they were monitoring the temperature of the vapor at the top of the still, not the coolant.

This was new to me, I had heard of controlling the coolant by the temperature of the coolant exiting the dephlegmator, reflux ratio or rate of production. But vapor temperature kind of makes sense--you set the controller for the vapor temperature of the abv you are targeting and the controller will cycle the coolant valve to maintain that temperature / abv. The system will crank away at that abv until it cannot hit that abv based on your theoretical plates and remaining abv in the boiler.

Seems like this could be useful in a couple of ways. My focus is making bourbon, but with a CM column I'm always looking for ways to keep the abv on the relatively low end (around 120-130 proof), usually by dialing back the reflux using a needle valve. A high vapor temperature setting would be good for hitting a lower abv. For NGS a temp close to the azeotrope would give a high proof product. In both cases the still would run at the abv associated with the temperature until the still could not produce that abv any more. Not sure whether this would work as a good tails cut, but it would definitely give you a sign that the run was reaching an end.

Curious if anyone has seen or used a still that controls the coolant this way. Any downside to running a still this way? I did a few searches here and did not come up with anything./i]
Better bad weather than no weather

Offline ShiFu

  • eParrot.org
  • Admin
  • Posts: 1984
Re: PID Arduino Control by ElectroMech
« Reply #14 on: December 17, 2018, 05:04:14 AM »
K3, that is an amazing concept, and one that I probably would never have thought of.
Obviously a DS18B20 temperature sensor would not be good enough here, it would need the finer resolution of the SMT172.

I can't keep switching horses in the middle of projects, so I'll need to come back to that later.
Having changed everything when switching from a stepper motor to a servo motor taught me to stop changing things during a project.

So far, the lag time - and the big temperature overshoot - has been the biggest issue but in retrospect both types of motors were using the same basic code from the same coder and was having the same problems. 
We have new eyes on the project now and the hope is that at least one of them can make this successful.
Stay calm and follow the screaming people.

Offline ketel3

  • Admin
  • Posts: 1377
  • Eparrot.org
Re: PID Arduino Control by ElectroMech
« Reply #15 on: December 17, 2018, 10:01:15 PM »
Let see I just wanted to contribute this as it is the only thing I can do as coding is not my skill,but pointing into a certain direction can always help.
And I think a ds sensor will do the job.
Better bad weather than no weather

Offline ElectroMech

  • Posts: 7
Re: PID Arduino Control by ElectroMech
« Reply #16 on: December 18, 2018, 12:18:32 AM »
Hi All
I want to get permission

Can i change some changes in hardware:

need to change the servo value setting by using variable resistance (Why? By using PID values its best to set up the position of servo from     0 to 180 by using it)

Benefits:  From it the system will be professional easy to use and highly accurate

How to set temperature (PID Implemented): 

up button = increment in target temperature as 0.1
down button =  decrement in target temperature as 0.1
Right button = increment in target temperature as 10
Left button =  decrement in target temperature as 10
 
Any more thing if you want then tell me ?
   

Offline ElectroMech

  • Posts: 7
Re: PID Arduino Control by ElectroMech
« Reply #17 on: December 18, 2018, 12:27:30 AM »
The code is attached

Offline ElectroMech

  • Posts: 7
Re: PID Arduino Control by ElectroMech
« Reply #18 on: December 18, 2018, 01:07:11 AM »
This is the coding that what i was talking about and potentiometer is attached to A1 port

Offline ketel3

  • Admin
  • Posts: 1377
  • Eparrot.org
Re: PID Arduino Control by ElectroMech
« Reply #19 on: December 18, 2018, 01:12:41 AM »
Hello EM,
Thanks for posting ,Shifu will be online in about 6 hours or so let see what he tinks about your idea,thanks for ventilating your idea ,
Cheers K3
Better bad weather than no weather