bobby_dhanush
Published

Sensor switch for another sensor

Touch sensor is used as switch for ultrasonic distance sensor. it is a type of obstacle finding sensor with touch sensor

BeginnerFull instructions provided232
Sensor switch for another sensor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
touch sensor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

code

Schematics

circuit images

circuit images

circuit images

Code

code

C#
#define touchpin 4// sets the capactitive touch sensor @pin 4
#define echoPin 9
#define tringPin 10
long duration;
int distance;
int ledPin = 2; // sets the LED @pin 2
int vccPin = 8;
int rgbPin = 7;
int nontouchPin = 5;
void setup() {
  pinMode(touchpin, INPUT); //sets the touch sensor as input
  pinMode(ledPin, OUTPUT);  //sets the led as output
  pinMode(tringPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT);  // Sets the echoPin as an INPUT
  pinMode(vccPin, OUTPUT);
  pinMode(rgbPin, OUTPUT);
  pinMode(nontouchPin,OUTPUT);
}
void loop() {
  int touchValue = digitalRead(touchpin); //reads the touch sensor signal
  if (touchValue == HIGH){      //if sensor is HIGH
    digitalWrite(vccPin, HIGH);
    digitalWrite(ledPin, LOW);
    digitalWrite(rgbPin,HIGH);
  }
 else{       //otherwise
    digitalWrite(vccPin,LOW);
    digitalWrite(ledPin,LOW);
    digitalWrite(rgbPin,LOW);
    digitalWrite(nontouchPin,HIGH);
  } 
  delay(300);   //delay of 300milliseconds

  int duration, distance;
digitalWrite(tringPin, HIGH);
delay(1);
digitalWrite(tringPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 50 && distance >= 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
delay(600);
}

Credits

bobby_dhanush
1 project • 0 followers

Comments