like the topic indicate, I am working on the Arduino Starter Kit project "Light Theremin". Learning from here should be: Using a phototransistor and a Piezo. So, I am going to make a light-based theremin/tone.
Please note: I am till beginner. All the parts I have wired up are provided by the Kit. I do have DMM.
Status quo: I have wired all up, and upload the code. No coding errors occurred.
Issue: After I have plugged in/power on the Arduino and the 5 sec celibate window is over, a constant, steady, and high peep tone appeared. No regulation, no stop what's however via the phototransistor. Interesting so: If I swap the phototransistor with Potentiometer, everything's goes after plan. I can stir the tone, like in project purpose.
Interesting so: If I hook of the A0 wired connection, the tone disappear and just strange sound like almost R2D2 but no tone calibration.
Here the schematic of the circuit from the book.
I'll assume you can wire a project from the book for now.
I suggest adding serial printing so you can check the values of some variables and confirm the flow in your program.
Imma bet this
while (millis() > 5000) {
should be
while (millis() < 5000) {
and that for the first 5 seconds you are supposed to be training the sensor by moving it back and forth between the extremes of light and dark you expect to see and want to react to.
Do you need to set the pin mode on the pin connected to the sound making device?
@janosch1 it's worth taking a close look at this while loop that you fixed.
It is using a common programming pattern that crops up when we are looking for a maximum and/or a minimum in a set of data.
The idea is to preset the minimum detected at the maximum expected, and similarly to preset the maximum detected at the minimum expected.
Then as you view the data, however, when a new value comes in that is larger than the previous maximum, we refresh our idea about what the maximum is.
Same same the minimum.
Obvsly, in this case, for it to work, the body of the while loop must execute repeatedly for a calibration time.
Since your original did not run at all, the maximum was left at 0 and the minimum was left at 1023.
while (millis() < 5000) {
sensorValue = analogRead(A0);
if (sensorValue > sensorHigh){
sensorHigh = sensorValue; /// move up the max
}
if (sensorValue < sensorLow){
sensorLow = sensorValue; /// move down the min
}
}
You'll see this in code you read, promise, and you'll use it in code you write. Someday very probably.
Nice one! @alto777 Thank you for your support and recap. I appreciate it and take my leanings from it. I hope to get the laser scan like you have, some day.