Control a Relay with a Touch Sensor Using Arduino | Simple DIY Electronics Project

Описание к видео Control a Relay with a Touch Sensor Using Arduino | Simple DIY Electronics Project

In this video, we’ll show you how to control a relay using a touch sensor and an Arduino. This project is perfect for anyone looking to add touch-based control to their electronics projects.

Project Components:

Arduino board
Touch sensor
Relay module
Jumper wires
Key Highlights:

Circuit setup for touch sensor and relay
Step-by-step explanation of the Arduino code
Live demonstration of the relay toggling with a touch
This is a great project for beginners and those interested in home automation!

🔔 Don’t forget to subscribe to Digitech Dynamo for more DIY electronics projects!

Useful Links:

Arduino Code: [ Code]
// Define the pins
int touchSensorPin = 2; // Touch sensor input pin
int relayPin = 3; // Relay control pin

// Variable to store the current state of the relay
bool relayState = false;

void setup() {
// Initialize the relay pin as output
pinMode(relayPin, OUTPUT);

// Initialize the touch sensor pin as input
pinMode(touchSensorPin, INPUT);

// Ensure the relay is initially off
digitalWrite(relayPin, LOW);
}

void loop() {
// Read the state of the touch sensor
int touchValue = digitalRead(touchSensorPin);

// Check if the touch sensor is touched (HIGH state)
if (touchValue == HIGH) {
// Toggle the relay state
relayState = !relayState;

// Update the relay output
digitalWrite(relayPin, relayState ? HIGH : LOW);

// Wait for the touch to be released
while (digitalRead(touchSensorPin) == HIGH);

// Debounce delay to avoid multiple toggles
delay(200);
}
}

#Arduino #Electronics #DIY #RelayControl #TouchSensor #ArduinoProjects #DigitechDynamo

Комментарии

Информация по комментариям в разработке