Jump to content




General Electronics Forum - Questions etc.

amusement park coaster connecticut jonnycoaster quassy

  • Please log in to reply
132 replies to this topic

#61 Knexrule11

Knexrule11

    Sferico's President

  • 4456 posts

Posted 09 March 2011 - 09:39 AM

Wow, your really good! This stuff isn't too cheap, right? Maybe it would be a nice school project....

:ph34r: SSCoasters Moderator :ph34r:
Fear the Bankatana | The SSCoasters Forum Rules

MySSCoasterssig.png
SfericoUserbar-1.png
Maverick|Tatsu|TTD|Fahrenheit|Skyrush|MF|Cheetah Hunt|Storm Runner|SheiKra|Montu
Coaster Count: 102


#62 floris2burn

floris2burn

    Software Engineer

  • 414 posts

Posted 09 March 2011 - 10:11 AM

I wouldn't say just the basics as you already surpassed my coding skills ;)


For those who have never programmed before, arduino is easy to learn because of all the examples they supply in the program (and even more on their website).

It's easy to see how they do stuff, and just copy it. This can go for complex stuff like shift registers or some more advanced commands.
But there's more to it than just knowing the basics, you've got to understand them. If you don't understand the extend use of if, case, for, functions and so on, everything becomes very long and sometimes hard to understand for people who try to analyze the code.

TheSUCK was a good example of this. His self-made version of his station program is very long and consists of dozens of nested "if"s. After some help, his code was a lot more transparent and was even a lot easier to adjust to more complex functionality.

Posted ImagePosted Image


#63 TheSUCKCrew

TheSUCKCrew

    Way too old

  • 4095 posts

Posted 09 March 2011 - 10:46 AM

For those who have never programmed before, arduino is easy to learn because of all the examples they supply in the program (and even more on their website).

It's easy to see how they do stuff, and just copy it. This can go for complex stuff like shift registers or some more advanced commands.
But there's more to it than just knowing the basics, you've got to understand them. If you don't understand the extend use of if, case, for, functions and so on, everything becomes very long and sometimes hard to understand for people who try to analyze the code.

TheSUCK is a good example of this (no offense). His self-made version of his station program is very long and consists of dozens of nested "if"s. After some help, his code was a lot more transparent and was even a lot easier to adjust to more complex functionality.


Please change that to "was" please;)



#64 Jogumpie

Jogumpie

    Living through the great Gump hiatus...

  • 13586 posts

Posted 09 March 2011 - 12:23 PM

With plenty of PHP/MySQL knowledge and examples given with the Arduino's, programming that shit shouldn't be too hard for me either. Ah well, one day I'll get into that, too.


SSCoasters Administrator
The SSCoasters Forum Rules
DD_signature.jpg
YoutubeButton.pngFacebookButton.png


#65 Maxlaam

Maxlaam

    Tracing Tyrant's Steps

  • 8116 posts

Posted 09 March 2011 - 12:32 PM

For those who have never programmed before, arduino is easy to learn because of all the examples they supply in the program (and even more on their website).

It's easy to see how they do stuff, and just copy it. This can go for complex stuff like shift registers or some more advanced commands.
But there's more to it than just knowing the basics, you've got to understand them. If you don't understand the extend use of if, case, for, functions and so on, everything becomes very long and sometimes hard to understand for people who try to analyze the code.

TheSUCK was a good example of this. His self-made version of his station program is very long and consists of dozens of nested "if"s. After some help, his code was a lot more transparent and was even a lot easier to adjust to more complex functionality.


I have to admit that I never really went in depth on all the possibilities, right now my stuff works so I don't plan on changing it any time soon. If I were to spend some time on it my code could be optimized and I can probably run almost everything of the Mega. However I prefer to have everything be able to run stand alone. If my Mega dies at least my coaster look still fancy because of the lights.

My code is very sloppy but blame me for being a pioneer. I had to teach everything to myself and even then I still didn't get all of it. I had some help from Gump and a family member. If I'm correct I started the project before even SUCK of Floris was a member to KF or SSC. Besides, the craze only really started after everything already worked.

I'm still planning ahead on Phase 2.0 but there will be very little things to recycle. I promise Phase 2.0 will be very much optimized and will probably take a long time to develop.


SSCoasters Administrator
Read The Forum Rules(smart)

Posted Image
Posted ImagePosted Image


