Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: Servo Motor timed reaction on: March 13, 2013, 07:43:34 am
That code won't verify or Auto Format.  It may just be a copy/paste problem when you posted it or your program may actually be wrong.  If you put each curly bracket on its own line, which is a good habit to get into, it is easy to see the problem because the left/right curly brackets don't match
Code:
void loop()
{
  millis();
  bstate1 = digitalRead(button1);
  if(bstate1 != laststate1)
  {
    if(bstate1 == HIGH)
    {
      time1 = millis();
      servo1.write(100);
    }
  }
  laststate1 = bstate1;
  condition1 = millis() - time1;
  if (condition1 == 1000)
  {
    Serial.print("condition = ");
    Serial.println(condition1);
    servo1.write(0);
    count1--;

  }
That is the end of the code that you posted.  Is it the end of your program ?

Again sorry about that. didn't completely copied the whole code
2  Using Arduino / Programming Questions / Re: Servo Motor timed reaction on: March 13, 2013, 07:38:42 am
Hitting EXACTLY 1000 may be a problem.

i change the if condition to if(condition1 > 800 && condition < 1500)
the servo changed position accordingly from 100, and for a moment before changing to 0.
3  Using Arduino / Programming Questions / Re: Servo Motor timed reaction on: March 13, 2013, 07:23:59 am
Sorry about that. I typed on the spot and didn't really copy my code from notepad.

Code:
#include <Servo.h>

Servo servo1;
unsigned long time1;
unsigned long condition1;
const int button1 = 17;
int bstate1 = 0;
int laststate1 = 0;
int count1 = 100;

void setup(){
 pinMode (button1, INPUT);
 servo1.attach(9);
}

void loop(){
 millis();
 bstate1 = digitalRead(button1);
 if(bstate1 != laststate1){
   if(bstate1 == HIGH){
     time1 = millis();
     servo1.write(100);
   }
 }
 laststate1 = bstate1;
 condition1 = millis() - time1;
 if (condition1 == 1000){
    Serial.print("condition = ");
    Serial.println(condition1);
    servo1.write(0);
    count1--;

 }
4  Using Arduino / Programming Questions / Re: Servo Motor timed reaction on: March 13, 2013, 07:15:15 am
I tested the code.
Used the serial monitor to check the value of the "condition1" variable.


if (condition1 == 1000){
   servo1.write(0);
   Serial.print("condition = ");
   Serial.println(condition1);
}

The serial monitor didn't display the value of "condition1" even after pressing the button.
I checked that "button1" is HIGH while being pressed when i tested the code.
5  Using Arduino / Programming Questions / Servo Motor timed reaction on: March 13, 2013, 06:37:22 am
hey guys if anyone would be kind enough to check my codes for a bit... just want someones advice on this

Code:
#include <Servo.h>

Servo servo1;
unsigned long time1;
unsigned long condition1;
const int button1 = 17;
int bstate1 = 0;
int laststate1 = 0;
int count1 = 100;

void setup(){
 pinMode (button1, INPUT);
 servo1.attach(9);
}

void loop(){
 millis();
 if(bstate1 != laststate1){
   if(bstate1 == HIGH){
     time1 = millis();
     servo1.write(100);
   }
 }
 laststate1 = bstate1;
 condition1 = millis() - time1;
 if (condition1 == 1000){
    servo1.write(0);
    count1--;

 }

}


the result i'm looking for is that
When the USER presses the button, even if the user holds the button for a long period, the "count1" variable will only decrement once.
For the servo motor, its degree position would be 100 after pressing the button and after 1 Second (1000 ms) the degree position would be set to 0 degrees.

i'm want to avoid using DELAY

Is the code right?
6  Using Arduino / Programming Questions / Re: Push Button - Servo Motor - Variable problem on: March 11, 2013, 11:36:20 am
Thanks a lot... smiley-grin
7  Using Arduino / Programming Questions / Push Button - Servo Motor - Variable problem on: March 11, 2013, 11:22:52 am
Hey guys need help on some programming logic...
i'll go straight through the important part of my code:
Code:
.
.
.
void loop(){
buttonstate = digitalRead(button);
if (buttonstate == HIGH){
   num = num - 1;
   myservo.write(45);
}
lcd.setCursor (0,5);
lcd.write(num);
}

So here's the thing,
I know the logic of the code would be if you press the push button the servo motor would move to the programmed degree and the "num" variable would be subtracted by 1. I imagine if the user pressed and hold the push button the servo motor would move (but in real life it would seem like it wouldn't) and the variable "num" would continuously decrement by 1.

The outcome i'm trying to pursue is that even if you push and hold the button, the "num" variable will only decrement once. After releasing and pushing the button again would the "num" variable decrement again.

Any advise/codes on how can i do this?
8  Using Arduino / Programming Questions / Re: Arduino- COINSLOT to SERVOMOTOR - Pulses. Need Help. on: January 16, 2013, 10:58:33 pm
i'm sorry to have made a bad impression and for being rude to the other people reading this topic.  smiley-sad

let me rephrase my question:

as i am using a coin acceptor that generates pulses depending on the coin being inserted in the coin acceptor,
What can i do to program the arduino uno to identify as well the type of coin inserted in the coin slot using the pulses generated?
What codes should i use?

again, i'm sorry for being rude.
9  Using Arduino / Programming Questions / Arduino- COINSLOT to SERVOMOTOR - Pulses. Need Help. on: January 16, 2013, 09:11:48 pm
Hi... really need help on this.

IS THERE ANY OTHER WAY TO COUNT OCCURRING PULSES FIRST BEFORE ENTERING THE CONDITIONS IN THE LOOP?

By counting first all occurring pulses the system can identify what type of coin was inserted and move the servo motor to each degree with respect to the type of coin inserted.
TYPE 1 coin = 1 pulse.
TYPE 2 coin = 5 pulses.
TYPE 3 coin = 10 pulses.

With the limited knowledge i have i used a function with delay in it that is being called as a temporary solution to count first all occurring pulses. With the "Counter" function it gives the system the ability to count pulses first before entering the conditions.

Code:
#include <Servo.h>
#include <EEPROM.h>
Servo myservo;

volatile int coins = 0;
volatile int CoinChange = 0;
int CoinSub1 = 10;
int CoinTotal;
int COne;
int CFive;
int CTen;

void setup()
{
  myservo.attach(9);

//CoinSlot
EIFR = _BV (INTF0);
  pinMode(2,INPUT_PULLUP);
  attachInterrupt(0, coinInserted, FALLING);
//coinslot
}

void coinInserted(){
  coins = coins + 1;  
  CoinChange = 1;
}

void Counter(){
  delay(1500);
  delay(900);
}

void loop()
{
  COne = EEPROM.read(4);
  CFive = EEPROM.read(6);
  CTen = EEPROM.read(8);
  CoinTotal = (COne*1) + (CFive*5) + (CTen*10);

  Counter();
  delay(900);

  CoinSub1 = CoinSub1 - coins;

if(CoinChange == 1){
  if (CoinSub1 == 9/*coins == 1*/)
  {
     if(COne < 50 && CoinTotal <= 799)
     {
       COne = COne + 1;
       EEPROM.write(4, COne);
       myservo.write(30);
     }
  }
  else if (CoinSub1 == 5/*coins == 5*/)
  {
    if(CFive < 50 && CoinTotal <= 795)
    {
       CFive = CFive + 1;
       EEPROM.write(6, CFive);
       myservo.write(50);
    }
  }
  else if (CoinSub1 == 0/*coins == 10*/)
  {
     if(CTen < 50 && CoinTotal <= 790)
     {
       CTen = CTen + 1;
       EEPROM.write(8, CTen);
       myservo.write(70);
     }
  }
CoinSub();
}
}
void CoinSub(){
CoinSub = 10;
}

BUT with this coding, with repetitive insertion of coins, the ACCURACY isn't 100% because even if there is still pulses occurring it enters the conditions within the loop which results in a wrong identification of coin. And another result of this coding is that the response time of the servo motor to move in the degree respective to the coin inserted after a coin is inserted in the system is 3-5 seconds.

FOR EFFICIENCY, i require the system to be always 100% in identifying the coins being inserted and a much faster response time.
10  Using Arduino / Programming Questions / Re: Retaining Variable Value in Arduino - Possible? on: January 10, 2013, 07:16:17 pm
It seems that EEPROM only gives you a max of 256 value to store in each address.

IS THERE ANYWAY OF INCREASING IT TO 1000?
11  Using Arduino / General Electronics / Externa Power Source? - Maximum Voltage and Current to Turn on Arduino Uno on: January 09, 2013, 11:04:21 pm
... Hi and Sorry if my post has already been asked, but to be more direct in a way

WHAT IS THE RANGE OF VOLTAGE AND CURRENT NEEDED TO TURN ON ARDUINO UNO.?

the recommended voltage to operate atmega328, if i'm right, is 7 - 12V.
i have an ac-dc adaptor which outputs 12V and 1000ma
the voltage is in range, but i'm not sure if the current is.
12  Using Arduino / General Electronics / External POWER Source? - Maximum Voltage and Current to turn on Arduino Uno on: January 09, 2013, 10:54:11 pm
... Hi and Sorry if my post has already been asked, but to be more direct in a way

WHAT IS THE RANGE OF VOLTAGE AND CURRENT NEEDED TO TURN ON ARDUINO UNO.?

the recommended voltage to operate atmega328, if i'm right, is 7 - 12V.
i have an ac-dc adaptor which outputs 12V and 1000ma
the voltage is in range, but i'm not sure if the current is.


13  Using Arduino / Programming Questions / Re: Retaining Variable Value in Arduino - Possible? on: January 09, 2013, 10:40:31 pm
Just a quick question to make sure, in the topic of powering the arduino,
HOW MUCH VOLTAGE WOULD YOU NEED TO TURN ARDUINO UNO ON IF NOT CONNECTED TO A PC via Cable?
14  Using Arduino / Programming Questions / Re: Retaining Variable Value in Arduino - Possible? on: January 09, 2013, 07:41:07 pm
Thank you so much for the help.  smiley-grin
15  Using Arduino / Programming Questions / Retaining Variable Value in Arduino - Possible? on: January 09, 2013, 07:28:50 pm
Is there a way for a Variable declared in the program to retain it's value if it is change and the arduino is turned off then on again?

Example is that if "X" variable is declared as 0 from the start of the program, and then it became "X=1", is it possible when you turn off/on the arduino
the "X" retains it value change which is "1" ?
Pages: [1] 2 3 4