Skip to main content

Posts

Showing posts from April, 2023

Arduino Code for Controlling an LED with a Button

CIRCUIT DIAGRAM: This is the led turned on  by the push button: this is the led turned off by  the push button: COMPONENTS: CODE: int ledpin = 8 ; int buttonpin = 12 ; int buttonread ; int dt = 500 ; void setup () {   // put your setup code here, to run once: pinMode (ledpin,OUTPUT); pinMode (buttonpin,INPUT); Serial . begin ( 9600 ); } void loop () {   // put your main code here, to run repeatedly: buttonread = digitalRead (buttonpin); Serial . println (buttonread); delay (dt); if (buttonread == 1 ){ digitalWrite (ledpin,HIGH); } delay (dt); if (buttonread == 0 ){ digitalWrite (ledpin,LOW); } } EXPLANATION OF THE CODE: int ledpin =8;` - This line initializes an integer variable called `ledpin` with a value of 8. This variable will be used to store the pin number of an LED that is connected to the Arduino board. `int buttonpin = 12;` - This line initializes another integer variable called `buttonpin` with a value of 12. This variable will be used to store th...

How to Blink LED Lights in Binary Pattern with Arduino

Learn how to use four different colored LEDs In a faraway kingdom,  there was a powerful wizard who could control the elements with his magic.  He had four special orbs that glowed with the colors of the elements: red for fire, blue for water, green for earth and yellow for air. The wizard had discovered a secret language that only the wisest of creatures could understand. It was called binary and it used only two symbols: 0 and 1. With this language, the wizard could communicate with the spirits of the elements and command them to do his bidding. One day, the wizard decided to create a spell that would make his orbs glow in a special pattern. He wrote the spell using a magical code that looked like this: int yellowLED = 7 ; int redLED = 6 ; int blueLED = 13 ; int greenLED = 11 ; int dit = 100 ; int dat = 500 ; These lines declare variables that will be used in the program. The variables yellowLED, redLED, blueLED, and greenLED are set to specific numbers that ...