#66 TheSUCKCrew

TheSUCKCrew

    Way too old

  • 4095 posts

Posted 09 March 2011 - 02:27 PM

And how's the station program going? I may not have helped with the blinking leds, but after spending hours on the station stuff, I want to see result :)


I'll just post the edited version (for so far it's done) in here.
Togheter with Floris I've add a crapload of stuff, such as different modes and right now it features 11 tracks.

/*----------PINS----------*/
const int arrLDR[12] = {999, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const int arrLED[11] = {999, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
const int arrSWITCH_IN[11] = {31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41};
const int arrSWITCH_OUT[11] = {42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 53};
const int arrBUTTON[4] = {11, 12, 13, 14};

/*--------VARIABLES--------*/
// Values that contain the LDR's input status
boolean arrVAL[11];
// Free track
boolean x_FindFreeTrack = true;
int i_SendTrack = 0;
// blinking led
boolean x_ledState = false;
long previousMillis = 0;
long interval = 600;
// data EndLDR
boolean LastEndLDRState = true;
boolean EndLDRState = false;
// data buttons
boolean x_LongTrackManual = false;
boolean x_DriveThrough = false;
boolean x_currentButtonState[2] = {false, false};
boolean x_lastButtonState[2] = {false, false};

// data release-mode
boolean Tumble1;
boolean Tumble2;
// storage First-in first-out
boolean arrLDRlastState[11] = {false, false, false, false, false, false, false, false, false, false, false};
boolean arrLDRcurrentState[11];
int arrFiFoSequence[11] = {9999,999,999,999,999,999,999,999,999,999,999};
int i_EmptyFiFo = 0;
boolean x_ResetFiFo = true;

/*---------SETUP-----------*/
void setup(){
// here you program if the pins are inputs or outputs
for(int x=0; x<11; x++) {
pinMode(arrLDR[x+1], INPUT);
pinMode(arrLED[x], OUTPUT);
pinMode(arrSWITCH_IN[x], OUTPUT);
pinMode(arrSWITCH_OUT[x], OUTPUT);
}
for(int z=0; z<4; z++) {
pinMode(arrBUTTON[z], INPUT); }

Serial.begin(9600);
}
/*----------LOOP-----------*/
void loop(){
// --Reading and processing inputs--
for(int x=1; x<11; x++) {
// Read the LDR's value and store in Val
arrVAL[x] = digitalRead(arrLDR[x]);

// Turn on the control lights of the track where a train is on
digitalWrite(arrLED[x], arrVAL[x]);
}
// --EndLDR Settings--
EndLDRState = digitalRead(arrLDR[11]);

// -- processes button state --
for(int x=0; x<2; x++) {
x_currentButtonState[x] = digitalRead(arrBUTTON[x]);
if(x_lastButtonState[1] == LOW && x_currentButtonState[1] == HIGH){
if(x_DriveThrough == false) {
Serial.println("Drive-through mode");
x_DriveThrough = true; }
else{
Serial.println("Drive-through mode off");
x_DriveThrough = false; }
}
if(x_lastButtonState[0] == LOW && x_currentButtonState[0] == HIGH){
if(x_LongTrackManual == false) {
Serial.println("Manual Mode (9-10)");
x_LongTrackManual = true; }
else{
Serial.println("Automatic mode (1-9)");
x_LongTrackManual = false; }
}
x_lastButtonState[x] = x_currentButtonState[x];
}

// -- Settings ledState --
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
if (x_ledState == LOW)
x_ledState = HIGH;
else
x_ledState = LOW;
}
// -- Processing FiFo Functions --
// Reset FiFo at system-start
if(x_ResetFiFo == true){
FiFoResetting;
}
if(EndLDRState != LastEndLDRState){
LDRStateChange;
}
// -- TrainEntrance-options --

if(x_DriveThrough == true){
i_SendTrack = 0;
}
else{
if(x_LongTrackManual == true){
i_SendTrack = FindLongTrack();
}
if(x_LongTrackManual == false){
i_SendTrack = FindTrack();
}
}
WriteTrack(i_SendTrack);
// -- TrainRelease-options --

/*------FUNCTIONS------*/
// find a track in automatic mode
int FindTrack() {

boolean x_TrackFound = false;
int i_Track = 0;
for(int x=1; x<10; x++) {
if(x_TrackFound == false && arrVAL[x] == false) {
x_TrackFound = true;
i_Track = x;
}
}

return i_Track;

}
// find long track in manual mode
int FindLongTrack() {

boolean x_LongTrackFound = false;
int i_LongTrack = 0;

for(int x=10; x>8; x--) {
if(x_LongTrackFound == false && arrVAL[x] == false) {
x_LongTrackFound = true;
i_LongTrack = x;
}
}
return i_LongTrack;
}

// write tracknumber into a signal
void WriteTrack(int i_FreeTrack){

for (int x=0; x<11; x++){
if(x == i_FreeTrack){
digitalWrite(arrSWITCH_IN[x], HIGH);
digitalWrite(arrLED[x], x_ledState); }
else{
digitalWrite(arrSWITCH_IN[x], LOW); }
}
}
// --Reset FiFo when system starts up--
void FiFoResetting() {
for(int x=1; x<11; x++) {
if(arrVAL[x] == HIGH){
i_EmptyFiFo = FindEmptyFiFo();
arrFiFoSequence[i_EmptyFiFo] = x;
}
}
x_ResetFiFo = false;
}
// --Writes down LDR's current state and compares it with last one. If changed, it processes it into the First-in First-out sequence
void LDRStateChange(){
for(int x=1;x<11;x++){
arrLDRcurrentState[x] = arrVAL[x];
if(arrLDRlastState[x] == LOW && arrLDRcurrentState[x] == HIGH){
i_EmptyFiFo = FindEmptyFiFo();
arrFiFoSequence[i_EmptyFiFo] = x;
arrLDRlastState[x] = arrLDRcurrentState[x];
}
if(arrLDRlastState[x] == HIGH && arrLDRcurrentState[x] == LOW){
MoveFiFoSequence(x);
}
arrLDRlastState[x] = arrLDRcurrentState[x];
}
if(LastEndLDRState == true){
LastEndLDRState = false;}
else{
LastEndLDRState = true;}
}
// find empty place in FiFoSequence
int FindEmptyFiFo(){
boolean x_Found = false;
int i_EmptyFiFo = 0;
for(int x=1;x<11; x++){
if(arrFiFoSequence[x] == 999 && x_Found == false){
i_EmptyFiFo = x;
x_Found = true;
}
}
return i_EmptyFiFo;
}
// move whole Fifo sequence
void MoveFiFoSequence(int Track){
int MoveFrom;
for(int x=1; x<11; x++){
if(arrFiFoSequence[x] == Track){
MoveFrom = x;
}
}
for(int x=MoveFrom; x<11; x++){
arrFiFoSequence[x-1] = arrFiFoSequence[x];
}
arrFiFoSequence[10] = 999;
}


A few things aren't fully done yet, such as the modes for letting trains drive out of the station.



#67 floris2burn

floris2burn

    Software Engineer

  • 414 posts

Posted 09 March 2011 - 04:19 PM

Although this isn't actually electronics but more electrics, it's very cool to see and interesting to know.
There are a lot of motors. AC, DC, brushless, with brushes etc.
Now, on DC motors that don't have permanent magnets in the stator but field windings something dangerous can happen.
When the motor is started but the field windings disconnected, it'll try to go infinite speed.
This can be proven by using the DC motor formula, but no one's interested in that.
No, because it won't reach infinite speed for one reason: destruction!



Note:
This also happens with a DC series wound motor when there is no load on it.
The formula that proves this is:
Posted Image
So if the flux (Φ) reaches zero, the speed (N) will reach infinite.

Posted ImagePosted Image


#68 Maxlaam

Maxlaam

    Tracing Tyrant's Steps

  • 8116 posts

Posted 09 March 2011 - 05:16 PM

^
Fairly sure it started to generate plasma near the end. Right?


SSCoasters Administrator
Read The Forum Rules(smart)

Posted Image
Posted ImagePosted Image


#69 TheSUCKCrew

TheSUCKCrew

    Way too old

  • 4095 posts

Posted 09 March 2011 - 05:34 PM

Are you guys thinking what I'm thinking?
LAUNCH!!!!!

But now serious, thats epic.
That thing went hella-fast:)



#70 floris2burn

floris2burn

    Software Engineer

  • 414 posts

Posted 28 March 2011 - 04:41 PM

This thread could use a new subject:

Transistors.

These 3-legged black spiders (a general description of the most abundant shape) have mainly 2 purposes:
1. As switch
2. As amplifier

The second purpose is mostly for things like audio and video transmitters or amplifiers. These involve the use of the hFE value.

The first one on the other hand is about getting the transistor in saturation, which will just put the transistor in "open" state.
If you use transistors as switches, you need to make sure you don't overload it. When using LED's, don't forget the resistors. When using other components, try to figure out the current it will need and the current the transistor can endure.
On the other side, the base-emitter also needs protection, because just like diodes, transistors have little to no resistance.

Side note: if you need help calculating the resistors, check the internet or ask me.

But now, the part which a lot of people forget: NPN <> PNP
What's the difference? The internal structure of the Positive and negative layers. (I don't know the terms for all these things so I won't go into detail).
Still, what's the difference? You connect them differently!
(note the difference in symbol.)

NPN on the left; PNP on the right
Posted Image Posted Image

Images from: http://www.kpsec.fre...om/trancirc.htm

To all the people who want to use microcontrollers, I suggest using NPN transistors, so it's easier to use different voltages on the secondary (load) side.

That's it for today folks, cya next time!

Posted ImagePosted Image


#71 Jogumpie

Jogumpie

    Living through the great Gump hiatus...

  • 13586 posts

Posted 28 March 2011 - 04:44 PM

Uhoh, we're going into the territory of semiconductors now... ;) Nah, better just think of it as a switch.


SSCoasters Administrator
The SSCoasters Forum Rules
DD_signature.jpg
YoutubeButton.pngFacebookButton.png


#72 Maxlaam

Maxlaam

    Tracing Tyrant's Steps

  • 8116 posts

Posted 28 March 2011 - 04:47 PM

Great post Floris, transistors still remain a complex component for those who are starting with electronics. To be honest I only really get the basics about those things and that I can use them as a switch ;) But they can be very powerful components!


