Loading...
  Show Posts
Pages: [1] 2 3 ... 16
1  Using Arduino / Programming Questions / Re: servo (knob) on: April 17, 2013, 02:46:22 pm
I find if you don't on this form people get upset
2  Using Arduino / Programming Questions / Re: servo (knob) on: April 17, 2013, 12:37:05 pm
ok how the hell do I do that lol
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?
Quote
#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
Quote
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
6  Using Arduino / General Electronics / Re: 12v PWM to 5v PWM on: April 16, 2013, 10:45:57 am
cool ok thanks for that
7  Using Arduino / Programming Questions / Re: servo (knob) on: April 15, 2013, 03:41:24 pm
I have looked at the arduino examples but was struggling how to intergrade it in my code/ application
8  Using Arduino / Programming Questions / Re: servo (knob) on: April 15, 2013, 03:19:27 pm
how do we go about writing this
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
10  Using Arduino / General Electronics / Re: 12v PWM to 5v PWM on: April 15, 2013, 03:01:11 pm
that is fine but not if the voltage goes over 5v
11  Using Arduino / Programming Questions / Re: servo (knob) on: April 15, 2013, 01:04:26 pm
all gone a bit quiet lol
12  Using Arduino / General Electronics / Re: 12v PWM to 5v PWM on: April 15, 2013, 12:54:52 pm
ok cool the 12v could veriate from 11-14v so would it be a good idea to put some protection on it like a 5.1v zener diode?
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?


Code:
#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
Quote
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
Pages: [1] 2 3 ... 16