CONFUSED, FROM WHERE TO GIVE INPUT?

const int buttonPin = 3;

// setup initializes serial and the button pin
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}

// loop checks the button pin each time,
// and will send serial if it is pressed
void loop()
{
if (digitalRead(buttonPin) == HIGH)
Serial.write('H');
else
Serial.write('L');

delay(1000);
}

HERE:- if (digitalRead(buttonPin) == HIGH)
Serial.write('H');

FROM WHERE TO GIVE INPUT PIN NUMBER 3?OR FROM SERIAL MONITOR?
IF INPUT IS GIVEN FROM PIN NO 3 THEN WHAT IS THE INPUT?PUSH BUTTON?
PUSH BUTTON HAS 2 TERMINAL ,2ND SHOULD BE GROUNDED

NOTE:- APPLIED ON ARDUINO UNO R3

THANKS FOR GIVING A LOOK AT THIS,I HAVE STARTED WITH ARDUINO RECENTLY :slight_smile: :o

Yes, the serial monitor. Or else a third party serial comm program.

Edit - oh, sorry, that's the output.

I suggest that unless you have a pulldown resistor in place (highly unlikely unless you put it there) that you change

 pinMode(buttonPin, INPUT);

to

 pinMode(buttonPin, INPUT_PULLUP);

This will ensure that unless you do anything pin 3 will stay HIGH and the Serial monitor will print "H". Wire the pushbutton between pin 3 and GND so that when it is pressed it take pin 3 LOW and the Serial monitor will print "L"

can we use a push button to give input here? 2nd terminal should be grnded >?

rushabh007:

const int buttonPin = 3;

// setup initializes serial and the button pin
void setup()
{
 Serial.begin(9600);
 pinMode(buttonPin, INPUT);
}



FROM WHERE TO GIVE INPUT PIN NUMBER 3?OR FROM SERIAL MONITOR?
IF INPUT IS GIVEN FROM PIN NO 3 THEN WHAT IS THE INPUT?PUSH BUTTON?

PUT PUSH BUTTON OR SWITCH ON PIN 3. PIN MUST BE EITHER PULLED HIGH WITH A RESISTOR TO +5V, OR PULLED LOW WITH A RESISTOR TO GROUND. OTHER SIDE OF THE BUTTON GOES OPPOSITE BUT NO RESISTOR. OR YOU CAN USE THE INTERNAL PULL UP RESISTOR AND CONNECT THE OTHER SIDE OF THE BUTTON TO GROUND:

const int buttonPin = 3;

// setup initializes serial and the button pin
void setup()
{
  Serial.begin(9600);
  pinMode(buttonPin, INPUT_PULLUP);
}

THIS IS MUCH SIMPLER BECAUSE YOU DO NOT HAVE TO CONNECT ANY EXTERNAL RESISTORS. IF YOU RE HAVING DIFFICULTY FINDING YOUR CAPS LOCK YEY, IT IS USUALLY ON THE LEFT OF THE KEYBOARD ABOVER THE SHIFT KEY. IT SAYS 'Caps Lock'.

@PAUL

i have tried as you told,initially serial monitor showed high,and when i put on led on pin 13 and grnded the same i got low output

I AM ATTACHING THE SCREENSHOT BELOW

Why are you suddenly mentioning pin 13? Why would you ground a LED? Sounds like a good way to damage the board.

IT WAS SIMPLER TO GROUND LED NEAR PIN13 SO I SUDDENLY MENTIONED PIN 13
HOW CAN IT DESTROY THE BOARD BY GROUNDING THE LED?

Why would you ground the LED anyway? What is the purpose of that? This is highly entertaining.

Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile: