failed to compile what have i done wrong with this code please advise me?

// initialize serial communication at 9600 bits per second:

int door = 12; // door
int led = 13; // led
int threshold_voltage = 0.014000000;

void setup() {
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // Set threshold voltage
  // read the input on analog pin 0:
  int Input_Voltage = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = Input_Voltage * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
  // check input voltage
while (voltage > threshold_voltage){
// open door
digitalWrite(door, HIGH);   // turn the door on (HIGH is the voltage level)
digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(8000);   
digitalWrite(door, LOW);   // wait for 8 seconds
digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
}
}

the code fails to conpile this project is for reading an analogue pin to find its value and if a threshhold limit is met it should open door (function) but it not 100% correct what am i doing wrong (this is for reading 3 - 5 volts maximum) and opening a door via a relay when voltage of 3 - 5 volts is found on A0 (analogue pin example).

Hint: "int" is a contraction of "integer"

ok i tried this also and still it failed (took out int from the threashold line).

/// initialize serial communication at 9600 bits per second:

int door = 12; // door int led = 13; // led threshold_voltage = 0.04398827;

void setup() { Serial.begin(9600); }

// the loop routine runs over and over again forever: void loop() { // Set threshold voltage // read the input on analog pin 0: int Input_Voltage = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = Input_Voltage * (5.0 / 1023.0); // print out the value you read: Serial.println(voltage); // check input voltage while (voltage > threshold_voltage){ // open door digitalWrite(door, HIGH); // turn the door on (HIGH is the voltage level) digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(8000); digitalWrite(door, LOW); // wait for 8 seconds digitalWrite(led, LOW);// turn the LED off by making the voltage LOW } }

And C wants a type for variables - you can't leave them blank

AWOL:
And C wants a type for variables - you can’t leave them blank

ok so what type if not an int shal i use please?

Maybe instead of just taking 'int' out, you need to replace it with something else.

I know that this is not the fault, but when you convert an analogue reading to a voltage you should divide by 1024, not 1023.

JohnLincoln:
Maybe instead of just taking ‘int’ out, you need to replace it with something else.

I know that this is not the fault, but when you convert an analogue reading to a voltage you should divide by 1024, not 1023.

what type do i replace int with that will work?

How about 'float' as you use that again later.

// initialize serial communication at 9600 bits per second:

int door = 12; // door
int led = 13; // led
float threshold_voltage = 0.04398827;

void setup() {
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// Set threshold voltage
// read the input on analog pin 0:
int Input_Voltage = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = Input_Voltage * (5.0 / 1024.0);
// print out the value you read:
Serial.println(voltage);
// check input voltage
while (voltage > threshold_voltage){
// open door
digitalWrite(door, HIGH); // turn the door on (HIGH is the voltage level)
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(8000); 
digitalWrite(door, LOW); // wait for 8 seconds
digitalWrite(led, LOW);// turn the LED off by making the voltage LOW
}
}

I have updated using comments from you guys and still getting error!

Thanks for all your replys i am getting there slowly but surely :)

code.ino:29:1: error: stray ‘\’ in program code.ino:29:3: error: ‘ufeff’ does not name a type

ok i fixed with this ( also made sure no spaces were after any of the } )

// initialize serial communication at 9600 bits per second:

int door = 12; // door
int led = 13; // led
float threshold_voltage = 0.04398827;

void setup() {
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// Set threshold voltage
// read the input on analog pin 0:
int Input_Voltage = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1024) to a voltage (0 - 5V):
float voltage = Input_Voltage * (5.0 / 1024);
// print out the value you read:
Serial.println(voltage);
// check input voltage
while(voltage >= threshold_voltage){
// open door
digitalWrite(door, HIGH); // turn the door on (HIGH is the voltage level)
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(8000); 
digitalWrite(door, LOW); // wait for 8 seconds
digitalWrite(led, LOW);// turn the LED off by making the voltage LOW
}
}

it uploaded to uno fine now so i assume this is correct any errors that will stop it working let me know or if theres any way of making it better.

I can’t figure out what you’re doing with the pins.
You’re just turning the pull ups on and off.
Did you forget a couple of "pinMode"s?

its for sensing an external power source of 3 volts - 3.5 volts and then activating a relay if theres 3 or 3.5 volts but not if theres no voltage its using a common ground for the external power to be sensed!

Pins 12 and 13?

them pins are outputs 1 is for a built in led and 1 is for a relay thats for a door elec lock on my door, the wole reason for this project, as 3 - 3.5 volts wouldnt activate a relay thats the output from a rfid control unit from amazon you see!

them pins are outputs

Not until you tell the micro controller that that's what you want them to be, they aren't.

// initialize serial communication at 9600 bits per second:

int door = 12; // door
int led = 13; // led
float threshold_voltage = 0.04398827;

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

// the loop routine runs over and over again forever:
void loop() {
// Set threshold voltage
// read the input on analog pin 0:
int Input_Voltage = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1024) to a voltage (0 - 5V):
float voltage = Input_Voltage * (5.0 / 1024);
// print out the value you read:
Serial.println(voltage);
// check input voltage
while(voltage >= threshold_voltage){
// open door
digitalWrite(door, HIGH); // turn the door on (HIGH is the voltage level)
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(8000); // wait for 8 seconds
digitalWrite(door, LOW); // lock door again!
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
}
}

Thanks i forgot to add them lines lol

// initialize serial communication at 9600 bits per second: 

int door = 12; // door 
int led = 13; // led 
float threshold_voltage = 2; // Set threshold voltage 

void setup() { 
pinMode(led, OUTPUT); 
pinMode(door, OUTPUT); 
Serial.begin(9600); 
} // the loop routine runs over and over again forever: 

void loop() {
// read the input on analog pin 0:
int Input_Voltage = analogRead(A0); // Convert the analog reading (which goes from 0 - 1024) to a voltage (0 - 5V): // 
//float voltage = Input_Voltage * (5.0 / 1024); 
float voltage = Input_Voltage * 5 / 1023 -1; // print out the value you read: 
Serial.println(voltage); // check input voltage // while(voltage < threshold_voltage){ 
if(voltage > 1.1){ // open door 
digitalWrite(door, HIGH); // turn the door on (HIGH is the voltage level) 
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) 
delay(8000); // wait for 8 seconds 
digitalWrite(door, LOW); // lock door again! 
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
} }

I had to use above code to get it to work but it takes 5 seconds to do it, how can i speed this up so its pretty much instantly?

(i left commented out lines to show what iv tried before!