0% found this document useful (0 votes)
2 views2 pages

Arduino Stimulation

Uploaded by

raphaelmaju25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Arduino Stimulation

Uploaded by

raphaelmaju25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <SoftwareSerial.

h>

SoftwareSerial BT(0, 1); // RX, TX

const int fanPin = 3;

const int ledPin = 4;

const int buttonPin = 2;

bool fanStatus = false;

void setup() {

pinMode(fanPin, OUTPUT);

pinMode(ledPin, OUTPUT);

pinMode(buttonPin, INPUT_PULLUP);

BT.begin(9600);

digitalWrite(fanPin, LOW);

digitalWrite(ledPin, LOW);

void loop() {

if (BT.available()) {

String cmd = BT.readStringUntil('\n');

cmd.trim();

if (cmd == "ON") {

fanStatus = true;

} else if (cmd == "OFF") {


fanStatus = false;

updateFan();

if (digitalRead(buttonPin) == LOW) {

fanStatus = !fanStatus;

updateFan();

delay(500); // Debounce delay

void updateFan() {

digitalWrite(fanPin, fanStatus ? HIGH : LOW);

digitalWrite(ledPin, fanStatus ? HIGH : LOW);

BT.println(fanStatus ? "Fan ON" : "Fan OFF");

You might also like