This is another Arduino project for beginners, it shows how to control LED ON and OFF with push button where the LED changes its state whenever the pushbutton is pressed.
In this project, Seeed Studio Grove LED socket kit and Grove button modules will be used. With the Grove modules circuit connection is more easier.
To see Arduino LED blink example visit the following post:
Arduino LED Blink with Seeed Studio Grove LED Socket Kit
The Grove LED socket kit is shown below:
As shown in the Grove LED board there is a variable resistor of 10k ohm which is used to control the brightness of the LED.
We can easily change the color of the LED by replacing the red one with another with different color (yellow, white …).
And the following image shows the Grove button module:
The button module has a pull down resistor of 10k ohm, if the button is pressed the state of SIG (signal) pin will change from low to high.
Each module is connected to Seeed Studio Grove Base Shield via 4-pin Grove cable, the base shield is an add-on board that directly mounted to the Arduino/Genuino UNO board.
Both Grove modules can work with 3V3 and 5V systems.
Hardware Required:
- Arduino/Genuino UNO board
- Grove Base Shield —> official page
- Grove LED Socket Kit —> official page
- Grove Button —> official page
- 2 x Grove 4-pin cable
Arduino LED control with push button circuit:
The following image shows the connection of the Grove LED socket kit and button modules with the base shield using 4-pin cables.
Note that the base shield is directly mounted to the Arduino UNO board.
And the image below shows more detailed circuit:
The Grove LED is connected to base shield port D2 which is internally connected to the Arduino uno board as follows:
GND pin is connected to Arduino GND,
VCC pin is connected to Arduino +5V pin,
NC is a not connected pin (it looks as it is connected to pin D3),
SIG (signal) pin is connected to Arduino digital pin 2.
The Grove button module is connected to base shield port D5 where the SIG pin is connected to Arduino digital pin 5.
Arduino LED control with push button code:
Example Arduino code is below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | /************************************************************************* * * Arduino example shows how to use Seeed Studio Grove LED socket kit and * button modules. * The button controls the LED ON and OFF. * This is a free software with NO WARRANTY. * http://simple-circuit.com/ * ************************************************************************/ #define button 5 // button signal is connected to Arduino digital pin 5 #define LED 2 // LED is connected to Arduino digital pin 2 void setup() { pinMode(button, INPUT); // configure button pin as input pinMode(LED, OUTPUT); // configure LED pin as output } // main loop void loop() { if ( digitalRead(button) ) { // if the button is pressed digitalWrite( LED, !digitalRead(LED) ); // toggle the LED delay(500); // wait 500 milliseconds } } // end of example code. |
Arduino LED control with push button video:
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.