
Last night, I did a bit more work on the Flash Trigger project. The first thing was to remove the testing printouts to the Serial Monitor, and replace it with the LCD, and then I mounted the receiver and LED on either side of a bit of card to try it out as a reflective receiver. That was much easier to keep lined up with the dripping tap.
I've modified the loop() logic so that when the beam is interrupted, this triggers a quick beep, puts a message on the LCD, and starts a 3 second countdown. During the countdown period, the LED (on pin 13) will still flash to indicate when the beam is broken, but nothing else will happen. After 3 seconds, it all resets, and the trigger's ready to go again. I also added a counter to keep track of how many times the trigger is.... well, triggered. The latest version of the code looks like this...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #include <NewTone.h> #include <IRremote.h> #include <LiquidCrystal_I2C.h> #define PIN_IR 3 // Documentary value only - Pin 3 (OC2B) is hard-coded in the library. #define PIN_DETECT 2 #define PIN_STATUS 13 #define PIN_TONE 9 // Instantiate objects IRsend irsend; LiquidCrystal_I2C lcd(0x3F,20,4); // set up global variables int triggered = 0; long trigMs = millis(); int trigCount = 0; void setup() { // Set pins as IN or OUT pinMode(PIN_DETECT, INPUT); pinMode(PIN_STATUS, OUTPUT); pinMode(PIN_TONE, OUTPUT); // Put prompt on display (Coordinates = col 0-19, row 0-3) lcd.begin(); lcd.setCursor(0,0); lcd.print("IR Beamer waiting..."); // Start the IR LED sending irsend.enableIROut(38); irsend.mark(0); } void loop() { // Check beam and update LED in real time int beamState = !digitalRead(PIN_DETECT); digitalWrite(PIN_STATUS, beamState); // If newly triggered... if(beamState == 1 && triggered == 0) { // set flag and note the time triggered = 1; trigMs = millis(); trigCount++; // beep // NewTone(PIN_TONE,750,250); // The beep gets quite annoying // update LCD lcd.setCursor(10,0); lcd.print("TRIGGERED!"); lcd.setCursor(1,1); lcd.print("(Counter="); lcd.print(trigCount); lcd.print(")"); lcd.setCursor(1,3); lcd.print("resets in 3 seconds"); } // Once triggered... // If 3 seconds have passed, then reset if(triggered == 1 && (millis() > (trigMs + 3000))) { lcd.setCursor(10,0); lcd.print("waiting..."); lcd.setCursor(1,3); lcd.print(" "); triggered = 0; } // If 2 seconds have passed, update countdown else if(triggered == 1 && (millis() > (trigMs + 2000))) { lcd.setCursor(11,3); lcd.print("1"); lcd.setCursor(19,3); lcd.print(" "); } // If 1 second has passed, update countdown else if(triggered == 1 && (millis() > (trigMs + 1000))) { lcd.setCursor(11,3); lcd.print("2"); } } |
I checked it out with the tap, and it was working pretty well, as long as it was within about 3-6" of the drips. When IR remotes work from the sofa to the TV on the other side of the room, I was quite surprised that the range on my little contraption is only a few inches, but it is good enough for the particular job I have in mind.
The next step is to link the trigger action to an actual external device via a photocoupler - and then finally, introduce a delay.
By the way, the header pins that I ordered turned up at the end of last week, and the supplier also sent me a replacement set in case the originals had gone missing, and they turned up this morning. Also in the post this morning was part 1 of my regulated power supply project - the buck converter - which has arrived 2 days before the estimated timeframe! I must connect that up to some of my supplies and give it a bit of a test before I leave feedback for the seller.
With all these envelopes turning up, I felt a little like Julian Ilett and his " It's Postbag" videos on youtube. Speaking of which, I was a little concerned when I found he has done a video about 'fake' LM2596 boards exactly like the one I ordered from ebay... thankfully, it turned out that what he was describing was sellers claiming to be selling the High Voltage (HV) version of the LM2596 which is rated at up to 60VDC input, but only putting the standard LM2596 (relabelled to look like the HV version) on the board, which is rated to 40VDC, or putting a fake 65V capacitor on the input side of the circuit (looked like the standard 50V cap with overprinting) - so the boards worked OK up to around 40-45V as per the design of the standard components, but then started behaving very strangely, and sometimes smoking gently, at anything higher. Hopefully, as I have bought the standard 40V model, with the intention that it will never experience inputs above around 20VDC, there should not be a problem...
No comments:
Post a Comment