5V AC/DC Converter Switch Power Supply Module 3W 700mA Industrial Voltage Regulators

Following on from playing with the Hi-link HLK-PM01 I got this generic even cheaper board from Ben Dooks, after carefully wiring it up, I shoved it on the Kikusui TOS 8650 Withstand Voltage Tester: This shows the cheap chinese powersupply breaking just below 2 kVac. The following photos are from a Chinese seller via the Aliexpress link: Looking […]

Arduino Sidereal Clock

A work colleague has asked me to make him a Sidereal Clock.  I had never heard of a Sidereal Clock before but was certain I could do it so I agreed and started to think about how it could be done.  The most important thing for me would be accuracy…more on this later.

Wikipedia Entry on Sidereal time

The definition of Sidereal time is:

The sidereal time is measured by the rotation of the Earth, with respect to the stars (rather than relative to the Sun). Local sidereal time is the right ascension (RA, an equatorial coordinate) of a star on the observers meridian. One sidereal day corresponds to the time taken for the Earth to rotate once with respect to the stars and lasts approximately 23 hours and 56 minutes.

Basically Sidereal time is used by astronomers to be able to tell when an object of interest will be visible in the sky.
There is a formula (In fact there are quite a few) for calculating the Sidereal time based upon the current time and date….It’s quite complicated but here goes:
First Step – Calculate the Julian Date

Wikipedia Entry on the Julian date

The Julian Day Number (JDN) is the integer assigned to a whole solar day in the Julian day count starting from noon Greenwich Mean Time, with Julian day number 0 assigned to the day starting at noon on January 1, 4713 BC, proleptic Julian calendar (November 24, 4714 BC, in the proleptic Gregorian calendar), a date at which three multi-year cycles started and which preceded any historical dates. For example, the Julian day number for the day starting at 12:00 UT on January 1, 2000, was 2,451,545.

I was going to go through a calculation to check I have this understood and correct….I have tried several methods and found that with excel I can calculate the Julian Date Number and the Julian Date.  The spreadsheet I used to calculate this is here…

Alex’s Excel Julian Date Calculator

It shows that several different methods of calculating the Julian Date exist and that they have varying degrees of accuracy when compared with online calculators.  This is of course under the assumption that I have implemented the formula from wikipedia correctly in excel…which I’m fairly certain I haven’t as I don’t know how to implement the floor function required.

There are several online calculators for the Julian Date which work perfectly.  I may have copied the function from the javascript and tested that and found it works perfectly….

US Navy Online Julian Date Calculator

Once you have the correct Julian Date it is possible to calculate Greenwich Mean Sidereal time…

Calculating Greenwich Sidereal Time is discussed here:

Calculating Greenwich Mean Sidereal Time

Useful Formulae

In order to do this we need to know what the current date and time is…so that means we need a method of getting the time and storing it.  We also need to have the latitude and longitude of where the clock is…and to get that we need a GPS receiver module.

Lets define the electronic components needed to make a sidereal clock:
  • 1x Arduino R3 or compatible development board.
  • 1x GPS Receiver Module.
  • 1x RTC Module.
  • 1x LCD Display module – A 20×4 would be good.
  • 1x Lipo Battery, charger and boost module.
The idea is that the GPS receiver module will receive the location (latitude, longitude) and UTC time. This is probably the most accurate time we can get.  This value of time is passed to the RTC module so that if the GPS Link is lost the correct time is still available.  The arduino then passes this information to the 20×4 display which will show:
  • The UTC time on the first line (the current time in the UK not accounting for day light savings)
  • The Local Sidereal time on the second line.
  • The local latitude on the third line.
  • The local longitude on the forth line.
