Arduino Newbie Looking for Some Wiring Help

Hi,

I’m currently a student trying to use Arduino in one of my projects.
I’ve been helped out a lot with the code, but now I’m struggling with the wiring.

I’m not doing well with the wordy instructions given with the code, I just end up with a wiry mess.

If someone could give me a better explanation of how it’s supposed to wired I’d appreciate it a lot.

Here's the code and instructions.


/*
This sketch allows you to send a keystroke back to the computer
upon tilting a tilt switch. This keystroke can be used to control
any other program as a keyboard would, typically simulating a
SPACE keypress to play an audio file in an audio player.

Wiring setup:
Tilt sensor between +5v and pin2
10k resistor between pin2 and GND (for debouncing)
Optocoupler pins 1, 2 4 and 5 to Arduino pin7, GND, keyboard PCB
pinA and pinB respectively. You will have to identify the appropriate
two pins on your keyboard PCB to simulate the desired
keystroke - plug into your computer and short them out to test.
Keyboard PCB connected to computer.
LED long leg to Arduino pin8 and short leg to GND.
*/

int tiltPin = 2; // variable for setting the tilt sensor pin
int optPin = 7; // variable for setting the optocoupler pin
int ledPin = 8; // variable for setting the led pin
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// put your setup code here, to run once:
pinMode(tiltPin, INPUT); // sets up tiltPin as an Input
pinMode(optPin, OUTPUT); // sets up optPin as an Output
pinMode(ledPin, OUTPUT); // sets up ledPin as an Output
// Serial.begin(9600); // begins a Serial communication
}

void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(tiltPin); // sets buttonState to value of the tilt sensor
if (buttonState == HIGH) {
digitalWrite(optPin, HIGH); // turn on optocoupler
digitalWrite(ledPin, HIGH); // turn on LED
delay(100); // wait 0.1ms
digitalWrite(optPin, LOW); // turn off optocoupler
delay(1000); // wait 1s
}
else {
digitalWrite(optPin, LOW); // turn off optocoupler
digitalWrite(ledPin, LOW); // turn off LED
}
// Serial.println(tiltPin); // print the stated variable
}


Any help would be greatly appreciated.
Thanks.

You will have to identify the appropriate
two pins on your keyboard PCB to simulate the desired
keystroke - plug into your computer and short them out to test.

Have you done this part?

Yes, I know which are the correct pins for what I need.

It's more the wiring of the breadboard I'm having trouble with.

This may not be what you're looking for but with any project like this you need to break it up into small parts and make sure you can get each part working on its own before putting it all together. If, for example, you have never used a tilt switch, try looking for a tutorial (like this: Using a Tilt Sensor | Tilt Sensor | Adafruit Learning System) and make sure you understand how it is wired and how it works before going onto the next step.

sampj13:
Yes, I know which are the correct pins for what I need.

It's more the wiring of the breadboard I'm having trouble with.

Tilt sensor between +5v and pin2

10k resistor between pin2 and GND (for debouncing)

Optocoupler pins 1, 2 4 and 5 to Arduino pin7, GND, keyboard PCB
pinA and pinB respectively. You will have to identify the appropriate
two pins on your keyboard PCB to simulate the desired
keystroke - plug into your computer and short them out to test.

Keyboard PCB connected to computer.

LED long leg to Arduino pin8 and short leg to GND.

So, which part of the wiring description do you not understand?

LED long leg to Arduino pin8 and short leg to GND.

Recipe for disaster...