I want to make a circuit with the arduino that basically tells me when someone has tripped a laser in my room.
I know I should use a photoresistor and a laser. Now I wanted to do this and post it on twitter whenever somone passed the laser but now I want the computer to take a webcam picture and store it on my hard drive whenever someone passes the laser. Or even eaiser, just log what time the laser was tripped.
Anyone know how to at least log the time the laser was tripped?
Anyone know how to at least log the time the laser was tripped?
Sure, just wire up a real time clock chip (RTC) and that will allow you to read the time when the laser is tripped. You should break your project up into little parts, and build and test each section. Later you can combine it all together and add higher order functions like tweeting and such. First build the laser/detector circuit and write a simple sketch to light up the on-board pin 13 led when the laser path is broken.
Why not save the logging data to ram, and have a pushbutton to send the data to the serial monitor as and when required? Or let it transmit all the time.... This necessitates the connection of the arduino to a pc via usb running the ide though.
Given the fact that your computer is going to be on in order to take the picture from webcam, it seems only logical to power the circuit via the computer USB.
If you don't wish to purchase extra parts, I suggest the following:
Create and upload a sketch to the arduino, so the arduino sends a serial message to the computer every second of either "0", beam not broken, or "1" beam broken.
Then create a simple program in VB or something which reads the incoming serial data.
If incomingSerialData = "1" Then
'Log time here using Now() function or similar
'take picture, play an alarm sound etc etc.
End If
Using millis that lasts for a few day and then overflows and the EEPROM that the Atmega used in the arduino, you only need to add an LDR and a little bit of code, maybe to even 40 lines and its done.
Savers:
Given the fact that your computer is going to be on in order to take the picture from webcam, it seems only logical to power the circuit via the computer USB.
If you don't wish to purchase extra parts, I suggest the following:
Create and upload a sketch to the arduino, so the arduino sends a serial message to the computer every second of either "0", beam not broken, or "1" beam broken.
Then create a simple program in VB or something which reads the incoming serial data.
If incomingSerialData = "1" Then
'Log time here using Now() function or similar
'take picture, play an alarm sound etc etc.
End If
ok with your advice I got the arduino to output a 1 every time a certain value of my photo resistor is breached and a 0 when it goes below that. So basically I got it to write a 1 and 0 now but I need more explanation about VB and coding it from there now.
Ok, download VB express 2010, if you haven't already.
Start a new project.
Stick a timer control onto the form.
Then double click the form to get into the code.
After one of the "End Sub" 's, copy and paste the following function, not forgetting to set the correct COM port you are using:
Function ReceiveSerialData() As String
' Receive strings from a serial port.
Dim returnStr As String = ""
Using com As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("com4")
Dim Incoming As String = com.ReadLine()
If Incoming Is Nothing Then
MsgBox("No Data Captured.")
Else
returnStr &= Incoming & vbCrLf
End If
End Using
Return returnStr
MsgBox("Fail!")
End Function
Then scroll all the way to the top of the code for the program, and paste the following:
Imports System.IO
That's the code to get the serial data.
Now go back to your form, and click the timer you placed earlier. Change the interval to 1000.
Double click the timer to get into the code for it.
Here is where you will enter the code to be executed each time 1 second passes.
So you'd want something like:
If receiveSerialData() = "1" Then
'code here
End If
As I mentioned previously, the built-in Now() function is useful for getting the current date and time.
Savers:
Ok, download VB express 2010, if you haven't already.
Start a new project.
Stick a timer control onto the form.
Then double click the form to get into the code.
After one of the "End Sub" 's, copy and paste the following function, not forgetting to set the correct COM port you are using:
Function ReceiveSerialData() As String
' Receive strings from a serial port.
Dim returnStr As String = ""
Using com As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("com4")
Dim Incoming As String = com.ReadLine()
If Incoming Is Nothing Then
MsgBox("No Data Captured.")
Else
returnStr &= Incoming & vbCrLf
End If
End Using
Return returnStr
MsgBox("Fail!")
End Function
Then scroll all the way to the top of the code for the program, and paste the following:
That's the code to get the serial data.
Now go back to your form, and click the timer you placed earlier. Change the interval to 1000.
Double click the timer to get into the code for it.
Here is where you will enter the code to be executed each time 1 second passes.
So you'd want something like:
If receiveSerialData() = "1" Then
'code here
End If
As I mentioned previously, the built-in Now() function is useful for getting the current date and time.
Wow thanks for the help! I will try this when I get home