#include <CapacitiveSensor.h>
int LedPin = 12;
int LedPin2 = 11;
int SolenoidPin = 2;
CapacitiveSensor cs1 = CapacitiveSensor(5,6);
CapacitiveSensor cs2 = CapacitiveSensor(7,8);
void setup()
{
Serial.begin(9600);
}
void loop()
{
long start = millis();
long sensor1 = cs1.capacitiveSensor(100);
long sensor2 = cs2.capacitiveSensor(100);
if (sensor1 > 70) {
digitalWrite(LedPin, HIGH); // turn LED1 ON
delay(200);
} else{
digitalWrite(LedPin, LOW); // turn LED1 OFF
}
if (sensor2 > 70) {
digitalWrite(LedPin2, HIGH); // turn LED2 ON
delay(200);
} else{
digitalWrite(LedPin2, LOW); // turn LED2 OFF
}
Serial.print(sensor1);
Serial.print("\t");
Serial.println(sensor2);
delay(100);
if (sensor1 > 70 && sensor2 >70 )
{
digitalWrite(SolenoidPin, HIGH);
delay (100);
}else {
digitalWrite (SolenoidPin,LOW);
}
}
Tidak ada komentar:
Posting Komentar