Webhook publishing

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

my project is supposed to

  1. measure voltage changes from hitting the piezoelectric elements (particle)
  2. show the spikes using a graph (arduino serial plotter)
  3. display a total voltage (lcd screen)
  4. show a countdown timer and the total on a computer screen (???)

i’ve done most of the things in the project (including somehow connecting a large push button so i don’t have to reach through the wiring to reset the “game”), but i still can’t display a timer or the total voltage on a computer screen. so that’s that.

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

You can use USBSerial1 as a secondary virtual usb serial port to print the desired values. The data printed to that port can be displayed via any serial terminal program (including CLI or Arduino Serial Monitor).
You can also use the cloud features Particle.publish() or Particle.variable().

However, in your code you are printing your total reading off screen.

        lcd.setCursor(0, 1);
        lcd.print("0               ");
        for (int i = 100; i > 0; i--) {
            ...
            lcd.print(total);
        }

Lets suppose you are increasing total by one each iteration of for() you are printing

|Power:          |
|0               |123456789....

For one you need to reset the cursor to 0,1 before you print total and I guess you only want to print the final value after the 100 iterations of for(). The update speed of the LCD won't really show all the intermediate values properly anyway.

Also your variable names voltage and power are slightly misleading.
You don't actually measure the voltage in Volt but the ADC gives you only a relative value of the voltage range 0..3.3V split up in 4096 units. To get the voltage, you need to have your variable as double (or float) and calculate voltage = analogRead(pin) * 3.3 / 4095.0.
And for the actual power (in Watt) you'd also need to calculate the current since Power = Voltage * Current which would need to be measured with much higher resolution than 20ms.

BTW, what's this

Counting down what, where? I can't see any inidaction of a timer in your code.

1 Like

thanks for the new info about the value, i always assumed it meant millivolts.

the timer is simple – the 2 delay(10); in the code looped using for() effectively creates a countdown; the program stops logging data once the countdown hits 0 and wont be reactivated until the button is pressed.

technically, it isn’t power… my aim was to show how much electricity one could generate by hitting those piezoelectric transducers in a certain amount of time.

(i also have a problem but that’s probably just me: the lcd screen refuses to display ‘o’ properly – sometimes it says “Pkwer:” instead

Hmm, your original code featured this portion

        analog = (base/1024);
        delay(50);
        voltage = (analog*5);

This is exactly what does the ADC-unit to voltage conversion for Arduino ADC 5V@10bit - my code above does the same thing for 3.3V@12bit.

OK, but if you want to display that on screen, you'd need to read rather quickly since you will be writing 100 figures within 2 seconds, which isn't going to be readable while counting down :wink:

Your setup may be good to illustrate how it works, but not really how much electrical energy you could collect from the kinetic energy put into the crystal, since you are only taking snapshots of the voltage every 20ms. This doesn't really give you what the integral of the voltage function actually would be, and when we are talking energy (Joule or Watt Seconds) we would inevitably also need to know what current we are dealing with.

One way to get the data you want might be to charge a capacitor to "integrate" the voltage function and then discharge the cap in a controlled manner to effectively measure the stored charge. But I guess that's beyond the scope of this project :wink:

That's probably a bad contact or timing issue.

technically i could create a variable that goes down by 1 every 5 reps (not sure how though, very confused; could probably figure out myself) or just display a rounded-off value of i multiplied by 0.02 reps per second

but i have to find a way to actually display this on-screen