Hi, I'm a complete beginner to Arduino coding and It's one of the first codes I've written. The code that I have under turns at my LED on every time my laser is cut. I want my serial monitor to count every time the laser is cut, but I can't seem to make that work.
int ldrPin = A4; // the cell and 10K pulldown are connected to a0
int sirenPin = 11; //pin 3 selected!
int ledPin = A0;
int ldrValue1, ldrValue2;
const int pinLaser = 2; // output signal pin of laser module/laser pointer
const int pinReceiver = 3; // input signal pin of receiver/detector (the used module does only return a digital state)
const int BUTTON_PIN = 2;//Pin2 connected to Button
const int LED_PIN = 13;//Pin3 connected to a LED
void setup() {
pinMode (sirenPin,OUTPUT); // set the siren pin as output
pinMode (ledPin,OUTPUT); // set the siren pin as output
pinMode (ldrPin,INPUT); // set the siren pin as output //Serial.begin(9600);
pinMode(pinLaser, OUTPUT); // set the laser pin to output mode
pinMode(pinReceiver, INPUT); // set the laser pin to output mode
digitalWrite(pinLaser, HIGH); // emit red laser
}
When you run this sketch, what values get displayed on Serial Monitor when the laser hits the LDR and what values get displayed on Serial Monitor when the laser is blocked?
int LDRPin = A4;
const int pinLaser = 2; // Laser power
void setup()
{
Serial.begin(115200);
// Turn on the laser
pinMode(pinLaser, OUTPUT);
digitalWrite(pinLaser, HIGH); // emit red laser
}
void loop(void)
{
// Report the reading from the LDRPin
Serial.println(analogRead(LDRPin));
delay(1000);
}