Show Posts
Pages: 1 ... 45 46 [47] 48 49 ... 72
691  Using Arduino / Programming Questions / Re: How do i stop blink with out delay with a input trigger? on: July 03, 2013, 09:04:21 pm
So I'm using blink without delay in my sketch which is trigger by a sensor input.  Everything works great until the sensor want to tell the loop to stop blinking, while the led is high, the led stay HIGH. Is there a good way to exit the loop? 

I've tried standard blink without delay sketch controlled by a switch and a "ledFlasher" library they all do the same thing.   
We're supposed to be able to tell you what's wrong without seeing your code?
We're not mindreaders.
692  Using Arduino / Project Guidance / Re: Checking water level in an electric kettle on: July 03, 2013, 08:54:03 pm
Thanks for all of the replies.

An external solution such as weight/load sensor sounds like a brilliant plan. Any recommendations on that?

To clarify the project (if anyone's interested): my remote input will be offset by how far I am from the kettle - determined by GPS on my phone - how much water is currently in it, and the temperature.

Temperature of the water in the kettle or the external temperature (or both)? You're unlikely to want a hot drink if it's over 80 degrees F outside! Cold water takes longer to boil.
693  Using Arduino / Project Guidance / Re: Switching sketch on: July 03, 2013, 08:45:27 pm
The idea is simple , there's one input , the button and two outputs .

-first mode, a classic ON/OFF switching , the ouput 1 goes low to high.
-second mode, the tricky one : if the button is pressed twice quickly (say 1/2 second) it actives the second output . With no effect
on the first ouput.
to put the second output low , the same operation has to be done. two quick hits.
Think about it this way.
1) detect the button press.
2) wait until the button is released (important to distinguish between two short presses and one long one).
3) detect if button is pressed again within time limit.
4) if no second press within time limit, do action 1
5) if second press within time limit, do action 2
694  Using Arduino / Programming Questions / Re: Problem with multiple button brightness control on: July 02, 2013, 10:58:52 pm
I'm really bad at coding and often end up with riddles instead of tidy codes,
I solved the problem I had before, now I'll try to modify my code with your method,

here's the working code,

//Variables won't change
const int lamp1 = 11;      //led #1
const int lamp2 = 10;       //led #2
const int upPin = 2;      //button for brightness up
const int downPin = 3;    //button for brightness down
const int upPin2 = 4;      //button for brightness up
const int downPin2 = 5;    //button for brightness down
const int upPin3 = 6;      //ALL LIGHT UP AND DOWN
const int downPin3 = 7;    //button for brightness down

int lastCounter = 5;
int counter;              //the basic counter
int up;                   //brightnes up button reading
int down;                 //brightnes down button reading

int lastCounter2 = 5;
int counter2;              //the basic counter
int up2;                   //brightnes up button reading
int down2;                 //brightnes down button reading

int lastCounter3 = 5;
int counter3;              //the basic counter
int up3;                   //brightnes up button reading
int down3;                 //brightnes down button reading
int volt;                 //PWM value sent to the leds
int volt2;                 //PWM value sent to the leds
int volt3;                 //PWM value sent to the leds

