Go Down

Topic: Problem With Sensor Readings not update at the same time with the real value (Read 167 times) previous topic - next topic

aruskrisna

Hello people, i just start to learn arduino, and sorry  for my bad english

so i just try to using temperature sensor and a solenoid push pull,
i used MPXM2053GS, and for the output i used an amplifier ADC623 like in this project

https://create.arduino.cc/projecthub/itmightbeworse/pressure-airflow-measure-device-with-analog-sensor-037d15

and there is no problem with it, it worked fine. i just want to control the solenoid with the output from the sensor, so the solenoid will start to move at 5kPa and stop at 20kPa, and i just do some code to control delay for on-off the solenoid so it could give different push power ... and here is the problem

i displayed the sensor output to the lcd, and it was able to update the output at the same time( real value from the sensor and arduino reading is update in the same time and it is displayed on LCD) but when the solenoid start to move, my arduino is not update the sensor output at the same time, it was just like hang for some seconds and it start to update the value again, sometimes it was just stuck until the condition when the solenoid stop to move... i used a mosfet and a diode for the solenoid and a 12V/3A psu, and because the reading is not update at the same time with the real value, my solenoid not giving the right push like what i want... how can i still make the reading still update at the same time when the solenoid is moving

wvmarle

Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

jremington

For informed help, please read and follow the directions in the "How to use this forum" post.

aruskrisna

Are you a fan of the delay() function, by chance?
actually i'm really just a beginner to arduino, i just want to control solenoid to do an action every 750ms
so my idea is to control the power with delay, example

digitalWrite(solenoid,HIGH);
delay(10);
digitalWrite(solenoid,LOW);
delay(740);

it will move every 750ms isn't it?

the problem is when the solenoid start to move, the reading from the pressure sensor is stuck, for example
i setting the solenoid start to move at 10kPa and stop when it is pass 30kPa, the sensor reading start from 0 and increase till 10kPa and my arduino display it normally, but when the solenoid start to move, my arduino didn't update the reading, it is show the last value ( 10 kPa) and the reading start to be normal again when the solenoid is stop moving ( after pass the 30kPa)

wvmarle

Then that 750 ms the Arduino is not doing anything, just twiddling its thumbs. Only after the delay it can start doing anything else.

If you want to be able to read the sensor during that time you have to switch to millis() based timing (see Blink Without Delay on how that works). You probably also have to read upon how to implement a finite state machine.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

aruskrisna

Then that 750 ms the Arduino is not doing anything, just twiddling its thumbs. Only after the delay it can start doing anything else.

If you want to be able to read the sensor during that time you have to switch to millis() based timing (see Blink Without Delay on how that works). You probably also have to read upon how to implement a finite state machine.
Hey thanks for the solution, now i can move the solenoid while arduino reading the sensor output,
but now i have another problem, like i said i want to control the push power of the solenoid so my idea at first is controlling the time for on off the solenoid, it is work like when i using the delay, it is move corresponding to the code... for example ( i already used milis now)

unsigned long tOn = 10;
unsigned long tOff = 750;

i set the time here, and the solenoid move like the time i was set, but when i combine with the code for the sensor, the solenoid just do on-off like normally (HIGH-LOW) it is not move according to the time i set.

here is the example of my code

void loop() {
 
  //PressureSensor(); this is the function that i made for the sensor i used

   
  current milis = millis();
 
    if((statusSolenoid == HIGH) && (currentmilis - prevmilis >= tOn)) {
 
        statusSolenoid = LOW;                 
        prevmilis = currentmilis;           
        digitalWrite(solenoid, statusSolenoid);
 
   
    } else if ((statusSolenoid == LOW) && (currentmilis - prevmilis >= tOff)) {
   
        statusSolenoid = HIGH;               
       prevmilis = currentmilis;           
        digitalWrite(solenoid, statusSolenoid);
 
    }
}
 
when i dont call the PressureSensor() function the solenoid move according to the time i was set, when i call the function the solenoid just do HIGH-LOW, i need help to control the push power of my solenoid push-pull , how can i solve this

wvmarle

Can't be sure without knowing the solenoid details.

Best guess: use PWM to control the amount of current it gets.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up