Digital output: Using digitalWrite we can turn the pins on and off. The pinMode of the pin is set to OUTPUT. We can use this action to switch on/off devices or things external to the microprocessor. Of course, the microprocessor is a tiny little integrated circuit (chip) and is not capable of delivering very much power. There is no way we can connect something that uses more than a few milliamperes of current to a microprocessor. Something like a light bulb would draw too much current and/or need too high a voltage. Later we'll see how we can use transistors or relays to switch on/off higher current loads.
SAFETY GLASSES ON!
OK. Let's begin.
The esp32 board in the picture above may not look exactly like your board but the pin out designations are accurate. This picture was made using Fritzing which is free to use under GNU GPL. Here is the schematic for the same circuit.
Follow the circuit in both diagrams. If GPIO13 is turned on with 3.3V then the LED will light up. Current will flow because it is a complete circuit. If GPIO13 is turned off, effectively 0 volts then the LED will switch off. GPIO13 is being used as a DIGITAL output. Remember earlier we used the digitalWrite command to turn the built-in LED connected to GPIO2 on and off. "Digital" means ones and zeros. A one or HIGH means the output is the same as the supply voltage, 3.3V, the output is ON. A zero or LOW means the output is OFF, 0V, the same potential as ground (GND).
Wire this circuit by following the pictorial view. Your black wire may be a different colour and different length. The connection from ground (GND) to the blue (-) rail should be a short green jumper as pictured. We can use the Blinkesp32 code from Getting Started with one change. Can you figure out what that change should be?
Connect your computer to the esp32 via USB and try it out.
NOTE. If the LED does not blink it may be wired backward or it may be burned out. Here is how you can check your LED.
Unplug the USB connection.
Move the wire connected to GPIO13 (mine is black) to the 3v3 output on the other side of the module.
Plug in the USB connection. The LED should glow. If it does not, unplug the USB, reverse the LED, then plug in the USB. If the LED still does not glow it is burned out. Get another LED and start again.
Unplug the USB. Move the wire (black in the pictorial) back to GPIO13
If you can't get the LED to blink talk to your instructor.
CHALLENGE Make the onboard LED and this new LED blink alternately by adding some code.
Don't forget to unplug the module from your computer when you are done.
All right! High fives! You can take off your safety glasses now!