Webhook publishing

Thanks for helping! The code is working now – I’m on the next stage of frustration: Why isn’t this updating? Why isn’t it measuring the voltage? IT’S DUE SOON COOPERATE WITH ME

I have been - in my free time, I may note!

It’s absolutely not appreciated to have all-caps demands thrown at people who volunteer in helping others.

oh wait sorry i was screaming at the particle
you see, i used code from somebody else and modified it to use webhooks instead of the nonfunctioning (to me at least) IFTTT but it isn’t registering any voltage change from the piezoelectric transducer i hooked it up with (i have a project to measure electricity generated from the transducers) so i’m not very happy about that currently

Can you post your code (e.g. via SHARE THIS REVISION in Web IDE)?
Also some schematics about your HW setup would be required.


BTW, Particle devices don’t read the forum posts - us humans do.

ummm… everything is almost directly copied off


and the wiring is

This might also translate to: “It may almost work as the original, but not quite.”

As I said in the other thread already

If you want to be helped to get your version do what you want, you should show your version of it, not some almost similar project.

1 Like

(How I wish people would actually do what they’re told :pensive: )
Screenshots are not really the preferred means to share code, as it would mean typing off the image.
That’s why I mentioned this

Which is refering to this

However, having a quick look at your code I did spot at least one issue.

And exactly that pin conflict is not present in the original code you linked to, so looking at that would not have done any good but only wasted time, if I had looked at it for any error.

Also the Arduino ADCs use 5V at 10 bit (raw reading 0…1023) while the Particle ADCs are 3.3V @12bit (0…4095).

And to sprinkle over the top, the piezo connections don’t look too reassuring either.
To have a proper connection you should employ a soldering iron :wink:

1 Like

in the original code, the ledPin variable didn’t exist, yet the code called for it, resulting in multiple errors.

and… my soldering iron isn’t exactly working. it isn’t heating anything at all so technically i don’t have a soldering iron

https://go.particle.io/shared_apps/5b2fa288ed8d6b1dad000c4f

On Arduinos the ledPin is usually set as #13 which is connected to the onboard LED.
For Particle devices that would be D7 and definetly not the same pin you are using to read the sensor.
If you strip down your code to the bare minimum to actually test the sensor input, you could use something like Arduino Serial Plotter to see if you get any useful readings at all since the ADCs on Particle devices operate slightly different than Arduino’s.

const int ledPin      = D7;
const int knockSensor = A0;
const int threshold   = 100;
int sensorReading     = 0;

void setup() {
    pinMode(ledPin, OUTPUT);
    Serial.begin(115200);
}

void loop() {
    sensorReading = analogRead(knockSensor);
    Serial.printlnf("%d", sensorReading);
    if (sensorReading >= threshold) {
        digitalWrite(ledPin, !digitalRead(ledPin));
    }
    delay(20);
}

i made the corrections you showed me!
https://go.particle.io/shared_apps/5b30887254e3ea38f6000b40
but now there’s nothing underneath the Current Voltage line… it’s completely blank.
can i replace Serial.printlnf() with lcd.print() ?

You can try this to test whether your piezo is working at all

void setup() {
  pinMode(A0, OUTPUT);
}
void loop() {
  digitalWrite(A0, !digitalRead(A0));
}

This should make the piezo emit a sound.

This is what I see on Arduino Serial Plotter with the code I provided in my previous post when knocking the sensor

1 Like

yep, it is working (very loudly)
but right now all it’s showing underneath (changing the print) is always above 4000
it’s usually hanging around 4086 - 4088 but it goes down to as far as 4031 when i tap it. huh.
https://go.particle.io/shared_apps/5b30971754e3ea38f6000bab

Have you tried Arduino Serial Plotter?
What does it show you?

What I can deduce from what I’m seeing is, that the threshold of 100 is definetly too low (at least for my piezo) and that the recovery time after a trigger might call for some kind of pull-down to “discharge” quicker.

ok… give me some time to google “arduino serial plotter” and some more to start using it
wait what is 'arduino ide"

Arduino Serial Plotter was just a convenient way to get the readings plottet nicely to get a feeling for the data your setup is producing.
If you don’t want to install Arduino IDE (integrated development environment) which contains the Serial Plotter, you could try to find any other tool that would catch the serial output and present it as chart.

However I’ve slightly reworked the knock detection logic this way

const int knockSensor = A0;
const int ledPin      = D7;
const int threshold   = 250;    // minimum difference between two readings to trigger
const int debounce    = 200;    // debounce period after a trigger in milliseconds

void setup() {
    Serial.begin(115200);
    pinMode(ledPin, OUTPUT);
}

void loop() {
    static int oldReading = analogRead(knockSensor);
    int        newReading = analogRead(knockSensor);
    
    Serial.printlnf("%d %d 0 4095", newReading, abs(oldReading-newReading));
    if (abs(oldReading-newReading) >= threshold) {
        digitalWrite(ledPin, !digitalRead(ledPin));
        delay(debounce);
        oldReading = analogRead(knockSensor); // new base after trigger
    }
    else
        oldReading = newReading;
        
    delay(20);
}

which produces this kind of data when knocking the sensor


The blue line is the raw data and the red (abs(oldReading - newReading)) is used to detect the trigger.

1 Like

thank you! i have a small problem though: how do you connect the photon to the IDE? i’m not really sure.

You just plug the Photon into your computer’s USB port, it will then register as a USB Serial device and show up as available Port in Arduino IDE’s Tools menu.
Once you have selected the corresponding port, you can just start Serial Plotter from the same Tools menu.

But with my sketch above you can just test your setup.
When you knock the sensor the D7 LED should toggle - if it doesn’t your setup doesn’t work as intended - simple.

2 Likes

it showed the spikes in the plotter, thanks!
is there a way to save the data though? i need the total as the final part of my project.

That’s only the first step of the project.
Once you have established you can detect the knocks, you need to expand the project to do the whatever else you need.
To do that you need to break down the assignment into single steps and build up the project step-by-step.
But that’s not what this community does for you. We hand you the tools and pointers to get there but the work has to be yours.

Just think, what do I need to get from the individually detected knock to the total?

BTW, you didn’t really explain what you mean by “total”.
If you can explain the actual assignment down to the individual sub-tasks, you have the outline how to build-up the project - if you can’t we wouldn’t be able to help you with that anyway.

Also ask yourself: “Have I understood why things are done that way? What do the individual code lines do? Does that really fit my need? …”

2 Likes