DaoRier sensor button switch input For Arduino Review and Code
This post talks about using the DaoRier sensor button switch input with an Arduino.
DaoRier sensor button switch input
The DaoRier sensor button switch input is a simple single button trigger.
Whenever the button is pressed the signal pin is set to LOW. When the button is not pressed the signal pin will be HIGH.
This is a useful little board as you don’t need to connect any additional resistors to safely use this with an Arduino. This is because they are included on the board.
The button is a standard large push button but in addition the button front can be removed and replaced with another. This means that if the standard grey colour is not what you want it can be replaced easily.
An additional benefit to this sensor is that there are two different ways to connect wires to it. Either using a standard four pin connector or the 3 pin headers.
Wiring it up to an Arduino
Since the sensor includes inbuilt resistors no additional electronic components are needed. This means that we can wire up the pins directly to the Arduino.
G needs to be connected to ground, V to the 5 volt line, and S to a digital pin that you want to read the data from.
Once these are connected you are ready to read the button state using the Arduino.
Programming the Arduino with the DaoRier sensor button switch input
To see whether the button is pressed or not I can use the following code.
#define SWITCH_PIN 2
void setup() {
Serial.begin(115200);
pinMode(SWITCH_PIN, INPUT);
}
void loop() {
int btnState = digitalRead(SWITCH_PIN);
Serial.println(btnState);
delay(25);
}
Here the switch pin, 2, is configured as a hash define. In the setup this is used to set the digital pin mode as an input. In addition to this, the serial connection is configured here at 115200 baud rate.
In the main loop the button state is read using the hash define. This is stored to an int and then printed out as either a 1 or a 0.
Each loop is delayed by 25 seconds so there is a very short delay in reading and printing the data. This stops the serial connection being flooded with data.
Final Review
This is a very useful button sensor as no additional components are needed for its use. This makes it very simple to install and use out of the box.
The ability to switch the button keycap is also very useful and means you can purchase a number of additional coloured keycaps and configure them as needed.
Overall a very nice little sensor to easily integrate with an Arduino. Would buy again!