Thanks everyone I found the problem. The circuit wiring was off. I connected the digital pin to a horizontal row of breadboard BUT I also inserted a resistor in same row. This was connected (in the same row) to one leg of anode one same row, the other across the middle gap in breadboard to GRND. Essentially shorting the circuit. Thanks everyone
Hello there, I have a huge problem that I can't seem to crack. It's regarding project 8, Digital Hourglass contained in the Arduino Starter Kit, beginner level. The code is available in the IDE. File --> Examples --> 10. Starterkit_Basickit --> p08_DigitalHourglass.
PROBLEM: ZERO LED's activate when the tilt sensor is closed or open. They each have to turn on separately once some time has elapsed. I'm not sure if its a hardware or software issue. I've double checked code and circuit and there are not similar issues online. This is my last resort
My code below. I changed the interval for 3 seconds for troubleshooting purposes. I am also using 3 LED's for simplicity thus my max x variable = 4.
Extra Notes:
- I am using correct COM port.
- I tried blink example and Arduino responds to this script.
- My LEDs are connected anode → cathode. Positive → Negative
- Farout, new issue. I cant view Serial Monitor SwitchState variable. Literally nothing shows up
const int SwitchPin = 8;
unsigned long previousTime = 0; // Holds the time an LED was LAST changed . Not sure if I understand
int switchState = 0;
int prevSwitchState = 0; // These 2 used to compare switch's position from one to the next
int led = 2; // This variable counts which LED is the next one to turn on. Starting with pin 2
long interval = 3000; // 3000ms = 3sec
void setup() {
// put your setup code here, to run once:
for (int x = 2; x < 5 ; x++) { // Using 4 loop for quick declaration of I/O of pins
/////// NOTE: x<5 = 3 LEDS using
pinMode(x, OUTPUT);
}
pinMode(SwitchPin, INPUT);
pinMode(LED_BUILTIN, OUTPUT); // Onboard LED
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentTime = millis(); // Recording elapsed time
if (currentTime - previousTime > interval) { // If 3 sec has passed, turn on led, prevTime gets overrided with current and processs loops
previousTime = currentTime;
digitalWrite(led, HIGH);
led++;
}
if ( led == 7 ) { // What occurs when all LED's on?
}
digitalWrite(LED_BUILTIN, LOW); // Blinking Onboard LED becaus why not. I'm stuck at a dead end. LED's no come on
delay(500);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
switchState = digitalRead(SwitchPin);
if (switchState != prevSwitchState) { // Resetting of LEDs through switcj. Also, != = NOT
for (int x = 2; x < 5; x++) {
digitalWrite(led, LOW);
}
led = 2;
previousTime = currentTime;
}
prevSwitchState = switchState; // Reaffirm zero into prevSwitchState so that another hour can elapse. Ensuring its zero
Serial.print("What's the SwitchState?: "); // Let's see what pin 8 is reading
Serial.print(SwitchPin);
}
It says new users cannot upload attachments. What?
How can I preview my post?
Many thanks