Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Forum / second input isn't read by the arduino on: January 19, 2011, 11:35:56 am
Hello there,
the problem i'm facing is that i can't get the arduino to read the 2nd input (pushbutton) even though i'm sure it's connected properly because i tried to use it as the 1st one instead and it worked..

so i have 2 pushbuttons and 4 LED's and i want the 1st pushbutton to make LED1 light and LED2 blink and then when i press the 2nd pushbutton i want LED 2 stop blinking and just be lit and LED3 to start blinking..  but i can't get the 2nd pushbutton 2 work... it doesn't read it at all.. so can someone please see my code and tell me what's wrong.. or why it doesnt read it?

Code:
#define LED 13 // THE PIN FOR THE LED
#define SENS1 0


//VARIABLES

int pin1 = 1;
int pin2 = 2;
int pin8 = 8;
int pin9 = 9;
int pin10 = 10;
int pin11 =11;

int sensorValue = 0;
int oldSensorValue=0;

boolean blinking = false;


void setup () {
 pinMode (8, OUTPUT);
 pinMode (9, OUTPUT);
 pinMode (10, OUTPUT);
 pinMode (11, OUTPUT);
  
 pinMode (1, INPUT);
 pinMode (2, INPUT);
}

void loop (){
  
 oldSensorValue = sensorValue;
 sensorValue = digitalRead(pin1);

 if(sensorValue == HIGH && oldSensorValue == LOW){
  
      digitalWrite(pin8, HIGH);
 if(sensorValue == HIGH && blinking == true){
      blinking = false;
    }
    else if(sensorValue == HIGH && blinking == false){
      blinking = true;
    }
      
    }
if (blinking == true) {
    digitalWrite(pin9, HIGH);
    delay(200);
    digitalWrite(pin9, LOW);
    delay(200);}
    
  sensorValue = digitalRead(pin2);
  
    
 if (blinking == false && sensorValue == HIGH){
   digitalWrite(pin9, HIGH);
   while (pin9, HIGH) {
   digitalWrite(pin10, HIGH);
   delay(200);
   digitalWrite(pin10, LOW);
   delay(200); }
 }
else if (blinking == false && sensorValue == HIGH){
   digitalWrite(pin9, HIGH);
   digitalWrite(pin10, HIGH);
   while (pin10, HIGH) {
   digitalWrite(pin11, HIGH);
   delay(200);
   digitalWrite(pin11, LOW);
   delay(200); }
 }
}

thank you =)
2  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: second input isn't read by arduino on: January 19, 2011, 03:20:18 pm
ok.. il try that and get back to you.. thanx for your help =)
3  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: second input isn't read by arduino on: January 19, 2011, 03:13:37 pm
2.  Stop using sensorValue, give each button their own state variable, and read them both at the beginning of loop().

what does their own state variable mean? can you please give me an example.. the reason i used it was so i could be able to tell the arduino to read a different input from the sensor each time, or then how else could i do that?
4  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: second input isn't read by arduino on: January 19, 2011, 03:08:50 pm
i know the if statements at the end are identical, but it doesn;t even execute the part before it, i can't get it to read the second input.. but otherwise everything is working fine..  

something i just realized now.. is that when i upload the sketch, if i press on the second pushbutton straight away (the first ordder given to the arduino) it runs the second part the way i want it... and if i press the first pushbutton( straight after its uploaded) it runs the first part... but i can't seem to combine them both.. and i know my code is messed up, i'm just a beginner and this is far as i've gone.. i'm just really stuck and helpless at the moment... i;ve reached a dead end and don;t know what to do. So any suggestions as how to start fixing it.. or how to get both pushbuttons to work?
5  Forum 2005-2010 (read only) / Frequently-Asked Questions / second input isn't read by arduino on: January 19, 2011, 01:34:17 pm
Hello there,
the problem i'm facing is that i can't get the arduino to read the 2nd input (pushbutton) even though i'm sure it's connected properly because i tried to use it as the 1st one instead and it worked..

so i have 2 pushbuttons and 4 LED's and i want the 1st pushbutton to make LED1 light and LED2 blink and then when i press the 2nd pushbutton i want LED 2 stop blinking and just be lit and LED3 to start blinking..  but i can't get the 2nd pushbutton 2 work... it doesn't read it at all.. so can someone please see my code and tell me what's wrong.. or why it doesnt read it?

Code:
Code:
#define LED 13 // THE PIN FOR THE LED
#define SENS1 0


//VARIABLES

int pin1 = 1;
int pin2 = 2;
int pin8 = 8;
int pin9 = 9;
int pin10 = 10;
int pin11 =11;

int sensorValue = 0;
int oldSensorValue=0;

boolean blinking = false;


void setup () {
 pinMode (8, OUTPUT);
 pinMode (9, OUTPUT);
 pinMode (10, OUTPUT);
 pinMode (11, OUTPUT);
  
 pinMode (1, INPUT);
 pinMode (2, INPUT);
}

void loop (){
  
 oldSensorValue = sensorValue;
 sensorValue = digitalRead(pin1);

 if(sensorValue == HIGH && oldSensorValue == LOW){
  
      digitalWrite(pin8, HIGH);
 if(sensorValue == HIGH && blinking == true){
      blinking = false;
    }
    else if(sensorValue == HIGH && blinking == false){
      blinking = true;
    }

    }
if (blinking == true) {
    digitalWrite(pin9, HIGH);
    delay(200);
    digitalWrite(pin9, LOW);
    delay(200);}
    
  sensorValue = digitalRead(pin2);
  
    
 if (blinking == false && sensorValue == HIGH){
   digitalWrite(pin9, HIGH);
   while (pin9, HIGH) {
   digitalWrite(pin10, HIGH);
   delay(200);
   digitalWrite(pin10, LOW);
   delay(200); }
 }
else if (blinking == false && sensorValue == HIGH){
   digitalWrite(pin9, HIGH);
   digitalWrite(pin10, HIGH);
   while (pin10, HIGH) {
   digitalWrite(pin11, HIGH);
   delay(200);
   digitalWrite(pin11, LOW);
   delay(200); }
 }
}


