P-solver
Posts: 17
Joined: Sun Mar 15, 2020 2:00 pm

Project: Controlsystem automation

Sun Mar 22, 2020 9:19 am

Ok, so I'm new to Raspberry Pi (and basically everything else I'm going to mention here, exept for some SQL and homepage experience) but have descided to try creating my own controlsystem for my home.

I will split the project into smaller pieces and update them in this thread, but before I do, I would like some help with some questions to make sure I won't go running in the wrong direction from start :)

So my idea looks like this:

1. Read tempvalue from heating device
1a. I will use a arduino to
1b. extract info from the heating device LCD screen
1c. that will be sent as a signal to the Raspberry Pi

2. Reading signals and acting as webserver
2a. The Raspberry Pi will read signals from 4 different temp sensors
2b. along with the signal from the arduino

3. The Raspberry Pi will also be used as a webserver and saving data in either
3a. a SQL database or
3b. as CSV file etc.

4. My coded program(s) will:
4a. Send the values to store in the SQL/CSV on a regular basis (1 update/minute or so)
4b. Control some relays or WiFi sockets depending on the input signals (1 run every 10 sec or so)

5. I will display graphs based on the information in the database

Questions:
- Communication between Arduino and Raspberry Pi, how should I do?
(Distance between them are about 12 meters in different rooms, concrete walls, so I would like to use WiFi if possible)
- Logging the data, using SQL or CSV etc?
(Is there any of them I should preffer in order of functionality or "speed"?)
control_system.PNG
control_system.PNG (138.73 KiB) Viewed 882 times

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Project: Controlsystem automation

Sun Mar 22, 2020 10:11 am

For Arduino to pi communication use MQTT over the home WiFi. Pi is the mqtt server, Arduino (e.g. Wemos D1 mini) publishes mqtt topics containing the data. Pi subscribes to the topic and stores data in database.
Logging I use influxdb on the pi and grafana to draw graphs of data (temperatures, voltages etc.)
For web server I use apache2.

User avatar
rin67630
Posts: 1017
Joined: Fri Mar 04, 2016 10:15 am

Re: Project: Controlsystem automation

Mon Mar 23, 2020 5:52 pm

Hi Neil,
where you already successful with that implementation?

I am currently struggling with a serial plotter and logger for data coming from an Arduino over serial.

We have a bit higher requirements and need to log five values together with a timestamp every second... for years.

We are looking forward to get a scrolling plotter for the last 15 min.
We would also want to be able to retrieve the data for any time series to replot them.

Our current project in GitHub
https://github.com/Gordon999/Pi-Arduino_Ser_Plotter
works, but has got progressively more and more patches to cope for glitches, so a general restart with a database design would probably be the best solution.

I would love to share your experience...

P.S. Are you sure that's "beginners" is the right folder for your project?

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Project: Controlsystem automation

Mon Mar 23, 2020 6:08 pm

Yes I am successfully using influxdb (non-relational) to record 6 temperatures and 1 voltage from several Wemos D1-mini devices using mqtt. And grafana draws graphs of it, with user selectable time ranges. It has been running since February 2019.

P-solver
Posts: 17
Joined: Sun Mar 15, 2020 2:00 pm

Re: Project: Controlsystem automation

Mon Mar 23, 2020 6:35 pm

neilgl wrote:
Sun Mar 22, 2020 10:11 am
For Arduino to pi communication use MQTT over the home WiFi. Pi is the mqtt server, Arduino (e.g. Wemos D1 mini) publishes mqtt topics containing the data. Pi subscribes to the topic and stores data in database.
Logging I use influxdb on the pi and grafana to draw graphs of data (temperatures, voltages etc.)
For web server I use apache2.
Ok, this sounds promising :)
I'll look into the MQTT communication, and also Grafana, wich I haven't heard of before.

Thanks for the startup!

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Project: Controlsystem automation

Mon Mar 23, 2020 11:48 pm

I would think this project will include in the program Loading and Diversity Factor , Also the program be Fail to Safe

Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Project: Controlsystem automation

Tue Mar 24, 2020 12:12 am

Yes and good layout this time. The most interesting part for me is 1b. the Arduino reading the display on the LCD screen.

P-solver
Posts: 17
Joined: Sun Mar 15, 2020 2:00 pm

Re: Project: Controlsystem automation

Tue Mar 24, 2020 11:44 am

neilgl wrote:
Tue Mar 24, 2020 12:12 am
Yes and good layout this time. The most interesting part for me is 1b. the Arduino reading the display on the LCD screen.
I think this will be the most time consuming part of the project for me. I have started to read about it since I'm still waiting for my hardware to arrive, and found this: https://www.instructables.com/id/Direct ... urpose-IO/

