Sunday, 28 July 2019

Finishing off the Interactive Confetti Room Controller

Last week I managed to help finish off the interactive confetti room controller.  It which was finally made up of the following components:

1x Arduino Uno R3 clone
1x prototyping shield
1x magnetic door sensor and complementary magnet
3x 10 kΩ resistors
1x DS1307 i2c real time clock module
1x Elegoo 8 channel relay module
5x Single UK mains plug socket extensions
1x 5 Vdc power supply for the Arduino Uno and Relay PCB

The build was put together as follows:


The mains power all came from a single input poorly shown coming in at the bottom left.  This connection was then used to power the 5 Vdc power supply for the arduino and the relay module.  The live connection to the outputs was controlled by the relay PCB between the normally open and common connections.  The relays inputs were connected to the arduino uno digital pins at 11, 10, 9 and 8 respectively.  The door sensor was connected via between 5 Vdc and digital pin 2 of the arduino, a 10  resistor and GND.  The real time clock module was connected to the i2c pins A4 and A5 of the arduino UNO.  The i2c lines were also 'pulled up to 5 Vdc via 10 kΩ resistors to ensure correct operation.  

Note: The Elegoo relay module screw terminals are quite small and it was difficult to insert 1.5 mm diameter mains cable into them.  I ended up getting some thick single core house wiring conductor and using that and when connecting the live conductor to that.  I then covered the lot in hot glue and insulating tape to try to prevent the exposed live being touched.  As everything is going inside a box it shouldn't be an issue anyway.  The final user who will be using this controller and developing the firmware was clearly warned!  

The whole assembly was mounted to a laser cut wooden baseboard...as this turned out to be a little undersized I then put the whole lot inside a 230 x 230 x 120 mm laser cut wooden box.  Strain relief was added to all cables using some cable ties. The lid was left off while the firmware was developed by the customer.  I assisted where I was requested but I am not the best at coding and was also short on time so I left them to it!

Here is a photo of the kit inside the box:


Here is a photo of the box with it's unattached lid:


Well that's it for this quick project.  I may well add source code and video of the final effect when I get the chance to see it!  I'm aware this post lacks the usual detail but there wasn't much to write about.

That's all for now - Langster!

Sunday, 7 July 2019

Elegoo 8 Channel Relay Module Tutorial

Carrying on from the previous post about an interactive confetti room...

https://langster1980.blogspot.com/2019/07/interactive-confetti-room-project.html

Lets get out the 8 channel relay PCB and see what makes it tick.

Here are the specifications of the device in case it is needed:

● Output Channels: 8
● Operating Voltage: 5 Vdc
● Operating Current: 480 ma
● Switching Voltages: 250 Vac at 10 Amps, 30 Vdc at 10 A

