Skip to content

Instantly share code, notes, and snippets.

@jreisstudio
Last active December 11, 2015 01:18
Show Gist options
  • Save jreisstudio/4521872 to your computer and use it in GitHub Desktop.
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!
#define LDR 0
void setup() {
Serial.begin(9600);
}
void loop() {
int LDR_value = analogRead(LDR);
Serial.println(LDR_value);
delay(250);
}
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