Arduino voltage sensing to trigger relay!

View previous topic View next topic Go down

Arduino voltage sensing to trigger relay!

Post by jamied_uk on 7th April 2015, 21:11

Arduino voltage sensing to trigger relay!

Code:

// initialize serial communication at 9600 bits per second:

int door = 12; // door
int led = 13; // ledArduino voltage sensing to trigger relay!
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
}
}



Enjoy!
avatar
jamied_uk
Admin

Posts : 2268
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum