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...
// Checking button for factory reset 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 ...
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 ...
Building a Garage Door Sensor with an Arduino Nano The Problem Our two car garage has a roller door on the front and back. The one on the front of the house is motorised and activated with a remote control. You cannot see if the front roller door is open from anywhere within our house...