Trying to get a sensor to set off a vibration motor but having problems

Hi guys

I am fairly new to this so I apologize if this question seems too obvious but I am having trouble getting my code to work. I have an infrared sensor and a vibration motor hooked up to a breadboard to an arduino uno and I am trying to code it so once the infrared sensor gives a reading over a certain number it sets off the vibration motor. At the moment when I try run this code I get the error "unexpected token:const" and if I remove the const and just leave them as int I get the error "Cannot find anything named "A0". Again I apologize if this question is too vague or obvious but I thank you in advance for your help.

CODE:

import processing.serial.;
import cc.arduino.
;

const int analogPin = A0; // pin that the sensor is attached to
const int motorPin = 13; // pin that the vibrationmotor is attached to
const int threshold = 25;
Arduino arduino;

void setup()
{
pinMode(motorPin, OUTPUT);

println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[5], 57600);

Serial.begin(9600);

}

void loop() {
// read the value of the infraredsensor:
int analogValue = analogRead(analogPin);

// if the analog value is high enough, turn on the vibrationmotor:
if (analogValue > threshold) {
digitalWrite(motorPin, HIGH);
} else {
digitalWrite(motorPin, LOW);
}

// print the analog value:
Serial.println(analogValue);
delay(1); // delay in between reads for stability
}

You seem to be terribly confused as to whether you are developing an Arduino sketch or a Processing sketch. That mess won't compile on either platform.

Im trying to get it working on processing. Am I any bit close to achieving the functionality I want?

You should post your code between code tags, not inline in your post.

Try this:-

const int analogPin = A0;    // pin that the sensor is attached to
const int motorPin = 13;       // pin that the vibrationmotor is attached to
const int threshold = 25;

void setup()
{
    pinMode(motorPin, OUTPUT);
    Serial.begin(9600);
}

void loop()
{
    // read the value of the infraredsensor:
    int analogValue = analogRead(analogPin);

    // if the analog value is high enough, turn on the vibrationmotor:
    if (analogValue > threshold)
        digitalWrite(motorPin, HIGH);
    else
        digitalWrite(motorPin, LOW);

    // print the analog value:
    Serial.println(analogValue);
    delay(500);        // delay in between reads for stability *** Increased to 500mS to slow the serial prints ***
}

Am I any bit close to achieving the functionality I want?

The part about importing stuff is right. The setup() function looks reasonable.

The A0 name is a #define on the Arduino side. You need to use the analog pin NUMBER not the name of the digital pin that shares the same space. The value for analogPin should be 0.

loop() is an Arduino function. The corresponding function in Processing is draw(), but it won't look anything like what you have for loop(), so don't just rename loop().

ConorB123:
Im trying to get it working on processing. Am I any bit close to achieving the functionality I want?

What? You want to run the Arduino sketch in Processing? Good luck.
My above code was your code modified to run in an Arduino UNO.

All very confusing. I know little or nothing about Processing.

Hi all thanks for help.
I don't know why I was trying to get it working in processing I switched to arduino and changed the code and got it working in the end.
Heres what worked for me (how do I put my code in the format done above?)

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(13, OUTPUT);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
if (sensorValue>300)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.println(sensorValue);

// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}

how do I put my code in the format done above?

The top left icon above the text field generates tags that look like [ code ][ /code ] (but without the space. Paste your code between the ] and the [.