● Mechanical Dimensions (Length*Width*Height): 137 mm x 56 mm x 17 mm (5.4" x 2.2" x 0.7")
● Mounting Hole Size: 3 mm (0.12")
● Mounting Hole Centres (L*W): 132 x 50 mm (5.2" x 2")

Here is the schematic diagram again:


I connected up the relay board to the Arduino R3 as shown in the diagram below:
This connection arrangement will actuate the channel 1 relay switching the positive feed (+5 Vdc) on it's common and normally closed connections.  Anything connected between the common pin and the normally closed pin will be switched, It could be anything as long as it is within the specifications of the relay contacts.  The normally open pin will also be switched as the common pin is in the middle of the switching contacts.

We want to write some simple test code to drive the relay coil on channel one on and off for a brief period of time:

1.  Initialise control variables
2.  Start the Serial Monitor
3.  Set the relay drive pins to be outputs
4.  Open channel 1 relay contacts
5.  Wait half a second
6.  Close channel 1 relay contacts
7.  Loop back to step 4 and repeat continuously

Here is the code:

/* Langster's Test Code for 
 *  Elegoo 8 Channel Relay PCB
 *  07/07/2019
 *  Test circuit output is a Green 5 mm LED 
 *  and a 220 Ohm resistor connected
 *  between common and Normally Closed screw
 *  terminals on the channel 1 relay outputs
 *  
 *  The Elegoo relay module is connected to
 *  an Arduino Uno R3 on the following pins:
 *  
 *  GND connects to GND of the Arduino
 *  IN1 connects to Pin 11 of the Arduino
 *  IN1 connects to Pin 10 of the Arduino
 *  IN2 connects to Pin 9 of the Arduino
 *  IN3 connects to Pin 8 of the Arduino
 *  IN4 connects to Pin 7 of the Arduino
 *  IN5 connects to Pin 6 of the Arduino
 *  IN6 connects to Pin 5 of the Arduino
 *  IN7 connects to Pin 4 of the Arduino
 *  VCC connects to Vin pin of the Arduino
 */

int eightChanRelayIN1 = 11;   //variable for relay channel 1 drive pin
int eightChanRelayIN2 = 10;   //variable for relay channel 2 drive pin
int eightChanRelayIN3 = 9;   //variable for relay channel 3 drive pin
int eightChanRelayIN4 = 8;   //variable for relay channel 4 drive pin
int eightChanRelayIN5 = 7;   //variable for relay channel 5 drive pin
int eightChanRelayIN6 = 6;   //variable for relay channel 6 drive pin
int eightChanRelayIN7 = 5;   //variable for relay channel 7 drive pin
int eightChanRelayIN8 = 4;   //variable for relay channel 8 drive pin

int relayDwellTimeMS = 500; //variable for setting the dwell time a relay is actuated for

void setup() {

Serial.begin(9600);      // open the serial port at 9600 bps:
pinMode(eightChanRelayIN1, OUTPUT); //set the relay drive pin for channel 1 to be an output
pinMode(eightChanRelayIN2, OUTPUT); //set the relay drive pin for channel 2 to be an output
pinMode(eightChanRelayIN3, OUTPUT); //set the relay drive pin for channel 3 to be an output
pinMode(eightChanRelayIN4, OUTPUT); //set the relay drive pin for channel 4 to be an output
pinMode(eightChanRelayIN5, OUTPUT); //set the relay drive pin for channel 5 to be an output
pinMode(eightChanRelayIN6, OUTPUT); //set the relay drive pin for channel 6 to be an output
pinMode(eightChanRelayIN7, OUTPUT); //set the relay drive pin for channel 7 to be an output
pinMode(eightChanRelayIN8, OUTPUT); //set the relay drive pin for channel 8 to be an output

}

void loop() {

digitalWrite(eightChanRelayIN1, LOW);   //switch relay channel 1
delay(relayDwellTimeMS);                //wait for the dwell time (500 ms)
digitalWrite(eightChanRelayIN1, HIGH);  //switch relay channel 1
delay(relayDwellTimeMS);                //wait for the dwell time (500 ms)
 
}

The code is fairly easy to understand.  Each relay channel has been assigned a variable to easily reference it.  A variable to select how long the relay will be open or closed is also added, commonly known as the dwell time.

Next in the setup function the serial terminal is initialised although it isn't actually used for anything (I had plans to add serial messages and then didn't bother).

After that all the relay channel drive pins are set to outputs. 

Finally in the loop function the relay on channel one is driven low which opens it's contacts.  The contacts stay open for half a second and then the contacts are closed - the pin is driven high for half a second and then the function loops back to the start and repeats.

Here is a short video of things in action:


Things to note - The relay drive pins are active low. That means in order to make a relay switch the contact open the drive pin must be driven low.

It would not be difficult to modify the code to drive all of the relays, just modify the code in the loop section:

void loop() {

  digitalWrite(eightChanRelayIN1, LOW);    //switch relay channel 1
  digitalWrite(eightChanRelayIN2, LOW);    //switch relay channel 2
  digitalWrite(eightChanRelayIN3, LOW);    //switch relay channel 3
  digitalWrite(eightChanRelayIN4, LOW);    //switch relay channel 4
  digitalWrite(eightChanRelayIN5, LOW);    //switch relay channel 5
  digitalWrite(eightChanRelayIN6, LOW);    //switch relay channel 6
  digitalWrite(eightChanRelayIN7, LOW);    //switch relay channel 7
  digitalWrite(eightChanRelayIN8, LOW);    //switch relay channel 8
  
  delay(relayDwellTimeMS);                 //wait for the dwell time (500 ms)
  
  digitalWrite(eightChanRelayIN1, HIGH);   //switch relay channel 1
  digitalWrite(eightChanRelayIN2, HIGH);   //switch relay channel 2
  digitalWrite(eightChanRelayIN3, HIGH);   //switch relay channel 3
  digitalWrite(eightChanRelayIN4, HIGH);   //switch relay channel 4
  digitalWrite(eightChanRelayIN5, HIGH);   //switch relay channel 5
  digitalWrite(eightChanRelayIN6, HIGH);   //switch relay channel 6
  digitalWrite(eightChanRelayIN7, HIGH);   //switch relay channel 7
  digitalWrite(eightChanRelayIN8, HIGH);   //switch relay channel 8
  
  delay(relayDwellTimeMS);                //wait for the dwell time (500 ms)
 
}

I haven't got eight LEDS to hand to give a demonstration of this but I have tested the code and the circuit it works perfectly...the clicking of the relays sounds a lot like an old fashioned watch tick or a metronome.

If one were to change value in the dwell time variable the relays will switch more quickly or slowly...the maximum speed they should be switched is 100 ms...any faster will work but might damage the relays and the noise exceptionally irritating! 

The code can also be modified to independently switch each relay with independent dwell times as required. 

That's about it for now, take care - Langster!

Thursday, 4 July 2019

Interactive Confetti Room Project

I was recently asked to help develop the electronics for an event.  The basic idea is that people would enter a room filled with different coloured confetti and air blowers.  These air blowers would be energised for short periods of time in prescribed sequences blowing the confetti about the room in a colourful display.  Hopefully a little bit reminiscent of a final game in a classic British TV program - the Crystal Maze!  If people aren't aware of the cult classic of the crystal maze then a link is below:


The part I'm referring to is this, don't watch all of it! - skip to 2:17 for the important bit:



Hopefully people reading this post will get what I mean.  Anyway...in order to create a similar effect Five air blower units will be sourced and placed inside a 15 mroom.  The fan units will be placed in the corners with one unit in the mid point in effort to ensure there is some form of uniform airflow.  The coloured confetti is placed in front of the fan units and when people enter the room and the door is closed the fans will come on in a prescribed sequence creating an atmospheric effect.  This hasn't been tried and tested yet so some development of the experience may be required...I'll probably leave that part to others as I haven't the time and to be honest I have only been asked to help develop the kit not the experience...I'll help out where I can but getting the desired effect is up to the customer...I'll provide the tools not the results...

The above diagram hopefully gets the general idea across.

The fan blower units have already been selected and are linked below:


Vacmaster Air Mover | High Power, Energy Efficient Turbo Fan/Blower/Dryer
Image Credit - Vacmaster, via Amazon.co.uk
The specifications given via the Amazon product page are:

  • POWERFUL AIR FLOW - The 150 W motor drives 266 litres of ambient air per second for rapid drying and cooling.
  • ENERGY EFFICIENT - Consumes 90% less power than a conventional 1000 W fan heater.
  • 3 TILT POSITIONS - Tilts at 45 degrees, horizontally and vertically for precise, focused air flow.
  • 3 POWER SETTINGS - Low, medium and high speed settings for quiet or fast drying.
  • INTEGRATED EXTENSION SOCKET - For powering additional Air Movers from a single wall socket. Daisy-chain them together to cover a large area.
The vendor doesn't mention the mains supply voltage required but as this is the UK and it's being sourced via amazon UK I'm going to assume the supply is 230 Vac.  The current draw will therefore be 0.65 Amps - as Current (Amps) = Power (Watts) / Volts from Ohms Law:

150 Watts / 230 Vac = 0.6521739130434782608695652173913‬ Amps
or 0.65 Amps to two significant figures...

Lets write some requirements:

  • Switch five fans on and off independently in a pre-arranged sequence
  • Choose specific times of day when fans will come on and off
  • Ensure fans can only actuate when the door to the room is closed.
  • Ensure fans have independent overrides for safety - be able to turn fans on/off via control buttons
  • The switching requirement is 230 Vac at 0.65 Amps for each fan 

There are several ways this could be achieved.  As time is of the essence...as it always seems to be, I'm going to use relays to switch the mains feed to the fans.  The relays will be controlled via a microcontroller which can be communicated with using a serial terminal or via the buttons which will be on the front panel of the control unit.  If necessary I'll add an indication LED and maybe a buzzer to show when the fans are about to begin operation...I suspect the fan noise will make that clear to all concerned though - 😃

I could design my own relay control PCB complete with drive electronics or I could make use of a pre-made module...again time and budget suggests I go with something off the shelf.  I need a five channel relay module capable of switching 230 Vac at 0.65 Amps. I found this module on Amazon.co.uk and it looks to have everything needed...that'll save some time!

Elegoo 8 Channel Relay Module - via Amazon.co.uk

Image Credit - Elegoo 8 channel Relay Module via Amazon.co.uk
There are eight relays are capable of switching 230 Vac at 10 Amps - far more than we need and they meet the switching requirements.  They can be driven from 5 Vdc which means that they can be driven from a five volt tolerant microcontroller output.  The relay drive coils are optically isolated so the microcontroller won't be affected by the relay switching.  There is an LED (light emitting diode) at each relay channel to display when the relay coil is being driven.  The cost was a very reasonable GBP £8.99 or USD $11.31 which I would struggle to compete with if I were to design my own version.

The schematic diagram for the relay module is here in case it is needed:

We will also need the following components:

An arduino uno R3 microcontroller or clone - Via Amazon.co.uk
Some Momentary Buttons  - via Amazon.co.uk
Some jumper wires - via Amazon.co.uk
Some tri-colour LEDS - via Amazon.co.uk
Some LED holders - via Amazon.co.uk
Six mains sockets and wire - via Amazon.co.uk
Some connector block - via Amazon.co.uk
A reed switch and magnet - via Amazon.co.uk
A power supply for the Arduino - via Amazon.co.uk

The current plan (always subject to change) is to connect all the above components as follows:


Please excuse the crudeness of the diagram...I didn't have time to sort everything as much as I would have liked but it gets the general idea across...I've missed off the power supply to the arduino.  It is also connected to the incoming mains and then to the dc input socket on the arduino.  Not all of the relays need to be controlled by the arduino so some of the wires can be omitted as necessary and finally the reed switch should have a 10 k resistor pulling it down to 0 Vdc as with the buttons so that it is properly detected by the microcontroller input.

That's enough for now.  The next post will be on testing and using the Elegoo 8 channel relay module.

Take care, especially with mains wiring - Langster!

Thursday, 20 June 2019

How to Drive a Solenoid from a Microcontroller

I haven't posted anything in a long time...I just haven't been motivated enough to do so.  I suppose it could be because I'm busy but its more likely I've just lacked the energy to do anything.

I recently designed a simple FET driver circuit for energising a solenoid.  It wasn't particularly special in my opinion but I thought it might be useful to share the experience so here goes:

I had to drive a solenoid based circuit for an electronic lock from a microcontroller.  As a solenoid is essentially an inductive load I would need a transistor based circuit to control the supply voltage from a 3.3 Vdc signal generated by an STM32 microcontroller.  In order to actuate the solenoid a short pulse (less than a second) was required from a 12 Vdc or 24 Vdc supply.

A solenoid is an electro-magnetic actuator which creates a concentrated magnetic field.  Here are a couple of links about solenoids and how they work:

https://sciencing.com/a-solenoid-work-4567178.html

https://en.wikipedia.org/wiki/Solenoid

A simple switching circuit is all that is required to energise the solenoid coil and actuate it.  Electronic switching can be performed in many ways - a relay switch in itself is a form of electro-magnetic actuator.  In my case I decided to use a Field Effect Transistor or FET.  I've blogged about field effect transistors in the past:

https://langster1980.blogspot.com/2012/09/using-field-effect-transistors.html

The same principles apply.  Recently I read an excellent blog post by James Lewis - 'The Bald Engineer' on some of the misconceptions about using field effect transistors...I recommend looking at James's website.  He writes some excellent articles and makes some great video content on electronics engineering.

https://www.baldengineer.com/7-mosfet-myths-and-misconceptions-addressed.html#more-7748

As I had to drive the field effect transistor directly from a microcontroller pin at 3.3 Vdc I needed what is known as a logic level FET - That is a device that will allow current to flow between the drain and the source pins when the gate pin is supplied with logic level voltages, logic level voltages are normally classed as 1.8 Vdc, 3.3 Vdc and 5 Vdc.  In the case for the microcontroller I am using - an STM32F439 a logic 1 (high) is 3.3 Vdc.  Therefore I needed a FET which had a VGS on threshold that was at or below 3.3 Vdc.  I chose to use the IRLZ44 as I had some of those components and I also had a spice model for them so I can simulate the circuit.

From some brief measurements of my solenoid I found that it had a series resistance of about 33 ohms and I guessed it's inductance at 3 Henrys....I didn't have my LCR meter to hand to measure it....I might dig that out later to see what the inductance actually is.

Here is the datasheet for the IRLZ44: http://www.irf.com/product-info/datasheets/data/irlz44n.pdf

I'm using the T0220 version for my circuit:

Image result for IRLz44

The critical parameters I was interested in are:

VDSS = 55 Vdc - The maximum voltage allowed on the drain pin with respect to the source pin.

RDS(on) = 0.022 Ω - The resistance of the drain with respect to the source pin when the transistor is on.

ID = 47 Amps - The maximum current allowed to flow from the drain to the source.

VGS On Threshold = 2.0 Vdc - The voltage at which the FET turns OFF - Thanks James, I always wrong about this too!  This means in order to turn the FET on (cause conduction between the drain and source pins we need to surpass this this voltage at the gate pin.  If the voltage at the gate pin drops below this voltage the transistor will stop conducting from the drain pin to the source pin.  The parameter name is a little confusing but hey ho...

So what does this all mean.  It means that I can turn the transistor on using an output pin from a
3.3 Vdc microcontroller and that will allow conduction through the drain pin to the source pin which will allow me to control the voltage supplied to the solenoid.

Here is the circuit:

Simple Solenoid Driver Using a Logic Level FET
Here is the circuit's operation.  A 3.3 Vdc pulse will be supplied from the microcontroller.  This pulse is applied to the gate of the IRLZ44 FET through a 270 Ω resistor (R2).  The resistor R2 is present to prevent a large in-rush current being presented to the gate pin of the FET.  It isn't always necessary if one is only applying long slow voltage pulses to the gate.  I always add a resistor as I like to be certain there will not be any in rush current issues.  The 10 kΩ resistor (R1) is a pull down resistor.  It ensures that the gate pin of the IRLZ44 when not driven from the microcontroller is in a known state - low.  It prevents the FET from spuriously switching on or off.  The drain of the FET is connected to the solenoid (modelled in this case by the 33 Ω resistor and the 3 H inductor.  The schottkey diode (D1) is present to prevent the back-emf generated by the inductive load switching on and off damaging the FET.  D1 is sometimes called a 'free wheel diode' or the 'flyback' diode....More on this later.
 
The voltage source VCC and switch S1 are not really present but a way of simulating what the output from the microcontroller will be. If S1 is closed for a short period the signal presented to the gate pin will be similar to the output pulse from the microcontroller.  This pulse voltage will cause the FET to become active allowing current to flow from the drain to the source which in turn will allow voltage to flow through the solenoid causing it to actuate (create a magnetic field which pulls the pin into the coil).

If we were to simulate the operation of the circuit and observe the input and the output with an oscilloscope connected as shown above this is what would be seen:


The red trace is the the solenoid operation and the blue trace is the input from the microcontroller - modelled in this case by the switch S1 and the 3.3 Vdc voltage supply.

So our circuit simulates will and will work.  The FET operates properly from a 3.3 Vdc supply and can go active within a milli-second.  More than adequate for our purpose!

The only thing left I wanted to discuss was the flyback diode D1...it's needed as when an inductive load has voltage and current applied it converts the electrical energy into magnetic energy creating a concentrated magnetic field.  When an inductive load is has the voltage and current removed the magnetic field collapses and any left over energy is passed back to the drive circuit as a large voltage spike.  This spike is often well over 100 Volts for a short period - more than enough to damage the Field Effect Transistor.  Therefore the flyback diode is applied to prevent this damaging voltage spike passing to the FET.

To illustrate the point here is a circuit with a switch added to the flyback diode.  As the switch is open the diode is not connected.  When the magnetic field collapses this is what is passed back to the FET:


Here is the oscilloscope trace:


If the flyback diode was not present in the circuit the FET would fail fairly quickly...

I'll add some photos of the circuit I built shortly to show it in operation.  It works perfectly for my application.  Take care people - Langster!





Here is a quick video of the circuit on a bread board.  It was driving an electronic lock using 5 Vdc as the gate voltage: