ESP32 I/O Project

Hey, this is my first post so sorry in advance for errors in my post. Also a very intermediate in C++ so bear with me.

I'm trying to build a vacuum monitoring system for two chambers, I have sourced small scale components at the start and will scale up later.

My component list consists of this:

  • Vacuum pump
  • 3-way electronic valve
  • 2 FSR (force-sensitive resistors)
  • manual switch (for one vacuum region)
  • proximity sensor ( for other vacuum regions)

My truth table:

Input Output
FSR-1 |FSR-2|MSwitch|ProxSens VacumPump | 3 way valve
1 0 0 0 1 1
0 1 0 0 1 0
0 0 1 0 1 1
0 0 0 0 1 0
0 0 0 0 0 0

The operation of the systems works as follows.

when the manual switch is pressed the vacuum pump would start from atmospheric to maximum vacuum. this is done by turning on the 3-way valve and pump until the pressure reaches maximum.

Pressure is monitored by FSR1 which triggers pump and 3-way valve to maintain pressure and set presure range.

when the proximity sensor is triggered it turns on pump from atmospheric pressure to pump down to maximum vacuum. FSR 2 maintains pressure and triggers pump in the selected region

I'm using a ESP32 due to the fact I can future proof it for Bluetooth later.

here is my code as follows, instead of prox sensor I used current sensor for now.

const int Carfsr = 34;  //pin link for car side FSR
const int Phonefsr = 35;  //pin link for phone side FSR
const int QiwirelessI = 32; //pink link for Qi wireless chearger
const int Threeway = 27;  //pin link for 3 way electronic valve
const int PumpL = 26; // pin link for Pump
const int Mswitch = 25; // manual switch

int Cfsrvalue = 0;  // setting value for car side to start at 0
int Pfsrvalue = 0;  // setting value for phone side to start at 0


void setup()
{
Serial.begin(115200);
delay(1000);

// Setting pins I/O mode
pinMode(Threeway, OUTPUT);
pinMode(PumpL, OUTPUT);
pinMode(Mswitch, INPUT);
pinMode(QiwirelessI, INPUT);

// Setting pin state
digitalWrite(Threeway, LOW);
digitalWrite(PumpL, LOW);
digitalWrite(Mswitch, LOW);
digitalWrite(QiwirelessI, HIGH);
}

void loop()

{

// Manual switch reading
int ManualS = digitalRead(Mswitch);

// Qi wireless charger current sensor trigger reading
int QwirelessA = digitalRead(QiwirelessI);

// Presure reading from car side
Cfsrvalue = analogRead(Carfsr);

// Presure reading from phone side
Pfsrvalue = analogRead(Phonefsr);


// if both car and phone presure is low
if ( Pfsrvalue >= 250 && Pfsrvalue <=3800 && Cfsrvalue >= 3000 && Cfsrvalue <= 3800)
{
     digitalWrite(Threeway, HIGH);
     delay(10);
     digitalWrite(PumpL, HIGH);
}

// if both manual switch and phone is on  
if(  ManualS == HIGH && QwirelessA == LOW)
{
     digitalWrite(Threeway, HIGH);
     delay(10);
     digitalWrite(PumpL, HIGH);      
}

// manual switch pump trigger
if( ManualS == HIGH )
{
     digitalWrite(Threeway, HIGH);
     delay(10);
     digitalWrite(PumpL, HIGH);
}

// wireless charger current senese pump trigger
if (QwirelessA == LOW)
{
     digitalWrite(PumpL, HIGH);  
}

// on condtions for car presure
if(Cfsrvalue >= 3000 || Cfsrvalue <= 3800)
{
     digitalWrite(Threeway,HIGH);
     delay(10);
     digitalWrite(PumpL, HIGH);  
}

//on conditons for phone  side
if(Pfsrvalue >= 250 || Pfsrvalue<=3800)
{
     digitalWrite(PumpL, HIGH);  
}


Serial.println(Cfsrvalue);
Serial.println(Pfsrvalue);
Serial.println(ManualS);
Serial.println(QwirelessA); 


}

I think there are flaws with my current approach to programming this as this doesn't work.

any suggestions would be appreciated.

I did not notice where these are configured:

const int Carfsr = 34;  //pin link for car side FSR
const int Phonefsr = 35;  //pin link for phone side FSR

Could you describe, in greater detail, the problem, over 'it does not work?' Perhaps stating what is supposed to happen and what actually happens.

You would realize a good performance increase and increased stability by using the ESP32 A:D API. Page not Found - ESP32 - — ESP-IDF Programming Guide latest documentation

You may want to review the GPIO & RTC GPIO API: GPIO & RTC GPIO - ESP32 - — ESP-IDF Programming Guide latest documentation

Hey thanks for your replay, by the looks of it my response from the ESP32 is that the manual switch and current sensor trigger the pump and 3 way valve as expected but the FSR readings work in reverse. I checked the FSR readings on the serial output.

the code you didnt see is used in this section here

// Presure reading from car side
Cfsrvalue = analogRead(Carfsr);

// Presure reading from phone side
Pfsrvalue = analogRead(Phonefsr);

Suggest you read the forum instructions for how to post code.

Please modify both your posts to comply.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

filipsons11:
but the FSR readings work in reverse. I checked the FSR readings on the serial output.

Are the FSR's working within their specific design parameters?

Hi,

filipsons11:
My component list consists of this:

  • Vacuum pump
  • 3-way electronic valve
  • 2 FSR (force-sensitive resistors)
  • manual switch (for one vacuum region)
  • proximity sensor ( for other vacuum regions)

My truth table:

Input Output
FSR-1 |FSR-2|MSwitch|ProxSens VacumPump | 3 way valve
1 0 0 0 1 1
0 1 0 0 1 0
0 0 1 0 1 1
0 0 0 0 1 0
0 0 0 0 0 0

The 3 way valve has 3 states, how do you output the three states.
I think the table function has, as usual, distorted your table.
A picture of s hand drawn truth table may be clearer.
Tom.... :slight_smile:

Paul_B I am only testing this with 2 switches for Current sense, manual switch, 2 adjustable pots for the two FSR and 2 LED for output on an ESP32. I'm trying to get the logic correct before I apply real figures. As I'm also waiting for parts to arrive.

TomG

the truth table is only a on-off state, the 3-way valve has two states which are off for one and on for the other as the 3 is the input or the pump in my case.

also ill work on getting a digram drawn up.

thanks