motorized computer desk

Hello all,
I am wondering, Can I use an arduino to control a 12v dc motor that has an external power supply when the computer is turned on the motor activates and when the computer is shutdown the motor retracts? How can this be achieved as I am new to arduino.

Should be possible.

A method that could work is having the arduino powered continuously and have it check a DC-line of the pc's power-supply.

The arduino can be programmed to activate the motor once it detects a voltage, and to retract when it's gone. By adding 2 contact-switches, arduino could check whether the desk/pc is in position to stop the motor.

Being "just" a controller, the Arduino isn't build to handle much current though, you will need a motorshield or the necessary electronics to drive motors.

If you don't want it to be wireless, you can use pyserial. Make a sketch like:

int motor = 3; //Define here the pin in which the motor will be

void setup(){
    Serial.begin(9600); //Start the serial communication
    pinMode(motor, OUTPUT); 
}

void loop(){
    if(serial.read() == "m"){             //When the "m" character is received on the Serial communication, the motor will turn on
        digitalWrite(motor, HIGH);
    }
}

And then make a script in python like that:

import serial
import time

arduino = serial.Serial('COM3', 9600) #Change COM3 for your Serial port
time.sleep(2) # waiting the initialization...

arduino.write('m') # turns motor ON if doesn't work try with arduino.write(b'm')

Save as arduino.py and make it execute with the start of windows. When you turn off your PC, the motor will shut down because the arduino will.

Also, I'm a beginner too, I don't certanly know if this will work with motors, but with a LED it will sure do. This is only orientative.

PS: DON'T FORGET TO INSTALL PYSERIAL LIBRARY FOR PYTHON! :slight_smile:

You mean, to determine whether the PC is on ?

To detect a voltage, ground of the arduino and ground of the PC (black wire) needs to be connected first. Standard an arduino can't measure a negative voltage, but it can detect/read up to +5v (red) on an IO-pin.