Pretty new to Arduinos and looking for some friendly advice on best way of doing my project. I am electrician by trade so know the 230v side of things and just require some advice on programming the kit really.
I have a snooker hall with 7 snooker tables in. Each have there own 230v light above table and im looking at creating a controller so they can be switched on from a office about 40 metres away from snooker hall. I have a 8 way relay board that i can connect to Arduino Uno and have all the equipment for the install. How would I go about programming the board please?
I basically want a 12 button number pad to be able to tell the arduino for example....
Table 1 Light on for 60 minutes, Table 2 Light on for 120 minutes etc etc. I would also like a screen in the install so you can check the remaining time on each table unless this could be seen from a PC? Or is there a GUI interface that could do the same job for this project?
do you wish to have the screen (what size) connected to the Arduino?
I would tend to have a PC with a GUI sending commands to an Arduino to control lights
I think a PC app, with a pictorial representation of the tables, showing the time remaining (if any) with icons to turn the lights on or off, would be a better idea. Connect the PC to the Arduino wirelessly - bluetooth is probably easiest, if the range isn't too far. XBees or NRFs are possible, too.
Have you considered using standard "home automation" equipment? Usually, I advise people to use home-automation switches/outlets, even if they want to build their own timer/controller, but you're certainly qualified to make that decision.
In any case, take it one step at a time. Make some "mini projects" based on the basic [u]examples[/u]. Maybe start with Blink Without Delay* and modify it with multiple longer outputs-delays. The trick is to use multiple previousMillis variables (PreviousMillisOne, PreviosMillisTwo, etc) and optionally multiple interval variables (IntervalOne ,IntervalTwo, etc.). Of course, there is only one currentMillis time.
Then, try the Digital Read Serial Example. Once the pushbutton is working, combine that with the blink code (with an if-statement) to start the timer when you push the button.
Etc...
Since you've got the relays & power under control, you can test everything on a small scale with LEDs.
Use the serial monitor to "watch" your program (to help with testing & debugging). For example, you can display messages like "Button 1 pushed", or you can display the elapsed time, etc. Whatever you need to confirm your program is doing what you expect.
7 Switches would be easier than a keypad, but setting time could be tricky (maybe push once for 60 minutes, twice for 120, etc?) There are keypad examples so you can figure-out what's best.
. I would also like a screen in the install so you can check the remaining time on each table unless this could be seen from a PC? Or is there a GUI interface that could do the same job for this project
A "simple" built-in LCD display would be easiest.
The only built-in computer interface is the USB/serial port. The USB is mostly for programming & debugging. If you want to do more, you have to write some kind of computer application and that can be a bigger deal than programming the Arduino-side. Another possibility is an Ethernet or Wi-Fi shield (which takes an add-on shield or one of the specialiazed Arduinos). I've never done that... It's easier because you can use a web browser, but I wouldn't say it's "easy" and with limited memory you can put a whole lot of HTML in the Arduino.
You can't use delay() in your application because it pauses execution during the delay time... You can't read a pushbutton or start/stop/read another timer until the delay is up.
horace:
do you wish to have the screen (what size) connected to the Arduino?
I would tend to have a PC with a GUI sending commands to an Arduino to control lights
Thank you for your reply. If i could do it with a pc with gui display that would be perfect. Is there somewhere good for me to look at to work this out?
I think a PC app, with a pictorial representation of the tables, showing the time remaining (if any) with icons to turn the lights on or off, would be a better idea. Connect the PC to the Arduino wirelessly - bluetooth is probably easiest, if the range isn't too far. XBees or NRFs are possible, too.
This would be absolutly perfect if i could get it with pictoral representation of the tables. I didnt really realise arduino could do this. I guess it would take a huge bit of programmong knowledge?
Bluetooth to the arduino would be good to. What is Xbee ot nrf please?
The arduino would 'just' control the lights and communicate with the PC using serial, WiFi, Bluetooth, Xbee, etc.
if you already have local WiFi I would use that using TCP/IP client/server protocol
the PC could be programmed using C++, C#, VB.NET, Java, Python, etc - depending upon your experience
initially if would build a simple system with the Arduino controlling the lights communicating with the PC runing a simple terminal program (such as Terterm) using serial communications with a character based protocol, e.g. to switch on lights an table one transmit "T1 ON" etc
once that is working add functionality
horace:
The arduino would 'just' control the lights and communicate with the PC using serial, WiFi, Bluetooth, Xbee, etc.
if you already have local WiFi I would use that using TCP/IP client/server protocol
the PC could be programmed using C++, C#, VB.NET, Java, Python, etc - depending upon your experience
initially if would build a simple system with the Arduino controlling the lights communicating with the PC runing a simple terminal program (such as Terterm) using serial communications with a character based protocol, e.g. to switch on lights an table one transmit "T1 ON" etc
once that is working add functionality
Thanks Horace,
I have just got my kit and have setup some bits now. Can you help in where i could find some information on how i can tell a output to switch on for x time and if i press a different button it would stay on for a different durarion of time?
Can you help in where i could find some information on how i can tell a output to switch on for x time
You can't. You can turn an output pin on or off. You must note when you turned it on, and turn it off when sufficient time has passed. There is no digitalWriteForSomeTime() method to do that for you.
here is a simple example reading two swiches which switch on an LED for 5 or 10 seconds
// DMU shield - test switches and LED
// press swich 1 to turn on LED for 5 seconds
// press swich 2 to turn on LED for 10 seconds
#define sw1Pin 10
#define sw2Pin 11
#define LED1 5
void setup() {
Serial.begin(115200);
Serial.println("DMU shield button test\n");
// LED1 ON for 5 seconds
pinMode(LED1, OUTPUT);
digitalWrite(LED1, HIGH); // on
delay(5000); // wait 5 seconds
digitalWrite(LED1, LOW); // off
}
void loop()
{
static unsigned int timer=millis(), timeDelay=0;
// check switches to see if LED is to be switched on
if(!digitalRead(sw1Pin))
{
Serial.println("Sw1 pressed ");
timeDelay=5000; // 5 seconds ON
timer=millis(); // start timer
digitalWrite(LED1, HIGH); // switch ON LED
}
if(!digitalRead(sw2Pin))
{
Serial.println("Sw2 pressed ");
timeDelay=10000; // 10seconds
timer=millis();
digitalWrite(LED1, HIGH);
}
// if ON time elapsed switch OFF LED
if(millis()-timer > timeDelay)
digitalWrite(LED1, LOW);
}
in setup() delay() is used to time the LED on for 5 seconds - the problem is while delay() is called you cannot do anything else (unless you use interrupts)
in loop() pressing switch 1 truns on LED for 5 seconds switch 2 for 10 seconds
if a switch has been pressed and is pressed again while the LED is on the LED will stay on for another 5 or 10 seconds
if you don't want this the program code gets a bit more complex
you could do the timing in a GUI sending commands to the Arduino
I would suggest experimenting with the Arduino first then look at adding a GUI
Have you used GUI builing environments such as Visual Studio (for C++, C#, VB, etc) or NetBeans (for Java)