Hi to everyone on the forum. Just started with an Arduino Uno and a Mega 2560 so if I let the smoke out it won´t hurt the wallet so much. I have done the blink LED with success. I have soldered an MPR121 board together and got that up and working switching 8 LED´s on with response to touch. I have taken that apart, then used the UNO board to randomly switch on LED´s. Thanks to everyone that writes the code to help us newbies. Now the question is I would like to build a unit that randomly turns on one of twelve relays and plays a random mp3 sound from a library of 8 sounds. The relays would need to turn off after approximately 2 seconds or after a touch sensor is touched (12 in total) relating to that particular relay. If a touch sensor is being touched then the corresponding relay cannot be switched. This cycle would need to run continuous. So am I correct in using the MPR121 and two relay boards and would it be better using the UNO or the Mega 256. Any hints on Code would be greatly appreciated as that is where I struggle the most. Regards Kryptonax
My advice would be to just write code for each step and test it out .
Look at writing each step as a separate function to keep it clean and tidy with lots of comments .
Have a read up on de bugging techniques , such as using print .
kryptonax:
The relays would need to turn off after approximately 2 seconds or after a touch sensor is touched (12 in total) relating to that particular relay. If a touch sensor is being touched then the corresponding relay cannot be switched. This cycle would need to run continuous.
I think the first part I have highlighted should read "after a touch sensor is released".
The usual way to do that is to check for the change of state of the sensor - something like this pseudo code
previousSensorState = sensorState;
sensorState = readSensor
if (sensorState == released and previousSensorState == touched) {
sensorReleasedTime = millis();
turnRelayOn
}
if (millis() - sensorReleasedTime >= 2000) {
turnRelayOff
}
So am I correct in using the MPR121 and two relay boards and would it be better using the UNO or the Mega 256.
I don't know what an MPR121 is - if you need help with it please post a link to its datasheet.
The only difference between an Uno and Mega is the amount of memory and the number of I/O pins. If the Uno has enough I/O pins for the job then it would not matter which of them you use.
Hi Everyone in Arduino Land, I´ve just put together on a schematic of what I am trying to achieve. If anyone has any comments on whether this would or would not work, they will be welcomed. Kindest regards Kevin. Apologies for not using my actual name in my first post.
A big thank you to Hammy and Robin2 for your early response. I will start with the basics as suggested and do my best to write something. Thanks for the guidance. Kindest regards Kevin.
Hi to Everyone in Arduino Land, Just to update. I got my head around the random relay after reading other peoples posts, too many to name. I have the mega 2560 board controlling 16 relays changing condition for 1 second, Then randomly selecting another relay. I have since found that the bare wire touch sensors MPR121 or similar are only good for cables up to about 50cm in length. So I will have to go with normal switches for now. The mega 2560 did not like outputting to a relay on pins 0 and 1. Not a big problem, just selected other pins (16 and 17) Now to get my head around inputs controlling outputs and then combining the two. Happy with my advance and big thanks to everyone that posts on the Arduino Forum, creating a wealth of information. Kindest regards Kevin.
kryptonax:
The mega 2560 did not like outputting to a relay on pins 0 and 1.
On the Mega, Uno and nano pins 0 and 1 are used by Serial and are best not used for other purposes unless you know what you are doing.
...R