Pressure Sensor – Arduino

So theres a number of sensors that you can use an interface within arduino or a microcontroller, but the goal here is to take an industrial version of a sensor that you can use in an industrial application. I.E, in my case, i want to use this in an automotive application and measure lets, say oil pressure or air pressure or fuel pressure for that matter, and use it in that industrial environment have that sensor be able to survive that type of environment but run the Values back to a computer, in this case this microcontroller and then display it on to a screen, thats readable to the human eye and is understandable to to you in real time. So I want to take this industrial sensor and read a lets, say oil PSI value of of my engine while its running Ill be linking all of this in the description below you can pick up these pressure transducers off of Amazon. These LCD displays off of Amazon, breadboards Arduino kit, everything here Ill link down below in case you want to purchase it and and use it to for your own projects, alright. So in this case, Im going to be using an LCD screen over the I squared C communication bus with the Arduino to communicate those values from the sensor through the microcontroller to the screen. Id really recommend if you have a smaller. So this is the 4 by 20 LCD screen. If you have the smaller 2 by 16 screen, I would recommend getting these backpacks that you can put on to the back of the screens to use the I squared C communication interface.

Otherwise, youre gon na have to use all these pins or most of these pins to interface it to the Arduino, or in this case its super simple, with the I squared C. All you have to use is, you can see, here is 4 pins and those pins are ground and then the five volt, and then a data pin and an oclock pin and those easily interface with the Arduino ground, the ground, five volt. And then you can use the clock and data pins which are on on this side. You can see the SDA and SCL just at the back here, alright, so just showing you how everythings connected so this pressure transducer has three wires on it. If I pull open the connection here, you can see how this is its got three pins on it and then theres the female end, so that just plugs in there nice and easy. So you can lets, say plug that into your engine block and then easily unplug. That so theres three wires on there, this red wire is positive, goes to five volt positive, the ground goes to ground and then the screen wire is the the output for the voltage going into the analog signal so that green wire, you want to interface with one Of your input analog pins on your Arduino, so in this case Im taking that and running that over to a zero on the Arduino and then, like, I said for the LCD screen Im running my ground, pin to ground on the Arduino VCC to five volts on The Arduino SDA to the SDA pin on the Arduino and then the SCL to the SCL pin on the Arduino so over here is the ground and five volt.

If you can see that and and then on, this side is where the SCL and SDA pins should be labeled on your Arduino, alright, so heres, a quick demonstration of me just using my mouth to blow onto the pressure transducer and then well see what the values Are on the screen and then I can also use it as a vacuum: Im not sure how accurate the vacuum side would be, but it works. Anyways pressure, transducer and the LCD screen Ill be running this line by line. If you want this code, Ill be putting it down in the description box below, if you have any questions, feel free to contact me at my email here. So this is just an example on how to take this pressure. Transducer read that value both on serial and then to display it on to you know: seedy screen, so these two includes here are just to use with the I squared C and interfacing with the LCD screen. Then coming down these constant integers, constant, integer pressure input. This is just to define the analog input pin for the pressure transducer, so you can use a zero one, two, three or four or five or however many input pins. You held on your Arduino in this case Im using the Arduino Uno, constant energy pressure, zero, so Ill scooch over to the notepad here and show you where these value values are coming from, but the the pressure transducer at zero, PS psi and at 100 psi because Im using a 100 psi, transducer inputs a certain value at zero psi and at a hundred psi on the analog pins, so Ill show you over here, alright, so just to show you real quick, and so you understand how this works.

The analog read function in the arduino ide. Essentially how that works is you put analog, read and brackets and then what that does? Is it takes the analog voltage value from the input of that pin, whichever pin that you select and it converts it to some digital or sorry? Now it converts it to a number between 0 and 123, so thats 1024 values that it can convert from a voltage. Thats being input to the analog pin, so if you come down here where I got those two numbers previously, the 102 point four and the 921 point six. So you just take a quick conversion equation, so theres one to 1024 values that are possible right. So we have x over 1024, is going to be equal to 0.5 over 5 volts. Now. This is because the pressure transducer on amazon theres a sheet that says at 0.5 volts the pressure transducer reads: zero psi and then at oh sorry, I wrote this one Im supposed to be a 4 at 4.5 volts its supposed to read 100 psi. So you just do this quick equation or quick calculation here, and you can figure out that, okay, so at this value, so at 0.5 volts whats, my analog value going to be so at 0.5 volts divided by 5, and then you just multiply that by a thousand 20, for that value gives you 100 and 2.4 so thats. What the analog input integer is going to be at 0 psi, and then you can do the same thing: to figure out what to figure out what your value is going to be at 100 psi.

So, in this case its 920 1.6 and then Ill jump down here and show you how to convert from that analog value into a voltage value but Ill jump back to the code here and just should run you through the code and then Ill Ill pop back Over here to show you this equation again, once we want to convert that value to voltage those two numbers from shown before so the next thing is the constant integer, so just define that as pressure transducer max PSI, so, depending on the transducer that you get just Input that number here so in this case I have a hundred psi transducer so Im putting that down as 100. I have a couple 30 psi transducers on the way to so itd be super easy to interface them with those ones, because all you have to do is just change that number okay, so baud rate. This is just to set the baud rate for the serial, monitor and then censor, read delay. This is the delay in milliseconds between reading the values and displaying it to the screen. So that way, it just slows it down a little bit and then float pressure value. So float is 2 to make sure that I can read the values as decimal points. I just define that as pressure values and thats the variable that I can store those values coming in. So this liquid crystal underscore i2c. This is the this initializes, the LCD screen.