But I still think that it's not covering all of the things I will need to do in order to fetch all the signals I want, but hey, I need to start somewhere.

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Project: Controlsystem automation

Tue Mar 24, 2020 2:02 pm

In that link he opens the device and solders wires to it - could be expensive /dangerous on your boiler (heating device) ?
What I do is to use a DS18B20 1-wire temperature sensor taped to the copper pipe just above my boiler. That gives a pretty accurate measurement of what the boiler temperature is. I then send that via a D1mini (esp8266) using MQTT to a pi3B+ for monitroing/control purposes.

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Project: Controlsystem automation

Tue Mar 24, 2020 8:37 pm

This project to control home electrics ,should
Only be carried out if you know what you are doing.( Qualified Electrician )
If you are switching mains using relays, on no
Account must you SWITCH THE EARTH
CONTINUITY WIRE to any appliance , Check
Regulations. If you controlling using sensors
Your program must be fail to SAFE, Do not
Modifier sensors on heating equipment
Keep within in your supply loading. And your
Domestic Ring main diversity factor.
Regards Boyoh
Retired Electrical / Electronic Technician
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Project: Controlsystem automation

Tue Mar 24, 2020 9:48 pm

Yes and not so good layout this time, but safety first!

P-solver
Posts: 17
Joined: Sun Mar 15, 2020 2:00 pm

Re: Project: Controlsystem automation

Wed Mar 25, 2020 5:54 am

neilgl wrote:
Tue Mar 24, 2020 2:02 pm
In that link he opens the device and solders wires to it - could be expensive /dangerous on your boiler (heating device) ?
What I do is to use a DS18B20 1-wire temperature sensor taped to the copper pipe just above my boiler. That gives a pretty accurate measurement of what the boiler temperature is. I then send that via a D1mini (esp8266) using MQTT to a pi3B+ for monitroing/control purposes.
There's a catch here, and that's why I want to get the signal from the heat pump display;

I want to fetch the value of the temp that the radiatorwater "should" be, a.k.a when the heat pump will stop heating the radiator water.
This temp is based on a graph that:
a. will have a different angle depending on settings in the heat pump
b. can be moved along the x-axis depending on settings on the heat pump.

I might have to end up doing it your way, but I want to automise the system as much as possible, and getting the exact value from the heat pump display would be a big solver for this problem.

P-solver
Posts: 17
Joined: Sun Mar 15, 2020 2:00 pm

Re: Project: Controlsystem automation

Wed Mar 25, 2020 6:04 am

boyoh wrote:
Tue Mar 24, 2020 8:37 pm
This project to control home electrics ,should
Only be carried out if you know what you are doing.( Qualified Electrician )
If you are switching mains using relays, on no
Account must you SWITCH THE EARTH
CONTINUITY WIRE to any appliance , Check
Regulations. If you controlling using sensors
Your program must be fail to SAFE, Do not
Modifier sensors on heating equipment
Keep within in your supply loading. And your
Domestic Ring main diversity factor.
Regards Boyoh
Retired Electrical / Electronic Technician
Always safety first!
I have a friend who's a certified electritian and a father in law who's a plumber so I will get help from them with the "installations".
"All" I will have to do is to set the chematics in the code of the control system to when to start and stop a waterpump based on values from the differnt sensors.
So I will be controlling an waterpump that sends extra heating to the radiator water when needed, that's all.

P-solver
Posts: 17
Joined: Sun Mar 15, 2020 2:00 pm

Re: Project: Controlsystem automation

Sun Mar 29, 2020 3:27 pm

One of the good thing with waiting for hardware is that it leaves you with time to think :)

So after talking to my father in law, I have changed my plans, and redrawn the plan:

1a & 1b: I will start by trying to get the signal from the display by using a camera and some sort of QR/text-reading.
(The reason is that I first of all want to confirm that my controlsystem will work. If it does, I might dig deeper and try reading the info from the LCD display directly)

4b: I will control a servo motor instead of turning on/off a waterpump. This servo motor will adjust a 4-way valve.

6a: I will monitor a blinking led light on the powermeter in the house, and send the signal to the Raspberry Pi.


So my quick questions at this time is:

1a: Is there any camera to prefer as this probably will be some "close up" images of the display? (Or can I just go with a regular webcam with a descent resolution?)

6a: Any suggestions on what light sensor to use? (I would like to monitor/count the number of flashes of a red diod.)


And I finally got some hardware delivered, and this is what I have to play with at the moment:

1 x Raspberry Pi 4b
1 x Arduino pro mini
2 x Arduino Nano
1 x Arduino Uno
1 x NodeMcu Lua WIFI module
1 x WIFI transceiver module, ESP8266
2 x 2.4 GHz trans. module
1 x 433 MHz rec/trans

Updated image:
control_system_v2.PNG
control_system_v2.PNG (158.36 KiB) Viewed 555 times

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Project: Controlsystem automation

Sun Mar 29, 2020 9:56 pm

1a and 1b - might not be that easy - maybe just tell the pi what you have entered into the display / heating controller?
That hardware looks good - 6a could just be a photodiode/phototransistor connected to the pi/NodeMCU?
The NodeMCU/esp8266 can probably be used as general purpose Arduino style microcontrollers - saving Arduino's
Camera - get a pi camera module V2. (for 1a)
Servo motor - has it got enough torque to turn the valve?

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Project: Controlsystem automation

Mon Mar 30, 2020 11:37 am

P-solver wrote:
Sun Mar 29, 2020 3:27 pm
One of the good thing with waiting for hardware is that it leaves you with time to think :)

So after talking to my father in law, I have changed my plans, and redrawn the plan:

1a & 1b: I will start by trying to get the signal from the display by using a camera and some sort of QR/text-reading.
(The reason is that I first of all want to confirm that my controlsystem will work. If it does, I might dig deeper and try reading the info from the LCD display directly)

4b: I will control a servo motor instead of turning on/off a waterpump. This servo motor will adjust a 4-way valve.

6a: I will monitor a blinking led light on the powermeter in the house, and send the signal to the Raspberry Pi.


So my quick questions at this time is:

1a: Is there any camera to prefer as this probably will be some "close up" images of the display? (Or can I just go with a regular webcam with a descent resolution?)

6a: Any suggestions on what light sensor to use? (I would like to monitor/count the number of flashes of a red diod.)


And I finally got some hardware delivered, and this is what I have to play with at the moment:

1 x Raspberry Pi 4b
1 x Arduino pro mini
2 x Arduino Nano
1 x Arduino Uno
1 x NodeMcu Lua WIFI module
1 x WIFI transceiver module, ESP8266
2 x 2.4 GHz trans. module
1 x 433 MHz rec/trans

Updated image:
control_system_v2.PNG
[/quot

From BoyOh
Take my advice on this project , it is your lacking of basic electronics that will hold you back.. 6a question is a very basic ,the use of a LDR Light Dependent Resister to monitor a flashing LED . This task one of the the first in the electronics learning
curve, If you are not at this level of understanding electronics you will not succeed on this project.
Sorry if I'm being blunt , but I don't want you wasting money on more parts. The Forum will point you in the right direction
Writing about it & Talking about it , Is different to putting in to practice


Regards BoyOh Retired Electrical / Electronics Technician, 88yrs old
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Project: Controlsystem automation

Mon Mar 30, 2020 3:48 pm

For 6a here is a python script that looks at GPIO4 to count the number of pluses seen by an LDR Light Dependent Resister as @boyoh said.
On my test rig I have an LDR and a transistor (and resistors) to set the input high - when the LDR sees light from a nearby LED (which flashes once per second), the input goes low - the python script looks for that "FALLING" edge.

Code: Select all

#!/usr/bin/python3
import RPi.GPIO as GPIO
from time import sleep
num=1
pin=4
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(pin, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

# Define function for detect edge on GPIO
def ldrSwitch(channel):
    global num
    print ("edge detected" ,num)
    num=num+1

# Set up the gpio event detection callback and set debounce
GPIO.add_event_detect(pin, GPIO.FALLING, callback = ldrSwitch, bouncetime = 200)

try:
    while True:
        sleep(0.1)

except KeyboardInterrupt:
    print ("keyboard CTRl-C pressed")
    GPIO.cleanup()

P-solver
Posts: 17
Joined: Sun Mar 15, 2020 2:00 pm

Re: Project: Controlsystem automation

Tue Mar 31, 2020 4:42 am

boyoh wrote: Take my advice on this project , it is your lacking of basic electronics that will hold you back.. 6a question is a very basic ,the use of a LDR Light Dependent Resister to monitor a flashing LED . This task one of the the first in the electronics learning
curve, If you are not at this level of understanding electronics you will not succeed on this project.
Sorry if I'm being blunt , but I don't want you wasting money on more parts. The Forum will point you in the right direction
Writing about it & Talking about it , Is different to putting in to practice


Regards BoyOh Retired Electrical / Electronics Technician, 88yrs old
I can admit that I'm not that good at the electronics part, but I believe (and hope) that I have enought between my ears to learn along the way.
I'm always into learning new things as a hobby, and if this project doesn't make it to the end, I can always by an existing automation system.
So I'm more into this to learn something new and see if I can bring this project into a working result in some way,

And thanks for the feedback, a LDR is ordered and on it's way,

P-solver
Posts: 17
Joined: Sun Mar 15, 2020 2:00 pm

Re: Project: Controlsystem automation

Tue Mar 31, 2020 4:51 am

neilgl wrote:
Mon Mar 30, 2020 3:48 pm
For 6a here is a python script that looks at GPIO4 to count the number of pluses seen by an LDR Light Dependent Resister as @boyoh said.
On my test rig I have an LDR and a transistor (and resistors) to set the input high - when the LDR sees light from a nearby LED (which flashes once per second), the input goes low - the python script looks for that "FALLING" edge.

Code: Select all

#!/usr/bin/python3
import RPi.GPIO as GPIO
from time import sleep
num=1
pin=4
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(pin, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

# Define function for detect edge on GPIO
def ldrSwitch(channel):
    global num
    print ("edge detected" ,num)
    num=num+1

# Set up the gpio event detection callback and set debounce
GPIO.add_event_detect(pin, GPIO.FALLING, callback = ldrSwitch, bouncetime = 200)

try:
    while True:
        sleep(0.1)

except KeyboardInterrupt:
    print ("keyboard CTRl-C pressed")
    GPIO.cleanup()
Great! Thanks, I'm just waiting for my LDR now, and then I'll get right to getting this setup and test it.

For the 1a & 1b, after reading some, I've come to the conclusion that I might be able to use a:

- Standalone camera with built in wifi or
- another raspberry pi with an attached camera module

So at this moment, I'm just deciding on what "way" to select.

P-solver
Posts: 17
Joined: Sun Mar 15, 2020 2:00 pm

Re: Project: Controlsystem automation

Tue Mar 31, 2020 5:04 am

neilgl wrote:
Sun Mar 29, 2020 9:56 pm
1a and 1b - might not be that easy - maybe just tell the pi what you have entered into the display / heating controller?
That hardware looks good - 6a could just be a photodiode/phototransistor connected to the pi/NodeMCU?
The NodeMCU/esp8266 can probably be used as general purpose Arduino style microcontrollers - saving Arduino's
Camera - get a pi camera module V2. (for 1a)
Servo motor - has it got enough torque to turn the valve?

1a & 1b: After reading some, and noticing that the Arduino won't be able to handle the images in the way I would like, I've come to the conclusion that I might be able to use a:

- Standalone camera with built in wifi or
- another raspberry pi with an attached camera module (as you noted)

So at this moment, I'm just deciding on what "way" to select.

Since the heater itself changes the value I want to fetch depending on the outdoor temp combined with a selected curve, I can't set it static in my system.

4b: Well, I probably can't use the one in the image, but I can look for a bigger one, or see if I can use some gears to help it along the way.

6a: LDR ordered :)

Thank's for the feedback!

P-solver
Posts: 17
Joined: Sun Mar 15, 2020 2:00 pm

Re: Project: Controlsystem automation

Tue Apr 07, 2020 6:15 pm

Today I'm focusing on the part 3 and 4 in the latest image of my project:

The code and the database! (...or at least parts of it)

Setup:
I have got my Arduino Nano monitoring 6 different voltages (aka temperatures) from the heat pump and sending them through the USB-connection to my Raspberry Pi.
My python code in the Raspberry is currentlu fetching the values in a string looking like this " b'1302,1498,1429,1429,1615,1434\r\n' " (but with quotes excluded)

Since I want to update the mySQL database with the six values every 30 second, I'm not really sure on how to verify that I get the "latest" reading.
I'm was thinking of running the update of the voltages from the Arduino in a more frequent pace (Lets say once every 5 seconds) and then maybe add some ID to verify that when I fetch the info from the Arduino to the Raspberry I can first verify if the ID is the same as the last line before inserting it to the mySQL database. But there must be a better way... ;)

Questions:
a) Is there a simpler way to verify that the information sent to the mySQL database is a "new" reading from the Arduino and not the same as before? (Maybe something like "fetching" the data from the Arduino at the specific moment?)

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Project: Controlsystem automation

Wed Apr 08, 2020 10:46 am

If you don’t have a real time clock module, maybe add a “timestamp” (milliseconds since startup millis) on the Arduino side and send that back with the six values. It should increase every reading (until it rolls over!), so you know it is a “new” reading even though the values might be the same as last time (temperature constant for 3 hours say).

Return to “Beginners”