I want use this switch switch
My questions are How i connect this switch with arduino mega 2560 and what is the code for when i push a switch a led lighting
Thank you
Your topic was MOVED to its current forum category as it is more suitable than the original
When you have tested the LED light with a 5 volt supply and it lights, then you will know how to connect it to an Arduino pin and the Arduino ground. Write a program to make the pin output, write high to the pin, delay and write low to the pin.
Hello aubin_61
Take a look here to gain the knowledge.
Many thanks to LarryD
Have a nice day and enjoy coding in C++.
Дайте миру шанс!
Wire the push button from say, D3, to ground so button will read HIGH normally and LOW when pressed
// start by defining constants
const int myOutput = LED_BUILTIN;
const int myInput = 3; //change to pin wher you wired button to
// place this in setup()
pinMode(myInput, INPUT_PULLUP); //define pin as input with pullup resistor
// somewhere in loop()
digitalWrite(myOutput, !digitalRead(myInput) );
Has the OP looked at File|Examples and things like 02.Digital|Button?
Why LED_BUILTIN ?
Because every board has one and that eliminates wiring to test the led. once it works change it to whatever pin you wire the real led to.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.