Fun with Arduino - a Series of Introductory Videos

A series of tutorial videos for those who wish to learn more.
Chris
Posts: 72
Joined: Thu Oct 18, 2018 6:24 pm
Contact:

Re: Fun with Arduino 20 Railway Crossing Putting it all Together

#41

Post by Chris » Sat Mar 16, 2019 12:41 pm

RudyB wrote:
Sun Mar 10, 2019 11:24 am
We have seen the separate ingredients for a level crossing in the previous three videos: blinking LEDs, servo to operate the gate, sensors to detect the train ... it is time to put it all together now into one piece of software. We'll use the State Transition Diagram as our starting point and build up the software in 5 easy to follow steps.


Fun with Arduino 20 Railway Crossing Putting it all Together

Railway Crossing UK version


Image
Having looked at the code, it opens the gate as soon as the second sensor sees a train, this is fine for the closing stage but means that a long train will trigger the opening as the front leaves the crossing while the coaches are still over the road,
As a solution the second sensor needs to either see the train but not release the barrier until it looses the signal again, or have the opening signal combined from both sensors sensor one low sensor 2 high to low transition and give a short time delay

User avatar
RudyB
Posts: 33
Joined: Fri Jan 04, 2019 2:26 pm
Location: Netherlands
Contact:

Re: Fun with Arduino - a Series of Introductory Videos

#42

Post by RudyB » Sat Mar 16, 2019 12:57 pm

True. For the sake of simplicity in this example the 'open' trigger is at the moment sensor 2 sees the train. Would be better if the trigger comes at the end of the train. That will require some extra code to detect thet end of the train. A timer can be used, that starts after the sensor changed, and no other change should take place for n seconds ... then it is decided this was the end of the train.

Chris
Posts: 72
Joined: Thu Oct 18, 2018 6:24 pm
Contact:

Re: Fun with Arduino - a Series of Introductory Videos

#43

Post by Chris » Sat Mar 16, 2019 2:15 pm

given that sensor 1 would need to be mounted far enough in advance to get the barrier down before the train arrives sticking with a two sensor system then sensor 2 can be used as an occupancy sensor

*train approaching*
sensor 1 active, start flashing and close barrier
wait till sensor 2 active (having sensed train approaching waits till train is seen on crossing)

*crossing occupied*
is sensor 2 active run 2 second timer is sensor 2 still active (this allows for gaps in the carriages)
yes: go to *crossing occupied* (loops till train has passed)
no: go to *crossing clear*

*crossing clear*
wait 2 seconds (lets train clear)
open barrier
stop flashing
go to *train approaching*

User avatar
RudyB
Posts: 33
Joined: Fri Jan 04, 2019 2:26 pm
Location: Netherlands
Contact:

Fun with Arduino 23 Neopixel Addressable LED, WS2812, struct{...}

#44

Post by RudyB » Thu Mar 21, 2019 2:19 pm

Neopixels, or addressable LEDs, are color LEDs with a built in chip that takes care of the one wire data communication and of the Pulse Width Modulation for the built in RGB(+W) LEDs. The LEDs are connected via just 3 wires, GND, 5V, Data. The Data line is connected to an Arduino output and we can control the color and brightness of multiple LEDs, via just one output. Wonderful to use in say a village with multiple houses on our model railway layout. The wiring is super simple and the lights in every house switch independently and can each have their own color an brightnes ... just like real.


Link to Fun with Arduino 23 Neopixel Addressable LED, WS2812, struct{...}


Image

User avatar
teedoubleudee
Posts: 168
Joined: Fri Oct 05, 2018 2:53 pm
Location: Downham Market
Contact:

Re: Fun with Arduino - a Series of Introductory Videos

#45

Post by teedoubleudee » Thu Mar 21, 2019 4:56 pm

Fascinating stuff Rudy, the combinations seem endless.
Most people are shocked when they find out how bad I am as an electrician

User avatar
RudyB
Posts: 33
Joined: Fri Jan 04, 2019 2:26 pm
Location: Netherlands
Contact:

Fun with Arduino 24 Neopixel Sequencer with Flexible Timing and Colors

#46

Post by RudyB » Fri Mar 29, 2019 11:18 am

In video 23 we made a step sequencer for addressable LEDs (Neopixel). The beauty of it is that a LED on/off sequence is created in a visual way by editing a series of ‘1’s and ‘0’s: 1,1,1,0,0,0,1,1,0,0,1,0,1,1,0,0. The drawback being that the color of every LED is fixed and also the interval time is fixed. The sequencer in this video has full flexibility, every action step has its own timing and LED color / brightness.


Link to Fun with Arduino 24 Neopixel Sequencer with Flexible Timing and Colors


Image

User avatar
RudyB
Posts: 33
Joined: Fri Jan 04, 2019 2:26 pm
Location: Netherlands
Contact:

Fun with Arduino 25 Rotary Encoder with Switch

#47

Post by RudyB » Fri Apr 05, 2019 1:56 pm

A rotary encoder is a digital device, approximately the size of an analog potentiometer. When rotated, it generates 2 pulse signals from which we can deduct the number of rotation steps and the direction of rotation. It also has a push button on board. When connected to the Arduino we can read out the encoder and change the value of a variable. The variable can be used for anything we like: control the brightness of a LED(strep), control the angle of a servo motor, and more.

In this video we build the software to read out the encoder and switch and control the brightness of a LED (via PWM). In the next video we are going to beuild a servo tune application based on it.


Fun with Arduino 25 Rotary Encoder with Switch


Image

User avatar
RudyB
Posts: 33
Joined: Fri Jan 04, 2019 2:26 pm
Location: Netherlands
Contact:

Fun with Arduino 26 Tune a Servo with a Rotary Encoder

#48

Post by RudyB » Thu Apr 18, 2019 10:27 am

In the previous video we wrote code to read out the pulses and the switch of a rotary encoder. We are now going to use this to tune a servo motor.

With every mechanical construction where a servo is used to move something (garage doors, a gate beam, a turnout), the minimum and maximum servo angles need to be found for the construction to operate like we want it to. In this video we are going to build a 'servo tuner' to find those angles.

Fun with Arduino 26 Tune a Servo with a Rotary Encoder


Image

User avatar
RudyB
Posts: 33
Joined: Fri Jan 04, 2019 2:26 pm
Location: Netherlands
Contact:

Fun with Arduino 27 Recognize Slow / Fast Rotation of Rotary Encoder

#49

Post by RudyB » Thu Apr 18, 2019 10:27 am

The Servo Tuner that we built in the previous video can be enhanced with two features:
1: Recognition of slow or fast rotation of the rotary encoder, to be able to increment the motor with small steps or with larger steps.
2: Recognition of short or long press of the button, to be able to move to the min/max angles or to the midpoint of the servo.
In this video we will have a look how we can add these functions.

On the blog there's also code available to operate the Servo Tuner with a wire or with push buttons, in case you don't have a rotary encoder available.

Link to Fun with Arduino 27 Rotary Encoder Slow / Fast Recognition


Image

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest