An introductory activity for creating and programming circuits with Arduino. The objective is to build a simple door alarm using a laser beam.
What do we need?
Every student team will have:
- One Arduino Uno or compatible board with a USB cable for connection with PC
- One light sensor with digital output
- One buzzer
- One laser module
- One breadboard
- Jumper wires
- A PC or laptop with Arduino IDE installed
Connecting the wires
Before proceeding to the actual connections, every student team completes the following worksheet, drawing the connections using markers, according to the instructions.
When each team completes the schematic, we proceed by giving them the modules and wires to construct the circuit following their design.
Programming and testing
We proceed in a similar way to program the system. Instead of explaining in detail and step by step the structure of an Arduino program, we give each group a worksheet that includes a half-baked program and ask them to fill in the missing elements first with a pencil on paper.
We explain and help each team when they have questions, but in general, we try not to give them ready answers and let them solve the puzzle of the program. After completing the program on paper they can type it on their computer, upload it to the Arduino and test it.
void setup() {
pinMode(8,OUTPUT); //Laser pin
pinMode(9,INPUT); //Light sensor pin
pinMode(10,OUTPUT); //Buzzer pin
}
void loop() {
// Turn on the laser that points at the light sensor
digitalWrite(8,HIGH);
//Check the light sensor
//If there is no light that means that the resistance is low
//and the current is high
if (digitalRead(9) == HIGH) {
digitalWrite(10,HIGH); //Turn on the buzzer
delay(500); //for half a seconf
digitalWrite(10,LOW); //Turn off the buzzer
delay(500); //for half a second
}
}