Go Down

Topic: A Hamster wheel Projekt with hallsensor and timer (Read 663 times) previous topic - next topic

max-power

Code: [Select]
/*Hamsterrad Duechmesser 20cm Umfang 63cm */


const int hallPin = 4;          // 4 the number of the hall effect sensor pin
const int ledPin = 7;     // 7 the number of the LED pin
const int ledPin2 = 3;
const int ledPin3 = 1;
// variables will change:

int hallState = 0;          // variable for reading the hall sensor status
//

void setup() {
  // initialize the hall effect sensor pin as an input:
  pinMode(hallPin, INPUT);     
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
}

void loop(){

  // read the state of the hall effect sensor:
  hallState = digitalRead(hallPin);
// unsigned long currentMillis = millis();
   if (hallState == HIGH) {     
    // turn LED on:   
    digitalWrite(ledPin, HIGH); 
    delay(1000);
    digitalWrite(ledPin2, HIGH);
    delay(1000);
    digitalWrite(ledPin3, HIGH);
    delay(1000);
}
    else {
     // turn LED off:
    digitalWrite(ledPin, LOW);
    delay(5000);
    digitalWrite(ledPin2, LOW);
    delay(2000);
    digitalWrite(ledPin3, LOW);
    delay(2500);
}
}


hi i have this code for a Hamster wheel.

i want turn off all leds when the Hallsensor after 5 minutes not conneced.


330R

I don't understand the purpose of all the delays: what are you after? Do you just want a nice-looking pattern for your lights to turn on or do the delays have some technical purpose? Your code spends most of it's time delaying, and while it does, it can't begin the 5 minutes countdown you want. Also, you set a varable to millis(), but then you don't make any use of it.

When your sensor goes low, the program starts the procedure to turn the LEDs off, but only after the first group of 1 s delays is over.

JimboZA

Also, you set a varable to millis(), but then you don't make any use of it.
Nah it's remmed out:

Code: [Select]
// unsigned long currentMillis = millis();

Maybe OP was thinking about embarking on a delay-less approach?
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

Whandall

I think your program is just not working. The chances of testing the hall as triggered are very small because you only take a quick look at the sensor and then stall for seconds in the led handling.

I would suggest looking for the hall changing from low to high and remembering that time.

The display of the leds should not use delays.


Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

330R

Nah it's remmed out:

Code: [Select]
// unsigned long currentMillis = millis();
Yeah, i can see that now. But even without a comment, this line wuold have no effect: I think this was what triggered my answer.

max-power

yes i want a nice blinking led when the wheel runs when the wheel not run i want turn off all leds when the wheel stops

Go Up