Arduino Question !! \"Connect a resistor R and LED in series to pin 9 and GND on
ID: 2085916 • Letter: A
Question
Arduino Question !!
"Connect a resistor R and LED in series to pin 9 and GND on your arduino. Remember the LED is polarized so make sure the + is connected to the pin 9 side. The long pin is usually the + side"
This is the code I am using:
int ledPin = 9; // LED connected to digital pin 9
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
and it isnt working, I dont know what I am doing wrong
Explanation / Answer
We have to troubleshoot the problem.
1) First of all your code is seems to be correct. It has no compilation issues.
2) Check LED whether it is connected in correct polarity or not. Then connect it with a battery (5 or 9 Volts) to check if it is glowing or not.
3) You can check the output of your output pin 9 with a multimeter or if you don't have a multimeter you can check the output by input it back to some other pin with digital read function (you can use code is given below)
Note: Before run this code you just have to connect pin 8 with pin 9.
(I don't have a arduino yet this code should work)
int ledPin = 9; // LED connected to digital pin 9
int pinr = 8;
void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(pinr, INPUT);
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
// read the input pin:
int state = digitalRead(pinr);
// print out the state of the button:
Serial.println(state);
delay(5); // delay in between reads for stability
Serial.println(state);
delay(5);
Serial.println(state);
delay(1000);
digitalWrite(ledPin, LOW); // sets the LED off
state = digitalRead(pinr);
// print out the state of the button:
Serial.println(state);
delay(5); // delay in between reads for stability
Serial.println(state);
delay(5);
Serial.println(state);
delay(1000); // waits for a second
}
If after doing this all you still having problem you can ask for help in comments.
Thanks and Regards
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.