Maker Pro
Maker Pro

Serial port light bulb excel

Just to start I'm extremely new at this stuff but I'll try to explain it to the best of my ability. I am looking at a way to in excel type in a specific number(correct number) and thru serial port it will turn the bulb on for a specific duration. But if I type in the incorrect number nothing will happen. If someone could tell me how to do the programming and hardware needed that would be great. Please let me know if I'm not phrasing it right please let me know.
 

Harald Kapp

Moderator
Moderator
I assume you are familiar with coding in VBA because that's what you will need to do.
You will also need the hardware on the receiving end of the serial port to receive a control code from Excel and turn a lamp on or off. An Arduino could be used for example.

I'll move thtis thread to the appropriate forum as it is not related to sensors and actors.
 
Last edited:
Open up the VB Editor (Alt+F11 in Windows or Tools->Macros->Visual Basic Editor on Mac)

Double-click on the Sheet1 object and paste the following code:

Option Explicit

Public Sub Worksheet_Change(ByVal target As Range)
Debug.Print "Something changed in cell " & target.Address(0, 0)

Assign this to your message to send out to comport in within this


End Sub

This is a very basic example of how to start using the Worksheet_Change event. This method is what’s called an Event Handler, which simply means that “this is the method I want to use for handling when X event happens.”

Whenever a cell changes as we described above, Excel will execute the Worksheet_Change event and pass in the cells that were changed through the target object. We use this target object to take a look at which cells were affected.

To invoke this event, go to the Sheet1 worksheet and make a change to a cell. Then, in the VBE Immediate Window (Ctrl+G on Windows or in Mac this window should always be visible) you will see some text appear each time the event is fired.

For using comports I suggest reading these two links You would need to attach peripheral hardware that is capable of driving your lamp via an Arduino via serial port connection or FTDI device and relative code for decoding your serial port bytes sent

Here are tow such links for you to read up on using api calls

http://www.vbaexpress.com/forum/showthread.php?60184-Using-COM-port-with-Excel-VBA
http://www.thescarms.com/vbasic/commio.aspx

Hope this assist you and best of luck with what you are doing
 
Top