Activity 1. Serial and LEDs
This activity uses serial communication between the Arduino Uno and the monitor. (50 minutes)
Activity 1a
In this part the aim is for the Arduino Uno to flash an LED every 5 seconds. Each time the LED changes status, the Arduino Uno sends a corresponding message to the serial.
- The data sent by the Arduino Uno via the serial port is displayed on the Tinkercad monitor
Step 1. Draw the circuit in Tinkercad.
Step 2. Study the code and write it on the microcontroller:
/*
Blinking a LED and print to Serial
Circuit Connections:
PIN_2 => LED_Anode - LED_Cathode = > Resistor 220Ω => Gnd
PIN_0 => Serial_RX
PIN_1 => Serial_TX
*/
//The setup() function initializes and sets the initial values
//It will only run once after each power up or reset
void setup(){
//Configure the PIN_2 to behave as output
pinMode(2, OUTPUT);
//opens serial port, sets data rate to 9600 bps
Serial.begin(9600);
}
//loops consecutively
void loop(){
digitalWrite(2, HIGH); //Write a HIGH value (5V) to a digital pin
Serial.println("LED is ON");//sent data
delay(5000); // Pauses the program for 5000 milliseconds
digitalWrite(2, LOW); //Write a LOW value (0V) to a digital pin
Serial.println("LED is OFF");//sent data
delay(5000); // Wait for 5000 milliseconds
}
Step
3. Run
the simulation and check the correct operation of the circuit
Tip. Open the Tinkercad monitor to see the data