The lipo battery will keep the clock running just in case there is a power cut or the clock needs to be moved but for normal use the clock will be powered by a mains to USB converter.  To save power the backlight to the display will fade out after ten minutes unless the user presses a button.
I’ve ordered all of the parts we need from http://hobbycomponents.com/
Lipo Battery Charger and boost module – Protopic – £12.60
We are also going to need a case to hold the clock once it’s finished.  I’ve not designed it yet but I’m looking at a well finished laser cut case which looks something like this:
Well…that’s about it for now.  Next post will deal with calculating Sidereal time using the Arduino using the RTC module.

Voltage Measurements Using the Arduino

I often need to make voltage measurements using my arduino.  I recently built a voltage, current and temperature data logger for testing lithium batteries and I needed to be able to measure 50 Vdc safely into the Arduino although any ADC input from a microcontroller could be substituted.

Rather than reinvent the wheel I decided (possibly foolishly) to use a voltage measurement breakout board:

I bought mine from Hobby Components but they can be obtained everywhere:

To be fair I didn’t really look into the module properly as I was in a rush.  The circuit itself is a simple 5:1 voltage divider and a screw terminal and some header pins.  For the price of £1.99 I shouldn’t complain.  The circuit is below for those that are interested.

Not sure why they added the Banana connector footprint…but hey ho, Or why they used a 3 pin connector on the output…as one of the pins does nothing at all…

The circuit is a 5:1 voltage divider.  So a person using this circuit can measure voltage signals ranging from 0 volts to 25 volts.  If you were to change the resistor values you can then change the voltage measurement range.

Here is some simple code to get this to work with an arduino with the measurement output connected to A0 on the arduino:

/*
DC Voltmeter Using a Voltage Divider
*/

int analogInput = A0;  // Read the voltage from the divider on A0 
float vout = 0.0;      // variable for the calculated voltage 
float vin = 0.0;       // variable for the resulting voltage
float R1 = 30000.0;    // variable to store the value of R1  
float R2 = 7500.0;     // variable to store the value of R2
int raw = 0;           // variable to store the raw ADC measurement

void setup(){
   pinMode(analogInput, INPUT);  // set pin A0 to be an input
   
   Serial.begin(9600);           // start the serial monitor
   Serial.print(“DC VOLTMETER”); // display a welcome message
}
void loop(){
   
   // read the value at analog input A0
   // calculate the voltage from the raw adc value
   // account for the voltage divider
   // Display the result

   raw = analogRead(analogInput);
   vout = (value * 5.0) / 1023.0; 
   vin = vout / (R2/(R1+R2)); 
   
   Serial.print(“INPUT V= “);
   Serial.println(vin,2);
   delay(500);
}

I tested the above code and it works perfectly well and this board can be used to make voltage measurements.  My concerns with it are that it has no protection against a person trying to measure too much voltage or a signal too high in current.  With the above breakout board an over voltage or over current event will damage the ADC input of the arduino or microcontroller being used.  The maximum current an Atmel 328p pin can accept according to the datasheet is 20 mA.  

If we apply more than 25 Volts to input of the voltage divider the instantaneous current presented to the A0 input pin could be more than 20 mA and if the voltage is really high it will give us an incorrect reading.  It would be better if we protected the ADC input from over-voltage and current events and then ensure our circuit and our micro-controller ADC inputs work perfectly in any condition, fault or normal.

To protect against over current events we need to add a series resistor.  I’m choosing to add a 22 ohm resistor in series.  This prevents the current being presented to the ADC input ever becoming greater than 20 mA even if 2500 volts are applied (by mistake) to the voltage divider input.

Next we are going to add a low value capacitor (100 pF).  This takes some of energy out a high voltage transient (pulse) like an electrostatic discharge and also provide a small amount of filtering to the circuit.

Finally lets ensure that the voltage applied to the ADC input of the microcontroller is always about 5 volts.  This is achieved by adding some clamping diodes.  These are simple signal diodes – 1N4148 diodes will do…Here is the final circuit.

Just to prove the function of the circuit and what achieves for us lets simulate the different error conditions to show what happens.  I’m going to show pictures rather than a full video.

Lets set some parameters.  Lets assume by mistake someone tries to measure a voltage and by mistake they apply 2500 Vdc…This is what gets applied to the ADC input of the arduino.  It might not destroy it but it would certainly damage the microcontroller…

Lets add the current limiting 22 Ohm series resistor, which doesn’t affect the measurement but reduces the current presented to the load (the ADC input pin).

Lets now add the capacitor to the circuit.

Finally lets add the clamping diodes…which incidentally have the most effect!

What the simulation clearly shows is that if by mistake 2500 volts was applied to the voltage divider with the clamp diodes, series resistor and capacitor only 6.37 volts and 637 nA will be applied to the ADC input.  The voltage divider will still work as intended though and nothing will be damaged on the microcontroller – good things all round.

The point I’m getting at is that if a voltage divider circuit is used to measure voltages on an arduino or any other microcontroller then without the above components to provide protection bad things may happen.  This is why the 25 Volt measurement breakout boards are not the best circuit.  It would not cost much more to apply the protection components.

Well that’s all for now people – Enjoy and hope this post was helpful.  I might make a few voltage sensor breakout boards for sale if demand is high enough – I know I’ll need some from time to time.

Cheers – Langster!

Voltage Measurements Using the Arduino

I often need to make voltage measurements using my arduino.  I recently built a voltage, current and temperature data logger for testing lithium batteries and I needed to be able to measure 50 Vdc safely into the Arduino although any ADC input from a microcontroller could be substituted.

Rather than reinvent the wheel I decided (possibly foolishly) to use a voltage measurement breakout board:

I bought mine from Hobby Components but they can be obtained everywhere:

To be fair I didn’t really look into the module properly as I was in a rush.  The circuit itself is a simple 5:1 voltage divider and a screw terminal and some header pins.  For the price of £1.99 I shouldn’t complain.  The circuit is below for those that are interested.

Not sure why they added the Banana connector footprint…but hey ho, Or why they used a 3 pin connector on the output…as one of the pins does nothing at all…

The circuit is a 5:1 voltage divider.  So a person using this circuit can measure voltage signals ranging from 0 volts to 25 volts.  If you were to change the resistor values you can then change the voltage measurement range.

Here is some simple code to get this to work with an arduino with the measurement output connected to A0 on the arduino:

/*
DC Voltmeter Using a Voltage Divider
*/

int analogInput = A0;  // Read the voltage from the divider on A0 
float vout = 0.0;      // variable for the calculated voltage 
float vin = 0.0;       // variable for the resulting voltage
float R1 = 30000.0;    // variable to store the value of R1  
float R2 = 7500.0;     // variable to store the value of R2
int raw = 0;           // variable to store the raw ADC measurement

void setup(){
   pinMode(analogInput, INPUT);  // set pin A0 to be an input
   
   Serial.begin(9600);           // start the serial monitor
   Serial.print(“DC VOLTMETER”); // display a welcome message
}
void loop(){
   
   // read the value at analog input A0
   // calculate the voltage from the raw adc value
   // account for the voltage divider
   // Display the result

   raw = analogRead(analogInput);
   vout = (value * 5.0) / 1023.0; 
   vin = vout / (R2/(R1+R2)); 
   
   Serial.print(“INPUT V= “);
   Serial.println(vin,2);
   delay(500);
}

I tested the above code and it works perfectly well and this board can be used to make voltage measurements.  My concerns with it are that it has no protection against a person trying to measure too much voltage or a signal to high in current.  With the above breakout board an over voltage or over current event will damage the ADC input of the arduino.  The maximum current an Atmel 328p pin can accept according to the datasheet is 20 mA.  

If we apply more than 25 Volts to input of the voltage divider the instantaneous current presented to the A0 input pin could be more than 20 mA and if the voltage is really high it will give us an incorrect reading.  It would be better if we protected the ADC input from over-voltage and current events and then ensure our circuit and our micro-controller ADC inputs work perfectly in any condition, fault or normal.

To protect against over current events we need to add a series resistor.  I’m choosing to add a 22 ohm resistor in series.  This prevents the current being presented to the ADC input every becoming greater than 20 mA even if 2500 volts are applied (by mistake) to the voltage divider input.

Next we are going to add a low value capacitor (100 pF).  This takes some of energy out a high voltage transient (pulse) like an electrostatic discharge and also provide a small amount of filtering to the circuit.

Finally lets ensure that the voltage applied to the ADC input of the microcontroller is always about 5 volts.  This is achieved by adding some clamping diodes.  These are simple signal diodes – 1N4148 diodes will do…Here is the final circuit.

Just to prove the function of the circuit and what achieves for us lets simulate the different error conditions to show what happens.  I’m going to show pictures rather than a full video.

Lets set some parameters.  Lets assume by mistake someone tries to measure a voltage and by mistake they apply 2500 Vdc…This is what gets applied to the ADC input of the arduino.  It might not destroy it but it would certainly damage the microcontroller…

Lets add the current limiting 22 Ohm series resistor, which doesn’t affect the measurement but reduces the current presented to the load (the ADC input pin).

Lets now add the capacitor to the circuit.

Finally lets add the clamping diodes…which incidentally have the most effect!

What the simulation clearly shows is that if by mistake 2500 volts was applied to the voltage divider with the clamp diodes, series resistor and capacitor only 6.37 volts and 637 nA will be applied to the ADC input.  The voltage divider will still work as intended though and nothing will be damaged on the microcontroller – good things all round.

The point I’m getting at is that if a voltage divider circuit is used to measure voltages on an arduino or any other microcontroller then without the above components to provide protection bad things may happen.  This is why the 25 Volt measurement breakout boards are not the best circuit.  It would not cost much more to apply the protection components.

Well that’s all for now people – Enjoy and hope this post was helpful.  I might make a few voltage sensor breakout boards for sale if demand is high enough – I know I’ll need some from time to time.

Cheers – Langster!

Voltage Measurements Using the Arduino

I often need to make voltage measurements using my arduino.  I recently built a voltage, current and temperature data logger for testing lithium batteries and I needed to be able to measure 50 Vdc safely into the Arduino although any ADC input from a microcontroller could be substituted.

Rather than reinvent the wheel I decided (possibly foolishly) to use a voltage measurement breakout board:

I bought mine from Hobby Components but they can be obtained everywhere:

To be fair I didn’t really look into the module properly as I was in a rush.  The circuit itself is a simple 5:1 voltage divider and a screw terminal and some header pins.  For the price of £1.99 I shouldn’t complain.  The circuit is below for those that are interested.

Not sure why they added the Banana connector footprint…but hey ho, Or why they used a 3 pin connector on the output…as one of the pins does nothing at all…

The circuit is a 5:1 voltage divider.  So a person using this circuit can measure voltage signals ranging from 0 volts to 25 volts.  If you were to change the resistor values you can then change the voltage measurement range.

Here is some simple code to get this to work with an arduino with the measurement output connected to A0 on the arduino:

/*
DC Voltmeter Using a Voltage Divider
*/

int analogInput = A0;  // Read the voltage from the divider on A0 
float vout = 0.0;      // variable for the calculated voltage 
float vin = 0.0;       // variable for the resulting voltage
float R1 = 30000.0;    // variable to store the value of R1  
float R2 = 7500.0;     // variable to store the value of R2
int raw = 0;           // variable to store the raw ADC measurement

void setup(){
   pinMode(analogInput, INPUT);  // set pin A0 to be an input
   
   Serial.begin(9600);           // start the serial monitor
   Serial.print(“DC VOLTMETER”); // display a welcome message
}
void loop(){
   
   // read the value at analog input A0
   // calculate the voltage from the raw adc value
   // account for the voltage divider
   // Display the result

   raw = analogRead(analogInput);
   vout = (value * 5.0) / 1023.0; 
   vin = vout / (R2/(R1+R2)); 
   
   Serial.print(“INPUT V= “);
   Serial.println(vin,2);
   delay(500);
}

I tested the above code and it works perfectly well and this board can be used to make voltage measurements.  My concerns with it are that it has no protection against a person trying to measure too much voltage or a signal to high in current.  With the above breakout board an over voltage or over current event will damage the ADC input of the arduino.  The maximum current an Atmel 328p pin can accept according to the datasheet is 20 mA.  

If we apply more than 25 Volts to input of the voltage divider the instantaneous current presented to the A0 input pin could be more than 20 mA and if the voltage is really high it will give us an incorrect reading.  It would be better if we protected the ADC input from over-voltage and current events and then ensure our circuit and our micro-controller ADC inputs work perfectly in any condition, fault or normal.

To protect against over current events we need to add a series resistor.  I’m choosing to add a 22 ohm resistor in series.  This prevents the current being presented to the ADC input every becoming greater than 20 mA even if 2500 volts are applied (by mistake) to the voltage divider input.

Next we are going to add a low value capacitor (100 pF).  This takes some of energy out a high voltage transient (pulse) like an electrostatic discharge and also provide a small amount of filtering to the circuit.

Finally lets ensure that the voltage applied to the ADC input of the microcontroller is always about 5 volts.  This is achieved by adding some clamping diodes.  These are simple signal diodes – 1N4148 diodes will do…Here is the final circuit.

Just to prove the function of the circuit and what achieves for us lets simulate the different error conditions to show what happens.  I’m going to show pictures rather than a full video.

Lets set some parameters.  Lets assume by mistake someone tries to measure a voltage and by mistake they apply 2500 Vdc…This is what gets applied to the ADC input of the arduino.  It might not destroy it but it would certainly damage the microcontroller…

Lets add the current limiting 22 Ohm series resistor, which doesn’t affect the measurement but reduces the current presented to the load (the ADC input pin).

Lets now add the capacitor to the circuit.

Finally lets add the clamping diodes…which incidentally have the most effect!

What the simulation clearly shows is that if by mistake 2500 volts was applied to the voltage divider with the clamp diodes, series resistor and capacitor only 6.37 volts and 637 nA will be applied to the ADC input.  The voltage divider will still work as intended though and nothing will be damaged on the microcontroller – good things all round.

The point I’m getting at is that if a voltage divider circuit is used to measure voltages on an arduino or any other microcontroller then without the above components to provide protection bad things may happen.  This is why the 25 Volt measurement breakout boards are not the best circuit.  It would not cost much more to apply the protection components.

Well that’s all for now people – Enjoy and hope this post was helpful.  I might make a few voltage sensor breakout boards for sale if demand is high enough – I know I’ll need some from time to time.

Cheers – Langster!

Pressure Sensor Breakout Board – MPS20N0040D-D

I was checking the statistics of how many people read my blog and which pages are the most popular. I am always surprised and often humbled by how many people read my stuff – please keep reading and commenting and let me know if there is something specific I need to cover.  Anyway I noticed that one of my most popular posts concerned the usage of a cheap pressure sensor – the MPS20N0040D-D.  A lot of readers have commented and contacted me on getting this sensor up and running – I’m not surprised, its hard to do!

To try to make things more simple I’ve decided to design a small breakout board which should make things easier – If people are interested I will get a load manufactured, built and tested and that way all that’s needed is to connect the breakout board up to the microcontroller or ADC of choice and get on with using the sensor.

The original pressure sensor post

So referencing the previous post the sensor is essentially a 5 kOhm Wheatstone bridge sensor which measures pressure.  In order to get it to work a difference amplifier with some gain is required. To get the sensor to work well in any given situation I’m going to add some filtering to ensure that the sensor works properly as much as possible even if there is electrical noise present – it’s always a good idea to do that.

Here is the breakout board circuit:

I’ve already discussed the circuit function in the other post about the pressure sensor so I’m not going to go into great detail.

The left part of the schematic is the pressure sensor itself which is connected to a filter stage.  The filter stage contains ferrite beads which are special soft iron components designed to remove high frequency electronic noise.  The rest of the filter circuit is made up of standard RC filters to remove any other unwanted noise.

Wikipedia entry on Ferrite beads

The next part of the circuit is the difference amplifier made up on a ‘Jelly bean’ Op-Amp the LMV385 and some resistors.  The circuit amplifies the difference measured between pins 2 and 3 and passes the output to another gain stage which amplifies it further.  The output is then passed to a 3 pin connector which will be used to connect the breakout board to a breadboard before connecting this on to a microcontroller or ADC.

LMV358 datasheet.pdf

The important part of this design is going to be the PCB layout.  We need to ensure that the circuit is constructed and designed as robustly and efficiently as possible.  Because it is a breakout board it needs to be of a small form factor but we also want the circuit to be noise immune and still function as intended.  This isn’t always easy – lets set some parameters and see if they are achievable:

  • PCB dimensions – less than 25 x 25 mm
  • Use a complete ground plane on one layer
  • Ensure the external connections are accessible
  • Minimize track length as much as possible
  • Utilize surface mount components (0805)
The layout took me about an hour and a half!  I don’t think it came out too badly.  There was a great deal of moving components and tracks about.  It was completely routed by hand – I don’t agree with using an auto-router.  The results are always poor (in my opinion).

Top Layer of Pressure Sensor Breakout
Bottom Layer of Pressure Sensor Breakout
The combined layers with dimensions

I managed to get it all into a tight space – less than 22 mm is fair I feel.  The electronics is all on the top side and the pressure sensor is on the bottom side.  When in use the top side will be facing downwards but that is no hardship. I used a design rule checking file from a board manufacturing house to check that the design is viable and they can make it – It passed with no errors!  I must be getting better at this…

Just for fun and because I have found it lets me know if mechanically the design won’t work – here is the PCB rendered in 3D.

The rendered PCB top layer

The rendered PCB viewed isometrically

For those that are interested here is the parts list for this breakout board:

It’s a bit annoying that the minimum order quantity for surface mount resistors are sometimes in the hundreds…I never seem to need that many – hey ho.  The cost of 10 uF 0805 capacitors is extortion in my opinion!  The total component cost is £3.15 to populate a single PCB.  The problem is because of the minimum order quantity (MOQ) it would cost £7.28 to obtain all of the components and there will be some left over (moan…grumble…whinge)

No matter – Lets get some quotes for the cost of constructing the PCB.  I use Elecrow in China to make my PCBS but there are plenty of places you can get this service.

http://www.elecrow.com/

The quoted cost for manufacture from Elecrow was £9.70 for ten PCBS so that brings the cost for one complete breakout board to £4.12 – this doesn’t take into account design or manufacture or testing…If we were to include all of that it pushes the price up considerably.

– UPDATE – 25-09-2015

The boards arrived from Elecrow in record time and I’ve built one up.  Guess what…there were some mistakes.  The land pattern for the sensor I used was incorrect – I had to bend the pins a little to get it to fit.  I also made a mistake with the OP-amp configuration.  Pins 5 and 6 need to be reversed in order for the circuit to work as intended.  I now have 8 PCBS which will need to be modified in order to get them to work.  No matter – I’ll update the design to ensure the correct connections and footprints are used.  I also want to increase the footprint for the 0805 parts as it was difficult to hand solder the boards.  The silk screen was absolutely useless!  I must have set the font size too low.  It didn’t take too long to populate the board so I’m pleased overall (read massively proud of myself!)

Here are some pictures of the completed board:

The underside of the board with the Sensor
The topside of the board with the components…and mistakes – hey ho!

I have setup an online store here selling this breakout board and some of my other designs –

Lang Electronics Design – Online Store

I will probably do a post using the breakout board soon as I can now make more use of the sensors.

That’s all for now, take care – Langster