Potentiometer won't work

Hi, I’m trying to get the potentiometer seen at the top left of the photo to work, essentially as a dimmer. I’ve managed to upload the Arduino sketch, but it isn’t working. Any help would be greatly appreciated!
NB: I have little-to-no electronics experience so my understanding of jargon is limited.

Thanks!


`/* SENSOR_LIGHTS: Potentiometer >> LED (Single Channel Script)

This example dims light levels using an LED on pin 11 and a potentiometer on A0.

Created by Ryan Achten | SOMA | somavisions.com

This example code is in the public domain. */

int potentLevel; int ledLevel;

//*************************CHECK*****************************

int led = 11; // the pin that the LED is attached to int inputPin = A0; // the pin that the potentiometer is attached to

//*************************CALIBRATE*************************

const int numReadings = 1; //change this to alter the number of values to be averaged int potentMin = 280; int potentMax = 700; //maximum output from potentiometer int loopDelay = 100; //delay time between loops. Too low may cause overclocking
// while too high may cause delayed sensor response

//***********************************************************

int potentAve = 0; int readings[numReadings]; int index = 0; int total = 0;

// the setup routine runs once when you press reset: void setup() {

//*************************POTENT >> LED SETUP CODE*************************

Serial.begin(9600);

pinMode(led, OUTPUT);

//***************************SMOOTH SETUP CODE***************************** // initialise all the readings to 0: for (int thisReading = 0; thisReading < numReadings; thisReading++) readings[thisReading] = 0;

}

//****************************SMOOTH LOOP CODE****************************

void loop() {

total= total - readings[index];
readings[index] = analogRead(inputPin); total= total + readings[index];
index = index + 1;

if (index >= numReadings)
index = 0;

potentAve = total / numReadings;
Serial.print("Average Potentiometer Readings: "); Serial.println(potentAve);

//*************************POTENT >> LED LOOP CODE*************************

ledLevel = map(potentAve, potentMin, potentMax, 0, 255); Serial.print("LED Level: "); Serial.println(ledLevel, DEC); analogWrite(led, ledLevel);

Serial.println(); delay(loopDelay);

}

int led = 11; // the pin that the LED is attached to int inputPin = A0; // the pin that the potentiometer is attached to

inputPin is commented out.

int led = 11; // the pin that the LED is attached to
int inputPin = A0; // the pin that the potentiometer is attached to

If it's on a new line it's not.

There are many (copy?) mistakes like that in the code.
Leo..

Hi,
Also you will need a resistor, 1K0, between pin 11 and the base of the transistor, to limit base current and not damage the Base-Emitter junction.

Your sketch you posted will not compile, how did you get it to load?
For example you have no void setup().
Please post your working sketch.

Tom… :slight_smile:

Your attractive looking diagram does not actually illustrate the wiring connections - at least not so I can understand them.

Make a pencil drawing of all the connections and post a photo of the drawing.

...R

Hi,
In the IDE, select
Files
Examples
Analog
Fading

load the example and modify the pin numbers for output to suit your project.

Then you can modify it to use your pot.

There is not need to calibrate the pot, or average the analog reading from the pot.

Tom.... :slight_smile:

+1 about the base resistor.
void setup was also commented out :slight_smile:

This might work.
I just corrected the many mistakes I saw. Might have missed one…

/* SENSOR_LIGHTS: Potentiometer >> LED (Single Channel Script)
This example dims light levels using an LED on pin 11 and a potentiometer on A0.
Created by Ryan Achten | SOMA | somavisions.com
This example code is in the public domain. */

int potentLevel;
int ledLevel;

//*************************CHECK*****************************

int led = 11; // the pin that the LED is attached to
int inputPin = A0; // the pin that the potentiometer is attached to

//*************************CALIBRATE*************************

const int numReadings = 1; //change this to alter the number of values to be averaged
int potentMin = 280;
int potentMax = 700; //maximum output from potentiometer
int loopDelay = 100; //delay time between loops. Too low may cause overclocking
// while too high may cause delayed sensor response

//***********************************************************

int potentAve = 0;
int readings[numReadings];
int index = 0;
int total = 0;
// the setup routine runs once when you press reset:

void setup() {
//*************************POTENT >> LED SETUP CODE*************************

Serial.begin(9600);
pinMode(led, OUTPUT);

//***************************SMOOTH SETUP CODE*****************************

// initialise all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++) readings[thisReading] = 0;
}

//****************************SMOOTH LOOP CODE****************************

void loop() {
  total = total - readings[index];
  readings[index] = analogRead(inputPin); total = total + readings[index];
  index = index + 1;
  if (index >= numReadings)
    index = 0;
  potentAve = total / numReadings;
  Serial.print("Average Potentiometer Readings: ");
  Serial.println(potentAve);

  //*************************POTENT >> LED LOOP CODE*************************

  ledLevel = map(potentAve, potentMin, potentMax, 0, 255);
  Serial.print("LED Level: ");
  Serial.println(ledLevel, DEC);
  analogWrite(led, ledLevel);
  Serial.println();
  delay(loopDelay);
}

I think you have missed this but both ends of that pot are connected to ground. One end needs to be connected to +5V for it to work.

Why the comments about base resistor? I see a mosfet in the image.

aarg:
Why the comments about base resistor? I see a mosfet in the image.

the image shows a tach switch.... but that is least of the issues.

OP, please give us a real schematic, with things properly labelled.

Hi,

Needs a GATE resistor, sorry, my / fritzy misread.
I was halfway into fetal position when I noticed it.
Goes to show what a half decent schematic would do, I should give up trying to read fritzy when I'm tired.

Tom.... :sleeping:

This seems to be the project.
http://somavisions.com/329648/7184724/projects/sensorlights-led-tutorial-series
Led strip brightness control with smoothing.
Leo..

It is clear that @Velocir seems not to be interested in solving his problem.