Project tutorial
ARDUINO UNO or TRINKET PRO 5V 6 Chasing LEDS with POT and PB

ARDUINO UNO or TRINKET PRO 5V 6 Chasing LEDS with POT and PB © GPL3+

6 chasing LEDS with POT and pushbutton indicating waterpump is working. (PART 2 of 3)

  • 2,203 views
  • 2 comments
  • 5 respects

Components and supplies

About this project

This small project is part 2 of 3. The first part see: https://create.arduino.cc/projecthub/MichDragstar/ultrasonic-sensor-with-alarm-lcd-and-temperature-a5dbab?ref=user&ref_id=410358&offset=0

In this part there are 6 chasing LEDS mounted in a circle to indicate the waterpump is pumping. In the real project the push button is replaced by a relay contact witch is activated by a magnet contact (Waterlevel high). The speed of the chasing LEDS can be adjust with the POT. I made this project first on the UNO, in the real project I use the TRINKET PRO 5V 16MHz. The OUTPUTS and the CODE does not change for the UNO or TRINKET.

    byte ledPin[] = {8, 9, 10, 11, 12, 13};    // Create array for LED pins
   int ledDelay; // delay between changes
   int direction = 1;
   int currentLED = 0;
   unsigned long changeTime;
   int potPin = 2;    // select the input pin for the potentiometer
   int buttonPin = 4;   
   int buttonState = 0;    
void setup() {
   pinMode(buttonPin, INPUT);  
   for (int x=0; x<6; x++) {   // set all pins to output
   		pinMode(ledPin[x], OUTPUT); }
     	changeTime = millis();     
  }
void loop() 
  {
    buttonState = digitalRead(buttonPin);
    ledDelay = analogRead(potPin); // read the value from the pot 
    if ((millis() - changeTime) > ledDelay) {      // if it has been ledDelay ms since last change
 		changeLED();
  		changeTime = millis();
 	}
   }
void changeLED() {
   for (int x=0; x<6; x++ ) {   // turn off all LED's
   		digitalWrite(ledPin[x], LOW);
 	}
   if (buttonState == HIGH) {
   digitalWrite(ledPin[currentLED], HIGH);} // turn on the current LED    
   else digitalWrite (ledPin[currentLED], LOW);
  currentLED += direction; // increment by the direction value
  if (currentLED == 6){currentLED = 0;
  }
  }

Code

6 chasing LEDSC/C++
    byte ledPin[] = {8, 9, 10, 11, 12, 13};    // Create array for LED pins
    int ledDelay; // delay between changes
    int direction = 1;
    int currentLED = 0;
    unsigned long changeTime;
    int potPin = 2;    // select the input pin for the potentiometer
    int buttonPin = 4;   
    int buttonState = 0;    


void setup() {
    pinMode(buttonPin, INPUT);  
      
    for (int x=0; x<6; x++) {   // set all pins to output
    		pinMode(ledPin[x], OUTPUT); }
      	changeTime = millis();     
   }

void loop() 
   {
     buttonState = digitalRead(buttonPin);
     ledDelay = analogRead(potPin); // read the value from the pot 
     if ((millis() - changeTime) > ledDelay) {      // if it has been ledDelay ms since last change
  		changeLED();
   		changeTime = millis();
  	}
    }

void changeLED() {
    for (int x=0; x<6; x++ ) {   // turn off all LED's
    		digitalWrite(ledPin[x], LOW);
  	}
 
    if (buttonState == HIGH) {
    digitalWrite(ledPin[currentLED], HIGH);} // turn on the current LED    
    else digitalWrite (ledPin[currentLED], LOW);
    	
   currentLED += direction; // increment by the direction value

   if (currentLED == 6){currentLED = 0;
   }
   }
   

Schematics

6 chasing LEDS with UNO
pump_on_off_pot_pb_6leds_2iNv8q0Szt.fzz
6 chasing LEDS with TRINKET 5V
trinket_pump_on_off_pot_pb_6leds_poki91lcTn.fzz

Comments

Similar projects you might like

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 10,501 views
  • 7 comments
  • 24 respects

Control Arduino Uno Using ESP8266 WiFi Module and Blynk App

Project tutorial by Adithya TG

  • 36,244 views
  • 13 comments
  • 40 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 43,264 views
  • 21 comments
  • 122 respects

Arduino Digital Dice

Project tutorial by xXarduino_11Xx

  • 1,573 views
  • 5 comments
  • 8 respects

Electronic Piano Keyboard With Preset Songs

Project tutorial by Lindsay Fox

  • 88,524 views
  • 67 comments
  • 176 respects

The Magnetic Field and RGB Tester

Project tutorial by Kutluhan Aktar

  • 4,605 views
  • 0 comments
  • 17 respects
Add projectSign up / Login