I need urgent assistance. Project 8 - Digital Hourglass Starter Kit

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 :grinning:

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

I'm not surprised; you don't print it anywhere. You only print SwitchPin, which should always give '8' as its output.

So let's also see schematic + good photos of your actual setup to exclude the possibility of a simple hardware issue.

In the code, I think you may have a problem with setting the currentTime variable, which only happens in your final if-statement, which is dependent on the pin state, but that if-statement also turns all leds off. Still, you'd expect one led to be on for about a second due to your built-in led blink. BTW, does that part work, where you blink the built-in led?

Anyway, let's start by excluding any hardware issues. Your code looks a bit illogical in a few places to me, but I'd start by verifying you can actually turn all the leds you have on without any if-conditionals. Just see if they work properly, then take it from there.
Second stop would be to verify you actually get input from your sensor/switch, which at this point is also not clear to me.

Dont forget to change this to account for the number of LEDS

A strange LED description. Does a LED light up if you disconnect it from the Arduino pin and connect to 5V instead?

If you want to use Serial then start it up in setup() as Serial.begin(9600);

As suggested by https://forum.arduino.cc/u/koraks the schematic + good photos of your actual setup should help in the resolution.

This MAY be the error, you need resistors in series with the LEDs, if you have none, you MAY have blown the LEDs, and possibly damaged your Arduino IO pin as well..

Again, when you can, post an image of your setup, it MAY be something simple, hopefully we can get you up and running soon.

  • Yes, I an blink the onboard LED
  • Also, I can confirm the LEDs light up and are not blown
  • I was able to view the tilt sensor in Serial Monitor and confirm its operation.

Yes LEDs light up when connect to 9V battery with resistor in series.

I understand the wording is strange but I meant to say that the LED is not reverse biased. +ve current is entering anode and current leaving from cathode

@missdrew

I understood the flaw in my coding, I followed this schematic, booted up the vanilla script available in the IDE, adjusted it for 3 LEDs and now it works like gold

ALSO, did I sustain permanent damage to my Arduino? How severe is it? Because I wired it such: Arduino digital pin 2 --> LED --> GRND. The resistor was skipped
Thank you

If the pin still can light up a LED the damage is not too severe. If used as input it may draw some current.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.