Last active
December 11, 2015 01:18
-
-
Save jreisstudio/4521872 to your computer and use it in GitHub Desktop.
LDR sensor + Arduino + Ruby....The idea is to send an email when the light downs!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LDR 0 | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
int LDR_value = analogRead(LDR); | |
Serial.println(LDR_value); | |
delay(250); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "serialport" | |
@port = "/dev/tty.usbmodem1421" | |
@baud_rate = 9600 | |
@data_bits = 8 | |
@stop_bits = 1 | |
@parity = SerialPort::NONE | |
@serial_port = SerialPort.new(@port, @baud_rate, @data_bits, @stop_bits, @parity) | |
def lightControl() | |
sp_char = @serial_port.gets.chomp | |
if sp_char.to_i <=150 | |
sendMail() | |
@serial_port.close | |
else | |
lightControl() | |
end | |
end | |
def sendMail() | |
#implements your "send email" logic here!! | |
puts 'An email has sent to jreisstudio@gmail, to fix the light problem!' | |
end | |
sleep 2 | |
lightControl() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment