Created
July 30, 2019 13:18
-
-
Save archisman-panigrahi/45cd67dde6380da66edf67548fdbf224 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int sensor = 2; //one pin of sensor is connected to digital pin 2, the other is connected to 5volt. | |
int ledPin = 6; //longer pin of LED is connected to digital pin 6, the other is connected to ground through a resistor. | |
void setup() { | |
Serial.begin(9600); | |
pinMode(sensor, INPUT); | |
pinMode(ledPin, OUTPUT); | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
int buttonState = digitalRead(sensor); | |
//Serial.println(buttonState); //for debugging | |
if(buttonState == HIGH) | |
{ | |
digitalWrite(ledPin, LOW); | |
/**********NOTE: Instead of the above line for turning on LED, use code for sending message. | |
You can use a global variable (like sensor or ledPin), to make sure that only one message is sent | |
when the sensor is touched once. | |
***********/ | |
} | |
else | |
{ | |
digitalWrite(ledPin, HIGH); | |
} | |
delay(200); //wait for 200 milliseconds before sensing again | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment