Solid State Relay for microcontroller

For a specific project with the Arduino – that I will publish later– I needed to switch a few 230 Volt appliances. This always makes me having to decide between a relay, a triac with optocoupler, or a ready made Solid state relay.
SSR’s can be had for fairly little money with the 39MF22 only at 1.80 euro. For that money I am not buying mechanical relays and don’t mess with triacs.

The circuit is quite simple:
ssr

R1 is there to limit the current through the LED and the 39MF22. The LED shows when the switch is active. The 39MF22 comes in a DIL-8 but misses pin 7. The switch is between pin 6 and 8. Pins 1, 3 and 4 are the ground connectors and need to be connected. It is advisable to connect them on a PCB to a little mass of copper so that can act as cooling. There is no snubber circuit as I prefer to have that closer to the load. One could however use a 100nF capacitor in series with a 100 ohm resistor.

As I needed 4 switches, I just built the circuit 4 times on a PCB. Initially I had considered mounting the circuit and the Atmega328 on one PCB, but I opted for a separate PCB out of safety concerns as it is switching 230 Volts.

The PCB is quite simple. (The lay-out for heat transfer can be found here.):
Solid State Relay with 39MF22 PCB

ssr5

After finishing, I inserted the entire PCB in a plastic peppermint dispenser.

Solid State Relay with 39MF22

39MF22
The 39MF22 can handle 900mA and has an isolation voltage of 4kV. The datasheet can be found here.
39mf22

sharp_PR39MF22YSZF

 

Advertisements

Programming Hex-code on an Attiny85 with the Arduino

To get a HEX-code in your Attiny85 it is possible to use the Arduino as a programmer, but as you cannot load hexcode  in your IDE, it involves using avrdude.

First of all, we need to get the Attiny85 clocked to 8Mhz.

Open up your Arduino software and upload the ArduinoISP sketch to your board.

Disconnect the board from  your computer and attach the Attiny as shown  here. Also make sure you download and install the Attiny core files as described in that article

Connect your Arduino board in again and choose these settings.

Tools – Board – Attiny85 @ 8Mhz (internal oscillator; BOD disabled)
Tools – Programmer – Arduino as ISP
Tools – Serial Port – COMx (x being the com port that your arduino is connected to)

Then select

Tools – Burn Bootloader.

Just to clarify, you are not burning a bootloader here. You are resetting the fuses in the Attiny to clock it at 8Mhz.

Next, get the firmware into the chip. With that I mean the hex file you want in your chip

We do that by using the arduino as a programmer.  You should still still have the ArduinoISP sketch loaded on your Arduino.

Make sure your Attiny is still attached to your Arduino as described here and open a command prompt.  (In your windows start menu type cmd or chose the terminal in Linux/Ubuntu).

Type:

avrdude

This will bring up a list of options explaining what everything does.
Screenshot from 2013-12-11 14:09:55

Only need a few of those commands.

This is what to type in cmd (on 1 line)

avrdude -c avrisp -p t85 -P comX -b 9600 –U flash:w:example_attiny85.hex:i

What does all that mean?

Avrdude… This calls the program-c avrisp…  This tells avrdude which programmer you are using.  The Arduino shows up as avrisp

-p t85… This is the avrdude code for Attiny85.

-P comX… This is the com port your programmer is attached to.  (Change the X to suit your programmer.)

-b 9600… This is the baud rate (Use what is specified in the sketch loaded onto your Arduino.) .

-U flash:w:example_attiny85.hex:i   This tells avrdude you want to write (w) the firmware (example_attiny85.hex) to flash memory (flash).  The ‘i’ is at the end to tell avrdude what format it is writing in.

Avrdude should now read your chip, write to your chip, then read your chip.

If all goes well, you should get:    avrdude done.

Also check here:  Programming an Attiny with an Arduino Nano.