SSCoasters Administrator
Read The Forum Rules(smart)

Posted Image
Posted ImagePosted Image


#73 floris2burn

floris2burn

    Software Engineer

  • 414 posts

Posted 28 March 2011 - 04:48 PM

Yes, most of us just use them as a switch, but there's more to it than just wiring the base to the output pin. There's the whole thing of voltage loss, saturation current, switch frequency, load current and NPN vs PNP.

With this I want to warn people not to buy just any transistor.

By the way, "electronics" is the study of semiconductors, that's what makes it different from electrics.

EDIT:
Oh, and one more thing. Over here (Europe, or something like it) we use the conventional current. That's because we see the current flowing in the wrong direction. So Americans or people who use the true current, some explanations of the current flow might be wrong compared to the non-conventional current.

Posted ImagePosted Image


#74 Maxlaam

Maxlaam

    Tracing Tyrant's Steps

  • 8116 posts

Posted 28 March 2011 - 04:56 PM

With this I want to warn people not to buy just any transistor.


If you are to combine this with an Arduino, usually the right transistor can be found in the examples section on Arduino - HomePage

I know for a fact that when using a transistor with a relay with an arduino it is all listed what you should get; resistor, transistor and diode.


SSCoasters Administrator
Read The Forum Rules(smart)

Posted Image
Posted ImagePosted Image


