LDR sensor with Flash CS4


I am new at Arduino (USB) and I've got beginners kit just send in. I have a question. I want to make an interface that uses a LDR sensor and a laptop, on the laptop there's a flash api running that starts when the spacebar is pushed. Now I want the LDR to be working like a spacebar. So when the LDR sensor detects no light it will activate the flash Api. The LDR sensor is working like a spacebar on the keyboard. Still there??? :D I hope so cause I really need some help here.

Thnx in advance.

To be more clear i want to transform de LDR sensor in to a spacebar. But how?

here is something… keyboard shortcuts for arduino + working code - there must be only one button in this code, but i think it could be modified for more buttons
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254562195 - Reply #8

The idea is that when a button in certain pin is pressed,
Arduino sends letter A to serial monitor: Serial.print(“A”);
Then a program named “AAC keyboard” converts this serial character to keyboard character. And then a “Autohotkey script” will do the shortcut job.

You can change that button to LDR, but you must find out how is “space” written in serial.

This project could be nice game intrface idea :wink: … using right resistors to make the suitable sensitivity and at the end moving hands near the sensors could control game

Good luck with your project!

Thanx for quick reply. But it still doesn't work. This is the code in Ardiuno:

int ledPin = 11;                // LED connected to digital pin 13
int LDR = 0;                    //LDR input
int val = 0;                     //setup inital stored value

void setup()                    // run once, when the sketch starts
 pinMode(LDR, INPUT);
 pinMode(ledPin, OUTPUT);      // sets the digital pin as output

void loop()                     // run over and over again
 val = analogRead(LDR);
 digitalWrite(ledPin, HIGH);   // sets the LED on
 delay(val);                  // waits for a second
 digitalWrite(ledPin, LOW);    // sets the LED off
 delay(val);                  // waits for a second

This is the script in AutoHotKeys.

Send {Space}
MsgBox You pressed Spce

These are the settings I use in AAC port: COM3 Baud: 2400 exetended Character Inter.:ANSI

The Arduino uses the COM4 port.

The HotKey works because when I type 'a' on the keyboard the a becomes a SPACE.

These are the settings I use in AAC port: COM3 Baud: 2400 exetended Character Inter.:ANSI

The Arduino uses the COM4 port.

You need to have the Arduino on one end of a serial port, and AAC on the other end of the same port.

You have the Arduino on one end of COM4 and AAC on one end of COM3. No wonder they can't communicate.

Ok, I have the AAC and the Arduino on the same port. But when the Arduino is activated the computer freaks out. For example in the text editor it types all kinds of strange characters.
I use this code in Arduino:

int LDR_pin = 0; // analog pin 0 (connect LDR here)

int LDR_val = 0; // variable use to read input data

int LEDpin = 11; //This is the LED

// a threshold to decide when the LED turns on

int threshold = 500;

void setup(){

// declaration of pin modes

pinMode(LDR_pin, INPUT);

pinMode(LEDpin, OUTPUT);

// begin sending over serial port



void loop(){

// read the value on analog input

LDR_val = analogRead(LDR_pin);

// if value greater than threshold turn on LED

if (LDR_val < threshold){
  digitalWrite(LEDpin, HIGH); 
  Serial.println("Hello, world?"); 
} else { 
  digitalWrite(LEDpin, LOW);


I don’t even see the “Hello, World?” Message.

I use windows vista can that be the problem :slight_smile:

If AAC and Arduino are connected to the port COM4 I can’t upload the a new script to Arduino cause it´s says that the port COM4 is already in use by another program… :-?

In the sketch, you specify a baud rate to communicate with AAC or the serial monitor at:


In the serial monitor (and AAC), you need to specify the same rate. Did you?

Yes< perfect it works! Thanx for the replies :slight_smile: This project is gonna be awesome. It’s a digital minigolf with real mini golfballs. You have to putt the real ball in to the machine and the computer will calculate if you have won or not. It’s really cool.

Thanx for all the help.

Cool, maybe you could post a video...