This circuit consists of an Arduino Nano microcontroller, two LEDs (one yellow and one red), two resistors, and a 12V battery. The Arduino Nano is powered by the 12V battery and controls the blinking of the two LEDs at different rates. Each LED is connected in series with a resistor to limit the current through the LEDs, protecting them from damage. The Arduino Nano's digital pins D2 and D3 are used to control the LEDs, with D2 connected to the red LED and D3 to the yellow LED.
// Code for controlling the blinking of two LEDs using an Arduino Nano
void setup() {
pinMode(2, OUTPUT); // Set D2 as an output for the red LED
pinMode(3, OUTPUT); // Set D3 as an output for the yellow LED
}
void loop() {
unsigned long currentMillis = millis();
static unsigned long previousMillisLED1 = 0;
static unsigned long previousMillisLED2 = 0;
static bool led1State = LOW;
static bool led2State = LOW;
// Blink the red LED every 250 ms
if (currentMillis - previousMillisLED1 >= 250) {
previousMillisLED1 = currentMillis;
led1State = !led1State;
digitalWrite(2, led1State);
}
// Blink the yellow LED every 1000 ms
if (currentMillis - previousMillisLED2 >= 1000) {
previousMillisLED2 = currentMillis;
led2State = !led2State;
digitalWrite(3, led2State);
}
}
This code is designed to run on an Arduino Nano and will blink a red LED connected to pin D2 every 250 milliseconds and a yellow LED connected to pin D3 every 1000 milliseconds. The setup()
function initializes the pins as outputs, and the loop()
function toggles the state of each LED at the specified intervals using the millis()
function to keep track of time.