- Arduino uno= https://bit.ly/30v5XcY
- LDR sensor module= https://bit.ly/30X7Gs4
- leds = https://bit.ly/2RqpfMM
Diagram:-
Connections:-
Touch sensor to arduino
- Senor VCC = Arduino 5v
- Sensor GND = Arduino GND
- Sensor SIG = Arduino digital pin 7
LED to arduino
- LED ( - ) = Arduino GND
- LED ( + ) = Arduino digital pin13
Code:-
const int touch = 7;
const int led = 13;
void setup() {
pinMode(touch,INPUT);//define pin as input sensor
pinMode(led,OUTPUT);//define pin as output sensor
}
void loop() {
int y =digitalRead(touch);//read the sensor
if (y==1){
digitalWrite(led,HIGH);//turn on led
}else{digitalWrite(led,LOW);//turn off led
}
delay(500);
}