Arduino Digital Power Switch is a “silent” digital electric
switch circuit built around the exemplary µC Arduino (UNO) and a
homemade solid-state relay (SSR). The finished system, which operates in
low voltage dc catered by the usb port, can be used to toggle (switch
on/off) a mains powered device through your desktop/laptop computer.
Hardware Setup
Only a few commonly available elecronic components are required as additional hardware for this little project/experiment. First of all, just follow the schematic to build your own solid-state relay switch, and then connect its input terminals (J1) to digital pin 13 (D12) and ground (GND) of the Arduino microcontroller as indicated. Output terminals (J2) of the circuit work like an electric switch. Since output section carries dangerously high ac mains voltages, take adequate precautions to avoid fatal electric shock. Use of a good-quality plastic/rubber enclosure looks good in this respect.
Now you can connect the Arduino to your computer. Next, copy-paste the given code, compile it, and upload to the microcontroller through the arduino IDE (as usual). The code is as simple as it gets, it reads from serial and if receives “1” the drive pin (D12) goes high and if “2” the pin goes low. You can test your project from the Arduino Environment by simply opening the Serial Monitor (under Tools) and sending pre-defined on/off commands from the computer keyboard (1 = load ON / 2 = load OFF)!
Arduino Sketch
The prototype was tested with a candent lamp as the output load. At that time, unwanted rapid flicker effects were observed when I connect/disconnect my hardware. Google told me that (!) the real culprit is the “autoreset” feature in the Arduino Uno platform.
Auto Reset: Arduino Uno is designed in a way that allows it to be reset by software running on a connected computer. One of the hardware flow control lines (DTR) of the ATmega8U2 is connected to the reset line of the ATmega328 via a 100nF capacitor. When this line is taken low, the reset line drops long enough to reset the chip. The Arduino software uses this capability to allow you to upload code by simply pressing the upload button in the Arduino environment. However this setup has other entailments, for example, when Uno is connected to a computer, it resets each time a connection is made to it from software (via usb), and it will intercept the first few bytes of data sent to the board after a connection is opened. Fortunately, Uno contains a trace (RESET-EN) that can be cut to disable the autoreset. The pads on either side of the trace can be soldered together to re-enable it.
Another “soft” way to keep off the autoreset issue is using alternative (third party) serial monitors like the HTERM (www.der-hammer.info/terminal/). Or try the Chrome Browser Serial Port Monitor (chrome.google.com/serialmonitor/)!
Hardware Setup
Only a few commonly available elecronic components are required as additional hardware for this little project/experiment. First of all, just follow the schematic to build your own solid-state relay switch, and then connect its input terminals (J1) to digital pin 13 (D12) and ground (GND) of the Arduino microcontroller as indicated. Output terminals (J2) of the circuit work like an electric switch. Since output section carries dangerously high ac mains voltages, take adequate precautions to avoid fatal electric shock. Use of a good-quality plastic/rubber enclosure looks good in this respect.
Now you can connect the Arduino to your computer. Next, copy-paste the given code, compile it, and upload to the microcontroller through the arduino IDE (as usual). The code is as simple as it gets, it reads from serial and if receives “1” the drive pin (D12) goes high and if “2” the pin goes low. You can test your project from the Arduino Environment by simply opening the Serial Monitor (under Tools) and sending pre-defined on/off commands from the computer keyboard (1 = load ON / 2 = load OFF)!
Arduino Sketch
ASCII: Understanding data types is especially important if you wish to build wireless projects like bluetooth that use serial communication to send data to your microcontroller and have the microcontroller act on this data. Note that characters typed into the serial terminal are interpreted as ASCII (American Standard Code for Information Interchange) characters and encoded with the decimal number corresponding to the character on the ASCII table. To give you an example, if you were to send “Chr 1” via serial, the numerical value would be “Dec 49”. Here in the sketch, when you enter “1” in the serial terminal, you will notice that the number 49 is returned to the terminal and output to the screen because the Serial.print() function by default prints the decimal value of the byte.
- int drivePin = 12; // relay drive output
- int incomingByte;
- void setup() {
- Serial.begin(9600); // start serial communication
- pinMode(drivePin, OUTPUT);
- }
- void loop() {
- if (Serial.available() > 0) {
- incomingByte = Serial.read();
- Serial.println(incomingByte);
- }
- if (incomingByte == 50) {
- digitalWrite(drivePin, LOW); // 50 is the ASCII value of 2 – see notes
- }
- else if (incomingByte == 49) {
- digitalWrite(drivePin, HIGH); // 49 is the ASCII value of 1 – see notes
- }
- }
The prototype was tested with a candent lamp as the output load. At that time, unwanted rapid flicker effects were observed when I connect/disconnect my hardware. Google told me that (!) the real culprit is the “autoreset” feature in the Arduino Uno platform.
Auto Reset: Arduino Uno is designed in a way that allows it to be reset by software running on a connected computer. One of the hardware flow control lines (DTR) of the ATmega8U2 is connected to the reset line of the ATmega328 via a 100nF capacitor. When this line is taken low, the reset line drops long enough to reset the chip. The Arduino software uses this capability to allow you to upload code by simply pressing the upload button in the Arduino environment. However this setup has other entailments, for example, when Uno is connected to a computer, it resets each time a connection is made to it from software (via usb), and it will intercept the first few bytes of data sent to the board after a connection is opened. Fortunately, Uno contains a trace (RESET-EN) that can be cut to disable the autoreset. The pads on either side of the trace can be soldered together to re-enable it.
Another “soft” way to keep off the autoreset issue is using alternative (third party) serial monitors like the HTERM (www.der-hammer.info/terminal/). Or try the Chrome Browser Serial Port Monitor (chrome.google.com/serialmonitor/)!
No comments:
Post a Comment