Yup, canada. I’ve used both Digikey.ca and Mouser.ca or .com before. I like digikey.ca. I like amazon.ca because I have prime. And I use amazon.com sometimes.
I’m not sure what the “original” is. I got the UNO R3 (kit) because I’m new, and whatever research I did suggested the UNO was a good choice for newbs. A smaller board might be better. I don’t mind getting something else.
OK. Last night I got the IDE installed on my macbook pro, this mbp is essentially empty and I haven’t been using it at all. I put the new IDE 2.0.x on it, I duno why. Anyway, it’s bit different (not that I’m that fluent with the original IDE), and I had to configure some things. Got that figured out.
For the last however many months, I’ve had the UNO and breadboard connected and “working” with a basic break beam demo, and wiring.
Wiring like this: LINK, with maybe a change or two. I might have more jumper wires used (for me to understand, at the time), and I powered it with a 12v/2a adapter via the DC in (barrel jack). Then I used the Vin pin for 12v for the solenoid, and the 5v pin for the break beam sensors.
The code I used is from here: Arduino | IR Breakbeam Sensors | Adafruit Learning System, with maybe a minor change or two (I just played with the “delay” for how long the solenoid fires when beam is broke, for eg.).
Here’s the actual code that’s been on, and is on the UNO now:
/*
MODIFIED IR Breakbeam sensor demo. V1.3. Attempt to have trap turn off after tripped
*/
#define LEDPIN 13
// Using pin 13 to control solenoid.
#define SENSORPIN 4
// Using pin 4 as the sensor pin for IR signal.
int sensorState; //State of IR sensor.
int triggerCount = 0; //Number of times trap (solenoid or beam?) has tripped.
void setup() {
// initialize the LED pin as an output:
pinMode(LEDPIN, OUTPUT);
// initialize the sensor pin as an input:
pinMode(SENSORPIN, INPUT);
digitalWrite(SENSORPIN, HIGH); // turn on the pullup
Serial.begin(9600);
}
void loop() {
// read the value of sensorState:
sensorState = digitalRead(SENSORPIN);
// read the value of the triggerCount?
int triggerCount = digitalRead(LEDPIN);
// check if the sensor beam is broken, if so, sensorState is LOW:
if (sensorState == LOW) {
// turn LED on:
digitalWrite(LEDPIN, HIGH);
delay(300);
}
else {
// turn LED off:
digitalWrite(LEDPIN, LOW);
}
// if the triggerCount is > 0, “disarm trap”:
if (triggerCount > 0) {
digitalWrite(SENSORPIN, LOW);
}
else {
digitalWrite(SENSORPIN, HIGH);
}
}
Obvious issue example, if the beam were to stay broken (like if it caught something) the solenoid would stay in “on”/actuated). I tried to play with some other statements/functions to learn how to deal with this, but failed.
Anyways,
Last night I connected the 12v/2a adapter to the setup I described above, and tested it, it works. I knew it did, I haven’t changed it since then.
Then, on the mbp, I uploaded “blink” and ran that (note: UNO was connected to mbp, and the break beam circuit while I tried blink, IIRC). It worked fine. I’ve done “blink” and I think “hello world”, maybe one or two others, while following a series on youtube long ago.
So, I reuploaded the “modified” breakbeam sensor demo sketch, and it still works.
Just now, I opened your sketch in the IDE 1.x.x on my windows laptop (no arduino connected right now). I tried to verify it and got this error:
"Arduino: 1.8.19 (Windows 10), Board: “Arduino Uno”
rattrap_FE_format:30:10: error: #include expects “FILENAME” or
** #include “LowPower.h”**
** ^**
C:\Users\admin\Desktop\RatTrapChronicles Code - Formatted By FE\rattrap - FE format\rattrap - FE format.ino:30:10: error: #include expects “FILENAME” or
** #include “LowPower.h”**
** ^**
exit status 1
#include expects “FILENAME” or
This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences."