Hi all.
I'm trying to connect a piece of apparatus (a hoop type thing with sensors in it for fish to swim through) to an Arduino which is connected to a Visual Basic form with Firmata. The hoop is attached to a relay shield and an external wall power source (that goes up to 24V) and the Arduino. I connected like I connected a previous sensor. I had it so when that sensor reading went below 100, it would trigger rotation of a food drum in a feeder.
I'm unsure if I'm missing some code for the relay shield or if 24V is still not enough power for this. I attached a few photos (of the hoop with sensors and then of my connections), though they might not be too helpful. It's a bit of a mess.
Here's my code. I have IN1 from the relay shield attached to digital pin 2. I'm using the analog port A1 to take sensor readings from (white wire from sensor is connected there). Some pieces of the code refer to LEDs that aren't shown in the photos (I took them out to simplify the mess until I can get this sensor business working).
Any suggestions would be fantastic. Thank you!
Public Class Form1
Dim analogread As Boolean = False
Dim lightOn As Boolean
Private arduino As New Firmata.FirmataVB
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FirmataVB1.COMPortName = "COM7"
FirmataVB1.Baud = "57600"
FirmataVB1.Connect()
FirmataVB1.PinMode(4, 9)
FirmataVB1.DigitalWrite(2, 0)
End Sub
Private Sub btnOn_Click(sender As Object, e As EventArgs) Handles btnOn.Click
analogread = True
FirmataVB1.AnalogPinReport(1, 1)
Do Until analogread = False
lblReading.Text = FirmataVB1.AnalogRead(1)
If FirmataVB1.AnalogRead(1) <= 100 And picboxCRF.Visible = True Then
FirmataVB1.DigitalWrite(8, 1)
timerFeeder.Start()
End If
Application.DoEvents()
Loop
End Sub
Private Sub btnCRF_Click(sender As Object, e As EventArgs) Handles btnCRF.Click
picboxCRF.Visible = True
picboxEXT.Visible = False
FirmataVB1.DigitalWrite(5, 0)
FirmataVB1.DigitalWrite(7, 1)
If lblReading.Text <= 100 Then
timerFeeder.Enabled = True
FirmataVB1.DigitalWrite(8, 1)
End If
End Sub
Private Sub form1_formclosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
FirmataVB1.Disconnect()
analogread = False
FirmataVB1.DigitalWrite(5, 0)
FirmataVB1.DigitalWrite(7, 0)
FirmataVB1.DigitalWrite(8, 0)
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles timerFeeder.Tick
FirmataVB1.DigitalWrite(8, 1)
timerFeeder.Interval = 8000 'ms
FirmataVB1.DigitalWrite(8, 0)
End Sub
Private Sub btnEXT_Click(sender As Object, e As EventArgs) Handles btnEXT.Click
picboxCRF.Visible = False
picboxEXT.Visible = True
FirmataVB1.DigitalWrite(5, 1)
FirmataVB1.DigitalWrite(7, 0)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnOff.Click
FirmataVB1.DigitalWrite(5, 0)
FirmataVB1.DigitalWrite(7, 0)
FirmataVB1.DigitalWrite(8, 0)
picboxCRF.Visible = False
picboxEXT.Visible = False
End Sub
Private Sub Timer1_Tick_1(sender As Object, e As EventArgs)
FirmataVB1.DigitalWrite(9, 1)
End Sub
Private Sub btnManual_Click(sender As Object, e As EventArgs) Handles btnManual.Click
FirmataVB1.DigitalWrite(8, 1)
timerFeeder.Start()
End Sub
End Class