Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
Garrett LissChristian Phelps
Published © GPL3+

Piezoelectric Sensor LED Light

This project uses 2 piezoelectric sensors and particle photon 2 devices to generate a signal that will light an LED bulb when it is touched.

IntermediateFull instructions provided5 hours377
Piezoelectric Sensor LED Light

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×2
Piezoelectric sensor
×2
LED (generic)
LED (generic)
×2
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×8
Through Hole Resistor, 10 kohm
Through Hole Resistor, 10 kohm
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Ubidots
Ubidots

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

LED Transmitter Schematic

Code

LED Transmitter Code

C/C++
Allows for the piezo to be processed through the photon and allows the LED to be lit as well as communicated with the other photon to trigger its LED as well.
int piezo = D0;            
int LED = D1;               
int setting = LOW;             
int val = 0;                  

int calibrateTime = 5000;      

void setup() {
    pinMode(LED, OUTPUT);
    pinMode(piezo, INPUT);     
}

void loop() {

 
  if (calibrated()) {

    readsensor();


    reportdata();
    }
}

void readsensor() {
    val = digitalRead(piezo);
}

bool calibrated() {
    return millis() - calibrateTime > 0;
}

void setLED(int state) {
    digitalWrite(LED, state);
}

void reportdata() {
    if (val == HIGH) {
       
        if (setting == LOW) {
         setting = HIGH;
          setLED(setting);
        }
    } else {
        if (setting == HIGH) {
          setting = LOW;
          setLED(setting);
        }
    }
}

Credits

Garrett Liss
1 project • 1 follower
Christian Phelps
1 project • 1 follower

Comments