Inputs are used to get information about what is happening in the real world. For example, you can check if the button is pushed or not by using thedigitalRead()command. Or you can check the temperature in the room by connecting a temperature sensor and using theanalogRead()command. By c...
How do I toggle pins on Arduino? When the pin is configured for OUTPUT, digitalWrite() figures out with Port and Bit to change, and writes to it. That is what enables a HIGH or LOW on the OUTPUT. So when you calldigitalRead(), it looks at the PORTx register and returns the curren...
Serial.println(digitalRead(button2); } CALCULATING THE VALUE OF THE RESISTOR The value of the resistor depends on two factors. First is consumption, waste of energy. If the value of the resistor is too low HIGH (+ 5V in the example above), the voltage will go through a pull-up resistor...
Here is an example Arduino sketch for a basic motion detector: const byte pirPin = 3; // PIR connected to pin 3 void setup(){ pinMode(pirPin, INPUT); // Set pin as input Serial.begin(9600); // Start serial monitor } void loop(){ byte state = digitalRead(pirPin); // Read ...
tmpState=digitalRead(doorUpSensor); if (tmpState==HIGH) tmpString+="HIGH "; else tmpString+="LOW "; if (tmpState != oldDoorUpSensorState) { doorUpSensorState=1-doorUpSensorState; delay(50); } oldDoorUpSensorState=doorUpSensorState; ...
if (digitalRead(BUTTON_PIN) == LOW) { // Push button pressed // Key debounce handling delay(100); int startTime = millis(); while (digitalRead(BUTTON_PIN) == LOW) { delay(50); if ((millis() - startTime) > 3000) { // If key pressed for more than 3secs, factory reset Zigbee...