Data Sheet
68 : circuit 3c
Open the Arduino IDE
Connect the RedBoard to a USB port on your computer.
Open the Sketch:
File > Examples > SIK_Guide_Code-V_4 > SIK_CIRCUIT_C-MOTION ALARM
Select Upload to program the sketch on the RedBoard.
WHAT YOU
SHOULD SEE
The RGB LED will behave as in
your last circuit. It will be green
when objects are far, yellow
when they are midrange and
red when they are close. When
an object is close, the buzzer
will also beep, and the servo
will rotate back and forth. If you
decided to attach a pop-up, it
will move back and forth.
CODE TO NOTE
CONSTANTS:
const int trigPin
= 11;
Constants are variables that have been marked as “read-only”
and cannot have their value changed as the program progresses.
Constants are great for declaring pin number variables that will
not change throughout the program.
PROGRAM OVERVIEW
Check what distance the sensor is reading.
: If the distance is less than 10 inches, make the RGB LED red. Then make the servo rotate back and
forth and make the buzzer beep.
: If the distance is between 10 and 20 inches, make the RGB LED yellow.
: If the distance value is not equal to the fist two conditions, make the RGB LED green.
SIK v4 Book Oct 13.indb 68 10/18/17 10:01 AM