int laser = 10;//define laser to pin 10int button = A0;//define button to pin A0int buttonVal; //define the val of button
void setup() { pinMode(laser, OUTPUT); //set laser as output pinMode(button, INPUT);// set button as input Serial.begin(9600); //start the serial communications at 9600 bauds
}
void loop() { buttonVal = analogRead(button); //define buttonVal to equal the value of the button if(buttonVal == 0 ){ digitalWrite(laser, HIGH);//if the button is pressed turn on laser }else{ digitalWrite(laser, LOW);//if else dont turn on the laser}Serial.println(buttonVal); //serial print the button value}
1 Comment
stivejoy18
Sep 10
Simple button-trigger circuits like this are such a great way to get comfortable with digital input and output logic. Using a tactile push button to toggle a laser diode module gives you immediate visual feedback on state changes, which makes testing the circuit super satisfying. Working through digital debouncing issues or setting up pull-down resistors can definitely trip people up during introductory electronics labs, so getting Expert Arduino Assignment Help for Studentscan be a huge help when troubleshooting unexpected signal noise or sketch loops. It is always interesting to see how these small basic builds lay the groundwork for bigger projects like tripwire security alarms. Did you implement any software debouncing in your code, or did you stick strictly to…
Simple button-trigger circuits like this are such a great way to get comfortable with digital input and output logic. Using a tactile push button to toggle a laser diode module gives you immediate visual feedback on state changes, which makes testing the circuit super satisfying. Working through digital debouncing issues or setting up pull-down resistors can definitely trip people up during introductory electronics labs, so getting Expert Arduino Assignment Help for Studentscan be a huge help when troubleshooting unexpected signal noise or sketch loops. It is always interesting to see how these small basic builds lay the groundwork for bigger projects like tripwire security alarms. Did you implement any software debouncing in your code, or did you stick strictly to…