thank you =)  
Back to top  
6  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Loops on: January 16, 2011, 04:37:32 pm
Code:
#define LED 13 // THE PIN FOR THE LED
#define SENS1 0


//VARIABLES
int state = 0;
int currentInput = 1;
int currentOutput = 8;

int sensorValue = 0;
int oldSensorValue=0;
boolean blinking = false;


void setup () {
 pinMode (8, OUTPUT);
  
 pinMode (1, INPUT);
}

void loop (){

 oldSensorValue = sensorValue;
 sensorValue = digitalRead(currentInput);

 if(sensorValue == HIGH && oldSensorValue == LOW){
   state= 1-state;
      digitalWrite(currentOutput, HIGH);
 if(sensorValue == HIGH && blinking == true){
      blinking = false;
    }
    else if(sensorValue == HIGH && blinking == false){
      blinking = true;
    }
      
    }
 if (blinking == true) {
    digitalWrite(currentOutput+1, HIGH);
    delay(200);
    digitalWrite(currentOutput+1, LOW);
    delay(200);}
    
else if (blinking == false && sensorValue == HIGH){
   digitalWrite(currentOutput+1, HIGH);
   digitalWrite(currentOutput+2, HIGH);
   delay(200);
   digitalWrite(currentOutput+2, LOW);
   delay(200);}  
 }  

what happens is that when i press the button, my first led goes on permenantly and the second goes blinking (which i needed and is correct) the problem is that i want when i press again the second led to stay on, the first led to keep staying on and the third goes blinking and then the same process with the fourth......... but what happens is that when i press on the button the second keeps lit steadily and the first keeps lit steadily but the third blinks once then stops... (which is my problem)
7  Forum 2005-2010 (read only) / Frequently-Asked Questions / Loops on: January 16, 2011, 04:33:53 pm
In the middle of my sketch I want to make a loop that starts when i push the push button and then stops when I press it again, how can this be made?????
8  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Need help with resistors on: January 16, 2011, 12:27:15 pm
ok.. so now, do u have any idea how i can get the second LED to blink strongly( because the light intensity is very low, its just a small spot inside the LED that u can barely see)
9  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Need help with resistors on: January 16, 2011, 11:34:36 am
nope.. the 10 k resistor is connected to the pushbutton and the ground the LED is just connected to the ground. honestly, I dnt know what the resistor is for, but i copied it from a diagram in the book "Getting started with Arduino."
10  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Need help with resistors on: January 16, 2011, 11:20:57 am
oh yeah.. and i didnt understand the part about the pull-up or pull-down for the switches? what does that mean?

and the pinMode is correct i guess..

excuse my ignorance... i've never done anything connected to programming code or electronics before.. =)
11  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Need help with resistors on: January 16, 2011, 11:14:39 am
first of all.. i have no idea how to post a diagram of the wiring and stuff..   :-[

and i'm sure there's nothing wrong with the code.. because it worked before.. but i changed a few things and can't get it to work again. The current status is that it's blinking only inside the LED which is very low and i don't why, except that i can't seem to remember how to link the 2nd resistor to it again. but just incase, i will post the code for you to understand what i'm doing:

Code:
define LED 13 // THE PIN FOR THE LED
#define SENS1 0


//VARIABLES
int state = 0;
int currentInput = 1;
int currentOutput = 7;

int sensorValue = 0;
int oldSensorValue=0;
boolean blinking = false;


void setup () {
  pinMode (7, OUTPUT); //tell Arduino LED is an output
  
  pinMode (1, INPUT);
}

void loop (){

  oldSensorValue = sensorValue;
  sensorValue = digitalRead(currentInput);

  if(sensorValue == HIGH && oldSensorValue == LOW){
   state= 1-state;
      digitalWrite(currentOutput, HIGH);
      delay(3000);
      
  if(sensorValue == HIGH && blinking == true){
      blinking = false;
    }
    else if(sensorValue == HIGH && blinking == false){
      blinking = true;
    }

  

  
      
    }
    if (blinking == true) {
    
    
    //START BLINKING
   { digitalWrite(currentOutput+1, LOW); // turn LED OFF
    delay(200);
    digitalWrite(currentOutput+1, HIGH); // turn LED OFF
    delay(200);}
    
    
  }
  
    if (currentInput+1 == HIGH){
      
      digitalWrite(currentOutput+1, HIGH);
   }
    
  }


//reads an input and gives an output




thank you soooo much for ur fast reply! =)
12  Forum 2005-2010 (read only) / Frequently-Asked Questions / Need help with resistors on: January 16, 2011, 10:56:01 am
It's my first time to use arduino and im a product designer, so its not exactly my thing..the problem i'm facing right now is that i'm using a pushbutton with 2 LEDs as outputs, whats supposed 2 happen is the first LED should stay on and the second LED should blink... it does work, but the blinking is not strong.. its like its only blinking from inside with a very small intensity, how do i get it to blink strongly, that it all lights and goes off? is that something wrong with the way i've connected the wires and stuff? or where is the problem?

would really appreciate it if someone could help me understand..  smiley

i'm using a 10k resistor, and the first one is connected to the pushbutton and the ground, but where do i connect the second one? or do i only use one?
Pages: [1]