Show Posts
Pages: 1 [2] 3 4 ... 27
16  Using Arduino / Project Guidance / Re: Two analog sensors controlling PWM on: March 03, 2013, 11:26:56 am
You should know that this part wont work, well it will but not the way you want it to be
Code:
// Naming the analog pins:
      int analog_pin_0 = 0;
      int analog_pin_1 = 1;
      int analog_pin_2 = 2;
      int analog_pin_3 = 3;
      int analog_pin_4 = 4;
      int analog_pin_5 = 5;

The right way to declare an analog pin is by using A0 to A5 in your case like this
Code:
// Naming the analog pins:
      int analog_pin_0 = A0;
      int analog_pin_1 = A1;
      int analog_pin_2 = A2;
      int analog_pin_3 = A3;
      int analog_pin_4 = A4;
      int analog_pin_5 = A5;

one part that i an wondering is that
Quote
I am working on a project that takes the input of two analog sensors and outputs one PWM signal as a function of the two.

but in your code
Code:
T_min = analogRead(analog_pin_0);
      T_max = analogRead(analog_pin_1);
      T = analogRead(analog_pin_2);
   ......
      P_min = analogRead(analog_pin_3);
      P_max = analogRead(analog_pin_4);
      P = analogRead(analog_pin_5);

do you use 2 or 6 Analog pin?

if you are using 2 analog input and you want min, max and current value something along this line should work

Code:
int min = 1023;
int max = 0;

int current = analogRead(A0) // Just and example
if ( current < min) min= current;
if ( current > max) max = current;
int Tout = (((1023/ (t_max - t_min)) * (t - t_min))/4);

you know for the output part you do not need any conditioning since the arduino know if 0 its equal to low and 255 equal to high so

Code:
analogWrite(pin_f_out, final_out);
would have been enough
17  Using Arduino / Project Guidance / Re: Reaction time test circuit. on: March 03, 2013, 10:00:24 am
try not to use delay could you?
18  Using Arduino / Project Guidance / Re: Guidance with deboucing on: March 03, 2013, 09:50:55 am
try this code maybe it will help u
Code:
uint8_t Switch = 2;
uint8_t Led =13;

boolean LedState =LOW;
int SwitchState =0;
int SwitchDebounce;
int LastSwitchState=HIGH;
int LastSwitchDebounce=LOW;

unsigned long LastDebounceTime = 0;
unsigned long DebounceDelay = 50;

