This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hi everyone,
Currently building a circuit that controls a single colour LED strip with a MOSFET. Built the circuit in tinkercad, and everything was working fine, but now when I'm making the actual circuit in real life, everything except for the LED turning on is working. I was hoping to get some help.
The circuit involves turning a potentiometer to set a timer, using a slider switch to set brightness, and then pressing the button to turn on the light for a specified amount of time. The LCD displays this information.
Uploaded the circuit diagram below; in place of the 9V battery is a 12V 2A power supply, and the LED is replaced with a single-colour blue LED strip. The LED strip turns on just fine when connected directly to the 12V supply. The code is down below.
Edit: link to mosfet
Thanks in advance for any help!
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 10, d5 = 9, d6 = 8, d7 = 7;
const int LED_Pin = 3; // strip connected to pin 3
const int ButtonPin = 4; Â // start/stop button connected to pin 4
const int Switch = 5; Â // Slider switch to control brightness connected to pin 5
const int PotPin = A0; Â // Potentiometer controlling the time connected to pin A0
int value = 0; // variable to read the analog potentiometer
int Brightness = 0; // variable for brightness value
unsigned int Time = 0; // variable to store the timer value
bool LedState = false; // variable to know the state of the strip on/off
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
 // set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(LED_Pin, OUTPUT);
pinMode(ButtonPin, INPUT);
pinMode(Switch, INPUT);
pinMode(PotPin, INPUT);
}
void loop() {
 value = analogRead(PotPin);         // read the potentiometer value of the time
 value = map(value, 0, 1023, 1, 10);     // map the potentiometer to value from 1 to 10
lcd.setCursor(2, 0);
lcd.print("Time = "); Â Â Â Â Â Â Â Â Â Â Â // print the timer value
lcd.print(value); Â Â Â Â Â Â Â Â Â Â Â Â Â // print the timer value
lcd.print(" min "); Â Â Â Â Â Â Â Â Â Â Â Â Â // print the timer value
if (digitalRead(Switch) == HIGH) { Â Â Â Â Â // Read the slider switch value
  Brightness = 127;              // set the brightness level one (dim)
lcd.setCursor(4,1);
lcd.print("Low Mode ");
}
else { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // else
  Brightness = 254;              // set the brightness level two (bright)
lcd.setCursor(4,1);
lcd.print("High Mode");
}
if (digitalRead(ButtonPin) == HIGH) { Â // read the on/off button
while (digitalRead(ButtonPin) == HIGH); Â // wait until it's released
if (LedState) { Â // if the LED strip is already on
analogWrite(LED_Pin, 0); Â // turn off the strip immediately
  LedState = false;  // set the state to off
}
else { Â // otherwise, turn the strip on and start the countdown timer
  LedState = true;  // set the state to on
analogWrite(LED_Pin, Brightness); Â // turn on the strip with the set brightness
  // Countdown timer loop
for (int sec = value * 60; sec >= 0; sec--) { Â // iterate from the set value down to zero
int min = sec / 60;
int remainder = sec % 60;
lcd.clear();
lcd.setCursor(4, 0); Â // move the cursor to the second row
lcd.print(" Â "); Â // clear the previous timer value
lcd.setCursor(4, 0); Â // move the cursor to the second row
lcd.print(min); Â // print the remaining minutes
lcd.print(":"); Â // print the separator
if (remainder < 10) { Â // print leading zero for single-digit seconds
lcd.print("0");
}
lcd.print(remainder); Â // print the remaining seconds
lcd.print(" min"); Â // print the timer unit
delay(1000); Â // wait for one second
lcd.clear();
if (digitalRead(ButtonPin) == HIGH) { Â // check if the button was pressed again
while (digitalRead(ButtonPin) == HIGH); Â // wait until it's released
analogWrite(LED_Pin, 0); Â // turn off the strip immediately
    LedState = false;  // set the state to off
break; Â // exit the timer loop
}
}
if (LedState) { Â // if the LED strip is still on after the timer loop
analogWrite(LED_Pin, 0); Â // turn off the strip
   LedState = false;  // set the state to off
}
}
}
}
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/arduino/com...