Show Posts
|
|
Pages: [1] 2 3 ... 16
|
|
3
|
Using Arduino / Programming Questions / Re: servo (knob)
|
on: April 17, 2013, 11:59:40 am
|
ok I have only altered code in the void setup so the first bit clears the eeprom and then the bit at the end which I presume is right but im guessing not lol writes to the eeprom when I have got this first bit right I will then alter the bit in the void loop to read the min and max value from the eeprom what do you think? #include <Servo.h> Servo myservo; // create servo object to control a servo
#include <EEPROM.h> // EEPROM int addr = 0;
int potpin = 0; // analog pin used to connect the potentiometer int ch1 = 5; // PWM input int val2; // variable to read the value from the analog pin int buttonPin = 11; // caliberate button int sensorValue = 0; // the sensor value int sensorMin = 740; // minimum sensor value int sensorMax = 0; // maximum sensor value
void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object pinMode(ch1, INPUT); pinMode(buttonPin, INPUT);
if (digitalRead(buttonPin)== HIGH) { // ** ...cailable... ** // digitalWrite(12, HIGH); // write a 0 to all 512 bytes of the EEPROM for (int i = 0; i < 512; i++) // clear the EEPROM EEPROM.write(i, 0); // calibrate during the first five seconds while (millis() < 5000) { sensorValue = analogRead(potpin);
// record the maximum sensor value if (sensorValue > sensorMax) { sensorMax = sensorValue; } // record the minimum sensor value if (sensorValue < sensorMin) { sensorMin = sensorValue; } } digitalWrite(12, LOW); EEPROM.write(addr, sensorMax); // wite max to the EEPROM EEPROM.write(addr, sensorMin); // wite min th the EEPROM } }
void loop() { sensorValue = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) ch1 = pulseIn(5, HIGH, 25000); // Read the pulse width of
// apply the calibration to the sensor reading sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 740);
// in case the sensor value is outside the range seen during calibration sensorValue = constrain(sensorValue, 0, 740);
val2 = map(ch1, 0, 1000, 0, 20); // scale from 0 to 20 for the zero for the servo sensorValue = map(sensorValue, 0, 740, val2, 150); // scale it to use it with the servo (value between 0 and 180) myservo.write(sensorValue); // sets the servo position according to the scaled value delay(5); // waits for the servo to get there }
|
|
|
|
|
4
|
Using Arduino / Programming Questions / Re: servo (knob)
|
on: April 16, 2013, 12:02:04 pm
|
|
always use values from the eeprom unless the button has been pressed to calibarate which will clear the eeprom then write new values. that's what I was thinking anyway. please say If I have missed anything.
|
|
|
|
|
5
|
Using Arduino / Programming Questions / Re: servo (knob)
|
on: April 16, 2013, 11:43:50 am
|
so can I save the values to the arduino, I presume we have to use the eeprom? What are "the values" that you want to save to EEPROM? the max and min values that the calibrate function come up with
|
|
|
|
|
9
|
Using Arduino / General Electronics / Re: 12v PWM to 5v PWM
|
on: April 15, 2013, 03:17:10 pm
|
|
yes that is fine but as I have said is it worth putting some sort of protection after that e.g. the zener diode or something else as the supply is up and down and quite possibly having a few spikes in it which could harm the arduino
|
|
|
|
|
13
|
Using Arduino / General Electronics / 12v PWM to 5v PWM
|
on: April 15, 2013, 12:05:22 pm
|
|
hi there the subject gives it away, I want to read a PWM on my arduino but the PWM is 12v so my question is what is the best way to drop the voltage down to 5 v for the arduino?
|
|
|
|
|
14
|
Using Arduino / Programming Questions / Re: servo (knob)
|
on: April 14, 2013, 11:44:48 am
|
as you can see I have added calibrate function what works fine, but when the arduino is powered down it forgets it range so can I save the values to the arduino, I presume we have to use the eeprom? how do we do that? #include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer int potpin2 = 1; // analog pin used to connect the potentiometer int val2; // variable to read the value from the analog pin int buttonPin = 11; //caliberate button int sensorValue = 0; // the sensor value int sensorMin = 740; // minimum sensor value int sensorMax = 0; // maximum sensor value
void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object pinMode(buttonPin, INPUT);
if (digitalRead(buttonPin)== HIGH) { // ** ...cailable... ** // digitalWrite(12, HIGH); // calibrate during the first five seconds while (millis() < 5000) { sensorValue = analogRead(potpin);
// record the maximum sensor value if (sensorValue > sensorMax) { sensorMax = sensorValue; } // record the minimum sensor value if (sensorValue < sensorMin) { sensorMin = sensorValue; } } digitalWrite(12, LOW); } }
void loop() { sensorValue = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
// apply the calibration to the sensor reading sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 740);
// in case the sensor value is outside the range seen during calibration sensorValue = constrain(sensorValue, 0, 740);
val2 = map(val2, 0, 1023, 0, 20); // scale from 0 to 10 for the zero for the servo sensorValue = map(sensorValue, 0, 740, val2, 150); // scale it to use it with the servo (value between 0 and 180) myservo.write(sensorValue); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there }
|
|
|
|
|
15
|
Using Arduino / Programming Questions / Re: servo (knob)
|
on: April 14, 2013, 11:26:59 am
|
you have used the serial monitor to check the values you get from analog read is my understanding, yes?
yes on the 10k pot 0-1023 nice and smooth but not linea on the 5k pot it go's 0-740 so I edited the 1023 to 740 what work fine but I still had the dead band so I played with the 0-180 and took it down the 0-150 and now seems to work over the full range
|
|
|
|
|