Outils pour utilisateurs

Outils du site


issue90:arduino

Ceci est une ancienne révision du document !


Last month, our circuit could determine whether a code entered via keypad was right or wrong. This month, I’ve added to it using a simple IF/ELSE statement to do one of two things.

I’ve added an LED and an integer called ‘armed’. Initially ‘armed’ equals zero, and armedLed equals A0. I’m now having to tweak the rules to use the analog pins for digital components as I’m quickly running out of pins all together!

The main crux of this ‘armed’ change is the IF/ELSE command that’s embedded in the existing IF/ELSE command in the guessPassword() section of the code. Basically here’s what’s happening: if the password is correct and armed=0 (in other words: the system is off) then it will clear the screen, display ARMED!, change armed to equal 1, and light the red LED. Finally it will display “Code to disarm:”. Otherwise, armed must equal 1 (system is on) so display DISARMED!, make armed=0, and display “Code to arm:”.

I have to admit to my faults and I spent hours trying to figure out why my IF/ELSE wasn’t working properly. Rookie mistake: I forgot to use == in the IF statement.

After getting success with armed/disarmed, I went and dug out one of my 37-in-1 sensors and a photoresistor (a Light Dependent Resistor, LDR for short). The LDR goes to A1 with a 220 ohm resistor on one leg and taking its other leg to ground. The laser sensor goes to the positive LED leg and to ground. Now, when the system is armed, the laser flicks on and is made to point at the LDR.

To test that the LDR is actually registering anything, you’ll notice that I’ve reintroduced the serial code (again, using 9600 baud rate). In the main loop, I have the code do an analog read from pin A1 and print the result to the IDE serial window. In other words, the number that the LDR is returning via its analog pin. With no laser and at room lighting, the serial window shows a stream of numbers averaging 400-450. When I cover the LDR, it drops to as low as 100-150. With the laser on, and pointing directly at the LDR, the serial output shoots up to a touch over 1,000. Almost the maximum it can reach. So, with the laser on, I place an obstruction to the beam and the LDR registers the loss of the laser.

Next time we meet, we’ll (hopefully!) have a working laser tripwire alarm…

Code: http://pastebin.com/AjFDajHm

Are there any similar projects you’d like me to try? Drop me an email at: ronnie@fullcirclemagazine.org. Remember: I’m a beginner, don’t ask me to design the next NASA rover!

issue90/arduino.1420209340.txt.gz · Dernière modification : 2015/01/02 15:35 de andre_domenech