PieMan
Hi,

I am new to the OpenPLC scene. I am looking to run a Small DC Fan (below 5V) when the temperature reaches a certain parameter. The temperature sensor I intend to use is a TMP 102 Digital Temperature Sensor Board. I am just wondering will this be possible to run of OpenPLC when all the components (any tips on extra components) are linked to my RaspberryPi.

Thanks
Quote 0 0
thiagoralves
OpenPLC can't read digital sensors. As any other PLC, it can only read analog voltages, current, or resistance. Therefore you will have to provide the code to read the TMP 102 yourself (in C/C++) and add that to the "custom hardware layer" section. Instructions for that are in the "Hardware" tab on the OpenPLC webserver.

Also, you will need a relay to switch the DC Fan. Raspberry Pi GPIO pins aren't strong enough to turn things on and off.
Quote 1 0
thiagoralves
This might be a good starting point: https://github.com/shrx/RaspberryPi/blob/master/senzorji/tmp102/tmp102.c
Quote 1 0
thiagoralves
You can use any NTC Thermistor like this one: https://www.amazon.com/CrocSee-NTC-10K-Meters-Temperature/dp/B0725HVHKR/ref=sr_1_2_sspa?keywords=thermistor+10k&qid=1573663505&sr=8-2-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEzQUo3UDNKQUtFR05ZJmVuY3J5cHRlZElkPUEwMjkzMTUxM0JZSTVPR05HN0hGQyZlbmNyeXB0ZWRBZElkPUEwODczMDE0TEpQSkhLTU5XNTZJJndpZGdldE5hbWU9c3BfYXRmJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ==

But then you need to connect it to an analog port. Unfortunately the Raspberry Pi has no analog inputs. Therefore, you need to add an Arduino board to your setup. Arduinos have plenty analog and digital inputs. You can follow the guide on OpenPLC website to learn how to install OpenPLC firmware on your Arduino board and how to connect it to your Raspberry Pi: https://www.openplcproject.com/getting-started-arduino

Then you need to wire your NTC sensor properly. Adafruit has a nice guide: https://learn.adafruit.com/thermistor/using-a-thermistor

This will give you a voltage reading on the analog input that varies according to the temperature. You need some math to convert the volts to temperature in Celsius. Fortunately I have a project where I did just that. I'm attaching the project here for your reference. Take a look at the function block that converts the raw temperature (volts) to Celsius (in integer format, so 25.76°C is 2576). You can reuse that as is.

For the relay, the Raspberry Pi won't "read" it, because a relay cannot be read. The Raspberry Pi will instead control it. For that, any 3.3V board relay should be good. I'm pretty sure Adafruit has plenty. You can also use Arduino pins to control the relay from OpenPLC. In that case, it might be even easier to find an Arduino compatible relay board.
Quote 1 0
thiagoralves
You need to upload the firmware through the Arduino IDE. You can do it on the Pi or on your PC, it doesn't matter, however it will probably be a lot easier to do it on your PC (installing Arduino IDE on the Pi can be nasty sometimes). After you upload the OpenPLC firmware, you won't need the Arduino IDE anymore, as the Arduino board will talk directly to the OpenPLC runtime running on your Pi.

There is plenty of information on the web explaining how to use Arduino IDE to upload a firmware (also called sketch). Here is one straight from the Arduino.cc website: https://www.arduino.cc/en/Guide/ArduinoUno#toc2
Quote 0 0
thiagoralves

I was wondering can I run everything off my Arduino such as my Relay for my DC Fan, My LED and Thermistor? Or is it possible to run off the RaspberryPi and Arduino at the same time.
Either one is fine. You can have it all connected to the Arduino or you can mix and match. It doesn’t matter.

Also which would be the best programming to use on OpenPLC to make the activity work.
The best programming language is the one you know best.

I want to the thermistor to recognise the a set temperature parameters which in turn will turn on the DC Fan and LED. Is Ladder Logic possible?
Yes.

Quote 0 0
thiagoralves
The code was written for 10k NTC sensors. If you’re using a different sensor you’ll need to rewrite the code according to the sensor you’re using. You’ll probably be able to reuse the voltage part since that is universal, just to convert the internal reading to volts.
Quote 0 0
thiagoralves
You got it all wrong. The ladder programming language is just a symbolism to facilitate programming for electrical engineers that are used to place wires all around. The power rail in the programming environment has nothing to do with real power on the breadboard. I suggest you follow the getting started tutorial first to understand how PLCs and ladder logic works. Trying to build your program without prior knowledge will just be painful and will get you running in circles, or making wrong assumptions.
Quote 0 0