I've recently picked up the arduino uno and am following the examples of how to use each component supplied in the starter kit.
I noticed that the range in my potentiometer seems a bit..off. When printing out the analog values to serial, I found that when i turn the knob half way, its still at 0. Then when i continue turning, it'll quickly rise from 0-253 (doesn't exactly go to 255 either). I dont think it was always like that. Am I doing something wrong? Is there a way to get a linear relation between the variable resistance and the pot?
What do you mean by "what value pot?" I get values from 0-253 from the serial terminal.
The pot has 3 pins. One goes to ground, the middle one goes to pin A0 on the Arduino Uno, and the other goes straight to power (5v). It is set up similar to the example tutorials from the arduino website.
It works, but the problem for me is that range is terribly exponential.
Opps sorry, you're right, it does not go from 0-255. That was for the analog pwm value for setting LEDs. I was getting 0-255 because i used the pot_value/4 to map 0-1023 to 0-255, but then i just used the map() function.
I'm still not getting a smooth fading LED though. Here is my code
#include <Tone.h>
#include "pitches.h"
int led = 9; // the pin that the LED is attached to
int pot = A0;
int button1 = 2;
int button2 = 4;
int speaker = 10;
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600);
// declare pin 9 to be an output:
pinMode(pot, OUTPUT);
pinMode(led, OUTPUT);
pinMode(button1, INPUT);
pinMode(speaker, OUTPUT);
pinMode(button2, INPUT);
}
int sensorValue, buttonState1, buttonState2;
void loop() {
// set the brightness of pin 9:
sensorValue = analogRead(pot);
buttonState1 = digitalRead(button1);
buttonState2 = digitalRead(button2);
Serial.println(sensorValue/4);
if (buttonState1 == HIGH){
analogWrite(led, map(sensorValue, 0, 1023, 0, 255) );
}
else
analogWrite(led, LOW);
if (buttonState2 == HIGH){
tone( speaker, map(sensorValue, 0, 1023, 120, 1500), 20);
}
delay(10);
}
Are you ignoring my question about the potentiometer value ?
(resistance )
Do you not know how to tell what the value is ?
Do you have a Multi Meter to measure it ?
Did you look at the code number on it (103,104 ets)
raschemmel:
Are you ignoring my question about the potentiometer value ?
(resistance )
Do you not know how to tell what the value is ?
Do you have a Multi Meter to measure it ?
Did you look at the code number on it (103,104 ets)
! Apologies! I did not know the value, and it didn't say in the guide that came with the kit. But, looking around the web it seems to be a 10k ohm potentiometer.
michinyon:
pinMode(pot, OUTPUT);
Why ?
This might be the problem! I'm not with my arduino right now, but I will test it ASAP.
Also, in some of the example codes posted by Arduino, they dont specify all the pins as INPUT or OUTPUT. Are they, by default, set to INPUT?