void setup(){
  pinMode(up, INPUT);
  pinMode(down, INPUT);
  pinMode(up2, INPUT);
  pinMode(down2, INPUT);
  pinMode(up3, INPUT);
  pinMode(down3, INPUT);


void loop(){
  counter = lastCounter;      //counter recyrculation
  counter2 = lastCounter2;      //counter recyrculation

  up = digitalRead(upPin);        //button pins reading
  down = digitalRead(downPin);
  up2 = digitalRead(upPin2);        //button two pins reading
  down2 = digitalRead(downPin2);
  up3 = digitalRead(upPin3);        //button two pins reading
  down3 = digitalRead(downPin3);
   if (up == HIGH) {                    //if the up button is pressed
      counter = counter+1;              //counter increases by one

   if (down == HIGH) {            //if down button is pressed
        counter = counter-1;       //counter decreases by one
   if (up2 == HIGH) {                    //if the up button is pressed
      counter2 = counter2+1;              //counter increases by one

   if (down2 == HIGH) {            //if down button is pressed
        counter2 = counter2-1;       //counter decreases by one
   if (up3 == HIGH) {                    //if the up button is pressed
      counter = counter+1 == counter2+1;
      //counter2 = counter2+1;
//counter increases by one

   if (down3 == HIGH) {            //if down button is pressed
        counter = counter-1;       //counter decreases by one
        //counter2 = counter2-1;
  if (counter > 6){      //check that counter won't get further than 5
    counter = 6;
  if (counter < 2){    //check that counter won't fall bellow 1
    counter = 1;
  switch (counter){    //depending on counter value the propper PWM value is sent to the leds
  case 1:
  volt = 0;
  case 2:
  volt = 50;
  case 3:
  volt = 100;
  case 4:
  volt = 150;
  case 5:
  volt = 200;
  case 6:
  volt = 250;

if (counter2 > 6){      //check that counter won't get further than 5
    counter2 = 6;
  if (counter2 < 2){    //check that counter won't fall bellow 1
    counter2 = 1;
  switch (counter2){    //depending on counter value the propper PWM value is sent to the leds
  case 1:
  volt2 = 0;
  case 2:
  volt2 = 50;
  case 3:
  volt2 = 100;
  case 4:
  volt2 = 150;
  case 5:
  volt2 = 200;
  case 6:
  volt2 = 250;
  analogWrite(lamp1, volt);    //leds turn on with the desirable PWM
  analogWrite(lamp2, volt2);

  lastCounter = counter;      //counter recylculation
  lastCounter2 = counter2;      //counter recylculation
  lastCounter3 = counter3;      //counter recylculation
Why all those counters and variables?
Pseudo code:
if (digitalRead(upPin) ==HIGH);     // up button pressed   
volts1 = volts1 + 50
if volts1>250 then volts1 =250 //keep in range.
serial.Print("LED 1   ")
serial.Println (1 + (volts1 / 50))
analogWrite(lamp1, volts1)

if (digitalRead(downPin) == HIGH)  // down button pressed     
volts1 = volts1 - 50
if volts1 < 0 then volts1 = 0 //keep in range.
serial.Print("LED 1   ")
serial.Println (1 + (volts1 / 50))
analogWrite(lamp1, volts1)


For up and down button3 you'll need to increment or decrement both volts1 and volts2 and check they're both within range before writing the PWMs.
695  Using Arduino / Project Guidance / Re: Serial Momentary Switch on: July 01, 2013, 09:09:01 pm
  unsigned long currentMillis = millis();
  if (Serial.available() > 0){
    incomingByte =;
    if (incomingByte == 48){
      Serial.println("digit 0");
      previousMillis == currentMillis; //??????????????????
      if(currentMillis - interval > previousMillis)
// suggest you use ... if(previousMillis - currentMillis > interval)

; //get rid of this semicolon

        digitalWrite(slndupPin,LOW);      }
    if (incomingByte == 49){
        Serial.println("digit 1");
And look up 'switch case' in the reference section and Functional State Machine.
696  Using Arduino / Programming Questions / Re: Pulsating output on: June 30, 2013, 11:07:50 pm
Looks to me as if you could probably treat each long pulse as two short pulses, so your problem reduces to outputting  a constant frequency bit stream.

Yes. If he changes each 1 to 10 and each 0 to 1100 and sends at constant 53uS intervals, there should be no problem.
697  Using Arduino / Programming Questions / Re: changing blink without delay from switches on: June 30, 2013, 10:54:13 pm
ok i went back to the drawing board of this one the orginal sketch does the same thing smiley-mad

would a switch case work better?
Remember also that you have 4 possible states for your switches:
Both off, both on, 1 on and 2 off, 2 on and 1 off. Some states can be ignored if you don't want to use them.
698  Using Arduino / Programming Questions / Re: windchill formula uses exponents, how do we do that? on: June 30, 2013, 10:45:28 pm
the windchill formula uses exponents

Windchill  = 35.74 + 0.6215*T - 35.75(V^0.16) + 0.4275*T(V^0.16);

where T is temperature
V is wind speed
^0.16 is an exponent.
this is the layout from the nws site but ofcourse the ^0.16 is giving errors on compile, can someone help me please?

As 35.74 and 35.75 are very nearly equal, this formula could be rewritten as
Windchill  = 35.74(1 - (V^0.16)) + T((0.4275(V^0.16)) + 0.6215) with very little error.
699  Using Arduino / Programming Questions / Re: How do i implement button state of change in this sketch turning pin array onoff on: June 30, 2013, 10:17:27 pm
I understand that all of you have giving me hints here but i am not good at understanding what is written right in front of me i am a hands on type of person.
Pseudo code:
int count = 1;
if (button pressed && count == 1),  // first time
while (button pressed); //do nothing. Wait for button to be released.
Do your 'turn on' stuff here.
if (button pressed && count ==2),  //second time
while (button pressed); //do nothing. Wait for button to be released.
Do your 'turn off' stuff here.

If you don't wait for the button to be released, then a long press could be counted as two pushes. Depending on the rest of your code, a 'long press' could be just a few microseconds.
700  Using Arduino / Programming Questions / Re: My first timer project on: June 29, 2013, 07:50:28 pm

void loop ()
  if ( (millis () - oneChanneltick) >= oneChannelinterval)
    digitalWrite(oneChannel, HIGH);   // This turns oneChannel = OFF
  if ( (millis () - twoGaptick) >= twoGapinterval) // Variable gap between oneChannel = ON and twoChannel = ON
       digitalWrite(twoChannel, LOW); // This turns twoChannel = ON, all works through this point
       twoChanneltick = millis (); //This is where I want to start an interval for the duration that twoChannel is ON
       //The following section is not working as I expected (Does not switch twoChannel OFF)- syntax errors? Function mistakes?
       if ( (millis () - twoChanneltick) >= twoChannelinterval)
       digitalWrite(twoChannel, HIGH); //This is where I want to turn twoChannel OFF
       // This is intended to be a one-pass loop, once a channel turns OFF, it is off forever

When the second if statement is true, twoChanel will always be turned on again each time around the loop(), whether or not the third if statement is true. Look up 'switch case' in Arduino reference and 'Functional State Machine' to solve this.
701  Using Arduino / General Electronics / Re: How to mount Arduino Nano to ABS plastic? on: June 29, 2013, 12:38:49 am
Thanks Geoff. Miniature screws seem irritatingly expensive over here (UK)
Depends where you are. There's an old fashioned hardware shop near me (East London) that sells screws, bolts, nuts, washers, etc. loose. Earlier this week, I bought 20 * M4 15mm long bolts and 20 * M4 nuts for £1.56. I know they have 10BA bolts (small enough for you?) of various types (cheesehead, roundhead, countersunk, brass or steel, etc.) and lengths at about 50p for 10 for the bolts and less for the nuts.
They stock anything from 10BA up to about 1/2" Whitworth and wood screws from 1/4" No. 2 to 6" No. 12 (and bigger) all at reasonable prices. The smaller items sell in lots of 10 (counted by hand), the larger ones are sold individually.
They have an ecclectic mix of stuff. I'm going again next week to try to get some 6BA stand-offs. (I've got some, but they're too short). If they don't have them, I don't know who does.
It's the pre-packaged stuff that's expensive.
702  Using Arduino / Programming Questions / Re: Running a loop for certain time on: June 28, 2013, 11:41:43 pm
You are putting data into the array indices v[1] to v[10] but, as array indices start from v[0], there's no v[10].
You haven't balanced your braces, so it won't compile.
i = i + 1; is the same as i++;
The endtime variable can be replaced with millis().
703  Using Arduino / Project Guidance / Re: attenuate DC Motor acoustic noise on: June 28, 2013, 10:17:14 pm
Are you driving the motors with PWM? If so, this may be causing the noise, usually a high pitched whine. The answer is to connect a 0.1uF ceramic capacitor between the contacts on the motor. Changing the PWM frequency is also said to cure it, but I've not tried that.
704  Using Arduino / Project Guidance / Re: Inputs and Open Circuits on: June 28, 2013, 09:49:33 pm
This may be a dumb question, but I haven't been able to find an answer.  I am trying to read a button (long presses) input using a digital in.

Setup:    5V ----  22OHM ----- Button  ------  Pin 2

Arduino detects the closed circuit fine, but when it is open (LOW)
But it's not LOW, it's floating anywhere between 0V and 5V.
Try 5V ----Button ---- Pin 2 ---- 10k ---- GND.
10k ohms will keep Pin 2 low until the button is pressed.
705  Using Arduino / Project Guidance / Re: Help with Arduino and Servo specifications. on: June 27, 2013, 09:48:17 pm
Ok I'll look it up. I've never heard of that so ill have to research it.
I'm getting the Arduino UNO. I only want the forward and reverse and off and on.

The title of your post says "Servo". You using motors or servos?
From another thread he wrote, it appears that he's using 4 motors and two servos. An Adafruit motor shield can handle that.
Pages: 1 ... 45 46 [47] 48 49 ... 72