#6 Project "Light Theremin" Arduino StarterKit- Constant, high steady tonee of

Hi everyone,

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.


Here my wired up circuit.

If requested, I would try to do skatch from my schematic.

int sensorValue;
int sensorLow = 1023;
int sensorHigh = 0;
const int ledPin = 13;
void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  while (millis() > 5000) {
    sensorValue = analogRead(A0);
    if (sensorValue > sensorHigh){
     sensorHigh = sensorValue;
    }
    if (sensorValue < sensorLow){
     sensorLow = sensorValue;
    }
   }
 digitalWrite(ledPin, LOW);  
}
void loop() {
  sensorValue = analogRead(A0);
  int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);
  tone(8, pitch, 20);
  delay(10);
}

@build_1971 Just feel free to join once again, like always. :slight_smile:

Is the photo-transistor a photo-transistor?
Also, is it wired up correctly?

It sounds like the code is working correctly and the wiring sounds correct, the problem most likely is with the photo-transistor.

I wonder why they changed chapter 6 from a photoresistor to a phototransistor?

1 Like

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?

a7

1 Like

Can you make a pic with the side of the phototransistor visible?
That would allow us to be sure that it is wired in the correct direction...

Good catch. It wouldn't calibrate with this error.
I'm curious if the project book has this error.

Hi @theeccentricgenius thank you for thought.

I agree with your post. Yes, I guess so. Long leg, Anode, 5V, power.

hi @2112 sorry mate I cant help you with answer. :smiley:

Hi @alto777 back here. Nice! Cheers mate. Good job. Yup you spotted the issue and delivered the solution. :grinning:
That was quick.

@build_1971 thank you, mate, for your support. It's always good to have on-board. :slightly_smiling_face: You help me out in recent times.

Sorry @2112 the book was/is right. This time it was my round to do the trouble. :joy:

@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.

a7

Nice one! :blush:@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. :slightly_smiling_face:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.