void setup()
{
  pinMode(Switch,INPUT);
  digitalWrite(Switch,HIGH);
  pinMode(Led,OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  int CurrentSwitch = digitalRead(Switch);
  if (CurrentSwitch != LastSwitchDebounce)
  {
    LastDebounceTime = millis();
  }
  if ((millis() - LastDebounceTime) > DebounceDelay)
  {
    SwitchState = digitalRead(Switch);
    if (SwitchState != LastSwitchState)
    {
      if (SwitchState == LOW)
      {
        LedState = !LedState;
        (LedState)?Serial.println("Led is On"):Serial.println("Led is Off");
      }
    }
    LastSwitchState=SwitchState;
  }
  digitalWrite(Led,LedState);
  LastSwitchDebounce = CurrentSwitch;
}
19  Using Arduino / Motors, Mechanics, and Power / Re: 30RPM Worm Drive on: February 21, 2013, 03:53:56 am
one option is to use a stepper motor...
wiper motor is an option you cannot overlook
20  Using Arduino / Motors, Mechanics, and Power / Re: L298n, Do I need flyback diodes? on: February 21, 2013, 03:52:07 am
yes you do since ln298 dont have internal flyback diode
21  Using Arduino / Programming Questions / Re: cruise control on motorcycle, need to read timing between wheel RPMs on reed swi on: February 12, 2013, 01:04:15 pm
i have this piece of code that maybe you could tinker with, what it does is if you press a switch that is connected to pin 2 on the arduino board, like so

pin2------|/|-----Ground

the code will measure how long the switch was press and will light up the on board led (pin 13) the same amount of time that the switch was press after the switch was release

Code:
uint8_t Switch = 2;
uint8_t Led =13;

boolean LedState =LOW;
int SwitchState =0;
int SwitchDebounce;
int LastSwitchState=HIGH;
int LastSwitchDebounce=LOW;

unsigned long LastDebounceTime = 0;
unsigned long DebounceDelay = 50;
unsigned long TimeRelease=0;
unsigned long TimePress=0;

void setup()
{
  pinMode(Switch,INPUT);
  digitalWrite(Switch,HIGH);
  pinMode(Led,OUTPUT);
  digitalWrite(Led,LOW);
}

void loop()
{
  int CurrentSwitch = digitalRead(Switch);
  if (CurrentSwitch != LastSwitchDebounce)
  {
    LastDebounceTime = millis();
  }
  if ((millis() - LastDebounceTime) > DebounceDelay)
  {
    SwitchState = digitalRead(Switch);
    if (SwitchState != LastSwitchState)
    {
      if(SwitchState)
      {
        TimeRelease=millis();
        digitalWrite(Led,HIGH);
      }
      if (!SwitchState)
      {
        TimePress=millis();
      }
      LastSwitchState=SwitchState;
    }
  }
  if ((millis()-TimeRelease)>=(TimeRelease-TimePress))
  {
    digitalWrite(Led,LOW);
  }
  LastSwitchDebounce = CurrentSwitch;
}

22  Using Arduino / Programming Questions / Re: Simple count down timer problem on: February 12, 2013, 12:21:53 pm
Arduino take a sequence of number and treat every digit as its own digit. what you need is someway of telling the arduino that the sequence of number is not just a single digit thing but a whole.

i found out that sending a terminator help alot
maybe you could use a special character like "/" or "*" as to tell the arduino this is the end

like
Code:
while(Serial.read()!="/")
{
  int val=Serial.read;
  int Sum=Sum*10+val;
  }
the snippet does not work, but it should show you how it is done.
23  Using Arduino / Motors, Mechanics, and Power / Re: controlling two transistors with same port on: February 12, 2013, 08:47:50 am
what your asking is consider as a push pull transistor circuit, althought i cant really get what your wiring do, heres a link for you to read on
http://en.wikipedia.org/wiki/Push%E2%80%93pull_output

one thing you need to consider is that, never switch on the same side at the same time since it will produce a dead short
24  Using Arduino / Programming Questions / Re: New to Arduino on: February 12, 2013, 05:18:44 am
Code:
int timer = 1000;           
int i = 1;

void setup()

  for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++) 
    for (int thisPin2 = 13; thisPin2 < 25; thisPin2++) 
      for (int thisPin3 = 24; thisPin3 < 38; thisPin3++) 
        for (int thisPin4 = 37; thisPin4 < 43; thisPin4++) 
        {
          pinMode(thisPin1, OUTPUT); 
          pinMode(thisPin2, OUTPUT);
          pinMode(thisPin3, OUTPUT);
          pinMode(thisPin4, OUTPUT);
          pinMode(51, OUTPUT);
          pinMode(52, OUTPUT);
          pinMode(53, OUTPUT);
        }
}


void loop()

  while (i<2) {
    i++;
    { 
      for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++) 
        for (int thisPin2 = 13; thisPin2 < 25; thisPin2++)
          for (int thisPin3 = 24; thisPin3 < 38; thisPin3++) 
            for (int thisPin4 = 37; thisPin4 < 43; thisPin4++) 
            {
              digitalWrite(52, HIGH);
              delay(3000);
              digitalWrite(52, LOW);

              digitalWrite(thisPin1, HIGH);
              digitalWrite(53, HIGH);
              delay(100);
              digitalWrite(53, LOW);
              delay(timer);
              digitalWrite(thisPin1, LOW);

              digitalWrite(thisPin2, HIGH);
              digitalWrite(53, HIGH);
              delay(100);
              digitalWrite(53, LOW);
              delay(timer);
              digitalWrite(thisPin2, LOW);

              digitalWrite(thisPin3, HIGH);
              digitalWrite(53, HIGH);
              delay(100);
              digitalWrite(53, LOW);
              delay(timer);
              digitalWrite(thisPin3, LOW);

              digitalWrite(thisPin4, HIGH);
              digitalWrite(53, HIGH);
              delay(100);
              digitalWrite(53, LOW);
              delay(timer);
              digitalWrite(thisPin4, LOW);
            }
    }
  }
}
25  Using Arduino / Programming Questions / Re: New to Arduino on: February 12, 2013, 05:17:56 am
i gave you the edited version ....
26  Using Arduino / Programming Questions / Re: New to Arduino on: February 12, 2013, 05:10:08 am
post your code with using the code tag function ok btw your code, you are using all your pin in maybe a mega i think
you just use ; in what should be ,
Code:
int timer = 1000;          
int i = 1;

