Hi everyone,
I'm quite new to Arduino and have recently started a project:
I want to monitor & control air pressure by an Arduino.
the Arduino is hooked up to a pressure sensor, witch feeds the arduino with data.
The Arduino processes this data and controls a 5v relay board, that switches the 12v compressor on or of.
I want it to switch on at <= 0.6 MPa (6 Bar) an switch of at > 1.0 MPa (10 Bar)
If compressor switched of because of reaching 1.0MPa then I just want it to start again at 0.6MPa, not somewhere in between.
I can read the data from the sensor, but can't get it to work right with the relay board...
I hope someone can help me!
Roy
this is my code:
[code]
/*macro definition of sensor*/
#define SENSOR A0 //the YELLOW pin of the Sensor is connected with A0 of Arduino/OPEN-SMART UNO R3
int relayPin = 8;
void setup()
{
//Innitiate Serial Communication
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
} //close setup
void loop()
{
// Sensor output
int sensorVal=analogRead(A0);
float voltage = (sensorVal*5.0)/1024.0;
float pressure_pascal = (3.0*((float)voltage-0.47))*1000000.0;
float pressure_bar = pressure_pascal/10e5;
Serial.print("Pressure = ");
Serial.print(pressure_bar);
Serial.println(" Bar");
// Compressor off:
if (pressure_bar >= 0.10);{
digitalWrite(relayPin,LOW);
}
// Compressor on:
if (pressure_bar <= 0.05);{
digitalWrite(relayPin,HIGH);
}
delay(200);
}
[/code]