#75 floris2burn

floris2burn

    Software Engineer

  • 414 posts

Posted 28 March 2011 - 05:02 PM

It's still a good idea to look up the datasheet of the components you are actually using. You can't always get the exact type of transistor that they use. And sometimes the saturation voltage/current and such are different.

Always do the calculation. :)
Posted Image

Posted ImagePosted Image


#76 Maxlaam

Maxlaam

    Tracing Tyrant's Steps

  • 8116 posts

Posted 28 March 2011 - 05:05 PM

It's still a good idea to look up the datasheet of the components you are actually using. You can't always get the exact type of transistor that they use. And sometimes the saturation voltage/current and such are different.

Always do the calculation. :)


I'm in luck that I have this awesome electronics store only 6 minutes away by bike. I just go there give them my plans/drawings and we do all the calculations there. They really don't mind helping me out. I can do most calculations myself though. I guess they just love seeing people my age being interested in crafting something with leds, sound etc.


SSCoasters Administrator
Read The Forum Rules(smart)

Posted Image
Posted ImagePosted Image


#77 floris2burn

floris2burn

    Software Engineer

  • 414 posts

Posted 13 April 2011 - 05:52 AM

Arduino and outputs


Today I'd like to talk about using the outputs on an arduino.
There will be 3 possibilities depending on your load.