void setup()
 {  for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++)  
    for (int thisPin2 = 13; thisPin2 < 25; thisPin2++)  
    for (int thisPin3 = 24; thisPin3 < 38; thisPin3++)  
    for (int thisPin4 = 37; thisPin4 < 43; thisPin4++)  
 {
    pinMode(thisPin1, OUTPUT);  
    pinMode(thisPin2, OUTPUT);
    pinMode(thisPin3, OUTPUT);
    pinMode(thisPin4, OUTPUT);
    pinMode(51, OUTPUT);
    pinMode(52, OUTPUT);
    pinMode(53, OUTPUT);
}}


void loop()
 {  while (i<2) {i++;
 {  for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++)  
    for (int thisPin2 = 13; thisPin2 < 25; thisPin2++)
    for (int thisPin3 = 24; thisPin3 < 38; thisPin3++)  
    for (int thisPin4 = 37; thisPin4 < 43; thisPin4++)  
   {
    digitalWrite(52, HIGH);
    delay(3000);
    digitalWrite(52, LOW);
 
    digitalWrite(thisPin1, HIGH);
    digitalWrite(53, HIGH);
    delay(100);
    digitalWrite(53, LOW);
    delay(timer);
    digitalWrite(thisPin1, LOW);
 
    digitalWrite(thisPin2, HIGH);
    digitalWrite(53, HIGH);
    delay(100);
    digitalWrite(53, LOW);
    delay(timer);
    digitalWrite(thisPin2, LOW);

    digitalWrite(thisPin3, HIGH);
    digitalWrite(53, HIGH);
    delay(100);
    digitalWrite(53, LOW);
    delay(timer);
    digitalWrite(thisPin3, LOW);

    digitalWrite(thisPin4, HIGH);
    digitalWrite(53, HIGH);
    delay(100);
    digitalWrite(53, LOW);
    delay(timer);
    digitalWrite(thisPin4, LOW);
}}}}
27  Using Arduino / Motors, Mechanics, and Power / Re: Proximity Sensor and 5 solenoids on: February 12, 2013, 04:56:26 am
actually DDRYA,
though picture speak a thousand word, for the life of me i cant actually see what type of transistor ur using, whether the yellow wire on top is the positive or the negative side of the circuit. however about our question, usually when you are powering a project and want to switch on and of a solenoid it is always better that you make the connection parallel.So in that sense you could use a 12Vdc power supply but 14Vdc would be a better choice since there would be a drop in the transistor, however i would also warn you that the arduino have an absolute max Vdc input of 12Vdc.
So my suggestion to you is that,
if you are willing to use 2 power supply then,
1 7Vdc power supply for your arduino and 1 14Vdc power supply for your solenoid.
or
use a single 12Vdc power supply, is good for both.
28  Using Arduino / Motors, Mechanics, and Power / Re: Servo Motor Position Control with potentiometer on: February 08, 2013, 06:53:54 pm
Then its better to use an encorder. But 1 work around that i could think of if he turn thr pot to 0 if every time he what to move the servo
29  Using Arduino / Project Guidance / Re: RC servo control on: February 08, 2013, 09:10:57 am
Simplest way is to impliment delay. But for a more profesional looking code use what the technique shown on blink without delay. How abou u post yourcode for us to really help you
30  Using Arduino / Motors, Mechanics, and Power / Re: Latte Printer on: February 07, 2013, 02:30:42 am
I second what robtillaart said. But to answer your question about how to trick the paper sensor, just block the perticular photointeruptor the detect the paper...
Pages: 1 [2] 3 4 ... 27