Hi guys,
I am trying to get the HC-sr505 sensor working with nodeMCU but I get aways the same value logged from the sensor, I always get "1". I have tried both pin D1 and D2.
Any idea?
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			I am trying to get the HC-sr505 sensor working with nodeMCU but I get aways the same value logged from the sensor, I always get "1". I have tried both pin D1 and D2.
Any idea?
			
				B4X:
			
		
		
		#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region
Sub Process_Globals
    Public Serial1 As Serial
    Private wifi As ESP8266WiFi
    Private server As WiFiServerSocket
    Private astream As AsyncStreams
    Private timer1 As Timer
    Private ser As B4RSerializator
    Private Pins As D1Pins
    Private CurrentValueFromSensor As Boolean
    Private Pin As Pin
End Sub
Private Sub AppStart
    Serial1.Initialize(115200)    
    Log("AppStart")
     If wifi.Connect2("Infostrada-3442ED","xxxxx") Then 'change to your network SSID (use Connect2 if a password is required).
        Log("Connected to wireless network.")
        Log("My ip: ", wifi.LocalIp)
    Else
        Log("Failed to connect.")
        Return
    End If
    Pin.Initialize(Pins.D1,Pin.MODE_INPUT_PULLUP)
    timer1.Initialize("timer1_Tick", 3000)
    timer1.Enabled = True
    server.Initialize(51042, "server_NewConnection")
    server.Listen
End Sub
Sub Server_NewConnection (NewSocket As WiFiSocket)
    Log("Client connected")
    astream.Initialize(NewSocket.Stream, "astream_NewData", "astream_Error")
End Sub
Sub Timer1_Tick
    Dim SensVal As Boolean
    SensVal = Pin.DigitalRead
    Log(SensVal)
    If SensVal <> CurrentValueFromSensor Then
        CurrentValueFromSensor = SensVal
        Log(SensVal)
        If server.Socket.Connected Then
            astream.Write(ser.ConvertArrayToBytes(Array("Time here is: ", SensVal)))
        End If
    End If
    
    
    If server.Socket.Connected Then
        astream.Write(ser.ConvertArrayToBytes(Array("Time here is: ", Millis)))
    End If
End Sub
Sub AStream_NewData (Buffer() As Byte)
    Dim be(10) As Object
    Dim data() As Object = ser.ConvertBytesToArray(Buffer, be)
    Log("Received:")
    For Each o As Object In data
        Log(o)
    Next
End Sub
Sub AStream_Error
    Log("Error")
    server.Listen
End Sub