Hi, I'm trying to code a laser sensor/receiver to turn a LED on and send a push notification to my phone . I'm having trouble with my code and I'm unsure what could be wrong. The laser sensor is not even turning on but the led is. I know one issue I'm probably having is the network not connecting. But I'm sure another issue is my code is incorrect. We are using a Arduino uno R4. Any help is greatly appreciated. Here is my current code:
#include "thingProperties.h"
int laser = 4;
int receiver = 12;
int LED = 8;
void setup() {
Serial.begin(9600);
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
pinMode(laser, OUTPUT);
pinMode(receiver, INPUT);
pinMode(LED, OUTPUT);
}
void loop() {
ArduinoCloud.update();
int value = digitalRead(receiver);
if (value == 0) {
digitalWrite(LED, HIGH);
onDeerChange();
}
else {
digitalWrite(8, LOW);
}
}
/*
Since Deer is READ_WRITE variable, onDeerChange() is
executed every time a new value is received from IoT Cloud.
*/
void onDeerChange() {
int deer = true;
}
// Add your code here to act upon Deer change}
// Code generated by Arduino IoT Cloud, DO NOT EDIT.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_OPTIONAL_PASS; // Network password (use for WPA, or use as key for WEP)
void onDeerChange();
bool deer;
void initProperties(){
ArduinoCloud.addProperty(deer, READWRITE, ON_CHANGE, onDeerChange);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);