Wen’s Halloween Costume Working Progress

I tried to build a circuit and write the code, but it just wont work even if i tried two different vibration sensors. So i decided to continue to work on this tomorrow with the teacher.

Code:

const int buttonPin = 2;
const int ledPin = 0;


int ledState = HIGH;
int buttonState;
int lastButtonState = LOW;


unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;

void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);


digitalWrite(ledPin, ledState);
}

void loop() {

int reading = digitalRead(buttonPin);


if (reading != lastButtonState) {
lastDebounceTime = millis();
}

if ((millis() – lastDebounceTime) > debounceDelay) {

if (reading != buttonState) {
  buttonState = reading;


  if (buttonState == HIGH) {
    ledState = !ledState;
  }
}

}
digitalWrite(ledPin, ledState);
lastButtonState = reading;
}

Video

Without the circuit, it is hard to make the wand, since the wires should be attached to the body of the wand.

One thought on “Wen’s Halloween Costume Working Progress”

  1. Hi Wen,
    Why didn’t I hear from you more over the weekend if you are still having issues prototyping with the vibration sensor? It doesn’t look like you followed the email advice I gave you on Saturday:
    1. your 3v pin on Gemma is a power pin, not a digital I/O pin. Attached is a circuit diagram I drew for you which moves the LED to pin D0 and GND.
    2. Don’t forget a resistor with your LED, 100 ohms should work. Also shown in the attached diagram.
    3. Insulate your LED legs with heat shrink tubing so the bare wires won’t be able to touch each other and short out.
    3. Prototype your project on the solderless breadboard with the sensor the way it is, then cut off the solid wire ends and solder the purple and blue wires directly to Gemma.

Comments are closed.