const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 600; // sensor maximum, discovered through experiment
void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// map the sensor range to a range of four options:
int A = map(sensorReading, sensorMin, sensorMax, 0, 3);
// do something different depending on the range value:
switch (A) {
case 0: // your hand is on the sensor
Serial.println("OFF MOTOR");
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
break;
case 1: // your hand is close to the sensor
Serial.println("MOTOR KEKANAN");
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
break;
case 2: // your hand is a few inches from the sensor
Serial.println("MOTOR KEKIRI");
break;
case 3: // your hand is nowhere near the sensor
Serial.println("OFF MOTOR");
break;
}
delay(1000); // delay in between reads for stability
}