Table of Contents (top down ↓)
- You will need a 470 ohm resistor, an LED of any color and an FTDI USB to serial module. We have tested the program on Windows 10 - no drivers were required. Please refer the appended video for all the details.
- Compile the program using visual studio - any version will be OK.
- Assemble the circuit on a bread-board or on a PCB and plug it ON.
- The COM port number can be obtained from the device manager.
- Run the program!
The source code
This is the program with all necessary comments -
#include <iostream> #include <windows.h> using namespace std; // COMPILE WITH A WINDOWS COMPILER // SUCH AS VISUAL STUDIO C++ 2005 // OR LATER. PROGRAM TESTED ON // WINDOWS 10, 8 and 7 #define ON SETDTR #define OFF CLRDTR int main() { // see the video below on how to // get the port number from // device manager printf("COM Port number[1-9]: "); // path format \.\COM1 char path[] = "\\.\\COMx"; cin >> path[6]; HANDLE hComm = CreateFileA( path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, NULL, 0); if (hComm == INVALID_HANDLE_VALUE) { printf("Error. Check COM Port?"); return -1; } // user input key char key = 0; // state of the LED int state = OFF; do { // toggle the state of the LED state = (ON == state) ? OFF : ON; // turn the DTR high/low EscapeCommFunction(hComm, state); // ask the user to enter // any key to toggle state // q to quit cout << "Enter any key to"; cout << " toggle LED [q to quit]:"; cin >> key; cout << "LED turned "; cout << (ON == state ? "ON":"OFF"); cout << endl; } while ('q' != key); // close the COM handle CloseHandle(hComm); return 0; }
Circuit diagram and Discussion
Please refer the video below for discussion and circuit diagram -
This Blog Post/Article "C/C++ Program to blink an LED WITHOUT Arduino, WITHOUT Microcontroller" by Parveen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.