So the format here is just LCD and then bracket thats, your address to the LCD screen, in my case, thats, 0x3 F. So this is for I squared C communication. Your screen might be different, theres, another sketch that you can run to figure out what the addresses of your LCD screen is, and then this is the amount of columns there are and then the amount of rows on the LCD screen. And then you come down to void setup, so this is the routine that runs once when the systems turn on or is reset. So in this case, Im doing serial dot begin and then its my baud rate, so that initializes my serial communication in bits per second and then I come down to LCD begins. So this is initializes malleus LCD screen and then Ill come down to the loop portion, and this runs over and over again so Im taking pressure value, equals analog, read at my pressure input pin. So this is at a zero and this reads my value and then assigns it to that variable pressure value, so pressure value. I then take that and do this conversion equation, because I want to convert it into two psi so Ill flip back over to the notepad. Here and show you what that conversion means, but I just Ill show you real quick. If I take this and then upload it to the Arduino Ill show you that my number does make sense, because at zero psi it should read the 102 point.

Four of that analog reading alright, so this is, with my code, uploaded with the without the conversion equation on there. So, as you can see, my numbers do make sense were at zero psi right now: okay, nothings! No pressure is being put on this sensor and we have a value of 102 coming out of that. That number, so I dont have this value floated. So I cant see the the digital number but Im not looking for that precise of a number anyways. For my psi value I aint here, I guess I could change the code a little bit to get this a little bit more accurate, but as of right now, this numbers not being but my my converted value is being floated all right now. So for the conversion equation, because that lower value does not start, let me bring this up because that lower value does not start at zero and it starts at 102. I have to take whatever that incoming value is and then minus that lower the not lower number. So the 102 and then I basically just the Ill multiply that by the PSI of the transducer that you using and then divide that by the total range from the max value to the minimum value of your pressure. Transducer is, and then that will give you a number thats output in psi, so thats, assuming that the relationship between the voltage and the PSI is linear, because if it isnt, then this equation would have to be different.

So at 0. In this case, if zero volts should be linear, so 0 volts incoming is zero psi actually sorry, it starts at zero. Zero psi is 0.5 volts and then at 4.5 volts its assuming that 100 psi in between all these values is linear, so thats. The way that equation is working now a way that I can confirm this back on the Arduino to the analog input pin is, I can take my small multimeter in this case and then I can go between the input of the analog pin. So this is at 0 psi nothings being on pushed on the pressure transducer and then I can go to the ground. Pin youre gon na see just so you can read that and then I can put that to ground pin then that should read about 0.5 volts. If you can see that theres a bit of a glare yeah, so thats point 5 volts, so that confirms the fact that at 0.5 volts the pressure transducer is reading 0 psi. Now I dont have a the proper adapters right now for my air compressor. But in theory I could take my air compressor and then a gauge on that air. Compressor put it our sorry regulator on the air compressor and put it out a hundred psi, and then I could test this sensor by putting a hundred psi of air pressure force on this and then confirm that value before going through this. And then I could do that out of range of values between zero and and 100 psi just to see if that equation makes sense, thats, where I got that equation from so thats the conversion equation to go from my analog value into a PSI value.

Now I can do I can display this either on to the serial monitor or at the same time I can display it on to the LCD screen. So well take a quick look at the serial monitor here, but this is how I get it to display on the serial, monitor so serial dot print and then pressure value, which is this and then two one one decimal place so well. Take a quick look at the serial mm whoa and then this is showing my zero psi Ill. Give this a quick change, see if that changes. So with my mouth, I can blow it up to 1.7 psi so moving on and the code Sharyl dot print line, psi that just prints the label to the serial monitor and that you get to display on to the LCD screen LCD set cursor at zero column D, Rho and Rho zero and then Im printing, the label pressure and in front of the value thats gon na be printed and then LCD print and then Im taking LC dot print pressure, value so thats this and then I want that printed out to one decimal Place and that I can do that because Ive floated the value at the beginning and then Ill print the label PSI right after it, and then this I had to put in because you need a way to clear the LCD screen. If that value goes over two digits or into the negatives, because if you print it and then allow to go through again, sometimes the I will stay at the end.

So this is an easy way to clear to clear the screen without having to clear the entire screen. So you have to that clear is just the digits right after psi, and then this is my delay between values between reading and each value. So lets take one final. Look at the screen see what it looks like all right. So now that weve taken a full look at the code, heres the screen and heres my pressure transducer Ill, give it one final blow all right. So that shows that my pressure transducer, is working as a pressure sensor here and then I can read it and output it to some psi value and display it on this screen. So hopefully, that helps, and thanks for watching stay tuned for some more projects in the future, because Im planning on making this a larger scale project for my truck, because I want it, I want to use it as a pre. So my truck is an older 92 dodge. I want to use it as a pre obd2 kind of computer for the truck so Ill have various input, sensor, values from ranging from oil pressure to feel pressure to turbo pressure, and then I also want to monitor the incoming voltage from the battery. So Ive got a couple things couple. Things still need to come in the mail, but Ive got this. This is a voltage sensor, so I can read the voltage value on my battery and see how its doing and then this is a voltage regulator.

So I can regulate the incoming voltage from 12 volts down to 5 volts for the Arduino computer system, and then I have a few more things coming, so I actually have a I dont have it down here, but I have a a pyro k, type thermocouple. So its to measure your exhaust gas temperatures and then Ill be able to interface that with the Arduino as well, and then Ive got a couple other small goodies too, that Im looking into, but this will be kind of my ongoing project.

Share.
Exit mobile version