Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help with a LEGO project!

Status
Not open for further replies.

duddadu

New Member
Hello everyone,

I am looking for some help in designing a system for allowing power to LEGO transformers. This needs to be a 120v system. As you can see in the image below, I need the system to only have one push button. The controller needs to sequentially activate each group, but only after the button press. Then, power runs to the various LEGO models for the length of time we set the timer to.

This project is for a really cool display fundraiser. For the last few years our club has done fundraising for the Wake A Wish foundation. This year, our display is going to be an amusement park. There are going to be at least a dozen custom LEGO built amusement park rides. Kids will hit the push button to make the rides move. Normally, our timers that we already have would work fine. However, LEGO motors are pretty expensive and having them run for 5+ hours per day for 30 days completely wrecks them. By using this system, the motors only run for 1/3 of the time, and have a chance to cool down and not overheat.

If possible, I would prefer to stay away from ICs.

So, if anyone here can help out, I'd be super appreciative.

VLC Timer.png
 
Welcome to ETO!
Why do you want to avoid ICs? They could simplify things considerably.
 
I avoid ICs because in the past... Well, lets just say that it was an expensive mistake. However, if using ICs will make it work, and it's cost efficient, I'll do it.

I also love the sound relays make :)
 
Okay! I took the advice of a friend and I ended up buying an Arduino UNO and a 4-channel relay shield. I've been tinkering with the programming for the last 7 hours and I'm getting nowhere. I can get the relay shield to work, small success! But I can't get a button to activate a relay. Now that I have the needed hardware, I could REALLY use a hand with the software.

Help... pretty please... with a cherry on top?
 
Hello again!

Progress report. I'm getting a feel for the Arduino but it is troublesome... I CAN now get a button to activate a relay. However, I can't seem to get the relay to turn off after a set amount of time. Here is my sketch:


int relayPin4 = 9;
const int buttonPin = 8;

int relayState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin

long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers

void setup()
{
pinMode(buttonPin, INPUT);
pinMode(relayPin4, OUTPUT); // sets the digital pin as output
digitalWrite(relayPin4, relayState); // Prevents relays from starting up engaged
}

void loop()
{
int reading = digitalRead(buttonPin);

if (reading != lastButtonState)
{
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay)
{
if (reading != buttonState)
{
buttonState = reading;
if (buttonState == HIGH)
{
relayState = !relayState;
}
}
}

digitalWrite(relayPin4, relayState);
delay(1000);

digitalWrite(relayPin4, !relayState);
delay(1000);
lastButtonState = reading;
}
 
Hello again, after some serious keyboard pounding, a lot of reading, and much forum chatter, here is the arduino sketch that actually works. I share this in the hopes that others can benefit form my trials.

// single-tasking sketch: switch relay ON for certain time
const byte NUMRELAYS = 4;
const byte RELAYACTIVE = LOW; // many mechanical relay boards are "active LOW" switching
const byte relayPins[] = {2, 3, 4, 5};
const byte buttonPin = 8; // connect button pins to D8 and GND
const long relayTimes[] = {1000L, 1000L, 1000L, 1000L}; // task duration in milliseconds (long)

void setup() {
for (int i = 0; i < NUMRELAYS; i++)
{
digitalWrite(relayPins, !RELAYACTIVE);
pinMode(relayPins, OUTPUT);
}
pinMode(buttonPin, INPUT_PULLUP); // connect button pins to D8 and GND
}

boolean buttonPressed() // reading button presses of a button with
{
static unsigned long lastTime;
static byte lastState = digitalRead(buttonPin);
if (millis() - lastTime < 10) return false; // debounce 10 milliseconds
byte currentState = digitalRead(buttonPin);
if (currentState == lastState) return false;
lastState=currentState;
if (currentState==LOW) return true;
else return false;
}

byte currentRelay = 0;
void loop() {
if (buttonPressed())
{
digitalWrite(relayPins[currentRelay], RELAYACTIVE);
delay(relayTimes[currentRelay]);
digitalWrite(relayPins[currentRelay], !RELAYACTIVE);
currentRelay++;
if (currentRelay >= NUMRELAYS) currentRelay = 0;
}
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top