Desperately trying to set up something that I know will be very simple for most of you, but as a newbie, I'm struggling to get to work as soon as I'd like to use it. I want to have Arduino:
Wait (do nothing) for 16 hours
Play a 1Khz tone from a buzzer on and off for 1s (1s ON, 1 OFF) for 4 hours
Stop
If anyone can help me with some code to get started asap, I'd happily acknowledge them in the paper I am going to publish in a good journal, once the experiments I need to use Arduino for are complete.
If accuracy is not very important, the following sketch should do the trick.
uint8_t const buzzerPin = 2; // Change this if the buzzer is connected to an other pin.
void setup() {
delay(57600000);
for (size_t i = 0; i < 7200; i++) {
tone(buzzerPin, 1000, 1000);
delay(2000);
}
}
void loop() {}
Nicely. But it also isn't going to work very well if there is any interruption in the power.
@virhunter please say how accurate the timing has to be, and whether you are at all concerned about affording some degree of reliability.
It would still be a simple project, but perhaps not quite so literally minimal as the offered sketch.
You might as well reiterate that after having done the 16/4 thing, there is literally no more activity.
And I am so sure I am not the only one wondering, so while you are at it and if you wouldn't have to kill us for doing, say a bit about what this is for, and woyncha go ahead and name that good journal?
@alto777 accuracy is of course, important. I didn't want to muddy original post with unnecessary detail (no-one wants to read an essay), but as you asked:
I'm using the buzzer to generate a vibration that stimulates a particular group of neurons (a type of proprioceptor) that are active and necessary for normal development of locomotion. Specifically, they seem to slow and so normalise the rhythm generated by a CPG, during a ~2h critical period of development (which overlaps with some other stuff, hence me asking for 4). The cool part is that if you 'break' the neural circuit in which all of this is happening, with drugs that elicit aberrant increased activity, you might be able to rescue this increase using the proprioceptors I'm interested in. So yeah, that's what this code is for - to stimulate cells that may rescue aberrant activity in a circuit that demonstrates symptoms similar to those observed in epilepsy.
As for journal, it will be decent, but naming would be misleading. If you've published, you'll know that you submit something and hope that it is accepted. If it isn't, you submit it to a different journal. For that reason, I can't promise anything. What I am willing to say is that I'm a career scientist so take publishing in good journals seriously enough - I plan to submit to Elife first, and haven't yet been rejected when I've submitted things.
Adding a push button to get things started if you don’t want to just have to power cycle the arduino each time could be a nice addition
Wire a push button to pin 3 on one side and GND the other side and then (slight modification of @jfjlaros sketch) you would do
const byte buzzerPin = 2; // Change this if the buzzer is connected to an other pin.
const byte startButtonPin = 3; // pin 3 — button — GND
void setup() {
pinMode(startButtonPin, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
while (digitalRead(startButtonPin) == HIGH) ; // wait for the button to be pressed
digitalWrite(LED_BUILTIN, HIGH); // turn Built in LED on to show device is activated
// key part of the code
delay(57600000);
for (size_t i = 0; i < 7200; i++) {
tone(buzzerPin, 1000, 1000);
delay(2000);
}
while (digitalRead(startButtonPin) == LOW) ; // ensure the button is released
delay(15); // anti bounce just to be sure
digitalWrite(LED_BUILTIN, LOW); // LED OFF to show end of cycle
}
(Typed here from my iPhone so…)
The built in LED will be ON to show the device has been activated. The only way to stop the code is to reset the arduino
Great, thank you very much! I'll upload and test it out. I'm sure it'll do a great job of what I'm trying to do and plus or minus a couple of seconds is no biggie. The biological scale of the things I'm interested in, isn't sensitive to that level of time resolution.
@jfjlaros@J-M-L, thanks for help. Assuming code works (and i'm sure it will!) can I get in touch for details regarding names, affiliations etc., for paper?
Thanks but it's very much etiquette to do so. I'll even have to include code (e.g. link to github) in paper, so makes sense that's it's yours, as long as you're comfortable with it.
I'd like to do both (so please do say and I'd like to include you) and will definitely include code with button, but won't push you. If not your thing, understand.
Well thanking someone in the Acknowledgements is one thing and yeah that's a matter of etiquette.
But whether or not you do that, you still need to cite the forum thread as a source in your bibliography: that's no different from citing any other source you consulted, without which you are laying yourself open to suspicion of plagiarism.