1. Naturally, you'll have to determine the load first. This can either be done by looking up the datasheet, using a multimeter or calculating your way out of it.
Examples:
1.1. a LED: generally the resistor is calculated to draw 20-30 mA.
1.2. multiple LEDs: only add the current for each parallel branch.
1.3. a knex or other motor: preferably measured with a multimeter. Be sure to also put some load on the motor.
1.4. a light bulb (very unlikely): Sometimes you'll have a device which will have a certain wattage. For example, a light bulb of 50Watt on 230Volt will draw 50/230 = 0.217 Amp. Formulas on wiki.


2. But this is only one half of the story. The output of an arduino pin only has a potential difference of 5V. If you wish to alter from this, you already have to use additional switching elements.

Now, let's proceed.

2.1. Loads up to 40 mA

2.1.1. On 5V DC or lower: Direct connection to the arduino pin.
2.1.2. More than 5V DC to 24V DC: Transistor.
2.1.3. More than 24V DC or any AC signal: Relay.


2.2. Loads up to about 600mA

2.2.1. On 5V DC or lower: Transistor.
2.2.2. More than 5V DC to 24V DC: Transistor.
2.2.3. More than 24V DC or any AC signal: Relay.


2.3. Loads up to about 2A (2000mA)

2.3.1. On 5V DC or lower: Relay (or power transistor)
2.3.2. More than 5V DC to 24V DC: Relay (or power transistor).
2.3.3. More than 24V DC or any AC signal: Relay.


2.4. Loads above 2A
Are you sure? Check again, distribute your load or you'll have to reconsider working with a regular circuit board.


WARNING: What's mentioned above is a guideline. You always have to check the datasheet for the maximum load for the specific element you have or want to use. One ID-number can result in a very different element.


3. Now, the final part: connecting.
Transistors are used like switches. To control it, you need to send a signal to the base pin, or pull it to the ground if the switch has to be open.
This is done by attaching the base pin to the output pin and also installing the right resistor.

3.1. Example one: Transistor, 5 leds on the +5V pin. (if each draw 20-30mA, the total load current would be 100-150 mA)

http://www.sscoasters.net/gallery/data/915/medium/Trans_and_LED_4_1.bmp
http://www.sscoaster...and_LED_3_1.bmp
http://www.sscoaster...and_LED_1_1.bmp
http://www.sscoaster...and_LED_2_1.bmp


3.2. Example two: 5V Relay switches 2 motors. The current of the relay is too high for the output pin, so it has to be switched with a transistor.
(The DC motors are represented by a coil, in 3D they're the small resistors outside the green circuit board.)

http://www.sscoasters.net/gallery/data/915/medium/Relay_and_motors_4_.bmp
http://www.sscoaster...d_motors_1_.bmp
http://www.sscoaster...d_motors_2_.bmp
http://www.sscoaster...d_motors_3_.bmp


Image gallery: Link.
Schematics have been made with DesignSparkPCB

Posted ImagePosted Image


#78 TheSUCKCrew

TheSUCKCrew

    Way too old

  • 4095 posts

Posted 13 April 2011 - 03:34 PM

I probably didn't do too much of this stuff, therefor I am having some problems with the stuff I bought.
Great advice you got there, you should've posted that a while ago;)



#79 Maxlaam

Maxlaam

    Tracing Tyrant's Steps

  • 8116 posts

Posted 13 April 2011 - 03:59 PM

If you need help with wiring up certain things to the Arduino you can also look on youtube; search for "Arduino 101" and look at the videos by makemagazine. They explain Servos Potentiometers, buttons, leds and some other fun stuff.

I recommend watching all those videos before starting with an Arduino in general.


SSCoasters Administrator
Read The Forum Rules(smart)

Posted Image
Posted ImagePosted Image


#80 floris2burn

floris2burn

    Software Engineer

  • 414 posts

Posted 01 May 2011 - 03:09 AM

I have started on the programming guide, but I just got started and it's already getting huge.

Maybe I should split the beginner, intermediate and advanced sections into new replies. But this will break the general layout i've been maintaining. On the other hand, I could link to these sections on the overview in the first topic.

What do you guys think?

Posted ImagePosted Image