is it possible to plot potentiometer inputs in arduino diecimila
you can read potentiometers with the analogRead() command.
But i don't qiute understand what you mean by "plot".
Arduino can not by itself plot anything, but it can send the values to a PC that can do just about anything with it.
Or Arduino can control a LCD display that can show the values read from the potentiometer.
thanx a lot, i want to do a plot of resistence vs time, how do i get the value for plotting (for example if i was to move the potentiometer for 5s from 0K to 1K)
You hook the potentiometer up to an Arduino analog input as a voltage divider. The potentiometer has three terminals, the two on the "outsides" go to 5V and ground, the center pin to an arduino analog in pin.
Then you use the analogRead(pin number here) to read the value of the analog to digital conversion done by Arduino. This will return a value between 0 and 1023 for a voltage in the 0 - 5V range.
You can use the serial comm. functions to send this value to a PC. But you need some software on the PC that listens for the vale and do the plotting.
i have writen this code for the analog
int Read_Pot_Sensor() {
Pot = analogRead(PotPin);
Serial.print ("Pot = ");
Serial.println (Pot, DEC);
return Pot;
}
is there a code to display the values in the serial monitor
OR
a code to have an array of the readings which i could save in txt then plot using Matlab
i managed to get a code that i can run the inputs from the analog on the serial monitor,is a way of saving the value in a txt file some how?
void setup() {
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// print the time, in 100ths of a second:
Serial.print(millis()/10);
// print a comma:
Serial.print(",");
// print the sensor value (connected to analog pin 0):
Serial.println(analogRead(0));
}
Hi pkm,
Your code may need to be modified as follows to compile in the current Arduino version:
Serial.print(millis()/10,DEC);
If you want to reduce the number of bytes sent per sample, you could just send the time difference between samples :
void loop() {
static unsigned long prevTime;
int diff = millis() - prevTime;
prevTime = millis();
// print the time difference , in 100ths of a second:
Serial.print(diff/10,DEC);
// print a comma:
Serial.print(",");
// print the sensor value (connected to analog pin 0):
Serial.println(analogRead(0));
}
Your code in the receiving side would add the diff values to get the cume time
thanx a lot, at this stage m able to get the values of the potentiometer to display on the serial monitor, what i need to know is how to capture that data for plotting (say value from 0sec to 5sec)
If you are on a windows based computer you can use the Hyperterminal app. that comes with windows, it can save files.
thanx a lots mikmo that helped a lot, i have been trying to implement a counter or something that will let the program run for only 30 seconds then stop, please help
thanx a lot for ur help, i managed to run the program to the time that i need by using an if statement it took a while to get it right tho.
void setup() {
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
if (millis() < 3000){
// print the time, in 100ths of a second:
Serial.print(millis()/10);
// print a comma:
Serial.print(",");
// print the sensor value (connected to analog pin 0):
Serial.println(analogRead(0));
}
}
m actually using a potentiometer to trace the position of a servo motor and using a PID to control the motor
do you guys know how to control the servo motor's position using a PID. can you send a sample code please